<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2523" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Dear all,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>I am running a few tests on the itkKdTree and seem 
to be getting the wrong value</FONT><FONT face=Arial size=2>&nbsp;returned by 
the closest point search. If I create a 3D KD tree of floats and search for a 
closest point which happens to be exactly a point in the list, the value 
returned is wrong.&nbsp;I run a&nbsp;corresponding linear search through the 
same pointset (which is the one I copy into a sample and set&nbsp;into the KD 
tree )&nbsp; and the right value is returned i.e.&nbsp;the points have 
been&nbsp;loaded correctly,&nbsp;but the closest point returned&nbsp;by the KD 
tree accelerated search is different from the one returned by the linear 
search.</FONT></DIV>
<DIV><FONT face=Arial size=2>I have attached&nbsp; snippet of the code 
below.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>// KD tree typedefs<BR>typedef 
itk::Statistics::ListSample&lt; PointType 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
SampleType;<BR>typedef itk::Statistics::KdTreeGenerator&lt; SampleType &gt; 
TreeGeneratorType;<BR>typedef 
TreeGeneratorType::KdTreeType&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
TreeType;</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV><FONT face=Arial size=2>
<DIV>// Points typedefs<BR>typedef itk::PointSet&lt; float, 3 
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PointSetType;<BR>typedef 
PointSetType::PointType&nbsp;&nbsp;&nbsp;&nbsp; PointType;</DIV>
<DIV></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>/// Create vars<BR>// Create a sample variable for 
the tree<BR>SampleType::Pointer Sample = SampleType::New();</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>// Create tree 
generator<BR>TreeGeneratorType::Pointer TreeGenerator = 
TreeGeneratorType::New();</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>// create tree pointer&nbsp;&nbsp; 
<BR>TreeType::Pointer PointsTree;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>// load points from a mesh into a 
container<BR>PointsContainer::Pointer points = 
m_Mesh-&gt;GetPoints();</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>PointsIterator point_iterator = 
points-&gt;Begin();</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>// copy points into sample<BR>while ( 
point_iterator != points-&gt;End() ) <BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp; 
Sample-&gt;PushBack( point_iterator-&gt;Value() );<BR>&nbsp;&nbsp; 
++point_iterator;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
// advance to next point<BR>&nbsp;&nbsp; }</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>TreeGenerator-&gt;SetSample( Sample 
);<BR>TreeGenerator-&gt;SetBucketSize( 3 
);<BR>TreeGenerator-&gt;Update();</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>PointsTree = 
m_TreeGenerator-&gt;GetOutput();</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>unsigned int number_of_neighbors = 
1;<BR>TreeType::InstanceIdentifierVectorType 
neighbors;<BR>PointsTree-&gt;Search( query_point, number_of_neighbors, neighbors 
) ; </FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>min_distance = 
query_point.SquaredEuclideanDistanceTo( PointsTree-&gt;GetMeasurementVector( 
neighbors[0] ) );&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // WRONG 
VALUE</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>PointsContainer::Pointer points = 
Mesh-&gt;GetPoints();</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>PointsIterator point_iterator = 
points-&gt;Begin();<BR>float min_err = 10000;<BR>PointType best_pt;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>while ( point_iterator != points-&gt;End() ) 
<BR>{<BR>&nbsp;&nbsp; if( 
query_point.SquaredEuclideanDistanceTo(point_iterator-&gt;Value()) &lt; 
min_err)<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; min_err = 
query_point.SquaredEuclideanDistanceTo(point_iterator-&gt;Value());&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; / 
/RIGHT&nbsp;VALUE<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; best_pt = 
point_iterator-&gt;Value();<BR>&nbsp;&nbsp; }</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp; 
++point_iterator;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
// advance to next point</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>}</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>if ( best_pt.SquaredEuclideanDistanceTo( 
PointsTree-&gt;GetMeasurementVector( neighbors[0] ) ) &gt; 
0.0001)<BR>&nbsp;&nbsp; // I HAVE A PROBLEM</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Also, if I set the bucket size of the three to less 
than 3 I get an uncaught exception.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Any ideas?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Thank you all.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Ferdinando</FONT></DIV></BODY></HTML>