What is the difference between ProjectionTransformMatrix VTK and GL_PROJECTION OpenGL?

I am having serious problems understanding the transformations involved in the WTC. OpenGL has fairly good documentation, and I got the impression that VTK is very similar to OpenGL (it is in many ways). But when it comes to transformations, this seems to be a completely different story.

This is good OpenGL documentation on related transforms: http://www.songho.ca/opengl/gl_transform.html

Perspective projection matrix in OpenGL:

enter image description here

I was wondering if this formula in VTK would apply the VTK projection matrix (by cross-checking with the VTK projection matrix).

Corresponding camera and rendering options:

camera->SetPosition(0,0,20);
camera->SetFocalPoint(0,0,0);
double crSet[2] = {10, 1000};
renderer->GetActiveCamera()->SetClippingRange(crSet);
double windowSize[2];
renderWindow->SetSize(1280,720);
renderWindowInteractor->GetSize(windowSize);
proj = renderer->GetActiveCamera()->GetProjectionTransformMatrix(windowSize[0]/windowSize[1], crSet[0], crSet[1]);

      

The projection transformation matrix obtained for this configuration:

enter image description here

The values ​​(3,3) and (3,4) of the projection matrix (say indexed from 1 to 4 for rows and columns) should be - (f + n) / (fn) and -2 * f * n / (fn) respectively. In my camera settings, VTK is closest to you 10 and farz is 1000 and so I should get -1.020 and -20.20 respectively at (3,3) and (3,4) matrix places. But these are -1010 and -10000.

I changed my clipping range values ​​to see the changes and the position (3,3) is always close to + farz, which doesn't make any sense to me. It would also be great if someone can explain why it is 3.7320 in the (1,1) and (2,2) positions. And this value does NOT change when the render window is resized. Quite perplexing.

I can see in the VTKCamera class reference that GetProjectionTransformMatrix () returns a transformation matrix that maps from camera coordinates to view coordinates.

VTK camera class reference

This is a good description of the transforms involved in OpenGL rendering:

enter image description here

The OpenGL Projection Matrix is ​​a matrix that maps eye coordinates to clip coordinates. Undoubtedly, the coordinates of the eyes in OpenGL are the same as the coordinates of the camera in VTK. But are the coordinates of the clips in OpenGL the same as the coordinates of the VTK reel?

My goal is to simulate a real webcam (already calibrated) in VTK to render a 3D model.

+3


source to share


1 answer


Well, the documentation you link to actually explains it (emphasis mine):

vtkCamera::GetProjectionTransformMatrix

:

Returns a projection transformation matrix that transforms camera coordinates to view coordinates . This method calculates aspect, nearz and farz, then calls a more specific signature Get Composite ProjectionTransformMatrix

from:

vtkCamera::GetCompositeProjectionTransformMatrix

:

Returns the concatenation of the ViewTransform and ProjectionTransform. This transformation converts world coordinates to view coordinates. Aspect is the width / height for the viewport, and the near and far are the Z-buffer values ​​that are mapped to the near and far clipping planes. The coordinates of the point of view of the point inside the frustum are in the range ([-1, + 1], [- 1, + 1], [nearz, farz] ).



Note that this does not match OpenGL window space and normalized device space. If you find the term "viewport coordinates" for this poor choice, but whatever. What worries me more is that the matrix is ​​not actually converted to this "viewport space" but to some equivalent of a clip. Only after breaking the perspective will the coordinates be within the range specified above for the "view space" definition.

But are the clip coordinates in OpenGL the same as the view VTK coordinates?

So this answer is clear. But it's close. Basically, this projection matrix is ​​just scaled and z-shifted, and it's easy to convert between the two. Basically, you can just take znear

and zfar

from the VTK matrix and put it in the OpenGL matrix matrix formula you linked above, replacing only those two matrix elements.

+2


source







All Articles