() 1 #include<vtkSmartPointer.h> 2 #include<vtkRenderWindow.h> 3 #include<vtkRenderer.h> 4 #include<vtkRenderWindowInteractor.h> 5 #include<vtkInteractorStyleTrackballCamera.h> 6 #include<vtkCylinderSource.h> 7 #include<vtkPolyDataMapper.h> 8 #include<vtkActor.h> 9 10 #include "vtkAutoInit.h" 11 12 VTK_MODULE_INIT(vtkRenderingOpenGL2); // VTK was built with vtkRenderingOpenGL2 13 VTK_MODULE_INIT(vtkInteractionStyle); 14 //https://blog.csdn.net/thecentry/article/details/79111295 15 int main() 16 { 17 vtkSmartPointer<vtkCylinderSource>cylinder = vtkSmartPointer<vtkCylinderSource>::New(); 18 cylinder->SetHeight(3.0); 19 cylinder->SetRadius(1.0); 20 cylinder->SetResolution(10); 21 22 vtkSmartPointer<vtkPolyDataMapper> cylinderMapper = vtkSmartPointer<vtkPolyDataMapper>::New(); 23 cylinderMapper->SetInputConnection(cylinder->GetOutputPort()); 24 25 vtkSmartPointer<vtkActor> cylinderActor = vtkSmartPointer<vtkActor>::New(); 26 cylinderActor->SetMapper(cylinderMapper); 27 28 vtkSmartPointer<vtkRenderer> cylinderRender = vtkSmartPointer<vtkRenderer>::New(); 29 cylinderRender->AddActor(cylinderActor); 30 cylinderRender->SetBackground(0.1,0.2,0.4); 31 32 vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New(); 33 renWin->AddRenderer(cylinderRender); 34 renWin->SetSize(300,300); 35 36 vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New(); 37 iren->SetRenderWindow(renWin); 38 39 vtkSmartPointer<vtkInteractorStyleTrackballCamera> style = vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New(); 40 iren->SetInteractorStyle(style); 41 42 iren->Initialize(); 43 iren->Start(); 44 return 0; 45 }
VTK编译出现no override found for 'vtkPolyDataMapper'
我出现no override found for 'vtkPolyDataMapper',这种问题是因为没有用cmake,而是直接用控制台结合VTK的库函数进行开发的。
参考博文 https://blog.csdn.net/thecentry/article/details/79111295
demo运行结果:
一个vtkRender可添加多个actor,同时显示,结合上面代码:
1 vtkSmartPointer<vtkCylinderSource>cylinder1 = vtkSmartPointer<vtkCylinderSource>::New(); 2 cylinder1->SetHeight(6.0); 3 cylinder1->SetRadius(1.0); 4 cylinder1->SetResolution(10); 5 6 7 vtkSmartPointer<vtkPolyDataMapper> cylinderMapper1 = vtkSmartPointer<vtkPolyDataMapper>::New(); 8 cylinderMapper1->SetInputConnection(cylinder1->GetOutputPort()); 9 10 vtkSmartPointer<vtkActor> cylinderActor1 = vtkSmartPointer<vtkActor>::New(); 11 cylinderActor1->SetMapper(cylinderMapper1); 12 // 13 vtkSmartPointer<vtkRenderer> cylinderRender = vtkSmartPointer<vtkRenderer>::New(); 14 cylinderRender->AddActor(cylinderActor); 15 cylinderRender->AddActor(cylinderActor1); 16 cylinderRender->SetBackground(0.1,0.2,0.4);
类的介绍
(1)vtkCylinderSource
该类派生自vtkPolyDataAlgorithm。该类生成的数据类型是vtkPolyData,生成一个中心在渲染场景原点的柱体。
(2)vtkPolyDataMapper
该类用于渲染多边形几何数据(vtkPolyData),派生自类vtkMapper,将输入的数据转换为集合图元(点/线/多边形)进行渲染。
vtkPolyDataMapper::SetInputConnection(): VTK可视化管线的输入数据接口。
(3)vtkActor
该类派生自vtkProp类,渲染场景中的数据的可视化表达通过vtkProp的自类负责。
(4)vtkRenderWindow
(5)vtkRender
(6)vtkRenderWindowInteractor
(7) vtkInteractorStyleTrackballCamera