[vtkusers] Another Try : storing picked points

Steffen Oeltze Steffen.Oeltze at Student.Uni-Magdeburg.DE
Mon Nov 4 06:16:04 EST 2002


Hi George,

my guess is that the problem arises because you redefine the 
vtkPoints-array
( points = vtkPoints::New() ) each time the user selects a point.

Steffen

George Kamucha wrote:

> Hi,
> I posted the following question sometimes back, got no response and am
> trying once more,
> hoping and hoping to get a response........
>
> I am trying to use vtkSelectPolyData  to select a part of  my surface
> data using a loop. To define the loop, I am
> selecting points on a surface using vtkPointPicker, and then placing
> small spheres in the selected locations. The locations
> of the picked points are stored in vtkPoints and used in defining the
> loop. But it is simply not working! When I
> check the points stored in the vtkPoints, I find that only the last
> picked point is valid, the others don't make any
> sense at all. Below is the snippet (to stop picking, I pick three times
> outside the surface data).  Anybody with an idea on this?
>
>
> Best regards
> George.
>
> #include "vtkPolyDataReader.h"
> #include "vtkPolyDataMapper.h"
> #include "vtkRenderer.h"
> #include "vtkRenderWindow.h"
> #include "vtkRenderWindowInteractor.h"
> #include "vtkActor.h"
> #include "vtkPointPicker.h"
> #include "vtkSphereSource.h"
> #include "vtkGlyph3D.h"
> #include "vtkSelectPolyData.h"
> #include "vtkClipPolyData.h"
> #include  <stdio.h>
> #include  <ctype.h>
> #include  <iostream.h>
>
>
> static void pickControl(void *);
> static vtkRenderer *ren1;
> static vtkRenderWindow *renWin;
> static vtkPoints *points;
> static int n, p;
> vtkPolyDataReader *reader;
>
> void main( int argc, char *argv[] )
>
> {
>
> n=0;
> p=0;
>
> //Load the original Laser surface data LaserNewd.vtk
> reader = vtkPolyDataReader::New();
>      reader->SetFileName ("../../../vtkdata/LaserNewd.vtk");
>      reader->Update();
>
> vtkPolyDataMapper *dataMapper = vtkPolyDataMapper::New();
>      dataMapper->SetInput(reader->GetOutput());
>      dataMapper->ScalarVisibilityOff();
>
> vtkActor *dataActor = vtkActor::New();
>       dataActor->SetMapper(dataMapper);
>       dataActor->GetProperty()->SetColor(1, 1, 0);
>       dataActor->GetProperty()->SetOpacity(0.5);
>
> vtkPointPicker *pointpicker = vtkPointPicker::New();
>
>
> ren1 = vtkRenderer::New();
> renWin = vtkRenderWindow::New();
>    renWin->AddRenderer(ren1);
>  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
>    iren->SetRenderWindow(renWin);
>    iren->SetPicker(pointpicker);
>    iren->SetEndPickMethod(pickControl, (void *)iren);
>
> ren1->AddActor(dataActor);
>
> // render the image
>    ren1->SetBackground(1, 1, 1);
>    renWin->SetSize(500,500);
>    iren->Initialize();
>    renWin->Render();
>    iren->Start();
>
> //Clean up
>
> ren1->Delete();
> renWin->Delete();
> iren->Delete();
> //reader->Delete();
> dataMapper->Delete();
> dataActor->Delete();
> pointpicker->Delete();
>
> }
>
>
>
> // Define picking method
> static void pickControl(void *arg)
> {
> float *selPt;
> float *pickpos;
> float *pc;
> int i;
>
>
>
>
> vtkRenderWindowInteractor *iren = (vtkRenderWindowInteractor *)arg;
>  vtkPointPicker *pointpicker = (vtkPointPicker *)iren->GetPicker();
>
>
>
>  selPt = pointpicker->GetSelectionPoint();
>
>    cout<<"Screen location:"<<selPt[0]<<" "<<selPt[1]<<"\n";
>
>
>
> if ( pointpicker->GetPointId() >= 0 )
>    {
>    p = p+1; //count number of points picked
>    pickpos = pointpicker->GetPickPosition();
>
>    cout<<"Point location:"<<pickpos[0]<<" "<<pickpos[1]<<"
> "<<pickpos[2]<<"\n";
>
>
>
>
> //Define method for placing spheres
> points=vtkPoints::New();
>        points-> InsertNextPoint(pickpos);
>        points-> Modified();
>
> vtkPolyData *profile=vtkPolyData::New();
>   profile->SetPoints(points);
>
> vtkSphereSource *sphere=vtkSphereSource::New();
>  sphere->SetRadius(2);
>
> vtkGlyph3D *glyph=vtkGlyph3D::New();
>    glyph->SetInput(profile);
>    glyph->SetSource(sphere->GetOutput());
>
> vtkPolyDataMapper *glyphMapper=vtkPolyDataMapper::New();
>     glyphMapper->SetInput(glyph->GetOutput());
>
>
> vtkActor *glyphActor=vtkActor::New();
>  glyphActor->SetMapper(glyphMapper);
>  glyphActor->GetProperty()->SetColor(1, 0, 0); //Set colour to red
>
> ren1-> AddActor(glyphActor);
>
> renWin->Render();
>
>
> //points-> Delete();
> profile->  Delete();
> sphere->  Delete();
> glyph->  Delete();
> glyphMapper->  Delete();
> glyphActor->  Delete();
>
>
>   }
>   else   if ( pointpicker->GetPointId() < 0 )
>   {
>
>
>         cout<<"No point picked here!"<<"\n";
>         n=n+1;
>         cout<<"n" <<n<<"\n";
>
>       if (n >=3)
>        {
>         cout<<"Selection completed!"<<"\n";
>
>
> // check the picked points, stored in vtkPoints
>     for (i=0; i<p; i++)
>
>       {
>        pc = points->GetPoint(i);
>
>        cout<<"point:"<<pc[0]<<" "<<pc[1]<<" "<<pc[2]<<"\n";//See
> components points
>        }
>
>
>
> vtkSelectPolyData *loop = vtkSelectPolyData::New();
>    loop->SetInput(reader->GetOutput());
>    loop->SetLoop(points);
>    loop->GenerateSelectionScalarsOn();
>    loop->SetSelectionModeToSmallestRegion(); //negative scalars inside
> vtkClipPolyData *clip = vtkClipPolyData::New(); //clips out positive
> region
>    clip->SetInput(loop->GetOutput());
> vtkPolyDataMapper *clipMapper = vtkPolyDataMapper::New();
>    clipMapper->SetInput(clip->GetOutput());
> vtkActor *clipActor = vtkActor::New();
>    clipActor->SetMapper(clipMapper);
>    clipActor->AddPosition(1, 0, 0);
>    clipActor->GetProperty()->SetColor(0, 0, 1); //Set colour blue
>
> ren1->AddActor(clipActor);
> renWin->Render();
>
>
> reader->Delete();
> points-> Delete();
> loop->Delete();
> clip->Delete();
> clipMapper->Delete();
> clipActor->Delete();
>
>        }
>
>  }
>
> }
>
>
>
>
> _______________________________________________
> This is the private VTK discussion list. Please keep messages 
> on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers
>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20021104/5bdd6c4b/attachment.htm>


More information about the vtkusers mailing list