vtk Camera

3.4 相机

观众的眼睛就好比三维渲染场景中的相机,VTK则是用vtkCamera类来表示三维渲染场景中的相机。vtkCamera负责把三维场景投影到二维平面,如屏幕、图像等。图3.6为相机投影示意图。

从图3.6可以看出与相机投影相关的因素主要有:

l  相机位置:即相机所在的位置,用方法vtkCamera::SetPosition()设置。

l  相机焦点:用方法vtkCamera::SetFocalPoint()设置,默认的焦点位置在世界坐标系的原点。

l  朝上方向:即哪个方向为相机朝上的方向。就好比我们直立看东西,方向为头朝上,看到的东西也是直立的,如果我们倒立看某个东西,这时方向为头朝下,看到的东西当然就是倒立的。相机位置、相机焦点和朝上方向三个因素确定了相机的实际方向,即确定相机的视图。

 

图3.6相机vtkCamera投影示意图

l  投影方向:相机位置到相机焦点的向量方向即为投影方向。

l  投影方法:确定Actor是如何映射到像平面的。vtkCamera定义了两种投影方法,一种是正交投影(OrthographicProjection),也叫平行投影(Parallel Projection),即进入相机的光线与投影方向是平行的。另一种是透视投影(PerspectiveProjection),即所有的光线相交于一点。

l  视角:透视投影时需要指定相机的视角(View Angle),默认的视角大小为30º,可以用方法vtkCamera::SetViewAngle()设置。

l  前后裁剪平面:裁剪平面与投影方向相交,一般与投影方向也是垂直的。裁剪平面主要用于评估Actor与相机距离的远近,只有在前后裁剪平面之间的Actor才是可见的。裁剪平面的位置可以用方法vtkCamera::SetClippingRange()设置。

如果你想获取vtkRenderer里默认的相机,可以用方法vtkRenderer::GetActiveCamera()。

相机vtkCamera的使用方法:

vtkSmartPointer<vtkCamera>myCamera = vtkSmartPointer<vtkCamera>::New();

myCamera->SetClippingRange(0.0475,2.3786); //这些值随便设置的,为了演示用法而已

myCamera->SetFocalPoint(0.0573,-0.2134, -0.0523);

myCamera->SetPosition(0.3245,-0.1139, -0.2932);

myCamera->ComputeViewPlaneNormal();

myCamera->SetViewUp(-0.2234,0.9983, 0.0345);

renderer->SetActiveCamera(myCamera);

上述我们用SetClippingRange();SetFocalPoint();SetPosition()分别设置相机的前后裁剪平面,焦点和位置。ComputeViewPlaneNormal()方法是根据设置的相机位置、焦点等信息,重新计算视平面(View Plane)的法向量。一般该法向量与视平面是垂直的,如果不是垂直的话,Actor等看起来会有一些特殊的效果,如错切。SetViewUp()方法用于设置相机朝上方向。最后用方法vtkRenderer::SetActiveCamera()把相机设置到渲染场景中。

vtkCamera除了提供设置与相机投影因素相关的方法之外,还提供了大量的控制相机运动的方法,如:vtkCamera::Dolly(),vtkCamera::Roll(),vtkCamera::Azimuth()(纬度),vtkCamera::Yaw(),vtkCamera::Elevation()(经度),vtkCamera::Pitch(),vtkCamera::Zoom()。这些方法具体表示相机是怎么运动,以及相对哪个位置或者方向运动,请参考图3.7或者关于类vtkCamera的文档说明。

 

图3.7 相机运动方向示意图



void vtkCamera::Roll(double  angle) 

Rotate the camera about the direction of projection. This will spin the camera about its axis.

void vtkCamera::Azimuth(double  angle) 

Rotate the camera about the view up vector centered at the focal point. Note that the view up vector is whatever was set via SetViewUp, and is not necessarily perpendicular to the direction of projection. The result is a horizontal rotation of the camera.

void vtkCamera::Yaw(double  angle) 

Rotate the focal point about the view up vector, using the camera's position as the center of rotation. Note that the view up vector is whatever was set via SetViewUp, and is not necessarily perpendicular to the direction of projection. The result is a horizontal rotation of the scene.

void vtkCamera::Elevation(double  angle) 

Rotate the camera about the cross product of the negative of the direction of projection and the view up vector, using the focal point as the center of rotation. The result is a vertical rotation of the scene.

void vtkCamera::Pitch(double  angle) 

Rotate the focal point about the cross product of the view up vector and the direction of projection, using the camera's position as the center of rotation. The result is a vertical rotation of the camera.


  • 3
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值