[vtkusers] Bug in vtkPointLocator in GetOverlappingBuckets (+solution?)

Reinhold Niesner r.niesner at tu-bs.de
Fri Aug 17 07:00:42 EDT 2007


Hi vtk users,
 
I think i stumbled upon a bug in vtkPointLocator in method
GetOverlappingBuckets.
The following example does not work properly:

------------------------------
# vtk DataFile Version 3.0
vtk output
ASCII
DATASET POLYDATA
POINTS 6 float
0.000992855 -8.43769e-19 0.0038
0.000992855  0           0
0            0           0 
0           -8.43769e-19 0.0038
0.000992855 -1.68754e-18 0.0076
0           -1.68754e-18 0.0076 
 
POLYGONS 2 10
4 0 1 2 3 
4 4 0 3 5 
 
CELL_DATA 2
POINT_DATA 6
------------------------------
 
from vtk import *
reader = vtkPolyDataReader()
reader.SetFileName('grid.vtk')
reader.Update()
locator = vtkPointLocator()
locator.SetDataSet(reader.GetOutput())
x = (0, 0, 0.0076)
ptId = locator.FindClosestPoint(x)
print "IN : ", x
print "OUT: ", reader.GetOutput().GetPoint(ptId)
 
------------------------------
 
The correct result should be (0, -1.68754e-18, 0.0076), instead
FindClosestPoint returns (0, -8.43769e-19, 0.0038).
 
The problematic line in vtkPointLocator.cxx in method GetOverlappingBuckets
is: 
 
maxLevel[i] = (int) ((double) (((x[i]+dist) - this->Bounds[2*i]) / 
        (this->Bounds[2*i+1] - this->Bounds[2*i])) * this->Divisions[i]);

Casting a very large (positive) double to int results in MIN_INT (negative).
This occurs when the bounding box in one direction is very small, e.g.
1e-18.
 
Possible solution: 
Replace above line with:
 
double xx;
xx = ((double) (((x[i]+dist) - this->Bounds[2*i]) / 
        (this->Bounds[2*i+1] - this->Bounds[2*i])) * this->Divisions[i]);
if (xx > VTK_INT_MAX) maxLevel[i] = VTK_INT_MAX;
else maxLevel[i] = (int) xx;
 
Could someone with access to CVS check this or niftier solution in?
 
 
Regards, 
Reinhold Niesner
 
 
 
 
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070817/77c55692/attachment.htm>


More information about the vtkusers mailing list