项目场景:
实现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;

最低0.47元/天 解锁文章
201

被折叠的 条评论
为什么被折叠?



