<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Hi, <br>
<br>
I discovered a possible bug in the <span>vtkKdTreePointLocator for distant points. I included a small example in python. For compatibility reasons, I'm still at commit <span>2d7055f19972012e8120281d50604d5bfd2a9be2 so it might be already solved...</span></span></p>
<p><span><span><br>
</span></span></p>
<p><span><span>It only occurs when the point is further than double the distance of the maxDist of the target dataset (in the example > 2*10+5) and if there are significant number of points so that multiple regions exist.</span></span></p>
<p><span><span><br>
</span></span></p>
<p><span><span>Regards,</span></span></p>
<p><span><span>Christophe</span></span></p>
<p><span><span><br>
</span></span></p>
<p><span><span>Code: </span></span></p>
<p><span><span><br>
</span></span></p>
<p><span><span></p>
<div>import vtk</div>
<div><br>
</div>
<div># Setup point coordinates</div>
<div>source = vtk.vtkSphereSource()</div>
<div>source.SetCenter(0,0,0)</div>
<div>source.SetRadius(5.0)</div>
<div>source.SetThetaResolution(120)</div>
<div>source.SetPhiResolution(70)</div>
<div>source.Update()</div>
<div><br>
</div>
<div>polydata = vtk.vtkPolyData()</div>
<div>polydata.DeepCopy(source.GetOutput())</div>
<div><br>
</div>
<div># Create the tree</div>
<div><span style="font-size: 12pt;">kDTree = vtk.vtkKdTreePointLocator()</span><br>
</div>
<div>kDTree.SetDataSet(polydata)</div>
<div>kDTree.BuildLocator()</div>
<div><br>
</div>
<div>testPoint = [0.0, 0.0, 25.] # all points up to [0., 0., 24.9999...] give [0., 0., 5.] as closest point </div>
<div><br>
</div>
<div>print("Test point: ", ', '.join([str(x) for x in testPoint]))</div>
<div><br>
</div>
<div># Find the closest points to TestPoint</div>
<div><span style="font-size: 12pt;">iD = kDTree.FindClosestPoint(testPoint)</span></div>
<div>print("\nThe closest point is point %d" % iD)</div>
<div><br>
</div>
<div>#Get the coordinates of the closest point</div>
<div>closestPoint = [0.0, 0.0, 0.0]</div>
<div><span style="font-size: 12pt;">kDTree.GetDataSet().GetPoint(iD, closestPoint)</span></div>
<div><span class="Apple-tab-span" style="white-space:pre"></span></div>
<div>print("Coordinates: %f, %f, %f" % (closestPoint[0], closestPoint[1], closestPoint[2])) # Should be <span style="font-family: Calibri, Arial, Helvetica, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols; font-size: 16px;">[0.,
 0., 5.] but returns <span> [-2.452237, -1.985783, -3.878556]</span></span></div>
<div><br>
</div>
<div><br>
</div>
<br>
</span></span>
<p></p>
</div>
</body>
</html>