[vtkusers] Trouble with vtkCamera rendering

jsl jsantam.gm at gmail.com
Thu May 31 06:35:42 EDT 2007


Hi all,

   I've noticed that there are few replies to user questions ... Perhaps
I'll be lucky this time :)

   (to the grain) My software program loads a 3D model and a 2D image. The
image is
supposed to be in the image plane of a CCD camera at (0,0,1) with focal
distance 1./tan(angle-of-view)
and with the Z coordinate axis passing throught the center of the image
plane. First, a specific
routine searches for the best fit between the 3D model and the 2D image. To
do it, several
parameters of an affine (rotation, translation, and uniform scaling) and a
perspective (angle of
view) transform should be searched for. The sequence of matrix
multiplications are the following:

M = R*S*T*P  (applied from left to right)

where R is the rotation done around an axis vector that could be placed in
any place of the
world space (mainly inside the 3D model); S is the uniform scaling; T is the
translation; and
P is the perspective matrix. It is important to note that the 3D-2D
projection of the 3D model
gives us an inverted projection of the 3D points to the 2D image plane, so
before compare
with the 2D image, a simple change of the sign of the projected 3D points is
done.

How to render the result with VTK?

What I've done is:

1.- Transform the rendering camera with he inverse of previous matrix:

M' = (R*S*T)^-1  (the perspective matrix is removed)

The vtk code is:

    // Create the 3D model renderer
    vtkRenderer* geomRen = vtkRenderer::New();
    geomRen->GetActiveCamera()->SetPosition(0,0,1);
    geomRen->GetActiveCamera()->SetViewUp(0,1,0);
    geomRen->GetActiveCamera()->SetDistance( 1.0/tan(degreesToRadians(phi))
);
    geomRen->GetActiveCamera()->ComputeViewPlaneNormal();
    geomRen->GetActiveCamera()->ApplyTransform(Transform);
    .....
    .....
    vtkRenderWindow* renwin = vtkRenderWindow::New();
    renwin->AddRenderer(geomRen);
    geomRen->ResetCamera();
    .....
    .....
    iren->Initialize();
    iren->Start();


Also, I use the vtkRenderWindow::SetSize() for achieving a viewing window
with the
same size of the 2D image.

The trouble is regarding the rendering after the camera transformation (with
M'). It
doesn't visualize any change in scale and it seems that is considering a
3D-2D orthogonal
projection of the world space, what is wrong?

Finally, once the previous is properly done, the last part is to achieve the
rendering
of the 2D image together with the 3D model. As the vtkRenderWindow instance
has the same size of the 2D image, could I just paste the 2D image in the
image
plane of the vtkCamera? If so, how? Otherwise, how could it be done with
VTK?


(Anyway) Many many thanks everybody ... at least for reading ;)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070531/94739444/attachment.htm>


More information about the vtkusers mailing list