当前位置:网站首页>Qt+vtk+occt reading iges/step model
Qt+vtk+occt reading iges/step model
2022-07-03 11:56:00 【windSnowLi】
Reference link
Main code
#include "VTKOCCT.h"
#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepPrimAPI_MakeCone.hxx>
#include <IVtkTools_ShapeDataSource.hxx>
#include <BRepBuilderAPI_Transform.hxx>
#include <vtkAutoInit.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyDataMapper.h>
#include <IGESControl_Reader.hxx>
#include <STEPCAFControl_Reader.hxx>
//Lesson 17
#include <Bnd_Box.hxx>
#include <BRepBndLib.hxx>
#include <BRepBuilderAPI_MakeVertex.hxx>
#include <vtkCubeSource.h>
#include <vtkEllipseArcSource.h>
#include <vtkSphereSource.h>
#include <vtkConeSource.h>
#include <vtkAppendPolyData.h >
#include <vtkCleanPolyData.h >
#include <vtkNew.h>
#include <vtkPoints.h>
#include <vtkCellArray.h>
#include <vtkBoundingBox.h>
#include <vtkAxesActor.h>
decltype(auto) ReadIges(const char* file) {
IGESControl_Reader reader;
reader.ReadFile(file);
reader.TransferRoots();
TopoDS_Shape shape = reader.OneShape();
vtkNew<vtkPolyData> polydata;
vtkNew<vtkPolyDataMapper> mapper;
vtkNew<vtkActor> actor;
vtkNew<IVtkTools_ShapeDataSource> shapeSource;
shapeSource->SetShape(new IVtkOCC_Shape(shape));
shapeSource->Update();
mapper->SetInputConnection(shapeSource->GetOutputPort());
actor->SetMapper(mapper);
return actor;
}
decltype(auto) ReadStep(const char* file) {
STEPControl_Reader readerSTEP;
IFSelect_ReturnStatus statSTEP = readerSTEP.ReadFile(file);
IFSelect_PrintCount modeSTEP = IFSelect_ListByItem;
readerSTEP.PrintCheckLoad(Standard_False, modeSTEP);
readerSTEP.TransferRoots();
TopoDS_Shape shape = readerSTEP.OneShape();
vtkNew<vtkPolyDataMapper> mapper;
vtkNew<vtkActor> actor;
vtkNew<IVtkTools_ShapeDataSource> shapeSource;
shapeSource->SetShape(new IVtkOCC_Shape(shape));
shapeSource->Update();
mapper->SetInputConnection(shapeSource->GetOutputPort());
actor->SetMapper(mapper);
return actor;
}
decltype(auto) TopoDSShapeSphere() {
//TopoDS_ShapeSphere
gp_Ax2 sphere_origin(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1));
BRepPrimAPI_MakeCone mkCone(sphere_origin, 1.0, 0.01, 1);
const TopoDS_Shape& TopoDS_ShapemkConeTMP = mkCone.Shape();
TopoDS_Shape TopoDS_ShapeCONE = static_cast<TopoDS_Shape>(TopoDS_ShapemkConeTMP);
gp_Trsf TSPHERE;
TSPHERE.SetScaleFactor(0.9);
TSPHERE.SetTranslationPart(gp_Vec(0, 0, 0));
BRepBuilderAPI_Transform stepBRepTransformationTOPBOX(TopoDS_ShapeCONE, TSPHERE, Standard_True);
TopoDS_ShapeCONE = stepBRepTransformationTOPBOX.Shape();
vtkNew<IVtkTools_ShapeDataSource> TOPOCONESource;
TOPOCONESource->SetShape(new IVtkOCC_Shape(TopoDS_ShapeCONE));
vtkNew<vtkActor> actorTOPOCONE;
vtkNew<vtkPolyDataMapper> mapperTOPOCONE;
actorTOPOCONE->SetMapper(mapperTOPOCONE);
mapperTOPOCONE->SetInputConnection(TOPOCONESource->GetOutputPort());
return actorTOPOCONE;
}
decltype(auto) VTKpointOnMeshes(const char* file) {
STEPControl_Reader readerSTEP;
IFSelect_ReturnStatus statSTEP = readerSTEP.ReadFile(file);
IFSelect_PrintCount modeSTEP = IFSelect_ListByItem;
readerSTEP.PrintCheckLoad(Standard_False, modeSTEP);
readerSTEP.TransferRoots();
TopoDS_Shape TopoDS_ShapeSTEP = readerSTEP.OneShape();
//VTKpointOnMeshes
vtkNew<vtkPoints> VTKpointsOnMeshes;
vtkNew<vtkCellArray> verticesForVTKpointsOnMeshes;
vtkIdType pid[1];
//vtkPolyData creation
vtkNew<vtkPolyData> PolyDataVTKPointsOnMeshes;
//vtkPolyData initialization
PolyDataVTKPointsOnMeshes->SetPoints(VTKpointsOnMeshes);
PolyDataVTKPointsOnMeshes->SetVerts(verticesForVTKpointsOnMeshes);
//VTKpoint IGES, STEP TopoDS_ShapeBOX CALC
Bnd_Box aabb;
//AABB ALGO Per TopoDS_Shape mesh , Please choose the source you like to run and put it in next line
BRepBndLib::Add(TopoDS_ShapeSTEP, aabb, true); //TopoDS_ShapeIGES //TopoDS_ShapeSTEP //TopoDS_ShapeCONE
//VTKpointIGES CALC per TopoDS_Shape mesh
int density = 20;
gp_XYZ Pmin = aabb.CornerMin().XYZ();
gp_XYZ Pmax = aabb.CornerMax().XYZ();
gp_XYZ D = Pmax - Pmin;
double dim[3] = {
D.X(),D.Y(),D.Z() };
double mind = Min(dim[0], Min(dim[1], dim[2]));
const double d = mind / density;
int nslice[3] = {
int(Round(dim[0] / d)) + 1 ,
int(Round(dim[1] / d)) + 1 ,
int(Round(dim[2] / d)) + 1 };
for (int i = 0; i < nslice[0]; ++i)
for (int j = 0; j < nslice[1]; ++j)
for (int k = 0; k < nslice[2]; ++k)
{
gp_XYZ p = Pmin
+ gp_XYZ(d * i, 0, 0)
+ gp_XYZ(0, d * j, 0)
+ gp_XYZ(0, 0, d * k);
pid[0] = VTKpointsOnMeshes->InsertNextPoint(p.X(), p.Y(), p.Z());
verticesForVTKpointsOnMeshes->InsertNextCell(1, pid);
};
//Append the meshes
vtkNew<vtkAppendPolyData> appendFilter;
appendFilter->AddInputData(PolyDataVTKPointsOnMeshes);
//Remove any duplicate points.
vtkNew<vtkCleanPolyData> cleanFilterForMapperVTKShapes;
cleanFilterForMapperVTKShapes->SetInputConnection(appendFilter->GetOutputPort());
cleanFilterForMapperVTKShapes->Update();
vtkNew<vtkPolyDataMapper> mapperVTKShapes;
mapperVTKShapes->SetInputConnection(cleanFilterForMapperVTKShapes->GetOutputPort());
vtkNew<vtkActor> actorVTKShapes;
actorVTKShapes->SetMapper(mapperVTKShapes);
return actorVTKShapes;
}
VTKOCCT::VTKOCCT(QWidget* parent)
: QMainWindow(parent)
{
vtkWidget = new QVTKOpenGLNativeWidget(this);
this->resize(600, 400);
this->setCentralWidget(vtkWidget);
// ViewPort Division
double xmins[4] = {
0, 0.5, 0 ,0.5 };
double xmaxs[4] = {
0.5, 1, 0.5,1 };
double ymins[4] = {
0, 0, 0.5,0.5 };
double ymaxs[4] = {
0.5, 0.5, 1,1 };
auto igesActor = ReadIges("D:/TEST/3D/igs/ Laser sword .igs");
auto rendererIges = vtkSmartPointer< vtkRenderer >::New();
rendererIges->SetViewport(xmins[0], ymins[0], xmaxs[0], ymaxs[0]);
rendererIges->AddActor(igesActor);
auto stepActor = ReadStep("D:/TEST/3D/step/Assem1.STEP");
auto rendererStep = vtkSmartPointer< vtkRenderer >::New();
rendererStep->SetViewport(xmins[1], ymins[1], xmaxs[1], ymaxs[1]);
rendererStep->AddActor(stepActor);
auto topoActor = TopoDSShapeSphere();
auto rendererTopo = vtkSmartPointer< vtkRenderer >::New();
rendererTopo->SetViewport(xmins[2], ymins[2], xmaxs[2], ymaxs[2]);
rendererTopo->AddActor(topoActor);
auto vTKpointOnMeshes = VTKpointOnMeshes("D:/TEST/3D/step/ Leaves .STEP");
auto rendererVTKpointOnMeshes = vtkSmartPointer< vtkRenderer >::New();
rendererVTKpointOnMeshes->SetViewport(xmins[3], ymins[3], xmaxs[3], ymaxs[3]);
rendererVTKpointOnMeshes->AddActor(vTKpointOnMeshes);
vtkNew<vtkAxesActor> axes;
// Chief,
// Initialize array
double axesLength[3]{
100,100,100 };
axes->SetTotalLength(axesLength);
rendererIges->AddActor(axes);
vtkWidget->renderWindow()->AddRenderer(rendererIges);
vtkWidget->renderWindow()->AddRenderer(rendererStep);
vtkWidget->renderWindow()->AddRenderer(rendererTopo);
vtkWidget->renderWindow()->AddRenderer(rendererVTKpointOnMeshes);
}
VTKOCCT::~VTKOCCT()
{
}
## effect 
边栏推荐
- (数据库提权——Redis)Redis未授权访问漏洞总结
- R language uses data The table package performs data aggregation statistics, calculates window statistics, calculates the median of sliding groups, and merges the generated statistical data into the o
- Go语言实现静态服务器
- Slam mapping and autonomous navigation simulation based on turnlebot3
- Momentum of vulnhub
- 导师对帮助研究生顺利完成学业提出了20条劝告:第一,不要有度假休息的打算.....
- Kubernetes three dozen probes and probe mode
- Test classification in openstack
- 剑指offer专项32-96题做题笔记
- Introduction to the implementation principle of rxjs observable filter operator
猜你喜欢

