当前位置: 首页 > 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;
}

相关文章:

  • 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基础操作
  • 做网站高校视频/图片优化是什么意思
  • 前端开发 网站建设/经典seo伪原创
  • 如何制作网站页面/怎样优化标题关键词
  • 电脑初级入门课程自学网课/杭州seo网站建设靠谱
  • 台州自助建站/无锡百度竞价推广
  • 鹰潭做网站的/百度sem是什么意思