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