[vtkusers] vtkPointLocator
John Biddiscombe
jbiddiscombe at skippingmouse.co.uk
Mon Apr 23 10:43:30 EDT 2001
>I have posted it once, but I got no replays. Still the problem
>with vtkPointLocator persists. Maybe it is a bug?
Perhaps not. Below are some methods you can use...
> vtkPointLocator *tree = vtkPointLocator::New();
> tree->Initialize();
> tree->InitPointInsertion(PointArray,PointArray->GetBounds());
> int pt;
> for (i=0;i<point_num;i++) {
> tree->InsertNextPoint(PointArray->GetPoint(i));
> }
> tree->BuildLocator();
>
>and when I try to use BuildLocator() here I get an error message
>"No data to subdivide!"
>What is the meaning?
>How should I use it?
Well you have told it that it should begin preparing to insert points by
calling
> tree->InitPointInsertion(PointArray,PointArray->GetBounds());
but so far you haven't inserted any points (there are some already in your
supplied point array, but you're mixing two methods up.
If you go
locator->SetDataSet(mydata);
locator->Buildlocator()
then we're happy.
But what you've done is this.
Fill a list with points
Set points array into locator,
Copy points from list into list again
(When you call initpointsinsertion, you're saying, get ready to fill this
list with points - but you've already filled the list!)
Now here's two methods to make it work...
1) (basically, the same, but do the initpointinsertion BEFORE reading the
points from file). Unfortunately, you do need to supply the bounds as well
(otherwise the locator doesn't know how many BBoxes to divide into), but as
you've not read the points yet you can either
a) Create Locator
b) Make a guess at BBox
c) read points and insert into locator
d) no need to call Buildlocator, because it will be initialized as points
are stuffed in.
vtkPoints *PointArray = vtkPoints::New().....
vtkPointLocator *tree = vtkPointLocator::New();
tree->InitPointInsertion(PointArray, Best Guess BBox float[6]);
int pt;
while (1)
{
if (fgets(buf, 80, fd) == NULL) break;
if (sscanf(buf, "%f %f %f", &x1, &y1, &z1) == 3) {
P[0]=x1;
P[1]=y1n;
P[2]=z1;
tree->InsertNextPoint(PointArray->GetPoint(i));
// this puts the data into pointarray
point_num++;
}
}
fclose(fd);
2) ALTERNATIVELY (my choice)
simply do exactly what you've done except
vtkPoints *PointArray = vtkPoints::New().....
while (1)
{
if (fgets(buf, 80, fd) == NULL) break;
if (sscanf(buf, "%f %f %f", &x1, &y1, &z1) == 3) {
P[0]=x1;
P[1]=y1n;
P[2]=z1;
PointArray->InsertNextPoint(P);
point_num++;
}
}
fclose(fd);
Now fake a dataset by doing this
vtkPolyData *dummy = vtkPolyData::New();
dummy->SetPoints(PointArray);
locator->SetDataSet(dummy);
locator->BuildLocator();
All of this is from memory, so apologies if I've missed a bit of syntax or
whatnot
John B
More information about the vtkusers
mailing list