0 引言
在利用PCL的交互功能解決尺寸關聯幾何的指定問題時,涉及到一些顯示上的操作。目前的需求是:將投影到注釋平面上的點雲,以與屏幕平齊的方式,顯示在屏幕正中,這樣方便用戶進行操作。但是,在運用setCameraPosition 對點雲視圖進行設置時,由於不了解參數意義,所以無法達到目的。
setCameraPosition 的API如下所示。
/** \brief 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調整點雲視圖效果
將點雲投影到某一個平面上,並使其平行於屏幕顯示,方便用戶在該平面上與點雲進行交互。