<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hello,<div><br></div><div>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:</div><div><br></div><div>WARNING: In /usr/local/include/ITK-4.1/itkImageSource.hxx, line 112<br>DanielssonDistanceMapImageFilter (0x26707d0): dynamic_cast to output <br>type failed</div><div><br></div><div>These are the methods you should be come familiar with:</div><div><div><br></div><div>OutputImageType * <span class="Apple-tab-span" style="white-space:pre">        </span>ImageSource::GetOutput (unsigned int idx)</div></div><div><br></div><div>VectorImageType * <span class="Apple-tab-span" style="white-space:pre">        DanielssonDistanceMapImageFilter</span>::GetVectorDistanceMap (void)</div><div><br></div><div><br></div><div>Then there is:</div><div>DataObject * <span class="Apple-tab-span" style="white-space:pre">        </span>ProcessObject::GetOutput (const DataObjectIdentifierType &key)</div><div><br></div><div>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.</div><div><br></div><div>Brad</div><div><br><div><div>On Jun 14, 2012, at 11:41 AM, Ramón Casero Cañas wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><br>Hi,<br><br>The problem in brief:<br><br>I'm finding that itk::DanielssonDistanceMapImageFilter (derived from <br>itk::ImageToImageFilter) is returning NULL for the 2nd and 3rd outputs <br>when using the method GetOutput(i), while returning correct pointers <br>when using the method GetVectorDistanceMap().<br><br>this->derivedFilter->GetOutput(0) = 0x26750a0<br>this->derivedFilter->GetOutput(1) = 0<br>this->derivedFilter->GetOutput(2) = 0<br>this->derivedFilter->GetOutput() = 0x26750a0<br>this->derivedFilter->GetVoronoiMap() = 0x2674cb0<br>this->derivedFilter->GetVectorDistanceMap() = 0x2675480<br><br><br><br>The problem in detail:<br><br>I have a class with a pointer to a filter<br><br>class MexBaseFilter {<br><br>protected:<br><br>typedef typename itk::ImageToImageFilter<double, double> <br>ImageToImageFilterType;<br><br>typename ImageToImageFilterType::Pointer filter;<br><br>};<br><br>Then a derived class with the DanielssonDistance filter, which derives <br>from itk::ImageToImageFilter<br><br>class MexDanielssonDistanceMapImageFilter :<br> public MexBaseFilter {<br><br>private:<br> typedef itk::DanielssonDistanceMapImageFilter<<br> itk::Image<double, 3>,<br> itk::Image<double, 3> > DerivedImageToImageFilterType;<br><br> typename DerivedImageToImageFilterType::Pointer derivedFilter;<br><br>};<br><br><br>The filter gets instantiated in the constructor of the derived class, <br>and derivedFilter just points to it, using a dynamic_cast that compiles <br>thanks to polymorphism<br><br><br>MexDanielssonDistanceMapImageFilter::MexDanielssonDistanceMapImageFilter() <br>: MexBaseFilter() {<br><br> // using polymorphism<br> // (this->filter is ImageToImageFilterType)<br> this->filter = DerivedImageToImageFilterType::New();<br><br> derivedFilter =<br> dynamic_cast<DerivedImageToImageFilterType <br>*>(this->filter.GetPointer());<br><br>}<br><br><br>Then inputs and parameters are passed to the filter, filter->Update() is <br>run, and later a method gets called to inspect the outputs of the filter<br><br>void MexDanielssonDistanceMapImageFilter::InspectOutputs() {<br><br> std::cout << "this->derivedFilter = "<br> <span class="Apple-tab-span" style="white-space:pre">        </span> << this->derivedFilter << std::endl;<br> std::cout << "this->derivedFilter->GetOutput(0) = "<br> <span class="Apple-tab-span" style="white-space:pre">        </span> << this->derivedFilter->GetOutput(0) << std::endl;<br> std::cout << "this->derivedFilter->GetOutput(1) = "<br> <span class="Apple-tab-span" style="white-space:pre">        </span> << this->derivedFilter->GetOutput(1) << std::endl;<br> std::cout << "this->derivedFilter->GetOutput(2) = "<br> <span class="Apple-tab-span" style="white-space:pre">        </span> << this->derivedFilter->GetOutput(2) << std::endl;<br><br> std::cout << "this->derivedFilter->GetOutput() = "<br> <span class="Apple-tab-span" style="white-space:pre">        </span> << this->derivedFilter->GetOutput() << std::endl;<br> std::cout << "this->derivedFilter->GetVoronoiMap() = "<br> <span class="Apple-tab-span" style="white-space:pre">        </span> << this->derivedFilter->GetVoronoiMap() << std::endl;<br> std::cout << "this->derivedFilter->GetVectorDistanceMap() = "<br> <span class="Apple-tab-span" style="white-space:pre">        </span> << this->derivedFilter->GetVectorDistanceMap() << std::endl;<br><br>}<br><br>As can be seen from the following output, it seems that the 2nd and 3rd <br>outputs from the filter have been correctly created, and can be accessed <br>with methods GetVoronoiMap() and GetVectorDistanceMap(), but not with <br>GetOutput(i).<br><br><SCREEN><br>this->derivedFilter = DanielssonDistanceMapImageFilter (0x26707d0)<br> RTTI typeinfo: <br>itk::DanielssonDistanceMapImageFilter<itk::Image<short, 3u>, <br>itk::Image<unsigned char, 3u>, itk::Image<short, 3u> ><br> Reference Count: 3<br> Modified Time: 82<br> Debug: Off<br> Observers:<br> none<br> Inputs:<br> Primary: (0x2679d50) *<br> Required Input Names: Primary<br> Outputs:<br> Primary: (0x26750a0)<br> IndexedDataObject1: (0x2674cb0)<br> IndexedDataObject2: (0x2675480)<br> NumberOfIndexedInputs: 1<br> NumberOfRequiredInputs: 1<br> NumberOfIndexedOutputs: 3<br> NumberOfRequiredOutputs: 3<br> Number Of Threads: 4<br> ReleaseDataFlag: Off<br> ReleaseDataBeforeUpdateFlag: Off<br> AbortGenerateData: Off<br> Progress: 0.8<br> Multithreader:<br> RTTI typeinfo: itk::MultiThreader<br> Reference Count: 1<br> Modified Time: 32<br> Debug: Off<br> Observers:<br> none<br> Thread Count: 4<br> Global Maximum Number Of Threads: 128<br> Global Default Number Of Threads: 4<br> Danielson Distance:<br> Input Is Binary : 0<br> Use Image Spacing : 1<br> Squared Distance : 0<br><br>this->derivedFilter->GetOutput(0) = 0x26750a0<br>this->derivedFilter->GetOutput(1) = 0<br>this->derivedFilter->GetOutput(2) = 0<br>this->derivedFilter->GetOutput() = 0x26750a0<br>this->derivedFilter->GetVoronoiMap() = 0x2674cb0<br>this->derivedFilter->GetVectorDistanceMap() = 0x2675480<br>WARNING: In /usr/local/include/ITK-4.1/itkImageSource.hxx, line 112<br>DanielssonDistanceMapImageFilter (0x26707d0): dynamic_cast to output <br>type failed<br><br>WARNING: In /usr/local/include/ITK-4.1/itkImageSource.hxx, line 112<br>DanielssonDistanceMapImageFilter (0x26707d0): dynamic_cast to output <br>type failed<br></SCREEN><br><br><br>Best regards,<br><br>Ramon.<br><br>-- <br>Dr. Ramón Casero Cañas<br><br>Computational Biology<br>Department of Computer Science<br>University of Oxford<br>Wolfson Building, Parks Rd<br>Oxford OX1 3QD<br><br>tlf +44 (0) 1865 610737<br>web <a href="http://www.cs.ox.ac.uk/people/Ramon.CaseroCanas">http://www.cs.ox.ac.uk/people/Ramon.CaseroCanas</a><br>photos <a href="http://www.flickr.com/photos/rcasero/">http://www.flickr.com/photos/rcasero/</a><br>_____________________________________<br>Powered by <a href="http://www.kitware.com">www.kitware.com</a><br><br>Visit other Kitware open-source projects at<br><a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br><br>Kitware offers ITK Training Courses, for more information visit:<br>http://www.kitware.com/products/protraining.php<br><br>Please keep messages on-topic and check the ITK FAQ at:<br>http://www.itk.org/Wiki/ITK_FAQ<br><br>Follow this link to subscribe/unsubscribe:<br>http://www.itk.org/mailman/listinfo/insight-users<br></div></blockquote></div><br><div>
<span class="Apple-style-span" style="font-size: 12px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: normal normal normal 12px/normal Helvetica; ">========================================================</font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: normal normal normal 12px/normal Helvetica; ">Bradley Lowekamp<span class="Apple-converted-space"> </span><span class="Apple-converted-space"> </span></font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: normal normal normal 12px/normal Helvetica; ">Medical Science and Computing for</font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: normal normal normal 12px/normal Helvetica; ">Office of High Performance Computing and Communications</font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: normal normal normal 12px/normal Helvetica; ">National Library of Medicine<span class="Apple-converted-space"> </span></font></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font face="Helvetica" size="3" style="font: normal normal normal 12px/normal Helvetica; "><a href="mailto:blowekamp@mail.nih.gov">blowekamp@mail.nih.gov</a></font></p><br class="Apple-interchange-newline"></span></div></span><br class="Apple-interchange-newline">
</div>
<br></div></body></html>