<!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> </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> 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. I run a corresponding linear search through the
same pointset (which is the one I copy into a sample and set into the KD
tree ) and the right value is returned i.e. the points have
been loaded correctly, but the closest point returned 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 snippet of the code
below.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>// KD tree typedefs<BR>typedef
itk::Statistics::ListSample< PointType
>
SampleType;<BR>typedef itk::Statistics::KdTreeGenerator< SampleType >
TreeGeneratorType;<BR>typedef
TreeGeneratorType::KdTreeType
TreeType;</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV><FONT face=Arial size=2>
<DIV>// Points typedefs<BR>typedef itk::PointSet< float, 3
> PointSetType;<BR>typedef
PointSetType::PointType PointType;</DIV>
<DIV></FONT> </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> </DIV>
<DIV><FONT face=Arial size=2>// Create tree
generator<BR>TreeGeneratorType::Pointer TreeGenerator =
TreeGeneratorType::New();</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>// create tree pointer
<BR>TreeType::Pointer PointsTree;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>// load points from a mesh into a
container<BR>PointsContainer::Pointer points =
m_Mesh->GetPoints();</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>PointsIterator point_iterator =
points->Begin();</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>// copy points into sample<BR>while (
point_iterator != points->End() ) <BR> {<BR>
Sample->PushBack( point_iterator->Value() );<BR>
++point_iterator;
// advance to next point<BR> }</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>TreeGenerator->SetSample( Sample
);<BR>TreeGenerator->SetBucketSize( 3
);<BR>TreeGenerator->Update();</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>PointsTree =
m_TreeGenerator->GetOutput();</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>unsigned int number_of_neighbors =
1;<BR>TreeType::InstanceIdentifierVectorType
neighbors;<BR>PointsTree->Search( query_point, number_of_neighbors, neighbors
) ; </FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>min_distance =
query_point.SquaredEuclideanDistanceTo( PointsTree->GetMeasurementVector(
neighbors[0] ) ); // WRONG
VALUE</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>PointsContainer::Pointer points =
Mesh->GetPoints();</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>PointsIterator point_iterator =
points->Begin();<BR>float min_err = 10000;<BR>PointType best_pt;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>while ( point_iterator != points->End() )
<BR>{<BR> if(
query_point.SquaredEuclideanDistanceTo(point_iterator->Value()) <
min_err)<BR> {<BR> min_err =
query_point.SquaredEuclideanDistanceTo(point_iterator->Value());
/
/RIGHT VALUE<BR> best_pt =
point_iterator->Value();<BR> }</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>
++point_iterator;
// advance to next point</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>}</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>if ( best_pt.SquaredEuclideanDistanceTo(
PointsTree->GetMeasurementVector( neighbors[0] ) ) >
0.0001)<BR> // I HAVE A PROBLEM</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </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> </DIV>
<DIV><FONT face=Arial size=2>Any ideas?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Thank you all.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Ferdinando</FONT></DIV></BODY></HTML>