From f45c930e8a0aa9752ac6f717cbcb993f28249247 Mon Sep 17 00:00:00 2001 From: Julien Michel <julien.michel@orfeo-toolbox.org> Date: Wed, 8 Apr 2015 15:28:20 +0200 Subject: [PATCH] BUG: Avoid a cast that can fail if ImageBase* does not downcast to OutputImageType* --- .../otbOGRDataSourceToLabelImageFilter.txx | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/Modules/Segmentation/Conversion/include/otbOGRDataSourceToLabelImageFilter.txx b/Modules/Segmentation/Conversion/include/otbOGRDataSourceToLabelImageFilter.txx index 922d831dbd..c1927f0cba 100644 --- a/Modules/Segmentation/Conversion/include/otbOGRDataSourceToLabelImageFilter.txx +++ b/Modules/Segmentation/Conversion/include/otbOGRDataSourceToLabelImageFilter.txx @@ -117,21 +117,13 @@ void OGRDataSourceToLabelImageFilter<TOutputImage> ::SetOutputParametersFromImage(const ImageBaseType * image) { - if (dynamic_cast<const OutputImageType*>(image)) - { - const OutputImageType * src = dynamic_cast<const OutputImageType*>(image); - - this->SetOutputOrigin ( src->GetOrigin() ); - this->SetOutputSpacing ( src->GetSpacing() ); - //this->SetOutputStartIndex ( src->GetLargestPossibleRegion().GetIndex() ); - this->SetOutputSize ( src->GetLargestPossibleRegion().GetSize() ); - this->SetOutputProjectionRef(src->GetProjectionRef()); - //this->SetOutputKeywordList(src->GetImageKeywordlist()); - } - else - { - itkExceptionMacro(<< "Image can't be casted to output image type."); - } + this->SetOutputOrigin ( image->GetOrigin() ); + this->SetOutputSpacing ( image->GetSpacing() ); + this->SetOutputSize ( image->GetLargestPossibleRegion().GetSize() ); + + ImageMetadataInterfaceBase::Pointer imi = ImageMetadataInterfaceFactory::CreateIMI(image->GetMetaDataDictionary()); + + this->SetOutputProjectionRef(imi->GetProjectionRef()); } template< class TOutputImage> -- GitLab