1 #include "vtkAutoInit.h" 2 VTK_MODULE_INIT(vtkRenderingOpenGL2); 3 VTK_MODULE_INIT(vtkInteractionStyle); 4 #include <vtkConeSource.h>//源数据 5 #include <vtkCubeSource.h>//立方体 6 #include <vtkPolyDataMapper.h>//数据映射 7 #include <vtkRenderer.h>//绘制器 8 #include <vtkRenderWindow.h>//绘制窗口 9 #include <vtkCamera.h>//照相机 10 #include <vtkRenderWindowInteractor.h>//加入交互机制类 11 12 13 int main() 14 { 15 //指针创建一个锥体cone 16 vtkConeSource* cone = vtkConeSource::New(); 17 cone->SetResolution(5);//圆锥的棱边数 18 cone->SetHeight(3);//指定高度 19 cone->SetRadius(1);//指定半径 20 21 //指针创建一个柱体 22 vtkCubeSource* cube = vtkCubeSource::New(); 23 24 //实例化一个映射器coneMapper 25 vtkPolyDataMapper* coneMapper = vtkPolyDataMapper::New(); 26 coneMapper->SetInputConnection(cone->GetOutputPort());//源数据输出给映射器输入 27 28 //实例化一个映射器cubeMapper 29 vtkPolyDataMapper* cubeMapper = vtkPolyDataMapper::New(); 30 cubeMapper->SetInputConnection(cube->GetOutputPort());//源数据输出给映射器输入 31 32 //创建一个演员对象coneActor 33 vtkActor* coneActor = vtkActor::New(); 34 coneActor->SetMapper(coneMapper);//为演员指定mapper进行映射 35 36 //创建一个演员对象cubeActor 37 vtkActor* cubeActor = vtkActor::New(); 38 cubeActor->SetMapper(cubeMapper);//为演员指定mapper进行映射 39 40 //搭建舞台 实例化渲染器对象renderer 41 vtkRenderer* renderer = vtkRenderer::New(); 42 renderer->AddActor(coneActor);//将演员加入场景 43 renderer->SetBackground(0.0, 0.0, 1.0);//设置场景背景颜色为蓝色(R,G,B) 44 //在绘制窗口指定视口(Xmin,Ymin,Xmax,Ymax)(x,y范围都为0~1) 45 renderer->SetViewport(0.0, 0.0, 0.5, 1.0);//左边视口 46 47 //搭建舞台 实例化渲染器对象renderer2 48 vtkRenderer* renderer2 = vtkRenderer::New(); 49 renderer2->AddActor(cubeActor);//将演员加入场景 50 renderer2->SetBackground(1.0, 0.0, 0.0);//设置场景背景颜色为红色(R,G,B) 51 renderer2->SetViewport(0.5, 0.0, 1.0, 1.0);//右边视口 52 53 //实例化一个窗口对象renWin 54 vtkRenderWindow* renWin = vtkRenderWindow::New(); 55 renWin->SetSize(400, 200);//设置窗口大小宽*高 56 renWin->AddRenderer(renderer);//将场景renderer加入renWin窗口中 57 renWin->AddRenderer(renderer2);//将场景renderer2加入renWin窗口中 58 59 //实例化一个交互对象 60 vtkRenderWindowInteractor* interactor = vtkRenderWindowInteractor::New();//交互对象加入renWin窗口中 61 interactor->SetRenderWindow(renWin); 62 63 renWin->Render();//绘制舞台上的东西 64 65 interactor->Initialize();//交互对象初始化 66 interactor->Start();//开始交互事件 67 68 cone->Delete(); 69 cube->Delete(); 70 coneActor->Delete(); 71 cubeActor->Delete(); 72 coneMapper->Delete(); 73 cubeMapper->Delete(); 74 renderer->Delete(); 75 renderer2->Delete(); 76 renWin->Delete(); 77 interactor->Delete(); 78 79 return 0; 80 }
标签:VTK,renderer2,renWin,实例,renderer,坐标,New,include,Delete From: https://www.cnblogs.com/ybqjymy/p/17628690.html