我想要獲得一個4x4投影矩陣,將世界中的一個點轉換爲顯示座標。vtk投影矩陣:從世界到顯示
有一個像素(x,y)和相應的z值(來自zbuffer
),我得到它的3D世界座標與vtkWorldPointPicker
類。讓我們用x來表示結果。
根據documentation,我可以通過將矩陣GetCompositeProjectionTransformMatrix
應用於x來計算世界點的視圖座標。接着,我使用從視圖到初始顯示座標變換通過使用vtkViewport::ViewToDisplay
找到的代碼(*):
dx = (v[0] + 1.0) * (sizex*(v[2]-v[0]))/2.0 + sizex*v[0];
dy = (v[1] + 1.0) * (sizey*(v[3]-v[1]))/2.0 + sizey*v[1];
其中sizex
和sizey
是寬度和像素表示的圖像的高度,並且v
是計算的視圖座標。
不幸的是,我回來的值不匹配原:
display [0, 0, 0.716656] // x,y-pixel coordinates and the zbuffer
x = [0.0255492, -0.0392383, 0.00854707] // world coordinates (using vtkWorldPointPicker)
// camera->GetCompositeProjectionTransformMatrix
P = [
-1.84177 0 0 0
0 1.20317 1.39445 0
0 -757.134 653.275 -9.9991
0 -0.757126 0.653268 0 ]
v = [-0.0470559, -0.0352919, 25.2931, 0.0352919] // P*x
a = [7697.18, -0.597848] // using (*)
是這種方法(一般)是正確的,或者是有一個更傳統的方式做到這一點?謝謝你的幫助。
編輯:從vtkViewport::ViewToDisplay
提供的片段不正確。它應該閱讀:
dx = (v[0] + 1.0) * (sizex*(vp[2]-vp[0]))/2.0 + sizex*vp[0];
dy = (v[1] + 1.0) * (sizey*(vp[3]-vp[1]))/2.0 + sizey*vp[1];
注意,那v
指歸一化視圖座標,vp
是視(默認情況下,vp := [0, 0, 1, 1]
)!