[vtkusers] viewport aspect

MathewPhilip mathew115 at gmail.com
Fri May 27 12:15:16 EDT 2011


I found an alternative to do this. I couldn't get the getPixelAspect to work
and couldn't find an alternative on this forum. This may help someone
searching for a similar solution. By default the aspect ratio is set by the
size of the window and this is what the projection matrix uses.   

I used the SetUserTransform in vtkCamera . This function concatenates a
userMatrix with the projection 
matrix. (Note this is different from the SetUserViewTransform which modifies
the viewMatrix of the camera.) 

By setting the first element of the UserTransform matrix appropriately we
can change the aspect ratio to any value that is desired. All other elements
of the Usertransform are from the identity matrix. 

Some sample code: 

vtkTransform *transform1=vtkTransform::New(); 
vtkMatrix4x4 *mat1=vtkMatrix4x4::New(); 
mat1->setvalue(0,0,x); 
mat1->setvalue(1,1,1); 
mat1->setvalue(2,2,1); 
mat1->setvalue(3,3,1); 

//make sure the rest of the elements of mat1 are zero.. I explicitly
initialized them to zero 
transform1->setmat(mat); 
cam->SetUserTransform(transform1); 

Computing x; 
x=aspect/aspect_i_want; aspect can be determined from the size of the
window. 

**************** 
If you want to go deeper: 
These links helped me to understand the projection matrix. 
http://www.songho.ca/opengl/gl_projectionmatrix.html

http://old.uvr.gist.ac.kr/wlee/web/techReports/ar/Camera%20Models.html

If you assume a symmetric frustum (which I belive VTK does) then the aspect
ratio appears only in the first element of the projection matrix and that is
the only element we need to modify by our user transform to get the aspect
ratio we need. 

The first element of the projection transform (for a symmetric frustum) is 
cot(field_of_view/2)/aspect_ratio 

where aspect_ratio is determined by the size of the window. 

So when you multiply by your usertransform matrix, you can mutliply by a
value that will effectively change your projection matrix so that it
reflects the aspect ratio you want. After multiplication by the user
transform you want the first element of your projection matrix to read: 

cot(field_of_view/2)/aspect_i_want 

So x (the first element of your user transform) can be computed from the
equation below: 

x*cot(fov/2)/aspect=cot(fov/2)/aspect_i_want 




Mathew

--
View this message in context: http://vtk.1045678.n5.nabble.com/viewport-aspect-tp3394508p4432555.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list