[vtkusers] Getting 3D position of a clicked point
Victor Levy
vlevy at myrealbox.com
Tue May 1 09:21:21 EDT 2001
Mohammad, this is a sligtly modified version of MFC-based code that works
for us, but only when the data being rendered is opaque. m_pVtkRenderer is
a pointer to a vtkRenderer object. m_resWindow is a CSize object containing
the resolution of the render window. If you're not using MFC you should be
able to adapt it without too much trouble.
Hope it helps, Vic
P.S. Does anyone know how to get this to work when the data in the renderer
is translucent, i.e., its opacity is less than 1.0?
/*
%=======================================================================%
% ICmn3DImageRenderer::Convert2Dto3D %
% Returns the 3-D point at a specified 2-D point. %
*/
HRESULT CCmn3DRendererVtk::Convert2Dto3D (
/* Returns */
/* Function result code */
DOUBLE_POINT_3D* a_pPt3)
/* Input: */
/* 2-D point (z coordinate ignored) relative to the render */
/* window. The origin is at the top-left. */
/* Output: */
/* 3-D point in global coordinates of the voxel closest to the */
/* viewer at the specified 2-D point. */
/*
% Notes: %
% Returns S_FALSE if there are no voxels at the specified %
% 2-D point. %
%=======================================================================%
*/
{
HRESULT
result = S_OK;
int
status;
float
*arrPickPosition;
vtkPropPicker
*pVtkPicker = NULL;
/*
%----------%
% Validate %
%----------%
*/
if (m_pVtkRenderer == NULL) {
result = RLT_MAKE_FAILURE (ERR_SUP_OBJECT_NOT_INITIALIZED);
goto exit;
}
/*
%----------------------------------------%
% Pick the object at the specified point %
%----------------------------------------%
*/
a_pPt3 -> y = m_resWindow.cy - 1 - a_pPt3 -> y; // VTK uses bottom-left
origin for this function
pVtkPicker = pVtkPicker -> New ();
status = pVtkPicker -> Pick (a_pPt3 -> x, a_pPt3 -> y, a_pPt3 -> z,
m_pVtkRenderer);
if (status) {
// Data at specified point
arrPickPosition = pVtkPicker -> GetPickPosition ();
a_pPt3 -> x = arrPickPosition [0];
a_pPt3 -> y = arrPickPosition [1];
a_pPt3 -> z = arrPickPosition [2];
}
else {
// No data at specified point
result = S_FALSE;
}
exit:
if (pVtkPicker != NULL) {
pVtkPicker -> Delete ();
}
return result;
}
----- Original Message -----
From: "Mohammad R. Siadat" <msiadat at zeus.cs.wayne.edu>
To: <vtkusers at public.kitware.com>
Sent: Monday, April 30, 2001 4:04 PM
Subject: [vtkusers] Getting 3D position of a clicked point
> Hi,
>
> I need to get the 3D coordinate of a clicked point in a VTK window (for a
> program like samlpe medical2.cxx). The answer would be greatly
> appreciated.
>
> Thanks,
> Mohammad Siadat
>
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
<http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>
More information about the vtkusers
mailing list