[Insight-users] filter->GetOutput(i) returning NULL

Ramón Casero Cañas rcasero at gmail.com
Thu Jun 14 11:41:13 EDT 2012


Hi,

The problem in brief:

I'm finding that itk::DanielssonDistanceMapImageFilter (derived from 
itk::ImageToImageFilter) is returning NULL for the 2nd and 3rd outputs 
when using the method GetOutput(i), while returning correct pointers 
when using the method GetVectorDistanceMap().

this->derivedFilter->GetOutput(0) = 0x26750a0
this->derivedFilter->GetOutput(1) = 0
this->derivedFilter->GetOutput(2) = 0
this->derivedFilter->GetOutput() = 0x26750a0
this->derivedFilter->GetVoronoiMap() = 0x2674cb0
this->derivedFilter->GetVectorDistanceMap() = 0x2675480



The problem in detail:

I have a class with a pointer to a filter

class MexBaseFilter {

protected:

typedef typename itk::ImageToImageFilter<double, double> 
ImageToImageFilterType;

typename ImageToImageFilterType::Pointer filter;

};

Then a derived class with the DanielssonDistance filter, which derives 
from itk::ImageToImageFilter

class MexDanielssonDistanceMapImageFilter :
   public MexBaseFilter {

private:
   typedef itk::DanielssonDistanceMapImageFilter<
   itk::Image<double, 3>,
   itk::Image<double, 3> > DerivedImageToImageFilterType;

   typename DerivedImageToImageFilterType::Pointer derivedFilter;

};


The filter gets instantiated in the constructor of the derived class, 
and derivedFilter just points to it, using a dynamic_cast that compiles 
thanks to polymorphism


MexDanielssonDistanceMapImageFilter::MexDanielssonDistanceMapImageFilter() 
: MexBaseFilter() {

   // using polymorphism
   // (this->filter is ImageToImageFilterType)
   this->filter = DerivedImageToImageFilterType::New();

   derivedFilter =
     dynamic_cast<DerivedImageToImageFilterType 
*>(this->filter.GetPointer());

}


Then inputs and parameters are passed to the filter, filter->Update() is 
run, and later a method gets called to inspect the outputs of the filter

void MexDanielssonDistanceMapImageFilter::InspectOutputs() {

     std::cout << "this->derivedFilter = "
     	      << this->derivedFilter << std::endl;
     std::cout << "this->derivedFilter->GetOutput(0) = "
     	      << this->derivedFilter->GetOutput(0) << std::endl;
     std::cout << "this->derivedFilter->GetOutput(1) = "
     	      << this->derivedFilter->GetOutput(1) << std::endl;
     std::cout << "this->derivedFilter->GetOutput(2) = "
     	      << this->derivedFilter->GetOutput(2) << std::endl;

     std::cout << "this->derivedFilter->GetOutput() = "
     	      << this->derivedFilter->GetOutput() << std::endl;
     std::cout << "this->derivedFilter->GetVoronoiMap() = "
     	      << this->derivedFilter->GetVoronoiMap() << std::endl;
     std::cout << "this->derivedFilter->GetVectorDistanceMap() = "
     	      << this->derivedFilter->GetVectorDistanceMap() << std::endl;

}

As can be seen from the following output, it seems that the 2nd and 3rd 
outputs from the filter have been correctly created, and can be accessed 
with methods GetVoronoiMap() and GetVectorDistanceMap(), but not with 
GetOutput(i).

<SCREEN>
this->derivedFilter = DanielssonDistanceMapImageFilter (0x26707d0)
   RTTI typeinfo: 
itk::DanielssonDistanceMapImageFilter<itk::Image<short, 3u>, 
itk::Image<unsigned char, 3u>, itk::Image<short, 3u> >
   Reference Count: 3
   Modified Time: 82
   Debug: Off
   Observers:
     none
   Inputs:
     Primary: (0x2679d50) *
   Required Input Names: Primary
   Outputs:
     Primary: (0x26750a0)
     IndexedDataObject1: (0x2674cb0)
     IndexedDataObject2: (0x2675480)
   NumberOfIndexedInputs: 1
   NumberOfRequiredInputs: 1
   NumberOfIndexedOutputs: 3
   NumberOfRequiredOutputs: 3
   Number Of Threads: 4
   ReleaseDataFlag: Off
   ReleaseDataBeforeUpdateFlag: Off
   AbortGenerateData: Off
   Progress: 0.8
   Multithreader:
     RTTI typeinfo:   itk::MultiThreader
     Reference Count: 1
     Modified Time: 32
     Debug: Off
     Observers:
       none
     Thread Count: 4
     Global Maximum Number Of Threads: 128
     Global Default Number Of Threads: 4
   Danielson Distance:
   Input Is Binary   : 0
   Use Image Spacing : 1
   Squared Distance  : 0

this->derivedFilter->GetOutput(0) = 0x26750a0
this->derivedFilter->GetOutput(1) = 0
this->derivedFilter->GetOutput(2) = 0
this->derivedFilter->GetOutput() = 0x26750a0
this->derivedFilter->GetVoronoiMap() = 0x2674cb0
this->derivedFilter->GetVectorDistanceMap() = 0x2675480
WARNING: In /usr/local/include/ITK-4.1/itkImageSource.hxx, line 112
DanielssonDistanceMapImageFilter (0x26707d0): dynamic_cast to output 
type failed

WARNING: In /usr/local/include/ITK-4.1/itkImageSource.hxx, line 112
DanielssonDistanceMapImageFilter (0x26707d0): dynamic_cast to output 
type failed
</SCREEN>


Best regards,

Ramon.

-- 
Dr. Ramón Casero Cañas

Computational Biology
Department of Computer Science
University of Oxford
Wolfson Building, Parks Rd
Oxford OX1 3QD

tlf     +44 (0) 1865 610737
web     http://www.cs.ox.ac.uk/people/Ramon.CaseroCanas
photos  http://www.flickr.com/photos/rcasero/


More information about the Insight-users mailing list