graphics - vtk projection matrix: from world to display -


i'm trying obtain 4x4 projection matrix transforms point in world display coordinates.

having pixel (x, y) , corresponding z-value (from zbuffer), obtain 3d world coordinates vtkworldpointpicker class. let's denote result x.

according documentation, can compute view coordinates of world point applying matrix getcompositeprojectiontransformmatrix x. next, i'm using transformation view initial display coordinates using code found in 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]; 

where sizex , sizey width , height of image in pixels, , v computed view coordinates.

unfortunately, values not match original:

display [0, 0, 0.716656] // x,y-pixel coordinates , 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 = [7697.18, -0.597848] // using (*) 

is approach (in general) correct, or there more conventional way this? help.

edit: provided snippet vtkviewport::viewtodisplay incorrect. should read:

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]; 

note, v refers normalised view coordinates, vp viewport (by default, vp := [0, 0, 1, 1])!

the conversion indeed valid, although there might built-in ways obtain final matrix.

assuming 1 (default) viewport used, matrix converting view display coordinates is:

m = [x/2,   0, 0, x/2,        0, y/2, 0, y/2,        0,   0, 1,   0,        0,   0, 0,   1] 

where x , y width , height of image in pixels. hence, given point x in world coordinates, display coordinates in homogeneous form are:

c = m * p * x; 

where p compositeprojectiontransformmatrix. after normalising (c[i] /= c[3], i = 0,1,2) arrive @ original pixel values.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -