[vtkusers] How to map the point in 3D coordinate to 2D coordinate locates in 2D image by using vtkCellPicker?
朱文武
cool.wenwu at gmail.com
Mon Apr 26 10:17:44 EDT 2010
hi all,
i encounter a problem, and need your kind help ! I get 3D global
coordinate by using vtkCellPicker, then i want to know the 2D coordinate of
point which is picked in the 3D scene. However, the 2D coordiante i
transformed was not accurate. Could anyone give some suggestion or better
methods? thanks in advance!
All related code is as follows:
vtkBMPReader *m_read=... // read bmp image
m_read->SetDataSpacing(CReadBmp::m_Dx,CReadBmp::m_Dy,CReadBmp::m_Dz);//
m_read->SetDataExtentCReadBmp::m_Xmin,CReadBmp::m_Xmax,CReadBmp::m_Ymin,CReadBmp::m_Ymax,CReadBmp::m_Zmin,CReadBmp::m_Zmax);//
vtkInteractorStyleTrackballCamera *style;
vtkRenderWindowInteractor *iren;
vtkCellPicker *picker;
iren->SetInteractorStyle(style);
style->AddObserver(vtkCommand::MiddleButtonReleaseEvent, cmd);
cmd->SetCallback(MyExecute);
picker->SetTolerance(0.0001);
iren->SetPicker(picker);
void MyExecute(vtkObject *caller, unsigned long eid, void *clientdata, void
*calldata)
{
double globalCoordinate[3]; //
double selPt[2];
picker->Pick(psurface->iren->GetEventPosition()[0],psurface->iren->GetEventPosition()[1],0,
psurface->aRenderer);
picker->GetPickPosition(globalCoordinate);
int _2DCoor[3];
// this is the map formula
_2DCoor[0] = static_cast<int>(globalCoordinate[0] / CReadBmp::m_Dx);
//2D x Coordinate
_2DCoor[1] = CReadBmp::m_Ymax + 1 - static_cast<int>(globalCoordinate[1]
/ CReadBmp::m_Dy);//2D y Coordinate
_2DCoor[2] = static_cast<int>(globalCoordinate[2] / CReadBmp::m_Dz +
0.5) + CReadBmp::m_Zmin ; // the index of image
}
wenwu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100426/77097261/attachment.htm>
More information about the vtkusers
mailing list