[vtkusers] Question on vtkPerspectiveTransform::SetupCamera()

David Gobbi david.gobbi at gmail.com
Wed Nov 3 09:29:19 EDT 2010


Hi Michael,

The SetupCamera() method is meant to do only one thing: to create a
transformation matrix that converts world coordinates to camera
coordinates.  The math does the following:

1) Translate the scene to move the camera position to (0,0,0).

2) Rotate the scene according to the camera's orientation.

The final translation is equal to -position multiplied by the rotation matrix.

  David


On Wed, Nov 3, 2010 at 1:50 AM, Müller Michael
<michael.mueller at dkfz-heidelberg.de> wrote:
> Good morning (at least for all those europeans reading this),
>
>
>
> I have a question regarding the method
> vtkPerspectiveTransform::SetupCamera() which is used by the vtkCamera to
> recalculate the view transform matrix. Here is the complete code of the
> function since it will be easier to describe what irritates me:
>
> --------------------
>
> void vtkPerspectiveTransform::SetupCamera(const double position[3],
>
>                                           const double focalPoint[3],
>
>                                           const double viewUp[3])
>
> {
>
>   double matrix[4][4];
>
>   vtkMatrix4x4::Identity(*matrix);
>
>
>
>   // the view directions correspond to the rows of the rotation matrix,
>
>   // so we'll make the connection explicit
>
>   double *viewSideways =    matrix[0];
>
>   double *orthoViewUp =     matrix[1];
>
>   double *viewPlaneNormal = matrix[2];
>
>
>
>   // set the view plane normal from the view vector
>
>   viewPlaneNormal[0] = position[0] - focalPoint[0];
>
>   viewPlaneNormal[1] = position[1] - focalPoint[1];
>
>   viewPlaneNormal[2] = position[2] - focalPoint[2];
>
>   vtkMath::Normalize(viewPlaneNormal);
>
>
>
>   // orthogonalize viewUp and compute viewSideways
>
>   vtkMath::Cross(viewUp,viewPlaneNormal,viewSideways);
>
>   vtkMath::Normalize(viewSideways);
>
>   vtkMath::Cross(viewPlaneNormal,viewSideways,orthoViewUp);
>
>
>
>   // translate by the vector from the position to the origin
>
>   double delta[4];
>
>   delta[0] = -position[0];
>
>   delta[1] = -position[1];
>
>   delta[2] = -position[2];
>
>   delta[3] = 0.0; // yes, this should be zero, not one
>
>
>
>   vtkMatrix4x4::MultiplyPoint(*matrix,delta,delta);
>
>
>
>   matrix[0][3] = delta[0];
>
>   matrix[1][3] = delta[1];
>
>   matrix[2][3] = delta[2];
>
>
>
>   // apply the transformation
>
>   this->Concatenate(*matrix);
>
> }
>
> -------------------
>
> The calculation of the three rotation axes is straight forward but then the
> position is calculated by multiplying it with -1 and then with the
> previously defined rotation matrix. What is the reason for this?
>
> I am working with pose estimation algorithms with the effect that I have to
> recalculate my estimated position in an inverted scheme (multiply with the
> inverted rotation matrix and then with -1) to adjust the vtk camera
> correctly.
>
>
>
> Thank you for your answers,
>
>
>
> Michael
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>



More information about the vtkusers mailing list