[Insight-users] Segmentation fault when calling itk::KdTree::Search(queryPoint, radius, neighbors)

Karthik Krishnan karthik.krishnan at kitware.com
Sun Nov 29 04:27:36 EST 2009


If you get a segfault, please post the stack trace using gdb.

On Sat, Nov 28, 2009 at 5:47 AM, motes motes <mort.motes at gmail.com> wrote:
> I use the following types to create a KdTree:
>
>  typedef Vector<TScalarType, SpaceDimension>
>          VectorType;
>  typedef itk::Statistics::ListSample<VectorType>
>              SampleType;
>  typedef itk::Statistics::KdTreeGenerator< SampleType >
>        TreeGeneratorType;
>  typedef typename TreeGeneratorType::KdTreeType
>         TreeType;
>  typedef typename TreeType::InstanceIdentifierVectorType
>       NeighborsType;
>
>
>  typename SampleType::Pointer sample  = SampleType::New();
>  typename TreeGeneratorType::Pointer treeGenerator = TreeGeneratorType::New();;
>  typename TreeType::Pointer tree;
>
>
> I create the tree with:
>
>  this->sample->SetMeasurementVectorSize(Dimension);
>  VectorType mv;
>  for (unsigned int i = 0 ; i < 1000 ; ++i ) {
>    mv[0] = (float) i;
>    mv[1] = (float) ((1000 - i) / 2 );
>    mv[2] = (float) ((1000 - i) / 2 );
>    sample->PushBack( mv );
>  }
>
>  treeGenerator->SetSample(sample);
>  treeGenerator->SetBucketSize(16);
>  treeGenerator->Update();
>  tree = treeGenerator->GetOutput();
>
>
>
>
> From the function"TransformPoint" (in a transform I have created) I
> then call the Search method:
>
>  NeighborsType neighbors;
>    VectorType vectorPoint;
>    vectorPoint.Fill(0);
>    for (int i=0; i<NDimensions; i++) {
>      vectorPoint[i] = point[i];
>    }
>  tree->Search(vectorPoint, 10.0, neighbors);
>
>
>
>
> But when I run the application I get a segmentation fault. I have
> tried to run the application with Valgrind but I get no error:
>
> valgrind --leak-check=yes --track-origins=yes ./MyApp
> INFO:: Computing registered image
> ==8389==
> ==8389== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 8 from 1)
> ==8389== malloc/free: in use at exit: 0 bytes in 0 blocks.
> ==8389== malloc/free: 13,153,309 allocs, 13,153,309 frees,
> 8,529,290,300 bytes allocated.
> ==8389== For counts of detected errors, rerun with: -v
> ==8389== All heap blocks were freed -- no leaks are possible.
>
>
>
> I am pretty sure that the problem is the dynamic array 'neighbors'. If
> I call the version of Search where the number of neighbors are
> specified I don't get any segmentation fault:
>
>
>  NeighborsType neighbors;
>    VectorType vectorPoint;
>    vectorPoint.Fill(0);
>    for (int i=0; i<NDimensions; i++) {
>      vectorPoint[i] = point[i];
>    }
>  unsigned int numberOfNeighbors = 3;
>  tree->Search( vectorPoint, numberOfNeighbors, neighbors ) ;
>
> But since I need the version where the radius is specified the above
> is not an option.
>
>
>
> Another thing. The error only occurs when I run a resampling Filter.
> If I run the transform through a registration process it works fine.
> The resampling Filter is created like this:
>
> typedef itk::ResampleImageFilter< FixedImageType, FixedImageType >
>                           ResampleFilterType;
> typedef itk::LinearInterpolateImageFunction< FixedImageType, double >
>                           LinearInterpolatorType;
>
>  LinearInterpolatorType::Pointer linearInterpolator =
> LinearInterpolatorType::New();
>  ResampleFilterType::Pointer resampler = ResampleFilterType::New();
>  resampler->SetInput(imageM);
>  resampler->SetTransform(adaptiveTransform);
>  resampler->SetInterpolator(linearInterpolator);
>  resampler->SetOutputOrigin(imageF->GetOrigin());
>  resampler->SetOutputSpacing(imageF->GetSpacing());
>  resampler->SetSize(imageF->GetLargestPossibleRegion().GetSize());
>  resampler->SetDefaultPixelValue(0);
>
>
>  try {
>
>    resampler->Update();
>
>  }
>
>  catch( itk::ExceptionObject & err ) {
>
>    std::cerr << "ExceptionObject caught !" << std::endl;
>
>    std::cerr << err << std::endl;
>
>  }
>
>
> Any ideas are most welcome!
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>


More information about the Insight-users mailing list