在Opencascade项目中使用VTK可视化窗口

项目场景:

实现IGES文件、点云文件(.txt、.pcd)、STL文件的读取显示、STL模型及点云模型在三维空间中的旋转(这里使用的是使用旋转矩阵)。

将该这些功能集成到QT中。

问题描述:

问题一

有关三维模型文件读取不成功的可能问题:
VTK进行IGES文件读取及显示遇到的文件路径不正确问题的解决方法

问题二

在窗口中进行交互操作时并不是我们常用的交互方式。
常用方式:
鼠标左键按住不动拖动旋转
鼠标右键按住不动拖动移动
鼠标滚轮对模型进行放大

问题三

在将VS中的代码移植到QT Creator中时,因为在VS中添加四个初始化操作,在VS中如果不添加会出现:

Error: no override found for ‘vtkRenderWindow’.
Error: no override found for ‘vtkRenderer’.
Error: no override found for ‘vtkPolyDataMapper’.

这三个错误。

问题四

在我将PCL中的VTK8.1换成我自己编译的VTK8.2后(因为想使用QVTKWidgetPlugin),构建工程的时候报错:

ImmediateModeRenderingOff 不是vtkMapper的成员


原因分析:

问题二

没有添加渲染窗口交互操作的样式导致

问题三

寻找合适的位置放置四个初始化代码


解决方案:

问题二

添加如下代码:

	vtkInteractorStyleTrackballCamera *style =
		vtkInteractorStyleTrackballCamera::New();

	renderWindowInteractor->SetInteractorStyle(style);

问题三

在QT工程文件中的mainwindow.cpp文件中添加如下代码:
在这里插入图片描述
同时在.cpp文件最前面添加头文件

#include <vtkAutoInit.h>

问题四

直接双击报错的位置,自动寻找到报错的行数,然后将那几行注释掉即可。


VS全部代码

//#define WNT
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>


#include <gp_Circ.hxx>
#include <gp_Elips.hxx>
#include <gp_Sphere.hxx>

#include <Poly_Polygon3D.hxx>
#include <Poly_Triangulation.hxx>

#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopTools_HSequenceOfShape.hxx>

#include <BRepBuilderAPI_MakeVertex.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>

#include <IGESControl_Controller.hxx>
#include <IGESControl_Writer.hxx>
#include <IGESControl_Reader.hxx>

#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS.hxx>

#include <BRep_Tool.hxx>
#include <BRepMesh.hxx>
#include <BRepMesh_IncrementalMesh.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>

#include <BRepAdaptor_Curve.hxx>
#include <GCPnts_TangentialDeflection.hxx>
#include <TopExp_Explorer.hxx>
#include <Standard_TypeDef.hxx>


//vtk lib
#include <vtkSmartPointer.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkCellArray.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkAutoInit.h>
//VTK显示坐标轴
#include <vtkAxesActor.h>
#include <vtkLineSource.h>
#include <vtkAxis.h>
#include <vtkAxes.h>
#include <vtkConeSource.h>
#include <vtkCaptionActor2D.h>

#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleTrackball.h>  
#include <vtkInteractorStyleTrackballCamera.h>  
#include <vtkProperty.h>
#include <vtkTriangle.h>
#include <vtkSTLReader.h>

//进行旋转操作所需的头文件
//vtkTransform, vtkTransformFilter, vtkMatrix4x4
#include <vtkTransform.h>
#include <vtkTransformFilter.h>
#include <vtkMatrix4x4.h>

VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2);

Standard_Integer ReadIGES(const Standard_CString& aFileName,
	Handle(TopTools_HSequenceOfShape)& aHSequenceOfShape)
{
   
   

	IGESControl_Reader Reader;

	Standard_Integer status = Reader.ReadFile(aFileName);

	if (status != IFSelect_RetDone)
	{
   
   
		return status;
	
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值