<div dir="ltr"><div>Hello,</div><div><br></div><div>While I wait for the book arrive, I tried to create basic selection from examples.</div><div><br></div><div>In the following example you can do:</div><div>click + Shift over sphere --> creates a small sphere on it</div><div>click + Alt over small spheres --> select the actor. In the second selection creates a line between its centers.</div><div><br></div><div>click + Shift on empty space --> creates a point (green, there are 3 blue points by default)</div><div><br></div><div><br></div><div>My problem: I can not create a line between points because I do not know how to select the actor of my new points.</div><div><br></div><div>Why a sphere is "selectable" and a point is not in this context?</div><div><br></div><div><br></div><div>As I said, I'm waiting the VTK book arrive and from help I could not get what I misunderstood.</div><div><br></div><div><br></div><div><br></div><div>I saw HighlightSelectedPoints, but I do not want a rectangular area, I want to select only one point by clicking.</div><div><br></div><div>My idea is a basic editor for add/remove point, line, arc., so the first thing is how to select a point to gets its coordinates.</div><div><br></div><div><br></div><div>Thanks in advance for play with this code and tell me any example that drives this task.</div><div><br></div><div><br></div><div>Best Regards,</div><div><br></div><div>Juan Pablo</div><div><br></div><div><br></div><div><br></div><div>[code from Internet]</div><div><br></div><div><div><font face="courier new, monospace">/*</font></div><div><font face="courier new, monospace"> This example demonstrates cell picking using vtkCellPicker.  It displays</font><span style="font-family:'courier new',monospace"> the results of picking using a vtkTextMapper.</span></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"> converted from TCL</font></div><div><font face="courier new, monospace">*/</font></div><div><font face="courier new, monospace">#include "vtkSphereSource.h"</font></div><div><font face="courier new, monospace">#include "vtkPolyDataMapper.h"</font></div><div><font face="courier new, monospace">#include "vtkLODActor.h"</font></div><div><font face="courier new, monospace">#include "vtkConeSource.h"</font></div><div><font face="courier new, monospace">#include "vtkGlyph3D.h"</font></div><div><font face="courier new, monospace">#include "vtkCellPicker.h"</font></div><div><font face="courier new, monospace">#include "vtkTextMapper.h"</font></div><div><font face="courier new, monospace">#include "vtkActor2D.h"</font></div><div><font face="courier new, monospace">#include "vtkInteractorStyleTrackballCamera.h"</font></div><div><font face="courier new, monospace">#include "vtkInteractorStyleRubberBand2D.h"</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">#include "vtkRenderer.h"</font></div><div><font face="courier new, monospace">#include "vtkRenderWindow.h"</font></div><div><font face="courier new, monospace">#include "vtkRenderWindowInteractor.h"</font></div><div><font face="courier new, monospace">#include "vtkTextProperty.h"</font></div><div><font face="courier new, monospace">#include "vtkCallbackCommand.h"</font></div><div><font face="courier new, monospace">#include "vtkCamera.h"</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">#include "vtkSmartPointer.h"</font></div><div><font face="courier new, monospace">#include "vtkProperty.h"</font></div><div><font face="courier new, monospace">#include "vtkLineSource.h"</font></div><div><font face="courier new, monospace">#include "vtkCellArray.h"</font></div><div><font face="courier new, monospace">#include "vtkLine.h"</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">vtkPoints* points;</font></div><div><font face="courier new, monospace">vtkCellArray* vertices;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">int MouseMotion;</font></div><div><font face="courier new, monospace">int SelectLine;</font></div><div><font face="courier new, monospace">vtkRenderer *ren1;</font></div><div><font face="courier new, monospace">vtkRenderWindow *renWin;</font></div><div><font face="courier new, monospace">vtkRenderWindowInteractor *iren;</font></div><div><font face="courier new, monospace">vtkCellPicker *picker;</font></div><div><font face="courier new, monospace">vtkActor2D *textActor;</font></div><div><font face="courier new, monospace">vtkTextMapper *textMapper;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">vtkActor* selectionActor1;</font></div><div><font face="courier new, monospace">vtkActor* selectionActor2;</font></div><div><font face="courier new, monospace">vtkCellPicker *pickerPointActor;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">vtkPolyData* pointPolyData;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">#define VTK_CREATE(type, name) \</font></div><div><font face="courier new, monospace">  vtkSmartPointer<type> name = vtkSmartPointer<type>::New()</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">void addPointActor(double p[3], vtkRenderer* renderer)</font></div><div><font face="courier new, monospace">{</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>// Create the geometry of a point (the coordinate)</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();</font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">      </span>// Create the topology of the point (a vertex)</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">    </span>vtkSmartPointer<vtkCellArray> vertices = vtkSmartPointer<vtkCellArray>::New();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>vtkIdType pid, cid;</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">       </span>pid = points->InsertNextPoint(p);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">      </span>cid = vertices->InsertNextCell(1, &pid);</font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>cout<<"addPointActor: pid="<<pid<<endl;</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">       </span>cout<<"addPointActor: cid="<<cid<<endl;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">     </span>// Create a polydata object</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">       </span>vtkSmartPointer<vtkPolyData> point = vtkSmartPointer<vtkPolyData>::New();</font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">   </span>// Set the points and vertices we created as the geometry and topology of the polydata</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">    </span>point->SetPoints(points);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">      </span>point->SetVerts(vertices);</font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">   </span>// Visualize</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">      </span>vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>#if VTK_MAJOR_VERSION <= 5</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">     </span>mapper->SetInput(point);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">       </span>#else</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">     </span>mapper->SetInputData(point);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">   </span>#endif</font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">  </span>vtkSmartPointer<vtkActor> actor =</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">   </span>vtkSmartPointer<vtkActor>::New();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">   </span>actor->SetMapper(mapper);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">      </span>actor->GetProperty()->SetPointSize(10);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">     </span>actor->GetProperty()->SetColor(0,0.5,0);</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">  </span>renderer->AddActor(actor);</font></div><div><font face="courier new, monospace">}</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">void addShpereActor(double p[3], vtkRenderer* renderer)</font></div><div><font face="courier new, monospace">{</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">  </span>vtkSmartPointer<vtkSphereSource> SphereSource = vtkSmartPointer<vtkSphereSource>::New();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">      </span>SphereSource->SetCenter(p);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">    </span>SphereSource->SetRadius(0.01);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>SphereSource->Update();</font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">      </span>vtkSmartPointer<vtkPolyDataMapper> Mapper = vtkSmartPointer<vtkPolyDataMapper>::New();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>Mapper->SetInput(SphereSource->GetOutput());</font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">      </span>vtkSmartPointer<vtkActor> Actor = vtkSmartPointer<vtkActor>::New();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">   </span>Actor->SetMapper(Mapper);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">      </span>Actor->GetProperty()->SetColor(255,0,0);</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">  </span>renderer->AddActor(Actor);</font></div><div><font face="courier new, monospace">}</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">class PickCommand : public vtkCommand</font></div><div><font face="courier new, monospace">{</font></div><div><font face="courier new, monospace">public:</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">    static PickCommand *New() { return new PickCommand; }</font></div><div><font face="courier new, monospace">    void Delete() { delete this; }</font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace">    virtual void Execute(vtkObject *caller, unsigned long l, void *callData)</font></div><div><font face="courier new, monospace">    {</font></div><div><font face="courier new, monospace">        if (picker->GetCellId() < 0 )</font></div><div><font face="courier new, monospace">        {</font></div><div><font face="courier new, monospace">            textActor->VisibilityOff();</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                     </span>double selpt[3];</font></div><div><font face="courier new, monospace">            picker->GetSelectionPoint(selpt); // Coordinates in the window space</font></div><div><font face="courier new, monospace">            double x = selpt[0];</font></div><div><font face="courier new, monospace">            double y = selpt[1];</font></div><div><font face="courier new, monospace">            double pickPos[3];</font></div><div><font face="courier new, monospace">            picker->GetPickPosition( pickPos ); // Coordinates in geometrical space</font></div><div><font face="courier new, monospace">            double xp = pickPos[0];</font></div><div><font face="courier new, monospace">            double yp = pickPos[1];</font></div><div><font face="courier new, monospace">            double zp = pickPos[2];</font></div><div><font face="courier new, monospace">       </font></div><div><font face="courier new, monospace">            char text[120];</font></div><div><font face="courier new, monospace">            sprintf( text, "(%5.5f,  %5.5f,  %5.5f)", selpt[0], selpt[1], selpt[2] );</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                       </span>cout <<"Click outside, selpt: "<< text << endl;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                     </span>sprintf( text, "(%5.5f,  %5.5f,  %5.5f)", xp, yp, zp );</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                       </span>cout <<"Click outside, pickPos: "<< text << endl;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">#define ADD_OUTSIDE_ACTOR</font></div><div><font face="courier new, monospace">#ifdef ADD_OUTSIDE_ACTOR</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                  </span>addPointActor(pickPos, ren1);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                             </span>/*</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                        </span>vtkSmartPointer<vtkSphereSource> SphereSource = vtkSmartPointer<vtkSphereSource>::New();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                      </span>SphereSource->SetCenter(xp, yp, zp);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                   </span>SphereSource->SetRadius(0.01);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                 </span>SphereSource->Update();</font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                      </span>vtkSmartPointer<vtkPolyDataMapper> Mapper = vtkSmartPointer<vtkPolyDataMapper>::New();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                        </span>Mapper->SetInput(SphereSource->GetOutput());</font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                      </span>vtkSmartPointer<vtkActor> Actor = vtkSmartPointer<vtkActor>::New();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                   </span>Actor->SetMapper(Mapper);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                      </span>//vtkProperty* color = Actor->GetProperty();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                   </span>//color-></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                      </span>Actor->GetProperty()->SetColor(255,0,0);</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                  </span>ren1->AddActor(Actor);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                 </span>*/</font></div><div><font face="courier new, monospace">#else</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                 </span>pointPolyData->BuildLinks();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                   </span>pointPolyData->DeleteCell(0);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                  </span>pointPolyData->RemoveDeletedCells();</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                 </span>//vertices->rem</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                        </span>vtkIdType pid,cid;</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                        </span>pid = points->InsertNextPoint(xp, yp, zp);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                     </span>cid = vertices->InsertNextCell(1,&pid);</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                      </span>int a = 2* cid;</font></div><div><font face="courier new, monospace">#endif</font></div><div><font face="courier new, monospace">        }</font></div><div><font face="courier new, monospace">        else</font></div><div><font face="courier new, monospace">        {</font></div><div><font face="courier new, monospace">            double selpt[3];</font></div><div><font face="courier new, monospace">            picker->GetSelectionPoint(selpt);</font></div><div><font face="courier new, monospace">            double x = selpt[0];</font></div><div><font face="courier new, monospace">            double y = selpt[1];</font></div><div><font face="courier new, monospace">            double pickPos[3];</font></div><div><font face="courier new, monospace">            picker->GetPickPosition( pickPos );</font></div><div><font face="courier new, monospace">            double xp = pickPos[0];</font></div><div><font face="courier new, monospace">            double yp = pickPos[1];</font></div><div><font face="courier new, monospace">            double zp = pickPos[2];</font></div><div><font face="courier new, monospace">       </font></div><div><font face="courier new, monospace">            char text[120];</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                    </span>sprintf( text, "(%5.5f,  %5.5f,  %5.5f)", selpt[0], selpt[1], selpt[2] );</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                     </span>cout <<"Click inside, selpt: "<< text << endl;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                      </span>sprintf( text, "(%5.5f,  %5.5f,  %5.5f)", xp, yp, zp );</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                       </span>cout <<"Click inside, pickPos: "<< text << endl;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">            textMapper->SetInput( text );</font></div><div><font face="courier new, monospace">            textActor->SetPosition(x, y);</font></div><div><font face="courier new, monospace">            textActor->VisibilityOn();</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                   </span>vtkSmartPointer<vtkSphereSource> SphereSource = vtkSmartPointer<vtkSphereSource>::New();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                      </span>SphereSource->SetCenter(xp, yp, zp);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                   </span>SphereSource->SetRadius(0.01);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                 </span>SphereSource->Update();</font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                      </span>vtkSmartPointer<vtkPolyDataMapper> Mapper = vtkSmartPointer<vtkPolyDataMapper>::New();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                        </span>Mapper->SetInput(SphereSource->GetOutput());</font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                      </span>vtkSmartPointer<vtkActor> Actor = vtkSmartPointer<vtkActor>::New();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                   </span>Actor->SetMapper(Mapper);</font></div><div><span class="" style="white-space:pre"><font face="courier new, monospace">                      </font></span></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                  </span>ren1->AddActor(Actor);</font></div><div><font face="courier new, monospace">        }</font></div><div><font face="courier new, monospace">   </font></div><div><font face="courier new, monospace">        renWin->Render();</font></div><div><font face="courier new, monospace">    }</font></div><div><font face="courier new, monospace">};</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">class PickPointActorCommand : public vtkCommand</font></div><div><font face="courier new, monospace">{</font></div><div><font face="courier new, monospace">public:</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">    static PickPointActorCommand *New() { return new PickPointActorCommand; }</font></div><div><font face="courier new, monospace">    void Delete() { delete this; }</font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace">    virtual void Execute(vtkObject *caller, unsigned long l, void *callData)</font></div><div><font face="courier new, monospace">    {</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">               </span>vtkPicker* currentPicker = (vtkPicker*) caller;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">         </span>vtkProp* prop = currentPicker->GetViewProp();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">          </span>vtkProp3D* prop3d = currentPicker->GetProp3D();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                </span>cout<<"prop="<<prop<<endl;</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">            </span>cout<<"prop3D="<<prop3d<<endl;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">              </span>cout<<"currentCellId="<<picker->GetCellId()<<endl;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">               </span>vtkActor* actor = currentPicker->GetActor();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">           </span>if (actor)</font></div><div><font face="courier new, monospace">        {</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                   </span>cout<<"PickPointActorCommand: there is actor" <<endl;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                     </span>if (selectionActor1==0)</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                   </span>{</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                         </span>// Mark start point</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                               </span>selectionActor1 = actor;</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                  </span>}</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                 </span>else</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                      </span>{</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                         </span>// Mark end point</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                         </span>selectionActor2 = actor;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                                </span>// Create line:</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                         </span>// Get center of actors</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                           </span>double bounds[6], center1[3], center2[3];</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                               </span>selectionActor1->GetBounds(bounds);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                            </span>center1[0] = (bounds[1]+bounds[0])/2;</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                             </span>center1[1] = (bounds[3]+bounds[2])/2;</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                             </span>center1[2] = (bounds[5]+bounds[4])/2;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                           </span>selectionActor2->GetBounds(bounds);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                            </span>center2[0] = (bounds[1]+bounds[0])/2;</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                             </span>center2[1] = (bounds[3]+bounds[2])/2;</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                             </span>center2[2] = (bounds[5]+bounds[4])/2;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                           </span>// Create source</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                          </span>vtkSmartPointer<vtkLineSource> lineSource = vtkSmartPointer<vtkLineSource>::New();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                            </span>lineSource->SetPoint1(center1);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                                </span>lineSource->SetPoint2(center2);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                                </span>lineSource->Update();</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                                </span>// Visualize</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                              </span>vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                                </span>mapper->SetInputConnection(lineSource->GetOutputPort());</font></div><div><span class="" style="white-space:pre"><font face="courier new, monospace">                            </font></span></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                          </span>vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                           </span>actor->SetMapper(mapper);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                              </span>actor->GetProperty()->SetLineWidth(2);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                              </span>actor->GetProperty()->SetColor(255,0,255);</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                                </span>// Activate</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                               </span>ren1->AddActor(actor);</font></div><div><span class="" style="white-space:pre"><font face="courier new, monospace">                         </font></span></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                          </span>// remove prvious selection</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                               </span>selectionActor1 = selectionActor2 = 0;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                          </span>SelectLine = 0; // stop selection</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                 </span>}</font></div><div><font face="courier new, monospace">        }</font></div><div><font face="courier new, monospace">        else</font></div><div><font face="courier new, monospace">        {</font></div><div><font face="courier new, monospace">            // No actor selected</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                 </span>cout<<"PickPointActorCommand: there is NO actor" <<endl;</font></div><div><font face="courier new, monospace">        }</font></div><div><font face="courier new, monospace">   </font></div><div><font face="courier new, monospace">        renWin->Render();</font></div><div><font face="courier new, monospace">    }</font></div><div><font face="courier new, monospace">};</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">void PickerInteractionCallback( vtkObject* vtkNotUsed(object),</font></div><div><font face="courier new, monospace">                                       unsigned long event,</font></div><div><font face="courier new, monospace">                                       void* clientdata,</font></div><div><font face="courier new, monospace">                                       void* vtkNotUsed(calldata) )</font></div><div><font face="courier new, monospace">{</font></div><div><font face="courier new, monospace">    vtkInteractorStyleTrackballCamera * style = (vtkInteractorStyleTrackballCamera*)clientdata;</font></div><div><span class="" style="white-space:pre"><font face="courier new, monospace">   </font></span></div><div><font face="courier new, monospace">    switch( event )</font></div><div><font face="courier new, monospace">    {</font></div><div><font face="courier new, monospace">    case vtkCommand::LeftButtonPressEvent:</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">          </span>//cout<<"PickerInteractionCallback::LeftButtonPressEvent"<<endl;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">          </span>if (iren->GetAltKey())</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">         </span>{</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                 </span>SelectLine = 1;</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                   </span>//cout<<"SelectLine = 1"<<endl;</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">             </span>}</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">         </span>else</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">              </span>{</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                 </span>selectionActor1 = selectionActor2 = 0;</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                    </span>SelectLine = 0; // stop selection</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                 </span>//cout<<"SelectLine = 0"<<endl;</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">             </span>}</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">               </span>MouseMotion = 0;</font></div><div><font face="courier new, monospace">        style->OnLeftButtonDown();</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">        break;</font></div><div><font face="courier new, monospace">    case vtkCommand::LeftButtonReleaseEvent:</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">               </span>//cout<<"PickerInteractionCallback::LeftButtonReleaseEvent"<<endl;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                </span>if (SelectLine == 1)</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">              </span>{</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                 </span>int *pick = iren->GetEventPosition();</font></div><div><font face="courier new, monospace">            pickerPointActor->Pick((double)pick[0], (double)pick[1], 0.0, ren1);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">         </span>}</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">         </span>else if (MouseMotion == 0)</font></div><div><font face="courier new, monospace">        {</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                   </span>if (iren->GetShiftKey())</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                       </span>{</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                         </span>int *pick = iren->GetEventPosition();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                          </span>picker->Pick((double)pick[0], (double)pick[1], 0.0, ren1);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">                     </span>}</font></div><div><font face="courier new, monospace">        }</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">        style->OnLeftButtonUp();</font></div><div><font face="courier new, monospace">        break;</font></div><div><font face="courier new, monospace">    case vtkCommand::MouseMoveEvent:</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">           </span>//cout<<"PickerInteractionCallback::MouseMoveEvent"<<endl;</font></div><div><span class="" style="white-space:pre"><font face="courier new, monospace">          </font></span></div><div><font face="courier new, monospace">        MouseMotion = 1;</font></div><div><font face="courier new, monospace">        style->OnMouseMove();</font></div><div><font face="courier new, monospace">        break;</font></div><div><font face="courier new, monospace">    }</font></div><div><font face="courier new, monospace">}</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">int main(int argc, char* argv)</font></div><div><font face="courier new, monospace">{</font></div><div><font face="courier new, monospace">    MouseMotion = 0;</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">       </span>SelectLine = 0;</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>// Original code:</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>vtkSphereSource *sphere = vtkSphereSource::New();</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">    vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();</font></div><div><font face="courier new, monospace">    sphereMapper->SetInput(sphere->GetOutput());</font></div><div><font face="courier new, monospace">    sphereMapper->GlobalImmediateModeRenderingOn();</font></div><div><font face="courier new, monospace">    vtkLODActor *sphereActor = vtkLODActor::New();</font></div><div><font face="courier new, monospace">    sphereActor->SetMapper(sphereMapper);</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">// create the spikes by glyphing the sphere with a cone.  Create the mapper</font></div><div><font face="courier new, monospace">// and actor for the glyphs.</font></div><div><font face="courier new, monospace">    vtkConeSource *cone = vtkConeSource::New();</font></div><div><font face="courier new, monospace">    vtkGlyph3D *glyph = vtkGlyph3D::New();</font></div><div><font face="courier new, monospace">    glyph->SetInput(sphere->GetOutput());</font></div><div><font face="courier new, monospace">    glyph->SetSource(cone->GetOutput());</font></div><div><font face="courier new, monospace">    glyph->SetVectorModeToUseNormal();</font></div><div><font face="courier new, monospace">    glyph->SetScaleModeToScaleByVector();</font></div><div><font face="courier new, monospace">    glyph->SetScaleFactor(0.25);</font></div><div><font face="courier new, monospace">    vtkPolyDataMapper *spikeMapper = vtkPolyDataMapper::New();</font></div><div><font face="courier new, monospace">    spikeMapper->SetInput(glyph->GetOutput());</font></div><div><font face="courier new, monospace">    vtkLODActor *spikeActor = vtkLODActor::New();</font></div><div><font face="courier new, monospace">    spikeActor->SetMapper(spikeMapper);</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">// Create a cell picker.</font></div><div><font face="courier new, monospace">    PickCommand* pickObserver = PickCommand::New();</font></div><div><font face="courier new, monospace">    picker = vtkCellPicker::New();</font></div><div><font face="courier new, monospace">    picker->AddObserver( vtkCommand::EndPickEvent, pickObserver );</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">// Create a Actor picker.</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">    </span>PickPointActorCommand* pickPointActorObserver = PickPointActorCommand::New();</font></div><div><font face="courier new, monospace">    pickerPointActor = vtkCellPicker::New();</font></div><div><font face="courier new, monospace">    pickerPointActor->AddObserver( vtkCommand::EndPickEvent, pickPointActorObserver );</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">// Create a text mapper and actor to display the results of picking.</font></div><div><font face="courier new, monospace">    textMapper = vtkTextMapper::New();</font></div><div><font face="courier new, monospace">    vtkTextProperty *tprop = textMapper->GetTextProperty();</font></div><div><font face="courier new, monospace">    tprop->SetFontFamilyToArial();</font></div><div><font face="courier new, monospace">    tprop->SetFontSize(12);</font></div><div><font face="courier new, monospace">    tprop->BoldOn();</font></div><div><font face="courier new, monospace">//    tprop->ShadowOn();</font></div><div><font face="courier new, monospace">    tprop->SetColor(1, 0, 0);</font></div><div><font face="courier new, monospace">    textActor = vtkActor2D::New();</font></div><div><font face="courier new, monospace">    textActor->VisibilityOff();</font></div><div><font face="courier new, monospace">    textActor->SetMapper(textMapper);</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">// Create the Renderer, RenderWindow, and RenderWindowInteractor</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">    vtkInteractorStyleTrackballCamera *style = vtkInteractorStyleTrackballCamera::New();</font></div><div><font face="courier new, monospace">    vtkCallbackCommand * pickerCommand = vtkCallbackCommand::New();</font></div><div><font face="courier new, monospace">    pickerCommand->SetClientData(style);</font></div><div><font face="courier new, monospace">    pickerCommand->SetCallback(PickerInteractionCallback);</font></div><div><font face="courier new, monospace">    style->AddObserver(vtkCommand::LeftButtonPressEvent, pickerCommand);</font></div><div><font face="courier new, monospace">    style->AddObserver(vtkCommand::MouseMoveEvent, pickerCommand);</font></div><div><font face="courier new, monospace">    style->AddObserver(vtkCommand::LeftButtonReleaseEvent, pickerCommand);</font></div><div><font face="courier new, monospace">    ren1 = vtkRenderer::New();</font></div><div><font face="courier new, monospace">    renWin = vtkRenderWindow::New();</font></div><div><font face="courier new, monospace">    renWin->AddRenderer(ren1);</font></div><div><font face="courier new, monospace">    iren = vtkRenderWindowInteractor::New();</font></div><div><font face="courier new, monospace">    iren->SetRenderWindow(renWin);</font></div><div><font face="courier new, monospace">    iren->SetInteractorStyle(style); // Is who calls the picker</font></div><div><font face="courier new, monospace">    //iren->SetPicker(picker);</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">// Add the actors to the renderer, set the background and size</font></div><div><span class="" style="white-space:pre"><font face="courier new, monospace">    </font></span></div><div><font face="courier new, monospace">    ren1->AddActor2D(textActor);</font></div><div><font face="courier new, monospace">    ren1->AddActor(sphereActor);</font></div><div><font face="courier new, monospace">    ren1->AddActor(spikeActor);</font></div><div><font face="courier new, monospace">    ren1->SetBackground(1, 1, 1);</font></div><div><span class="" style="white-space:pre"><font face="courier new, monospace">      </font></span></div><div><font face="courier new, monospace">    renWin->SetSize(500, 500);</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">// Get the camera and zoom in closer to the image.</font></div><div><font face="courier new, monospace">    vtkCamera *cam1 = ren1->GetActiveCamera();</font></div><div><font face="courier new, monospace">    //cam1->Zoom(1);</font></div><div><span class="" style="white-space:pre"><font face="courier new, monospace">       </font></span></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">    </span>// Create the geometry of a point (the coordinate), 3 points:</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">   </span>//vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">      </span>points = vtkPoints::New();</font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">      </span>// Create the topology of the point (a vertex)</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">    </span>//vtkSmartPointer<vtkCellArray> vertices =  vtkSmartPointer<vtkCellArray>::New();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">    </span>vertices = vtkCellArray::New();</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>vtkIdType pid;</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">    </span>pid = points->InsertNextPoint(1,1,0);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">  </span>vertices->InsertNextCell(1,&pid);</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>pid = points->InsertNextPoint(1,-1,0);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>vertices->InsertNextCell(1,&pid);</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>pid = points->InsertNextPoint(1,1,1);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">  </span>vertices->InsertNextCell(1,&pid);</font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>//vtkSmartPointer<vtkLine> line0 = vtkSmartPointer<vtkLine>::New();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">   </span>//line0->GetPointIds()->SetId(0, 0);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>//line0->GetPointIds()->SetId(1, 1);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>//vertices->InsertNextCell(line0);</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">   </span>// Create a polydata object</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">       </span>pointPolyData = vtkPolyData::New();</font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">     </span>// Set the points and vertices we created as the geometry and topology of the polydata</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">    </span>pointPolyData->SetPoints(points);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">      </span>pointPolyData->SetVerts(vertices);</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>// Visualize</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">      </span>vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>#if VTK_MAJOR_VERSION <= 5</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">     </span>mapper->SetInput(pointPolyData);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">       </span>#else</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">     </span>mapper->SetInputData(pointPolyData);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">   </span>#endif</font></div><div><font face="courier new, monospace"> </font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">  </span>vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">   </span>actor->SetMapper(mapper);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">      </span>actor->GetProperty()->SetPointSize(10);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">     </span>actor->GetProperty()->SetColor(0,0,255);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">    </span>actor->GetProperty()->SetLineWidth(5);</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">      </span>ren1->AddActor(actor);</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">    iren->Initialize();</font></div><div><font face="courier new, monospace">    iren->Start();</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">    picker->RemoveObserver( pickObserver );</font></div><div><font face="courier new, monospace">    sphere->Delete();</font></div><div><font face="courier new, monospace">    sphereMapper->Delete();</font></div><div><font face="courier new, monospace">    sphereActor->Delete();</font></div><div><font face="courier new, monospace">    cone->Delete();</font></div><div><font face="courier new, monospace">    glyph->Delete();</font></div><div><font face="courier new, monospace">    spikeMapper->Delete();</font></div><div><font face="courier new, monospace">    spikeActor->Delete();</font></div><div><font face="courier new, monospace">    picker->Delete();</font></div><div><font face="courier new, monospace">    textMapper->Delete();</font></div><div><font face="courier new, monospace">    textActor->Delete();</font></div><div><font face="courier new, monospace">    pickerCommand->Delete();</font></div><div><font face="courier new, monospace">    style->Delete();</font></div><div><font face="courier new, monospace">    ren1->Delete();</font></div><div><font face="courier new, monospace">    renWin->Delete();</font></div><div><font face="courier new, monospace">    pickObserver->Delete();</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">        </span>vertices->Delete();</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre">    </span>points->Delete();</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">    iren->Delete();</font></div><div><font face="courier new, monospace">}</font></div></div><div><br></div></div>