<DIV>I'm&nbsp;a university student from China and I have learned VTK for some time.I studied an example of VTK which demonstrates cell picking using vtkCellPicker.My questions are followed:</DIV>
<DIV>1.where is (0,0,0) or where is the origin?</DIV>
<DIV>2.Can you help me do some improvement?This example uses a picture drawed by the code itself.How to improve the code to load a file of .ply and then get coordinate value?</DIV>
<DIV>3.This program only demonstrates the coordinate value when I click at somewhere.How to&nbsp;improve the code to get normal vector of every triangle which is made up by three points?</DIV>
<DIV>&nbsp;</DIV>
<DIV>I'm looking forward to your reply!Thanks!</DIV>
<DIV>&nbsp;</DIV>
<DIV>Here is the code:</DIV>
<DIV>#include "vtkSphereSource.h"<BR>#include "vtkPolyDataMapper.h"<BR>#include "vtkLODActor.h"<BR>#include "vtkConeSource.h"<BR>#include "vtkGlyph3D.h"<BR>#include "vtkCellPicker.h"<BR>#include "vtkTextMapper.h"<BR>#include "vtkActor2D.h"<BR>#include "vtkInteractorStyleTrackballCamera.h"<BR>#include "vtkRenderer.h"<BR>#include "vtkRenderWindow.h"<BR>#include "vtkRenderWindowInteractor.h"<BR>#include "vtkTextProperty.h"<BR>#include "vtkCallbackCommand.h"<BR>#include "vtkCamera.h"</DIV>
<DIV>int MouseMotion;<BR>vtkRenderer *ren1;<BR>vtkRenderWindow *renWin;<BR>vtkRenderWindowInteractor *iren;<BR>vtkCellPicker *picker;<BR>vtkActor2D *textActor;<BR>vtkTextMapper *textMapper;</DIV>
<DIV>class PickCommand : public vtkCommand<BR>{<BR>public:</DIV>
<DIV>&nbsp;&nbsp; static PickCommand *New() { return new PickCommand; }<BR>&nbsp;&nbsp; void Delete() { delete this; }</DIV>
<DIV>&nbsp;&nbsp; virtual void Execute(vtkObject *caller, unsigned long l, void *callData)<BR>&nbsp;&nbsp; {</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (picker-&gt;GetCellId() &lt; 0 )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textActor-&gt;VisibilityOff();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double selpt[3];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; picker-&gt;GetSelectionPoint(selpt);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double x = selpt[0];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double y = selpt[1];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double pickPos[3];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; picker-&gt;GetPickPosition( pickPos );<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double xp = pickPos[0];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double yp = pickPos[1];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double zp = pickPos[2];</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char text[120];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sprintf( text, "(%5.5f,&nbsp; %5.5f,&nbsp; %5.5f)", xp, yp, zp );<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textMapper-&gt;SetInput( text );</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textActor-&gt;SetPosition(x, y);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textActor-&gt;VisibilityOn();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; renWin-&gt;Render();<BR>&nbsp;&nbsp; }<BR>};</DIV>
<DIV><BR>void PickerInteractionCallback( vtkObject* vtkNotUsed(object),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned long event,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void* clientdata,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void* vtkNotUsed(calldata) )<BR>{<BR>&nbsp;&nbsp; vtkInteractorStyleTrackballCamera * style =<BR>(vtkInteractorStyleTrackballCamera*)clientdata;<BR>&nbsp;&nbsp; switch( event )<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp; case vtkCommand::LeftButtonPressEvent:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MouseMotion = 0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; style-&gt;OnLeftButtonDown();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR>&nbsp;&nbsp; case vtkCommand::LeftButtonReleaseEvent:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (MouseMotion == 0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int *pick = iren-&gt;GetEventPosition();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; picker-&gt;Pick((double)pick[0], (double)pick[1], 0.0, ren1);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; style-&gt;OnLeftButtonUp();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR>&nbsp;&nbsp; case vtkCommand::MouseMoveEvent:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MouseMotion = 1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; style-&gt;OnMouseMove();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<BR>&nbsp;&nbsp; }<BR>}</DIV>
<DIV><BR>int main(int argc, char* argv)<BR>{<BR>&nbsp;&nbsp; MouseMotion = 0;<BR>&nbsp;&nbsp; vtkSphereSource *sphere = vtkSphereSource::New();</DIV>
<DIV>&nbsp;&nbsp; vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();</DIV>
<DIV>&nbsp;&nbsp; sphereMapper-&gt;SetInput(sphere-&gt;GetOutput());<BR>&nbsp;&nbsp; sphereMapper-&gt;GlobalImmediateModeRenderingOn();</DIV>
<DIV>&nbsp;&nbsp; vtkLODActor *sphereActor = vtkLODActor::New();<BR>&nbsp;&nbsp; sphereActor-&gt;SetMapper(sphereMapper);</DIV>
<DIV>// create the spikes by glyphing the sphere with a cone.&nbsp; Create the mapper<BR>// and actor for the glyphs.<BR>&nbsp;&nbsp; vtkConeSource *cone = vtkConeSource::New();<BR>&nbsp;&nbsp; vtkGlyph3D *glyph = vtkGlyph3D::New();</DIV>
<DIV>&nbsp;&nbsp; glyph-&gt;SetInput(sphere-&gt;GetOutput());<BR>&nbsp;&nbsp; glyph-&gt;SetSource(cone-&gt;GetOutput());<BR>&nbsp;&nbsp; glyph-&gt;SetVectorModeToUseNormal();<BR>&nbsp;&nbsp; glyph-&gt;SetScaleModeToScaleByVector();<BR>&nbsp;&nbsp; glyph-&gt;SetScaleFactor(0.25);</DIV>
<DIV>&nbsp;&nbsp; vtkPolyDataMapper *spikeMapper = vtkPolyDataMapper::New();<BR>&nbsp;&nbsp; spikeMapper-&gt;SetInput(glyph-&gt;GetOutput());<BR>&nbsp;&nbsp; vtkLODActor *spikeActor = vtkLODActor::New();<BR>&nbsp;&nbsp; spikeActor-&gt;SetMapper(spikeMapper);</DIV>
<DIV>// Create a cell picker.<BR>&nbsp;&nbsp; PickCommand* pickObserver = PickCommand::New();<BR>&nbsp;&nbsp; picker = vtkCellPicker::New();<BR>&nbsp;&nbsp; picker-&gt;AddObserver( vtkCommand::EndPickEvent, pickObserver );</DIV>
<DIV>// Create a text mapper and actor to display the results of picking.<BR>&nbsp;&nbsp; textMapper = vtkTextMapper::New();<BR>&nbsp;&nbsp; vtkTextProperty *tprop = textMapper-&gt;GetTextProperty();<BR>&nbsp;&nbsp; tprop-&gt;SetFontFamilyToArial();<BR>&nbsp;&nbsp; tprop-&gt;SetFontSize(12);<BR>&nbsp;&nbsp; tprop-&gt;BoldOn();<BR>//&nbsp;&nbsp;&nbsp; tprop-&gt;ShadowOn();<BR>&nbsp;&nbsp; tprop-&gt;SetColor(1, 0, 0);<BR>&nbsp;&nbsp; textActor = vtkActor2D::New();<BR>&nbsp;&nbsp; textActor-&gt;VisibilityOff();<BR>&nbsp;&nbsp; textActor-&gt;SetMapper(textMapper);</DIV>
<DIV><BR>// Create the Renderer, RenderWindow, and RenderWindowInteractor</DIV>
<DIV><BR>&nbsp;&nbsp; vtkInteractorStyleTrackballCamera *style =<BR>vtkInteractorStyleTrackballCamera::New();<BR>&nbsp;&nbsp; vtkCallbackCommand * pickerCommand = vtkCallbackCommand::New();<BR>&nbsp;&nbsp; pickerCommand-&gt;SetClientData(style);<BR>&nbsp;&nbsp; pickerCommand-&gt;SetCallback(PickerInteractionCallback);<BR>&nbsp;&nbsp; style-&gt;AddObserver(vtkCommand::LeftButtonPressEvent, pickerCommand);<BR>&nbsp;&nbsp; style-&gt;AddObserver(vtkCommand::MouseMoveEvent, pickerCommand);<BR>&nbsp;&nbsp; style-&gt;AddObserver(vtkCommand::LeftButtonReleaseEvent, pickerCommand);</DIV>
<DIV>&nbsp;&nbsp; ren1 = vtkRenderer::New();<BR>&nbsp;&nbsp; renWin = vtkRenderWindow::New();<BR>&nbsp;&nbsp; renWin-&gt;AddRenderer(ren1);<BR>&nbsp;&nbsp; iren = vtkRenderWindowInteractor::New();<BR>&nbsp;&nbsp; iren-&gt;SetRenderWindow(renWin);<BR>&nbsp;&nbsp; iren-&gt;SetInteractorStyle(style);<BR>&nbsp;&nbsp; iren-&gt;SetPicker(picker);</DIV>
<DIV><BR>// Add the actors to the renderer, set the background and size</DIV>
<DIV><BR>&nbsp;&nbsp; ren1-&gt;AddActor2D(textActor);<BR>&nbsp;&nbsp; ren1-&gt;AddActor(sphereActor);<BR>&nbsp;&nbsp; ren1-&gt;AddActor(spikeActor);<BR>&nbsp;&nbsp; ren1-&gt;SetBackground(1, 1, 1);</DIV>
<DIV>&nbsp;&nbsp; renWin-&gt;SetSize(300, 300);</DIV>
<DIV>// Get the camera and zoom in closer to the image.<BR>&nbsp;&nbsp; vtkCamera *cam1 = ren1-&gt;GetActiveCamera();<BR>&nbsp;&nbsp; cam1-&gt;Zoom(1.4);</DIV>
<DIV>&nbsp;&nbsp; iren-&gt;Initialize();<BR>&nbsp;&nbsp; iren-&gt;Start();</DIV>
<DIV>&nbsp;&nbsp; picker-&gt;RemoveObserver( pickObserver );<BR>&nbsp;&nbsp; sphere-&gt;Delete();<BR>&nbsp;&nbsp; sphereMapper-&gt;Delete();<BR>&nbsp;&nbsp; sphereActor-&gt;Delete();<BR>&nbsp;&nbsp; cone-&gt;Delete();<BR>&nbsp;&nbsp; glyph-&gt;Delete();<BR>&nbsp;&nbsp; spikeMapper-&gt;Delete();<BR>&nbsp;&nbsp; spikeActor-&gt;Delete();<BR>&nbsp;&nbsp; picker-&gt;Delete();<BR>&nbsp;&nbsp; textMapper-&gt;Delete();<BR>&nbsp;&nbsp; textActor-&gt;Delete();<BR>&nbsp;&nbsp; pickerCommand-&gt;Delete();<BR>&nbsp;&nbsp; style-&gt;Delete();<BR>&nbsp;&nbsp; ren1-&gt;Delete();<BR>&nbsp;&nbsp; renWin-&gt;Delete();<BR>&nbsp;&nbsp; pickObserver-&gt;Delete();<BR>//&nbsp;&nbsp;&nbsp; iren-&gt;Delete();</DIV>
<DIV><BR>&nbsp;&nbsp; return 0;<BR>}</DIV>