[vtkusers] Coordinates on a surface
James C. Robinson
j.robinson at kepler-systems.com
Tue Aug 19 11:17:52 EDT 2003
Hi All,
I have a very specific problem which I would like to solve.
I am using an MFC class derived window (CView) to view an unstructured grid
(3D FE mesh - 20 noded hexahedra converted to 8 noded). I wanted to have the
facility to output the coordinates of the point on the surface under the
mouse cursor as the mouse moves. I looked up the doc and saw the classes
derived from vtkAbstractPicker. I tried vtkWorldPointPicker, vtkPicker, and
vtkCellPicker. Here is some of the code I use in the WindowProc of my
vtkMFCView derived CView:
Firstly, I try to output the coords when "p" is pressed (NB: I have
interrupted a lot of the default interactor functionality so that my program
conforms with an previous version) using the vtkInteractor picker:
if (message == WM_CHAR) // Don't allow the toggle options for a
standard VTK window.
{
TCHAR chCharCode = (TCHAR) wParam; // character code
// Look for "f" or "F" for the "fly" facility.
if ((chCharCode != 70)&&(chCharCode != 102))
// Look for "p" or "P" for the "pick" facility. (Hopefully to invoke the
vtkCellPicker
{ if ((chCharCode != 80)&&(chCharCode != 112))
{ return vtkMFCView::WindowProc(message, wParam, lParam);
} else
{ pPicker =
(vtkCellPicker*)(this->Interactor->GetPicker());
wz = 0.0 ;
wx = float(LOWORD(lParam)); /* Saves the current value
*/
wy = float(HIWORD(lParam));
pPicker->Pick(wx,wy,wz,Renderer) ;
pPickPos = pPicker->GetPickPosition() ;
coords.Format(" X:%7.2f Y:%7.2f Z:%7.2f",
*(pPickPos+0),*(pPickPos+1),*(pPickPos+2)) ;
baseframe->p_wndStatusBar->SetPaneText(1,coords) ;
}
}
}
I also try to do it dynamically as the mouse moves across the window using a
vtkCellPicker that I instantiate as part of my vtkMFCView derived CView:
if (message == WM_MOUSEMOVE)
{ if (Panning||Zooming||Rotating)
{ GetDocument()->ViewAltered() ;// Default title if view changes
} else
{
wz = 0.0 ;
wx = float(LOWORD(lParam)); /* Saves the
current value */
wy = float(HIWORD(lParam));
pCellPicker->Pick(wx,wy,wz,Renderer) ;
pPickPos = pCellPicker->GetPickPosition() ;
coords.Format(" x:%7.2f y:%7.2f z:%7.2f",
*(pPickPos+0),*(pPickPos+1),*(pPickPos+2)) ;
baseframe->p_wndStatusBar->SetPaneText(1,coords) ;
}
}
The behaviour of the output from these procedures is slightly different, but
both erroneous. (Almost) invariably the "x" coordinate outputted is correct.
However, the y coordinate is often incorrect and the orientation of the Y
axis is invariably inverted. The "z" coordinate is inconsistent. The quality
of the outputted coordinates seems to depend on the level of zoom and the
camera orientation. NB: I have set the Tolerance to 0.0001 for my own
vtkCellPicker, but I get a crash when I try to set the tolerance of the
vtkInteractor's picker.
I would appreciate any help. For this functionality to be useful it must be
consistently accurate.
Many thanks in advance,
Jim
______________________
James C. Robinson, PhD,
Chartered Engineer,
Kepler Simulation Systems Ltd.,
Unit 10,
Melbourne Business Park,
Model Farm Road,
Cork,
Eire
Tel: +353-21-4822028
Tel: +353-21-4817267
Tel: +353-87-2393010
Fax: +353-21-4822721
E-mail: j.robinson at kepler-systems.com
______________________
More information about the vtkusers
mailing list