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

motes motes mort.motes at gmail.com
Sun Nov 29 07:13:23 EST 2009


Ups here is the whole thing:

(gdb) where
#0  itk::Statistics::KdTree<itk::Statistics::ListSample<itk::Vector<double,
3u> > >::NearestNeighborSearchLoop (this=0x1d0cf30, node=0x1d0e1f0,
query=@0x7f14a4298cf0,
    lowerBound=@0x7f14a4298ac0, upperBound=@0x7f14a4298aa0) at
/home/mort/local/InsightToolkit-3.14.0/Code/Numerics/Statistics/itkKdTree.h:448
#1  0x00000000005e4618 in
itk::Statistics::KdTree<itk::Statistics::ListSample<itk::Vector<double,
3u> > >::NearestNeighborSearchLoop (this=0x1d0cf30, node=0x1d0e370,
    query=@0x7f14a4298cf0, lowerBound=@0x7f14a4298ac0,
upperBound=@0x7f14a4298aa0) at
/home/mort/local/InsightToolkit-3.14.0/Code/Numerics/Statistics/itkKdTree.txx:312
#2  0x00000000005e4618 in
itk::Statistics::KdTree<itk::Statistics::ListSample<itk::Vector<double,
3u> > >::NearestNeighborSearchLoop (this=0x1d0cf30, node=0x1d0e3b0,
    query=@0x7f14a4298cf0, lowerBound=@0x7f14a4298ac0,
upperBound=@0x7f14a4298aa0) at
/home/mort/local/InsightToolkit-3.14.0/Code/Numerics/Statistics/itkKdTree.txx:312
#3  0x00000000005e4425 in
itk::Statistics::KdTree<itk::Statistics::ListSample<itk::Vector<double,
3u> > >::NearestNeighborSearchLoop (this=0x1d0cf30, node=0x1d0e7b0,
    query=@0x7f14a4298cf0, lowerBound=@0x7f14a4298ac0,
upperBound=@0x7f14a4298aa0) at
/home/mort/local/InsightToolkit-3.14.0/Code/Numerics/Statistics/itkKdTree.txx:291
#4  0x00000000005e4425 in
itk::Statistics::KdTree<itk::Statistics::ListSample<itk::Vector<double,
3u> > >::NearestNeighborSearchLoop (this=0x1d0cf30, node=0x1d0efb0,
    query=@0x7f14a4298cf0, lowerBound=@0x7f14a4298ac0,
upperBound=@0x7f14a4298aa0) at
/home/mort/local/InsightToolkit-3.14.0/Code/Numerics/Statistics/itkKdTree.txx:291
#5  0x00000000005e4618 in
itk::Statistics::KdTree<itk::Statistics::ListSample<itk::Vector<double,
3u> > >::NearestNeighborSearchLoop (this=0x1d0cf30, node=0x1d0eff0,
    query=@0x7f14a4298cf0, lowerBound=@0x7f14a4298ac0,
upperBound=@0x7f14a4298aa0) at
/home/mort/local/InsightToolkit-3.14.0/Code/Numerics/Statistics/itkKdTree.txx:312
#6  0x00000000006f02eb in
itk::Statistics::KdTree<itk::Statistics::ListSample<itk::Vector<double,
3u> > >::Search (this=0x1d0cf30, query=@0x7f14a4298cf0,
    numberOfNeighborsRequested=<value optimized out>,
result=@0x7f14a4298cd0) at
/home/mort/local/InsightToolkit-3.14.0/Code/Numerics/Statistics/itkKdTree.txx:291
#7  0x00000000006f0a5a in itk::MyDeformableTransform<double, 3u,
3u>::TransformPoint (this=0x12322b0, point=<value optimized out>,
outputPoint=@0x7f14a4298f50,
    weights=<value optimized out>, indices=<value optimized out>,
inside=<value optimized out>)
    at /home/mort/local/code/registration/my_deformable_transform.cpp:693
#8  0x00000000005fb9d2 in itk::MyDeformableTransform<double, 3u,
3u>::TransformPoint (this=0x12322b0, point=@0x7f14a4298f90)
    at /home/mort/local/code/registration/my_deformable_transform.cpp:778
#9  0x000000000067ad2f in itk::ResampleImageFilter<itk::Image<float,
3u>, itk::Image<float, 3u>, double>::NonlinearThreadedGenerateData
(this=0x1d11030,
    outputRegionForThread=<value optimized out>, threadId=<value
optimized out>) at
/home/mort/local/local/InsightToolkit-3.14.0/Code/BasicFilters/itkResampleImageFilter.txx:257
#10 0x000000000059f85e in itk::ImageSource<itk::Image<float, 3u>
>::ThreaderCallback (arg=<value optimized out>)
    at /home/mort/local/InsightToolkit-3.14.0/Code/Common/itkImageSource.txx:292
#11 0x000000000074eb56 in itk::MultiThreader::SingleMethodProxy
(arg=0x1d191d8) at
/home/mort/local/InsightToolkit-3.14.0/Code/Common/itkMultiThreader.cxx:853
#12 0x00007f14a6f1d3ba in start_thread () from /lib/libpthread.so.0
#13 0x00007f14a62dbfcd in clone () from /lib/libc.so.6
#14 0x0000000000000000 in ?? ()
(gdb)


On Sun, Nov 29, 2009 at 1:03 PM, motes motes <mort.motes at gmail.com> wrote:
> [New Thread 0x7f14a7c5f750 (LWP 4955)]
> [New Thread 0x7f14a4299950 (LWP 4958)]
>
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread 0x7f14a4299950 (LWP 4958)]
> itk::Statistics::KdTree<itk::Statistics::ListSample<itk::Vector<double,
> 3u> > >::NearestNeighborSearchLoop (this=0x1d0cf30, node=0x1d0e1f0,
> query=@0x7f14a4298cf0,
>    lowerBound=@0x7f14a4298ac0, upperBound=@0x7f14a4298aa0) at
> /home/mort/local/InsightToolkit-3.14.0/Code/Numerics/Statistics/itkKdTree.h:448
> 448             if ( m_Distances[i] > farthestDistance )
> (gdb)
>
>
>
>
>
>
> On Sun, Nov 29, 2009 at 10:27 AM, Karthik Krishnan
> <karthik.krishnan at kitware.com> wrote:
>> 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