[vtkusers] camera and projection problem

Cong Zhang winderzc at yahoo.com
Mon Mar 14 06:45:26 EST 2005


Dear all,

I am using vtk to do some work on 3D projection. We
have several 3D landmark points on a 3D model, and
want to get the corresponding 2D projected image
landmark points of those 3D points, in pixel unit. I
met some problem which can not properly compute the 2D
landmark projection. 
Here is my code.

double lmpoint[nlmk][4];  //store those 3D landmark
points in this array, in homogenous coordinates   
...                       //get landmark points

vtkCamera *cam = vtkCamera::New();       //create a
fixed camera
cam->SetPosition(0.0, 0.0, 1000);
cam->SetFocalPoint(0.0, 0.0, 950);  
double viewAngle = cam->GetViewAngle();
double camPos[3];
cam->GetPosition( camPos );
double clp[2] = {-500, 1000.0};
cam->SetClippingRange(clp);  

vtkRenderer *ren = vtkRenderer::New();    //vtk stuff
ren->SetBackground( 0.0, 0.0, 0.0 ); 
ren->AddProp( regActor );  
ren->SetActiveCamera( cam );    
ren->AddLight(light);     
  
vtkRenderWindow *renWin = vtkRenderWindow::New();  
//vtk stuff
renWin->SetSize(size[1]+1,size[3]+1);              
//set the pixel size of the render window  
renWin->AddRenderer(ren);
vtkRenderWindowInteractor *iren =
vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);  


ofstream outfile("GO/ori_020.rlmk", ios::app);        
  //save rendered landmark to file
double principlePoint[2]={(size[1]+1)/2,
(size[3]+1)/2};
int lmpoint2D[nlmk][2];   
double f =
(size[3]+1)/(2*tan(viewAngle*3.1415926/180));

//project the 3D landmark into 2D image plane and
store its 2D pixel coordinate
for (i=0; i<nlmk; i++)                                
      
{	  
    for (j=0; j<2; j++)
       lmpoint2D[i][j] = int (principlePoint[j] + f *
(lmpoint[i][j] / (camPos[2]-lmpoint[i][2])));
    outfile<<lmpoint2D[i][0]<<"
"<<lmpoint2D[i][1]<<endl;
}
outfile.close();

...


But these lmpoint2D[][] are not correct. It seems they
are shrinked. I attached a sample image to you. The
green dots are from the lmpoint2D[][], but they are
supposed to be close to the position of corresponding
red dots.

Do you have any idea about this problem? Thanks a lot!

cheers
chong


		
__________________________________ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/ 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0000.bmp
Type: image/bmp
Size: 36914 bytes
Desc: 0000.bmp
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20050314/b7e3cf44/attachment.bin>


More information about the vtkusers mailing list