本文主要是介绍OpenCascade VTK STEP/IGES文件读取显示,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
OpenCascade & VTK STEP/IGES文件读取显示,OpenCascade读取转成STL,VTK显示STL。
Download - Open CASCADE Technology
https://dev.opencascade.org/release
下载exe并安装,可以把source下载下来学习,官网速度慢,可到网盘下载
链接:https://pan.baidu.com/s/1_ARH9jRMPxO_GWNWXT64fw
提取码:zyes
安装完成后,把除了qt和vtk的文件夹的bin都加到环境变量,在不同的电脑有可能openvr没被自动安装,需要下载然后win64的bin加环境变量
GitHub - ValveSoftware/openvr: OpenVR SDK
https://github.com/ValveSoftware/openvr
pro添加
INCLUDEPATH += C:/OpenCASCADE-7.7.0-vc14-64/opencascade-7.7.0/inc
LIBS += C:/OpenCASCADE-7.7.0-vc14-64/opencascade-7.7.0/win64/vc14/lib/*.lib
基于OCC,将IGES模型文件转换为STL,进而在VTK中显示。网上别的一般都是错的。-CSDN博客
https://blog.csdn.net/hbwhzc/article/details/131571397
GitHub - Jelatine/JellyCAD: The simple CAD software which is based on OCC.
https://github.com/Jelatine/JellyCAD
Open Cascade Data Exchange --- STL - eryar - C++博客
http://www.cppblog.com/eryar/archive/2013/05/01/199882.aspx
#include <TopoDS_Shape.hxx>
#include <StlAPI_Writer.hxx>
#include <STEPControl_Reader.hxx>
#include <vtkSTLReader.h>
#include <TDocStd_Document.hxx>
#include <STEPCAFControl_Reader.hxx>
#include <BRepMesh_IncrementalMesh.hxx>
#include <IGESControl_Reader.hxx>
#include <IGESCAFControl_Reader.hxx>#define vtkNewMember(Var, Type) \if (Var) \{ \Var->Delete(); \} \Var = Type::New();void MainWindow::on_pushButton_stp_clicked()
{QString file = QFileDialog::getOpenFileName(this, QStringLiteral("打开IGES/STEP文件"), ".", "*.step;; *.iges");if (!file.isEmpty()){TopoDS_Shape shape;if (file.endsWith("step")){STEPControl_Reader reader;IFSelect_ReturnStatus stat = reader.ReadFile(file.toUtf8().data());if (stat != IFSelect_RetDone){return;}reader.TransferRoots();shape = reader.OneShape();}else if (file.endsWith("iges")){IGESControl_Reader reader;reader.ReadFile(file.toUtf8().data());reader.TransferRoots();shape = reader.OneShape();}StlAPI_Writer writer;const Standard_Real deflection = 0.1;BRepMesh_IncrementalMesh(shape,deflection,Standard_True);Standard_Boolean ret = writer.Write(shape, "output.stl");if (!ret){return;}vtkNewMember(mSTPSTLReader, vtkSTLReader);mSTPSTLReader->SetFileName("output.stl");mSTPSTLReader->Update();vtkNewMember(mSTPSTLMapper, vtkPolyDataMapper);mSTPSTLMapper->SetInputData(mSTPSTLReader->GetOutput());if (mSTPSTLRenderer && mSTPSTLActor){mSTPSTLRenderer->RemoveActor(mSTPSTLActor);ui->widget_stp->GetRenderWindow()->RemoveRenderer(mSTPSTLRenderer);}vtkNewMember(mSTPSTLActor, vtkActor);mSTPSTLActor->SetMapper(mSTPSTLMapper);vtkNewMember(mSTPSTLRenderer, vtkRenderer);mSTPSTLRenderer->AddActor(mSTPSTLActor);mSTPSTLRenderer->SetBackground(0.1, 0.2, 0.3);ui->widget_stp->GetRenderWindow()->AddRenderer(mSTPSTLRenderer);ui->widget_stp->GetRenderWindow()->Render();}
}
这篇关于OpenCascade VTK STEP/IGES文件读取显示的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!