• VS+Qt+opencascade三维绘图stp/step/igs/stl格式图形读取显示


    程序示例精选
    VS+Qt+opencascade三维绘图stp/step/igs/stl格式图形读取显示
    如需安装运行环境或远程调试,见文章底部个人QQ名片,由专业技术人员远程协助!

    前言

    这篇博客针对《VS+Qt+opencascade三维绘图stp/step/igs/stl格式图形读取显示》编写代码,代码整洁,规则,易读。 学习与应用推荐首选。


    运行结果


    文章目录

    一、所需工具软件
    二、使用步骤
           1. 主要代码
           2. 运行结果
    三、在线协助

    一、所需工具软件

           1. VS2019, Qt
           2. C++

    二、使用步骤

    代码如下(示例):
    
    //#define WNT
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    void BuildMesh(vtkRenderer* render, const TopoDS_Face& face, double deflection = 0.1)
    {
    	TopLoc_Location location;
    	//BRepMesh::Mesh(face, deflection);该函数已经弃用
    	BRepMesh_IncrementalMesh(face, deflection);
    
    	Handle_Poly_Triangulation triFace = BRep_Tool::Triangulation(face, location);
    	Standard_Integer nTriangles = triFace->NbTriangles();
    	gp_Pnt vertex1;
    	gp_Pnt vertex2;
    	gp_Pnt vertex3;
    	Standard_Integer nVertexIndex1 = 0;
    	Standard_Integer nVertexIndex2 = 0;
    	Standard_Integer nVertexIndex3 = 0;
    	TColgp_Array1OfPnt nodes(1, triFace->NbNodes());
    	Poly_Array1OfTriangle triangles(1, triFace->NbTriangles());
    	nodes = triFace->Nodes();
    	triangles = triFace->Triangles();
    	vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
    	vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
    	vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
    	points->Allocate(nTriangles * 3);
    	cells->Allocate(nTriangles);
    	int id = 0;
    	for (Standard_Integer i = 1; i <= nTriangles; i++)
    	{
    		Poly_Triangle aTriangle = triangles.Value(i);
    		aTriangle.Get(nVertexIndex1, nVertexIndex2, nVertexIndex3);
    		vertex1 = nodes.Value(nVertexIndex1).Transformed(location.Transformation());
    		vertex2 = nodes.Value(nVertexIndex2).Transformed(location.Transformation());
    		vertex3 = nodes.Value(nVertexIndex3).Transformed(location.Transformation());
    		points->InsertNextPoint(vertex1.X(), vertex1.Y(), vertex1.Z());
    		points->InsertNextPoint(vertex2.X(), vertex2.Y(), vertex2.Z());
    		points->InsertNextPoint(vertex3.X(), vertex3.Y(), vertex3.Z());
    		vtkSmartPointer<vtkTriangle> triangle = vtkSmartPointer<vtkTriangle>::New();
    		triangle->GetPointIds()->SetId(0, id * 3);
    		triangle->GetPointIds()->SetId(1, id * 3 + 1);
    		triangle->GetPointIds()->SetId(2, id * 3 + 2);
    		// Add the triangle to a cell array
    		cells->InsertNextCell(triangle);
    		id++;
    	}
    	polyData->SetPoints(points);
    	polyData->SetPolys(cells);
    	vtkSmartPointer<vtkPolyDataMapper> sourceMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    	//setInput函数已经弃用,使用SetInputData()
    	sourceMapper->SetInputData(polyData);
    
    	vtkSmartPointer<vtkActor> sourceActor = vtkSmartPointer<vtkActor>::New();
    	sourceActor->SetMapper(sourceMapper);
    	sourceActor->GetProperty()->SetColor(1, 0, 0);
    	render->AddActor(sourceActor);
    }
    void BuildScene(vtkRenderer* renderer, Handle(TopTools_HSequenceOfShape)& aHSequenceOfShape)
    {
    	Standard_Integer index = aHSequenceOfShape->Length();
    	TopoDS_Shape theCompSolid = aHSequenceOfShape->ChangeValue(index);
    	}
    }
    //这里添加三行代码
    VTK_MODULE_INIT(vtkRenderingOpenGL2);
    VTK_MODULE_INIT(vtkRenderingFreeType);
    VTK_MODULE_INIT(vtkInteractionStyle);
    
    int main(void)
    
    {
    	vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
    	vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
    	renderWindow->AddRenderer(renderer);
    	Standard_Integer status = ReadIGES("cylinder.igs", aHSequenceOfShape);
    	cout << "return status:" << status << endl;
    	BuildScene(renderer, aHSequenceOfShape);
    	renderer->SetBackground(1, 1, 1);
    	// Render and interact
    	renderWindow->Render();
    	renderWindowInteractor->Start();
    	return 0;
    
    }
    
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    运行结果

    三、在线协助:

    如需安装运行环境或远程调试,见文章底部个人 QQ 名片,由专业技术人员远程协助!

    1)远程安装运行环境,代码调试
    2)Visual Studio, Qt, C++, Python编程语言入门指导
    3)界面美化
    4)软件制作

    当前文章连接:https://blog.csdn.net/alicema1111/article/details/132666851
    个人博客主页https://blog.csdn.net/alicema1111?type=blog
    博主所有文章点这里:https://blog.csdn.net/alicema1111?type=blog

  • 相关阅读:
    PSINS工具箱学习(一)下载安装初始化、SINS-GPS组合导航仿真、习惯约定与常用变量符号、数据导入转换、绘图显示
    Vue生命周期函数相关——笔试/面试题
    【AI大模型】赋能儿童安全:楼层与室内定位实践与未来发展
    解决ntfs-3g-mount: mount failed硬盘无法挂载的问题
    上帝之眼Nmap简介及命令大全
    1200*C. Make It Good(二分 || 贪心)
    Nvidia-Xavier-NX配置
    【YOLOv7】Python基于YOLOv7的人员跌倒检测系统(源码&部署教程&数据集)
    pytorch里常用操作(持续更新)
    Ansible自动化运维
  • 原文地址:https://blog.csdn.net/alicema1111/article/details/133390422