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

Bradley Lowekamp blowekamp at mail.nih.gov
Thu Jun 14 13:21:41 EDT 2012


Hello,

You should look at the different types these methods are returning as thy are different an sometime incompatible. The warning message says what the problem is:

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

These are the methods you should be come familiar with:

OutputImageType * 	ImageSource::GetOutput (unsigned int idx)

VectorImageType * 	DanielssonDistanceMapImageFilter::GetVectorDistanceMap (void)


Then there is:
DataObject * 	ProcessObject::GetOutput (const DataObjectIdentifierType &key)

You can perform a dynamic_cast on the return of the ProcessObject's method to the correct image type. It is best to check that the result is not NULL in case the dynamic_cast fails.

Brad

On Jun 14, 2012, at 11:41 AM, Ramón Casero Cañas wrote:

> 
> 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/
> _____________________________________
> 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.php
> 
> 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

========================================================
Bradley Lowekamp  
Medical Science and Computing for
Office of High Performance Computing and Communications
National Library of Medicine 
blowekamp at mail.nih.gov



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120614/99bbd614/attachment.htm>


More information about the Insight-users mailing list