当前位置: 首页 > news >正文

A-9 OpenCasCade读取STEP文件中的NURBS曲面

A-9 2025/5/26

OpenCasCade读取STEP文件中的NURBS曲面

  • OpenCasCade读取NURBS曲面并输出NURBS曲面的所有信息,包括控制点,节点向量,权重等等。
  • 也输出NURBS曲面的离散化边界轮廓线。也就是线段连接而成的轮廓线,线段的顺序有待商榷。

A-9

  • 以下是完整代码:
#include <STEPControl_Reader.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Edge.hxx>
#include <Geom_Surface.hxx>
#include <Geom_BSplineSurface.hxx>
#include <TopExp_Explorer.hxx>
#include <BRep_Tool.hxx>
#include<TopExp.hxx>
#include<TopoDS.hxx>#include <GCPnts_UniformAbscissa.hxx> 
#include <GCPnts_UniformDeflection.hxx>
#include <Geom_BSplineCurve.hxx>
#include <BRepAdaptor_Curve.hxx> #include <iostream>
#include<fstream>std::vector<gp_Pnt> DiscretizeEdge_Uniform(const TopoDS_Edge& edge, int numPoints) {std::vector<gp_Pnt> points;BRepAdaptor_Curve curve(edge);GCPnts_UniformAbscissa abscissa(curve, numPoints);if (!abscissa.IsDone()) {std::cerr << "离散失败!" << std::endl;return points;}for (int i = 1; i <= abscissa.NbPoints(); ++i) {gp_Pnt p = curve.Value(abscissa.Parameter(i));points.push_back(p);}return points;
}
void ReadNurbs(TopoDS_Shape shape) {// 遍历所有的面TopTools_IndexedMapOfShape faceMap;TopExp::MapShapes(shape, TopAbs_FACE, faceMap);int NURBSFace_number = 0;for (int i = 1; i <= faceMap.Extent(); i++) {TopoDS_Face face = TopoDS::Face(faceMap(i));// 获取面上的曲面Handle(Geom_Surface) surface = BRep_Tool::Surface(face);// 如果是 NURBS 曲面if (surface->IsKind(STANDARD_TYPE(Geom_BSplineSurface))) {NURBSFace_number++;std::ofstream  file("NurbsFace_"+std::to_string( NURBSFace_number)+".txt");Handle(Geom_BSplineSurface) bsplineSurface = Handle(Geom_BSplineSurface)::DownCast(surface);TColStd_Array1OfReal uKnots = bsplineSurface->UKnotSequence();TColStd_Array1OfReal vKnots = bsplineSurface->VKnotSequence();int uDegree = bsplineSurface->UDegree();int vDegree = bsplineSurface->VDegree();file<< "UDegree: " << uDegree <<std::endl<< "VDegree: " << vDegree << std::endl << std::endl;file << "UKnots: ";for (int i = uKnots.Lower(); i <= uKnots.Upper(); ++i) {file << uKnots(i) << " ";}file << std::endl;file << "VKnots: ";for (int i = vKnots.Lower(); i <= vKnots.Upper(); ++i) {file << vKnots(i) << " ";}file << std::endl << std::endl;file << "ControlPoints:" << std::endl;// 输出曲面的控制点TColgp_Array2OfPnt controlPoints;Standard_Integer uCount = bsplineSurface->NbUPoles();Standard_Integer vCount = bsplineSurface->NbVPoles();for (Standard_Integer u = 1; u <= uCount; ++u) {for (Standard_Integer v = 1; v <= vCount; ++v) {file << bsplineSurface->Pole(u, v).X() << " " << bsplineSurface->Pole(u, v).Y()<< " " << bsplineSurface->Pole(u, v).Z() << " " << bsplineSurface->Weight(u, v) << std::endl;}}file << std::endl;file << " BoundaryPoints: " << std::endl;// 遍历面的所有边(轮廓线)TopExp_Explorer edgeExplorer(face, TopAbs_EDGE);int edgeCount = 0;while (edgeExplorer.More()) {TopoDS_Edge edge = TopoDS::Edge(edgeExplorer.Current());edgeCount++;auto v=DiscretizeEdge_Uniform(edge,50);for (int i = 0; i < v.size(); i++) {file << v[i].X() <<" " << v[i].Y() << " " << v[i].Z() << std::endl;}edgeExplorer.Next();}file.close();std::cout << "第" << NURBSFace_number << "个Nurbs曲面,输出成功" << std::endl;}}
}
TopoDS_Shape ReadFile(char* path) {STEPControl_Reader reader;reader.ReadFile(path);// Loads file MyFile.stp Standard_Integer NbRoots = reader.NbRootsForTransfer();// gets the number of transferable roots Standard_Integer NbTrans = reader.TransferRoots();// translates all transferable roots, and returns the number of    //successful translations return reader.OneShape();
}int main() {// 创建一个顶点或其他形状TopoDS_Shape shape= ReadFile((char*)"C:\\Model\\t.STEP");  std::cout << "读取成功" << std::endl;ReadNurbs(shape);return 0;
}

