[vtkusers] Problem with vtkPoint::GetPoint(vtk IdType)

Amy Squillacote amy.squillacote at kitware.com
Thu Apr 27 08:50:49 EDT 2006


Hi Ashley,

I'm copying this back to the vtkusers list so other people can help 
too in solving this problem.

- Amy

At 09:35 PM 4/26/2006, you wrote:
>Hi Amy,
>
>m_Points are the coordinates of the created points.
>I'm trying to get the coordinates of the point id 1.
>I've tried using id 0, but it doesn't seems to work too.
>
>Here's my code again.
>
>//Usual render stuffs
>//Create Points
>vtkPoints *pts = vtkPoints::New();
>pts->InsertPoint (0, 0, 3, 0);
>pts->InsertPoint (1, 1, 2, 0);
>pts->InsertPoint (2, 0, 2, 1);
>pts->InsertPoint (3, -1, 2, 0);
>pts->InsertPoint (4, 0, 2, -1);
>
>//Create Lines to link points
>vtkCellArray *lines = vtkCellArray::New();
>  lines->InsertNextCell (3);
>  lines->InsertCellPoint (1);
>  lines->InsertCellPoint (0);
>  lines->InsertCellPoint (2);
>
>  lines->InsertNextCell (3);
>  lines->InsertCellPoint (3);
>  lines->InsertCellPoint (0);
>  lines->InsertCellPoint (4);
>
>vtkPolyData *pd = vtkPolyData::New();
>pd->SetPoints(pts);
>pd->SetLines(lines);
>
>//Create tubes around the lines
>//Create Sphere
>vtkSphereSource *sphere = vtkSphereSource::New();
>
>//Map sphere to every input points
>vtkGlyph3D *spheres = vtkGlyph3D::New();
>spheres->SetInput(pd);
>spheres->SetSource(sphere->GetOutput());
>
>vtkPolyDataMapper *sphereMapper= vtkPolyDataMapper::New();
>sphereMapper->SetInputConnection(spheres->GetOutputPort());
>
>vtkActor *sphereActor = vtkActor::New();
>sphereActor->SetMapper(sphereMapper);
>
>//Create text as marker when pick
>//Create camera
>//Add spheresActors, edgeActors (the tubes) and textActors (text markers)
>
>//Create callback command
>PropCaller *caller = PropCaller::New();
>caller->SetRenderer (ren);
>caller->SetSelectionActor (textActor[0]); //set it to the first text only
>caller->SetPoints (pts); //passing in the pointer pts so that i can 
>get the coordinates in my subclass PropCaller for comparison
>
>renWin->Render();
>iren->AddObserver (vtkCommand::CharEvent, caller);
>iren->Start();
>
>///// In my PropCaller class //////
>class PropCaller : public vtkCommand {
>public:
>        static PropCaller *New() {return new PropCaller;}
>        void SetSelectionActor(vtkActor* marker){m_Marker = marker;}
>        void SetRenderer (vtkRenderer *myRenderer);
>        virtual vtkRenderer *MakeRenderer();
>        vtkRenderer *GetRenderer ();
>        void SetPoint(vtkPoints* pts) {
>               m_Points = pts;
>        }
>        virtual void Execute (vtkObject *caller, unsigned long, void*) {
>               int x,y;
>               vtkRenderWindowInteractor *iren = 
> reinterpret_cast<vtkRenderWindowInteractor*>(caller);
>               iren->GetEventPosition(x, y);
>               vtkPropPicker *picker = vtkPropPicker::New();
>               picker->Pick(x,y,0,this->renderer);
>               vtkActor *pickedActor = picker->GetActor();
>               if (picker->GetPickPosition() == m_Points->GetPoint(1)) {
>                       if (m_Marker) {
>                       m_Mark->VisibilityOn();
>                       m_Mark->SetPosition(picker->GetPickPosition());
>                       iren->Render();
>                       }
>              }
>       }
>protected:
>        PropCaller();
>       ~PropCaller();
>       vtkRenderer *renderer;
>       vtkActor *m_Marker;
>       vtkActor *m_Actor;
>       vtkPoints *m_Points;
>};
>
>
>----------
>From: Amy Squillacote
>Sent: Wed 26-Apr-06 8:16 PM
>To: Ashley Sher; vtkusers at vtk.org
>Subject: Re: [vtkusers] Problem with vtkPoint::GetPoint(vtk IdType)
>
>
>Hi Ashley,
>
>What is m_Points supposed to contain?  You didn't include the code
>showing where the values in this instance of vtkPoints comes
>from.  Also, what are you getting back from your call to GetPoint?  I
>see that you're calling GetPoint(1); remember that VTK numbers from
>0, so if you're trying to compare against the first point in
>m_Points, you should call GetPoint(0).
>
>- Amy
>
>At 05:46 AM 4/26/2006, Ashley Sher wrote:
>
> >Hi all,
> >
> >I tried to use GetPoint to retreive the coordinates of defined point,
> >however, it's not working. It is not returning the actual point coordinate.
> >
> >Anyone met with this problem before?
> >
> >vtkPoints *pts = vtkPoints::New();
> >pts->InsertPoint (0, 0, 3, 0);
> >pts->InsertPoint (1, 1, 2, 0);
> >pts->InsertPoint (2, 0, 2, 1);
> >pts->InsertPoint (3, -1, 2, 0);
> >pts->InsertPoint (4, 0, 2, -1);
> >
> >vtkPolyData *pd = vtkPolyData::New();
> >pd->SetPoints(pts);
> >
> >vtkSphereSource *sphere = vtkSphereSource::New();
> >vtkGlyph3D *spheres = vtkGlyph3D::New();
> >spheres->SetInput(pd);
> >spheres->SetSource(sphere->GetOutput());
> >vtkPolyDataMapper *sphereMapper= vtkPolyDataMapper::New();
> >sphereMapper->SetInputConnection(spheres->GetOutputPort());
> >vtkActor *sphereActor = vtkActor::New();
> >sphereActor->SetMapper(sphereMapper);
> >
> >iren->GetEventPosition(x, y);
> >vtkPropPicker *picker = vtkPropPicker::New();
> >picker->Pick(x,y,0,this->renderer);
> >vtkActor *pickedActor = picker->GetActor();
> >
> >if (picker->GetPickPosition() == m_Points->GetPoint(1)) {
> >                                             :
> >                                             :
> >}
> >--
> >View this message in context:
> >http://www.nabble.com/Problem-with-vtkPoint%3A%3AGetPoint%28vtk-IdT 
> ype%29-t1510830.html#a4098328
> >Sent from the VTK - Users forum at Nabble.com.
> >
> >_______________________________________________
> >This is the private VTK discussion list.
> >Please keep messages on-topic. Check the FAQ at:
> >http://www.vtk.org/Wiki/VTK_FAQ
> >Follow this link to subscribe/unsubscribe:
> >http://www.vtk.org/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060427/e2f61c05/attachment.htm>


More information about the vtkusers mailing list