Hi all,<br>
<br>
I've noticed that there are few replies to user questions ... Perhaps I'll be lucky this time :)<br>
<br>
(to the grain) My software program loads a 3D model and a 2D image. The image is <br>supposed to be in the image plane of a CCD camera at (0,0,1) with focal distance 1./tan(angle-of-view) <br>and with the Z coordinate axis passing throught the center of the image plane. First, a specific
<br>routine searches for the best fit between the 3D model and the 2D image. To do it, several <br>parameters of an affine (rotation, translation, and uniform scaling) and a perspective (angle of <br>view) transform should be searched for. The sequence of matrix multiplications are the following:
<br>
<br>
M = R*S*T*P (applied from left to right)<br>
<br>
where R is the rotation done around an axis vector that could be placed in any place of the<br>
world space (mainly inside the 3D model); S is the uniform scaling; T is the translation; and <br>
P is the perspective matrix. It is important to note that the 3D-2D projection of the 3D model <br>
gives us an inverted projection of the 3D points to the 2D image plane, so before compare<br>
with the 2D image, a simple change of the sign of the projected 3D points is done.<br>
<br>
How to render the result with VTK?<br>
<br>
What I've done is:<br>
<br>
1.- Transform the rendering camera with he inverse of previous matrix:<br>
<br>
M' = (R*S*T)^-1 (the perspective matrix is removed)<br>
<br>
The vtk code is:<br>
<br>
// Create the 3D model renderer<br>
vtkRenderer* geomRen = vtkRenderer::New();<br>
geomRen->GetActiveCamera()->SetPosition(0,0,1);<br>
geomRen->GetActiveCamera()->SetViewUp(0,1,0);<br>
geomRen->GetActiveCamera()->SetDistance( 1.0/tan(degreesToRadians(phi)) );<br>
geomRen->GetActiveCamera()->ComputeViewPlaneNormal();<br>
geomRen->GetActiveCamera()->ApplyTransform(Transform);<br>
.....<br>
.....<br>
vtkRenderWindow* renwin = vtkRenderWindow::New();<br>
renwin->AddRenderer(geomRen);<br>
geomRen->ResetCamera();<br>
.....<br>
.....<br>
iren->Initialize();<br>
iren->Start();<br>
<br>
<br>
Also, I use the vtkRenderWindow::SetSize() for achieving a viewing window with the <br>same size of the 2D image.<br>
<br>
The trouble is regarding the rendering after the camera transformation (with M'). It <br>doesn't visualize any change in scale and it seems that is considering a 3D-2D orthogonal <br>
projection of the world space, what is wrong?<br>
<br>
Finally, once the previous is properly done, the last part is to achieve the rendering <br>
of the 2D image together with the 3D model. As the vtkRenderWindow instance<br>
has the same size of the 2D image, could I just paste the 2D image in the image<br>
plane of the vtkCamera? If so, how? Otherwise, how could it be done with VTK?<br>
<br>
<br>
(Anyway) Many many thanks everybody ... at least for reading ;)<br>