<DIV>I'm 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 improve the code to get normal vector of every triangle which is made up by three points?</DIV>
<DIV> </DIV>
<DIV>I'm looking forward to your reply!Thanks!</DIV>
<DIV> </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> static PickCommand *New() { return new PickCommand; }<BR> void Delete() { delete this; }</DIV>
<DIV> virtual void Execute(vtkObject *caller, unsigned long l, void *callData)<BR> {</DIV>
<DIV> if (picker->GetCellId() < 0 )<BR> {<BR> textActor->VisibilityOff();<BR> }<BR> else<BR> {</DIV>
<DIV> double selpt[3];<BR> picker->GetSelectionPoint(selpt);<BR> double x = selpt[0];<BR> double y = selpt[1];<BR> double pickPos[3];<BR> picker->GetPickPosition( pickPos );<BR> double xp = pickPos[0];<BR> double yp = pickPos[1];<BR> double zp = pickPos[2];</DIV>
<DIV> char text[120];<BR> sprintf( text, "(%5.5f, %5.5f, %5.5f)", xp, yp, zp );<BR> textMapper->SetInput( text );</DIV>
<DIV> textActor->SetPosition(x, y);<BR> textActor->VisibilityOn();<BR> }</DIV>
<DIV> renWin->Render();<BR> }<BR>};</DIV>
<DIV><BR>void PickerInteractionCallback( vtkObject* vtkNotUsed(object),<BR> unsigned long event,<BR> void* clientdata,<BR> void* vtkNotUsed(calldata) )<BR>{<BR> vtkInteractorStyleTrackballCamera * style =<BR>(vtkInteractorStyleTrackballCamera*)clientdata;<BR> switch( event )<BR> {<BR> case vtkCommand::LeftButtonPressEvent:<BR> MouseMotion = 0;<BR> style->OnLeftButtonDown();<BR> break;<BR> case vtkCommand::LeftButtonReleaseEvent:<BR> if (MouseMotion == 0)<BR> {<BR> int *pick = iren->GetEventPosition();<BR> picker->Pick((double)pick[0], (double)pick[1], 0.0, ren1);<BR> }<BR> style->OnLeftButtonUp();<BR> break;<BR> case vtkCommand::MouseMoveEvent:<BR> MouseMotion = 1;<BR> style->OnMouseMove();<BR> break;<BR> }<BR>}</DIV>
<DIV><BR>int main(int argc, char* argv)<BR>{<BR> MouseMotion = 0;<BR> vtkSphereSource *sphere = vtkSphereSource::New();</DIV>
<DIV> vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();</DIV>
<DIV> sphereMapper->SetInput(sphere->GetOutput());<BR> sphereMapper->GlobalImmediateModeRenderingOn();</DIV>
<DIV> vtkLODActor *sphereActor = vtkLODActor::New();<BR> sphereActor->SetMapper(sphereMapper);</DIV>
<DIV>// create the spikes by glyphing the sphere with a cone. Create the mapper<BR>// and actor for the glyphs.<BR> vtkConeSource *cone = vtkConeSource::New();<BR> vtkGlyph3D *glyph = vtkGlyph3D::New();</DIV>
<DIV> glyph->SetInput(sphere->GetOutput());<BR> glyph->SetSource(cone->GetOutput());<BR> glyph->SetVectorModeToUseNormal();<BR> glyph->SetScaleModeToScaleByVector();<BR> glyph->SetScaleFactor(0.25);</DIV>
<DIV> vtkPolyDataMapper *spikeMapper = vtkPolyDataMapper::New();<BR> spikeMapper->SetInput(glyph->GetOutput());<BR> vtkLODActor *spikeActor = vtkLODActor::New();<BR> spikeActor->SetMapper(spikeMapper);</DIV>
<DIV>// Create a cell picker.<BR> PickCommand* pickObserver = PickCommand::New();<BR> picker = vtkCellPicker::New();<BR> picker->AddObserver( vtkCommand::EndPickEvent, pickObserver );</DIV>
<DIV>// Create a text mapper and actor to display the results of picking.<BR> textMapper = vtkTextMapper::New();<BR> vtkTextProperty *tprop = textMapper->GetTextProperty();<BR> tprop->SetFontFamilyToArial();<BR> tprop->SetFontSize(12);<BR> tprop->BoldOn();<BR>// tprop->ShadowOn();<BR> tprop->SetColor(1, 0, 0);<BR> textActor = vtkActor2D::New();<BR> textActor->VisibilityOff();<BR> textActor->SetMapper(textMapper);</DIV>
<DIV><BR>// Create the Renderer, RenderWindow, and RenderWindowInteractor</DIV>
<DIV><BR> vtkInteractorStyleTrackballCamera *style =<BR>vtkInteractorStyleTrackballCamera::New();<BR> vtkCallbackCommand * pickerCommand = vtkCallbackCommand::New();<BR> pickerCommand->SetClientData(style);<BR> pickerCommand->SetCallback(PickerInteractionCallback);<BR> style->AddObserver(vtkCommand::LeftButtonPressEvent, pickerCommand);<BR> style->AddObserver(vtkCommand::MouseMoveEvent, pickerCommand);<BR> style->AddObserver(vtkCommand::LeftButtonReleaseEvent, pickerCommand);</DIV>
<DIV> ren1 = vtkRenderer::New();<BR> renWin = vtkRenderWindow::New();<BR> renWin->AddRenderer(ren1);<BR> iren = vtkRenderWindowInteractor::New();<BR> iren->SetRenderWindow(renWin);<BR> iren->SetInteractorStyle(style);<BR> iren->SetPicker(picker);</DIV>
<DIV><BR>// Add the actors to the renderer, set the background and size</DIV>
<DIV><BR> ren1->AddActor2D(textActor);<BR> ren1->AddActor(sphereActor);<BR> ren1->AddActor(spikeActor);<BR> ren1->SetBackground(1, 1, 1);</DIV>
<DIV> renWin->SetSize(300, 300);</DIV>
<DIV>// Get the camera and zoom in closer to the image.<BR> vtkCamera *cam1 = ren1->GetActiveCamera();<BR> cam1->Zoom(1.4);</DIV>
<DIV> iren->Initialize();<BR> iren->Start();</DIV>
<DIV> picker->RemoveObserver( pickObserver );<BR> sphere->Delete();<BR> sphereMapper->Delete();<BR> sphereActor->Delete();<BR> cone->Delete();<BR> glyph->Delete();<BR> spikeMapper->Delete();<BR> spikeActor->Delete();<BR> picker->Delete();<BR> textMapper->Delete();<BR> textActor->Delete();<BR> pickerCommand->Delete();<BR> style->Delete();<BR> ren1->Delete();<BR> renWin->Delete();<BR> pickObserver->Delete();<BR>// iren->Delete();</DIV>
<DIV><BR> return 0;<BR>}</DIV>