1.坐标系统
计算机图形学里常用的坐标系统主要有四种,分别是:Model坐标系统、World坐标系统、View坐标系统和Display坐标系统,以及两种表示坐标点的方式:以屏幕像素值为单位和归一化坐标值(各坐标轴取值都为[-1, 1])。
Model坐标系统是定义模型时所采用的坐标系统,通常是局部的笛卡尔坐标系。例如,我们要定义一个表示球体的Actor,一般的做法是将该球体定义在一个柱坐标系统里。
World坐标系统是放置Actor的三维空间坐标系,Actor其中的一个功能就是负责将模型从Model坐标系统变换到World坐标系统。每一个模型可以定义有自己的Model坐标系统,但World坐标系只有一个,每一个Actor必须通过放缩、旋转、平移等操作将Model坐标系变换到World坐标系。World坐标系同时也是相机和光照所在的坐标系统。
View坐标系统表示的是相机所看见的坐标系统。X、Y、Z轴取值为[-1, 1],X、Y值表示像平面上的位置,Z值表示到相机的距离。相机负责将World坐标系变换到View坐标系。坐标之间的关系如下图所示:
Display坐标系统跟View坐标系统类似,但是各坐标轴的取值不是[-1, 1],而是使用屏幕像素值。屏幕上显示的不同窗口的大小会影响View坐标系的坐标值[-1, 1]到Display坐标系的映射。可以把不同的渲染场景放在同一个窗口进行显示,例如,在一个窗口里,分为左右两个渲染场景,这左右的渲染场景(vtkRenderer)就是不同的视口(Viewport)。
2.一个窗口分割为多个视窗
1 /*****************************************************
2 *Overview:窗口分割 2016-11-25
3 *Tsinghua Univ. All Rights Reserved@Shenchunxu
4 ******************************************************/
5 #include <vtkAutoInit.h>
6 VTK_MODULE_INIT(vtkRenderingOpenGL);
7 #include <vtkConeSource.h>
8 #include <vtkCubeSource.h>
9 #include <vtkCylinderSource.h>
10 #include <vtkSphereSource.h>
11 #include <vtkPolyDataMapper.h>
12 #include <vtkRenderer.h>
13 #include <vtkRenderWindow.h>
14 #include <vtkActor.h>
15 #include <vtkRenderWindowInteractor.h>
16 #include <vtkSmartPointer.h>
17
18 int main()
19 {
20 vtkSmartPointer<vtkConeSource> cone = vtkSmartPointer<vtkConeSource>::New();
21 vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New();
22 vtkSmartPointer<vtkCylinderSource> cylinder = vtkSmartPointer<vtkCylinderSource>::New();
23 vtkSmartPointer<vtkSphereSource> sphere = vtkSmartPointer<vtkSphereSource>::New();
24
25 vtkSmartPointer<vtkPolyDataMapper> coneMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
26 coneMapper->SetInputConnection(cone->GetOutputPort());
27 vtkSmartPointer<vtkPolyDataMapper> cubeMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
28 cubeMapper->SetInputConnection(cube->GetOutputPort());
29 vtkSmartPointer<vtkPolyDataMapper> cylinderMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
30 cylinderMapper->SetInputConnection(cylinder->GetOutputPort());
31 vtkSmartPointer<vtkPolyDataMapper> sphereMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
32 sphereMapper->SetInputConnection(sphere->GetOutputPort());
33
34 vtkSmartPointer<vtkActor> coneActor = vtkSmartPointer<vtkActor>::New();
35 coneActor->SetMapper(coneMapper);
36 vtkSmartPointer<vtkActor> cubeActor = vtkSmartPointer<vtkActor>::New();
37 cubeActor->SetMapper(cubeMapper);
38 vtkSmartPointer<vtkActor> cylinderActor = vtkSmartPointer<vtkActor>::New();
39 cylinderActor->SetMapper(cylinderMapper);
40 vtkSmartPointer<vtkActor> sphereActor = vtkSmartPointer<vtkActor>::New();
41 sphereActor->SetMapper(sphereMapper);
42
43 vtkSmartPointer<vtkRenderer> renderer1 = vtkSmartPointer<vtkRenderer>::New();
44 renderer1->AddActor(coneActor);
45 renderer1->SetBackground(1.0,0.0,0.0);
46 renderer1->SetViewport(0.0,0.0,0.5,0.5);
47 vtkSmartPointer<vtkRenderer> renderer2 = vtkSmartPointer<vtkRenderer>::New();
48 renderer2->AddActor(cubeActor);
49 renderer2->SetBackground(0.0,1.0,0.0);
50 renderer2->SetViewport(0.5,0.0,1.0,0.5);
51 vtkSmartPointer<vtkRenderer> renderer3 = vtkSmartPointer<vtkRenderer>::New();
52 renderer3->AddActor(cylinderActor);
53 renderer3->SetBackground(0.0,0.0,1.0);
54 renderer3->SetViewport(0.0,0.5,0.5,1.0);
55 vtkSmartPointer<vtkRenderer> renderer4 = vtkSmartPointer<vtkRenderer>::New();
56 renderer4->AddActor(sphereActor);
57 renderer4->SetBackground(1.0,1.0,0.0);
58 renderer4->SetViewport(0.5,0.5,1.0,1.0);
59
60 vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
61 renWin->AddRenderer(renderer1);
62 renWin->AddRenderer(renderer2);
63 renWin->AddRenderer(renderer3);
64 renWin->AddRenderer(renderer4);
65 renWin->SetSize( 640, 480 );
66 renWin->Render();
67 renWin->SetWindowName("ViewPort");
68
69 vtkSmartPointer<vtkRenderWindowInteractor> interactor =
70 vtkSmartPointer<vtkRenderWindowInteractor>::New();
71 interactor->SetRenderWindow(renWin);
72
73 renWin->Render();
74 interactor->Initialize();
75 interactor->Start();
76
77 return EXIT_SUCCESS;
78 }
运行结果:
3.空间变换
遵循几何变换,已经详细论述过,不在多谈!
4.总结视图
一张图可以考验之前学过的知识是否真正的理解了!