Into the cinema to watch VTK

  • VTK theater model:

  From this model to introduce applications VTK, the whole cinema is VTK display window (vtkRenderWindow), the stage is rendered scene VTK (vtkRenderer), the scene in a variety of three-dimensional model (vtkActor) is VTK different actors, actors figure looks action expressions vary as models of different sizes in different colors is VTK model properties (vtkPorperty), the audience is interacting with the actors interact VTK window with a mouse, etc. (vtkRenderWindowInteractor), but the audience and the actors interact not the same way, some waving, some cry like VTK sometimes and sometimes with the mouse using the keyboard (vtkInteractorStyle), when we watch, when we left the right to buy tickets in the front row of the cinema back on the decision, so for a different perspective as only one person in VTK camera (vtkCamera), according to the distance of the stage to see the location of different character sizes. VTK light on the stage as the lights (vtkLight) have a lot of lights with off stage effects. The following is a simple example:

 

  • Code is interpreted as follows:
 1 #include <vtkAutoInit.h> 
 2 VTK_MODULE_INIT(vtkRenderingOpenGL2);
 3 VTK_MODULE_INIT(vtkInteractionStyle);
 4 #include <vtkActor.h>
 5 #include <vtkCamera.h>
 6 #include <vtkLight.h>
 7 #include <vtkCylinderSource.h>
 8 #include <vtkConeSource.h>
 9 #include <vtkFloatArray.h>
10 #include <vtkNamedColors.h>
11 #include <vtkNew.h>
12 #include <vtkPointData.h>
13 #include <vtkPoints.h>
14 #include <vtkPolyData.h>
15 #include <vtkPolyDataMapper.h>
16 #include <vtkRenderer.h> 
17 #include <vtkRenderWindow.h>
18 #include <vtkRenderWindowInteractor.h>
19 #include <vtkInteractorStyleTrackballCamera.h>
20 #include <array>
21 
22 int main()
23 {//演员训练成什么类型,想要一个圆柱样子
24     vtkNew<vtkCylinderSource> cylinder;
25     cylinder->SetHeight(3.0);//柱体的高
26     cylinder->SetRadius(1.0);//柱体的横截面半径
27     cylinder->SetResolution(10);//柱体的等边多边形边数
28 //根据想要的圆柱演员样子,将他渲染训练成该样
29     vtkNew < vtkPolyDataMapper>cylinderMapper;
30     cylinderMapper->SetInputConnection(cylinder->GetOutputPort());
31     vtkNew < vtkActor>cylinderActor;//演员产生
32     cylinderActor->SetMapper(cylinderMapper);
33     vtkNew < vtkRenderer>renderer;//搭建舞台
34     renderer->AddActor(cylinderActor);//所有演员中的哪一个要上台
35     renderer->SetBackground(0.6, 0.5, 0.4);//舞台背景
36     vtkNew < vtkRenderWindow>renWin;//指定电影院
37     renWin->AddRenderer(renderer);//指定电影院要播放的电影(舞台)
38     renWin->SetSize(500, 500);//建立影院大小
39     
40     vtkNew<vtkRenderWindowInteractor> iren;//表演中有互动
41     iren->SetRenderWindow(renWin);//和那个演出互动
42     vtkNew<vtkInteractorStyleTrackballCamera>style;//互动的形式是什么
43 
44     iren->SetInteractorStyle(style);
45     iren->Initialize();
46     iren->Start();
47 
48     return EXIT_SUCCESS;
49 }

Guess you like

Origin www.cnblogs.com/fuzhuoxin/p/12112635.html