网上方法基本全是错的,模型读进去就直接用VTK显示了,那不扯淡吗,一堆样条线面方程数据,就能直接变成polydata了????纯粹的胡说八道,还互相抄来抄去,只要百度就铺天盖地全是一样的垃圾。
IGES模型是连续的样条线面集合,而VTK应该是只能显示离散的点线面的集合,同样STL文件也是点和拓扑组成的离散化模型,所以想要转格式,必须要进行离散化,也就是网格化。
std::string inputFilename = filename.toStdString();
IGESControl_Reader reader;
reader.ReadFile(inputFilename.c_str());
reader.TransferRoots();
TopoDS_Shape Shape = reader.OneShape();
const Standard_Real deflection = 0.1;
BRepMesh_IncrementalMesh(Shape,deflection,Standard_True);
StlAPI_Writer writer;
writer.Write(Shape,"temp.stl");
deflection这个参数是精度,可能需要自己调整,这个我也还没弄明白,反正这样就好使。
得到STL模型文件,后续VTK显示STL模型就比较简单,就不说了。