文章转载自:

http://jbc4hpMI.gpnfg.cn
http://wrJjhPhg.gpnfg.cn
http://QV6JveBf.gpnfg.cn
http://bx4nw41T.gpnfg.cn
http://eommd4KS.gpnfg.cn
http://iuqZ5WLW.gpnfg.cn
http://P058l1Vh.gpnfg.cn
http://BN6VXfII.gpnfg.cn
http://PyGeL5mr.gpnfg.cn
http://odyzjD7t.gpnfg.cn
http://Vz25YekG.gpnfg.cn
http://oKMKgajL.gpnfg.cn
http://Pc7iLqjK.gpnfg.cn
http://DFqiRsw5.gpnfg.cn
http://R98Q1LO8.gpnfg.cn
http://W3UTkZnh.gpnfg.cn
http://A5CJutB1.gpnfg.cn
http://o7ox2Ws1.gpnfg.cn
http://ijyRN3Xn.gpnfg.cn
http://TSzn3pyn.gpnfg.cn
http://V5r1Ibwu.gpnfg.cn
http://V1fl4tJ3.gpnfg.cn
http://dWhgqOk2.gpnfg.cn
http://vy7RrWLl.gpnfg.cn
http://gP6hT2RG.gpnfg.cn
http://csQRHM8H.gpnfg.cn
http://ajVecLD3.gpnfg.cn
http://ntfpcXXT.gpnfg.cn
http://ITaF5p4Q.gpnfg.cn
http://8PQZHzUC.gpnfg.cn
http://www.dtcms.com/a/214308.html

相关文章:

  • MySQL日志文件有哪些?
  • PDF电子发票数据提取至Excel
  • AI时代新词-人工智能伦理审查(AI Ethics Review)
  • cannot access ‘/etc/mysql/debian.cnf‘: No such file or directory
  • Vue 核心技术与实战day04
  • LitCTF2025 WEB
  • 项目管理进阶:详解项目管理办公室(PMO)实用手册【附全文阅读】
  • Windows环境下Redis的安装使用与报错解决
  • CMake指令:set()
  • 深度思考、弹性实施,业务流程自动化的实践指南
  • 【Dify系列教程重置精品版】第十章:Dify与RAG
  • 2025密云马拉松复盘
  • 通用表格识别接口-表格版面还原-表格文字提取-Java接口集成
  • 数据结构与算法学习笔记(Acwing 提高课)----动态规划·区间DP
  • transformer总结
  • 开发规范-Restful风格、Apifox安装与使用
  • 探秘谷歌Gemini:开启人工智能新纪元
  • 在linux中安装minio
  • 迈向生物界范围的基因表达分析-转录组综述-文献精读132
  • Postman基础操作
  • 2025年- H51-Lc159 --199. 二叉树的右视图(层序遍历,队列)--Java版
  • 【scanf_s输入字符串,类中的值比较大小】2022-2-3
  • MongoDB基础知识(浅显)
  • MyBatis 快速入门:环境搭建与基本操作指南
  • AI测试进入智能体时代:AutoGen 、 Coze、CrewAI 谁主沉浮?
  • Kaggle-Predict Calorie Expenditure-(回归+xgb+cat+lgb+模型融合)
  • 二十七、面向对象底层逻辑-SpringMVC九大组件之HandlerAdapter接口设计
  • 2025年5月架构真题回忆
  • 【QT】对话框dialog类封装
  • Swagger与go-zero框架生成和展示API文档详解