[Insight-developers] I'm seeing a dynamic_cast problem in ImageBase (gcc4-related?)

Zachary Pincus zpincus at stanford.edu
Mon Jul 25 05:10:24 EDT 2005


Hello,

I've been stymied by an odd problem with using some ITK filters in my  
code. This problem appeared in previously-working code when I  
switched to gcc4. Compiling with gcc3.3 leads to correct behavior.

Unfortunately, I haven't been able to isolate a simple test case yet.  
I'm (really) hoping, however, that someone will be able to recognize  
the general type of error this is and be able to point me in the  
right direction to find this. Anyone's expertise in this matter would  
be really appreciated, as I've pretty much exhausted my hypotheses.

The problem is that when I try to run an image through a particular  
ITK filter, this exception is raised:

/Developer/Local/ITK-CVS/Insight/Code/Common/itkImageBase.txx:239:
itk::ERROR: Image(0x685560): itk::ImageBase::CopyInformation() cannot  
cast PKN3itk10DataObjectE to PKN3itk9ImageBaseILj2EEE

The problem is that the code leading up to this error is all  
statically-typed, so there should be nothing unexpected happening at  
runtime with the dynamic casting. I pass in an appropriately-typed  
input image, and get this error on calling Update on the filter.  
Oddly enough, some filters don't do this -- and these all seem to be  
subclasses of InPlaceImageFilter.

Now, I haven't been able to isolate this because it seems to happen  
in the context of some python wrapper code I've written. Simpler test  
cases don't cause the error.

Anyhow, the offending code looks basically like this:

MedianFilterImage(const Py::Tuple& args, const Py::Dict &kws) {
   typedef itk::MedianImageFilter<FloatImageType,
     FloatImageType > MedianFilterType;

   try {
     // Unpack a float image from the python input
     // It's statically typed as the right image type...
     FloatImageType::ConstPointer input =
       FloatImageWrapper::GetImageFromWrapper(kws["input"]);
     // but let's test it at run-time too.
     std::cout <<"Run time type is: " <<  typeid(input.GetPointer 
()).name() << std::endl;
     MedianFilterType::Pointer medianFilter = MedianFilterType::New();
     medianFilter->SetInput(input);
     FloatImageType::SizeType radius;
     // unpack the parameters from the python input
     radius.Fill(Py::Int(kws["radius"]));
     medianFilter->SetRadius(radius);
     // exception is thrown here...
     medianFilter->Update();
     // pack the output back into a python wrapper.
     return FloatImageWrapper::NewWrapperFromImage(medianFilter- 
 >GetOutput());
   } catch( itk::ExceptionObject & err ) {
     throw Py::RuntimeError(err.what());
   }
}

At run-time, the standard output from the typeid line above is:
Run time type is: PKN3itk5ImageIfLj2EEE

The backtrace from the exception throw is (until the Update command  
above):
#1  0x06cc89cc in itk::ImageBase<2u>::CopyInformation (this=0x685520,  
data=0x60c120) at /Developer/Local/ITK-CVS/Insight/Code/Common/ 
itkImageBase.txx:237
#2  0x02023764 in itk::ProcessObject::GenerateOutputInformation  
(this=0x685480) at /Developer/Local/ITK-CVS/Insight/Code/Common/ 
itkProcessObject.cxx:1048
#3  0x0202297c in itk::ProcessObject::UpdateOutputInformation  
(this=0x685480) at /Developer/Local/ITK-CVS/Insight/Code/Common/ 
itkProcessObject.cxx:690
#4  0x06cb3844 in itk::ImageBase<2u>::UpdateOutputInformation  
(this=0x685520) at /Developer/Local/ITK-CVS/Insight/Code/Common/ 
itkImageBase.txx:173
#5  0x0200a9e8 in itk::DataObject::Update (this=0x685520) at / 
Developer/Local/ITK-CVS/Insight/Code/Common/itkDataObject.cxx:342


Thanks for any advice at all,

Zach Pincus

Program in Biomedical Informatics and Department of Biochemistry
Stanford University School of Medicine



More information about the Insight-developers mailing list