[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
Tue Apr 27 14:07:35 EDT 2010


Now i get it . You need the projection . Try the vtkCoordinate class , there
is an example in the VTK Wiki. This will give you the answer in viewport
coordinates.

Regards
Darshan

On Tue, Apr 27, 2010 at 4:55 AM, 朱文武 <cool.wenwu at gmail.com> wrote:

> hey, Darshan, thanks for your kind help. From my point of view, the
> function of the GetSelectionPoint() of vtkAbstractPicker is "get the
> selection point in screen (pixel) coordinates".   And my condition is that
> user can pick point  on the 3D model(surface), then i need to calculate the
> 2D coordinate of this point. The mean of 2D coordinate is the 3D point
> projected into original 2D image.  So, i think the point coordinate which i
> want  does not equalize the screen point coordinate. But, thank your all the
> same.
> Could anyone provide suggestion? thanks very much!
>
>
>
>
> On Tue, Apr 27, 2010 at 3:12 AM, Darshan Pai <darshanpai at gmail.com> wrote:
>
>> 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/20100427/daa927f4/attachment.htm>


More information about the vtkusers mailing list