View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0008681ITKpublic2009-03-06 09:412009-11-12 10:45
ReporterBradley Lowekamp 
Assigned ToBradley Lowekamp 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in VersionITK-3-14 
Summary0008681: ImageSource lacks type safety for multiple outputs of different types
DescriptionI was looking at ImageSource and noticed some problems when the filters have different outputs. As this lack of type safety can cause segfaults and pointers to the wrong type I think they are bugs.

The problem is with the following two methods:

typename ImageSource<TOutputImage>::OutputImageType *
ImageSource<TOutputImage>
::GetOutput(unsigned int idx)
{
  return static_cast<TOutputImage*>
    (this->ProcessObject::GetOutput(idx));
}


ImageSource<TOutputImage>
::AllocateOutputs()
{
  OutputImagePointer outputPtr;

  // Allocate the output memory
  for (unsigned int i=0; i < this->GetNumberOfOutputs(); i++)
    {
    outputPtr = this->GetOutput(i);
    outputPtr->SetBufferedRegion(outputPtr->GetRequestedRegion());
    outputPtr->Allocate();
    }
}

GraphNthOutput has a minor issue too.

I see a real problem with this implementation of AllocateOutputs. In that outputPtr may not be of the type we have a pointer to. In the case of BayesianClassifierImageFilter using this parent method causes a segfault. I see two solutions two this based on what is done in ImageSource and ImageToImageFilter. Perform a dynamic_cast and do nothing if the cast fails. Or we could case to ImageBase, but that is currently problematic since Allocate, is not a virtual method in ImageBase.

In GetOutput, a dynamic_cast could be used as well. I ran a couple of experimentals on choptank.nlm yesterday with and with out a dynamic_cast there:
http://www.cdash.org/CDash/buildSummary.php?buildid=282934 [^]
http://www.cdash.org/CDash/buildSummary.php?buildid=282954 [^]

From the dash board there appears no significant performance difference. But there are 4 new tests that are failing. I only looked at itkContourDirectedMeanDistanceImageFilterTest, and there is clearly a problem in it's Allocate method. I would think that there are bugs in the other classes as well.
TagsNo tags attached.
Resolution Date
Sprint
Sprint Status
Attached Files

 Relationships

  Notes
(0015590)
Bradley Lowekamp (developer)
2009-03-06 09:44

The failing tests on the experimental dashboard were traced to SignedDanielssonDistanceMapImageFilter using ImageSource::GetOutpu() method and getting an invalid pointer.
(0015593)
Bradley Lowekamp (developer)
2009-03-06 15:22

This was discussed at a TCON:
http://www.itk.org/Wiki/Agenda%26Status_030609 [^]

The conclusion was to implement dynamic_cast is GetOutput, and utilize an ImageBase::Allocate method in AllocateOutptus.
(0015680)
Bradley Lowekamp (developer)
2009-03-13 10:34

The following changes were commited (after complications with Borland):
http://public.kitware.com/cgi-bin/viewcvs.cgi/Code/Common/itkImageBase.h.diff?cvsroot=Insight&r1=1.76&r2=1.77 [^]
http://public.kitware.com/cgi-bin/viewcvs.cgi/Code/Common/itkImageSource.h.diff?cvsroot=Insight&r1=1.56&r2=1.57 [^]
http://public.kitware.com/cgi-bin/viewcvs.cgi/Code/Common/itkImageSource.txx.diff?cvsroot=Insight&r1=1.63&r2=1.64 [^]

And related corrections needed to be made here:
http://public.kitware.com/cgi-bin/viewcvs.cgi/Code/Review/itkMultiScaleHessianBasedMeasureImageFilter.h.diff?cvsroot=Insight&r1=1.4&r2=1.5 [^]
http://public.kitware.com/cgi-bin/viewcvs.cgi/Code/Review/itkMultiScaleHessianBasedMeasureImageFilter.txx.diff?cvsroot=Insight&r1=1.6&r2=1.8 [^]
http://public.kitware.com/cgi-bin/viewcvs.cgi/Code/BasicFilters/itkSignedDanielssonDistanceMapImageFilter.txx?root=Insight&r1=1.9&r2=1.10&sortby=date [^]
http://public.kitware.com/cgi-bin/viewcvs.cgi/Code/BasicFilters/itkSignedDanielssonDistanceMapImageFilter.h?root=Insight&r1=1.5&r2=1.6&sortby=date [^]
(0015712)
Bradley Lowekamp (developer)
2009-03-17 10:04

The changes seems to resolve the issue

 Issue History
Date Modified Username Field Change
2009-03-06 09:41 Bradley Lowekamp New Issue
2009-03-06 09:44 Bradley Lowekamp Note Added: 0015590
2009-03-06 15:20 Bradley Lowekamp Status new => assigned
2009-03-06 15:20 Bradley Lowekamp Assigned To => Bradley Lowekamp
2009-03-06 15:22 Bradley Lowekamp Note Added: 0015593
2009-03-06 15:22 Bradley Lowekamp Status assigned => confirmed
2009-03-13 10:34 Bradley Lowekamp Note Added: 0015680
2009-03-17 10:04 Bradley Lowekamp Note Added: 0015712
2009-03-17 10:04 Bradley Lowekamp Status confirmed => resolved
2009-03-17 10:04 Bradley Lowekamp Resolution open => fixed
2009-11-12 10:45 Bradley Lowekamp Status resolved => closed
2009-11-12 10:45 Bradley Lowekamp Fixed in Version => ITK-3-14


Copyright © 2000 - 2018 MantisBT Team