[vtkusers] How to map the point in 3D coordinate to 2D coordinate locates in 2D image by using vtkCellPicker?

Darshan Pai darshanpai at gmail.com
Mon Apr 26 15:12:15 EDT 2010


I think GetSelection() should be the function of choice

On Mon, Apr 26, 2010 at 10:17 AM, 朱文武 <cool.wenwu at gmail.com> wrote:

> 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
>
>
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100426/29150db3/attachment.htm>


More information about the vtkusers mailing list