37 VTK中的坐标系系统

0 引言

在利用PCL的交互功能解决尺寸关联几何的指定问题时,涉及到一些显示上的操作。目前的需求是:将投影到注释平面上的点云,以与屏幕平齐的方式,显示在屏幕正中,这样方便用户进行操作。但是,在运用setCameraPosition 对点云视图进行设置时,由于不了解参数意义,所以无法达到目的。

setCameraPosition 的API如下所示。

        /** rief Set the camera pose given by position, viewpoint and up vector
          * param[in] pos_x the x coordinate of the camera location
          * param[in] pos_y the y coordinate of the camera location
          * param[in] pos_z the z coordinate of the camera location
          * param[in] view_x the x component of the view point of the camera
          * param[in] view_y the y component of the view point of the camera
          * param[in] view_z the z component of the view point of the camera
          * param[in] up_x the x component of the view up direction of the camera
          * param[in] up_y the y component of the view up direction of the camera
          * param[in] up_z the y component of the view up direction of the camera
          * param[in] viewport the viewport to modify camera of (0 modifies all cameras)
          */
        void
        setCameraPosition (double pos_x, double pos_y, double pos_z,
                           double view_x, double view_y, double view_z,
                           double up_x, double up_y, double up_z, int viewport = 0);

其中,参数中涉及到两个位置和一个方向,分别是 camera location / view point /view up direction. 

1 PCL/VTK中的相机投影系统

在每个三维点的坐标、纹理和颜色获取之后,为了将世界坐标系中的三维场景投影到二维的屏幕上,需要建立相机模型。 

先上图

              

position 和 focal point定义了相机的位置和投影方向,Front Clipping Plane为CCD镜头平面(图像平面),Back Clipping Plane平面为物体平面。

2 PCL/VTK中的坐标系统

先上图吧

              

(1)模型坐标系 model coordinate system

  模型坐标系固定在模型上,该坐标系在建模时由建模者指定。

(2)世界坐标系 world coordinate system

  模型所处的位置,采用世界坐标系来描述。通常每个模型都有自己的坐标系,但是只有一个世界坐标系。在对模型进行旋转、平移、缩放时,世界坐标是不变的,但模型坐标系相对于世界坐标系的空间位置关系发生了变化。通常相机与光源也在世界坐标系中定义。

(3)视点坐标系 view coordinate system

  视点坐标系能够表达对相机可见的场景,其x和y坐标的范围在(-1,1)之间,z代表深度值。世界坐标系到视点坐标系之间的转换用4*4的相机矩阵来表达。

(4)屏幕坐标系 display coordinate system

   屏幕坐标系即图像坐标系,其坐标轴方向与视点坐标系一致,但是其x,y坐标值为像素坐标值。窗口尺寸决定了视点坐标与像素坐标的投影关系。不同的viewports(范围:0~1)能将同一个视点坐标系下的物体投影到不同的屏幕坐标系下。

(5)全过程

  物体最初在模型坐标系下建立,并展示在世界坐标系中。通过相机空间变换矩阵投影到视点坐标系下,并经viewport展示在屏幕上。

3 OpenGL中的坐标系

(1)世界坐标系

  在OpenGL中,世界坐标系是以屏幕中心为原点(0, 0, 0),且是始终不变的。你面对屏幕,你的右边是x正轴,上面是y正轴,屏幕指向你的为z正轴。

  长度单位这样来定:窗口范围按此单位恰好是(-1,-1)到(1,1),即屏幕左下角坐标为(-1,-1),右上角坐标为(1,1)。

(2)模型坐标系(又称绘图坐标系)  

  是绘制物体时的坐标系。程序刚初始化时,世界坐标系和当前绘图坐标系是重合的。当用glTranslatef(),glScalef(), glRotatef()等对当前绘图坐标系进行平移、伸缩、旋转变换之后,世界坐标系和当前绘图坐标系不再重合。注意,这里的平移旋转是将当前绘图坐标系看做一个整体在世界坐标系中进行旋转平移。然后,改变以后,再用glVertex3f()等绘图函数绘图时,都是在当前绘图坐标系进行绘图,所有的函数参数也都是相对当前绘图坐标系来讲的。

4 利用VTK调整点云视图效果

将点云投影到某一个平面上,并使其平行于屏幕显示,方便用户在该平面上与点云进行交互。

原文地址:https://www.cnblogs.com/ghjnwk/p/10305796.html