vulnhub之Nagini

Is BigDecimal safe to calculate the amount? Look at these five pits~~

基于turtlebot3实现SLAM建图及自主导航仿真

鸿蒙第三次培训(项目实训)

Unity3d learning notes 5 - create sub mesh

Excel表格转到Word中,表格不超边缘纸张范围

STL教程9-容器元素深拷贝和浅拷贝问题

Kibana - installation and configuration of kibana

OpenGL 绘制彩色的三角形

导师对帮助研究生顺利完成学业提出了20条劝告:第一,不要有度假休息的打算.....
随机推荐
Duplicate numbers in the array of sword finger offer 03
2022年湖南工学院ACM集训第二次周测题解
The world's most popular font editor FontCreator tool
Niuniu's team competition
R language uses grid of gridextra package The array function combines multiple visual images of the ggplot2 package horizontally, and the ncol parameter defines the number of columns of the combined g
vulnhub之tomato(西红柿)
After watching the video, AI model learned to play my world: cutting trees, making boxes, making stone picks, everything is good
XML (DTD, XML parsing, XML modeling)
Master and backup role election strategy in kept
Differences between MySQL Union and union all
mysql使用update联表更新的方法
php 获取文件夹下面的文件列表和文件夹列表
Hongmeng fourth training
The uniapp scroll view solves the problems of high adaptability and bullet frame rolling penetration.
R language uses the aggregate function to calculate the mean value (sum) of dataframe data grouping aggregation without setting na The result of RM calculation. If the group contains the missing value
R language uses grid of gridextra package The array function combines multiple visual images of the lattice package horizontally, and the ncol parameter defines the number of columns of the combined g
STL tutorial 10 container commonalities and usage scenarios
量化计算调研
STL教程8-map
Solution to the second weekly test of ACM intensive training of Hunan Institute of technology in 2022