[vtkusers] A problem of getting 2D coordinates of the point picked in the 3D world coordinate

朱文武 cool.wenwu at gmail.com
Tue Apr 27 05:55:45 EDT 2010


hi,all,
    i need your help! Now, user can pick a point on the 3D model(The model
is reconsturcted by MC algorithm). And i use vtkCellPicker to finish this
task. Then, i need to show the 2D bmp image with corresponding ZSlice to
user. I also need to calculate the 2D coordinate in the bmp image of that
picked point. The problem for me is that my projection formula is not
correct. The 2D coordinates i calculated is not right. Could any one give
suggestions or better strategies?
The program is developped by vc6.0.

   Related code and projection formula is as follows:

   vtkBMPReader *m_read;
   vtkInteractorStyleTrackballCamera *style;
   vtkRenderWindowInteractor *iren;
   vtkCellPicker *picker;

   iren->SetInteractorStyle(style);
   style->AddObserver(vtkCommand::MiddleButtonReleaseEvent, cmd); // the
middlebutton is used to pick point
   cmd->SetCallback(Execute);
   picker->SetTolerance(0.0001);
   iren->SetPicker(picker);

   void Execute(vtkObject *caller, unsigned long eid, void *clientdata, void
*calldata)
  {
    double globalCoordinate[3]; //
    picker->Pick(iren->GetEventPosition()[0],iren->GetEventPosition()[1],0,
aRenderer);
    picker->GetPickPosition(globalCoordinate);

    int _2DCoor[3];
// this is the projection formula
      _2DCoor[0] = static_cast<int>(globalCoordinate[0] / m_Dx +0.5); //m_Dx
represents space in x axies

    _2DCoor[1] = m_Ymax + 1 - static_cast<int>(globalCoordinate[1] / m_Dy)
+0.5 ;//m_Dy represents space in y axies, m_Ymax represents the length of a
2D image

    _2DCoor[2] = static_cast<int>(globalCoordinate[2] / m_Dz + 0.5)  ; //
m_Dz represents z space in Z axies

}

Any help or reply is highly appreciated.

thanks,
wenwu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100427/f43441b0/attachment.htm>


More information about the vtkusers mailing list