MantisBT - ITK
View Issue Details
0008681ITKpublic2009-03-06 09:412009-11-12 10:45
Bradley Lowekamp 
Bradley Lowekamp 
normalminorhave not tried
closedfixed 
 
ITK-3-14 
0008681: ImageSource lacks type safety for multiple outputs of different types
I 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.
No tags attached.
Issue History
2009-03-06 09:41Bradley LowekampNew Issue
2009-03-06 09:44Bradley LowekampNote Added: 0015590
2009-03-06 15:20Bradley LowekampStatusnew => assigned
2009-03-06 15:20Bradley LowekampAssigned To => Bradley Lowekamp
2009-03-06 15:22Bradley LowekampNote Added: 0015593
2009-03-06 15:22Bradley LowekampStatusassigned => confirmed
2009-03-13 10:34Bradley LowekampNote Added: 0015680
2009-03-17 10:04Bradley LowekampNote Added: 0015712
2009-03-17 10:04Bradley LowekampStatusconfirmed => resolved
2009-03-17 10:04Bradley LowekampResolutionopen => fixed
2009-11-12 10:45Bradley LowekampStatusresolved => closed
2009-11-12 10:45Bradley LowekampFixed in Version => ITK-3-14

Notes
(0015590)
Bradley Lowekamp   
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   
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   
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   
2009-03-17 10:04   
The changes seems to resolve the issue