Skip to content
Snippets Groups Projects
Commit 3e06502a authored by Guillaume Pasero's avatar Guillaume Pasero
Browse files

COMP: wrapperComplexInputImageParameter : template method body put in header,...

COMP: wrapperComplexInputImageParameter : template method body put in header, specializations put in cxx but also declared in header
parent 79628533
No related branches found
No related tags found
No related merge requests found
...@@ -17,9 +17,6 @@ ...@@ -17,9 +17,6 @@
=========================================================================*/ =========================================================================*/
#include "otbWrapperComplexInputImageParameter.h" #include "otbWrapperComplexInputImageParameter.h"
#include "itksys/SystemTools.hxx" #include "itksys/SystemTools.hxx"
#include "otbImageFileReader.h"
#include "itkCastImageFilter.h"
#include "otbImageToVectorImageCastFilter.h"
#include "otbWrapperTypes.h" #include "otbWrapperTypes.h"
...@@ -96,133 +93,6 @@ otbGetImageMacro(ComplexDoubleImage); ...@@ -96,133 +93,6 @@ otbGetImageMacro(ComplexDoubleImage);
otbGetImageMacro(ComplexFloatVectorImage); otbGetImageMacro(ComplexFloatVectorImage);
otbGetImageMacro(ComplexDoubleVectorImage); otbGetImageMacro(ComplexDoubleVectorImage);
template <class TOutputImage>
TOutputImage *
ComplexInputImageParameter::GetImage()
{
// Used m_PreviousFileName because if not, when the user call twice GetImage,
// it without changing the filename, it returns 2 different
// image pointers
// Only one image type can be used
// 2 cases : the user set a filename vs. the user set an image
if (m_UseFilename)
{
if( m_PreviousFileName!=m_FileName && !m_FileName.empty() )
{
//////////////////////// Filename case:
// A new valid filename has been given : a reader is created
m_PreviousFileName = m_FileName;
typedef otb::ImageFileReader<TOutputImage> ReaderType;
typename ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(m_FileName);
try
{
reader->UpdateOutputInformation();
}
catch(itk::ExceptionObject &)
{
this->ClearValue();
}
m_Image = reader->GetOutput();
m_Reader = reader;
// Pay attention, don't return m_Image because it is a ImageBase...
return reader->GetOutput();
}
else
{
// In this case, the reader and the image should already be there
if (m_Image.IsNull())
{
itkExceptionMacro("No input image or filename detected...");
}
else
{
// Check if the image type asked here is the same as the one used for the reader
if (dynamic_cast<TOutputImage*> (m_Image.GetPointer()))
{
return dynamic_cast<TOutputImage*> (m_Image.GetPointer());
}
else
{
itkExceptionMacro("Cannot ask a different image type");
}
}
}
}
else
{
//////////////////////// Image case:
if( m_Image.IsNull() )
{
itkExceptionMacro("No input image or filename detected...");
}
else
{
if (dynamic_cast<ComplexFloatVectorImageType*>(m_Image.GetPointer()))
{
return CastImage<ComplexFloatVectorImageType, TOutputImage>();
}
else if (dynamic_cast<ComplexDoubleVectorImageType*>(m_Image.GetPointer()))
{
return CastImage<ComplexDoubleVectorImageType, TOutputImage>();
}
else if (dynamic_cast<ComplexFloatImageType*>(m_Image.GetPointer()))
{
return CastImage<ComplexFloatImageType, TOutputImage>();
}
else if (dynamic_cast<ComplexDoubleImageType*>(m_Image.GetPointer()))
{
return CastImage<ComplexDoubleImageType, TOutputImage>();
}
else
{
itkExceptionMacro("Unknown image type");
}
}
}
}
template <class TComplexInputImage, class TOutputImage>
TOutputImage*
ComplexInputImageParameter::SimpleCastImage()
{
TComplexInputImage* realComplexInputImage = dynamic_cast<TComplexInputImage*>(m_Image.GetPointer());
typedef itk::CastImageFilter<TComplexInputImage, TOutputImage> CasterType;
typename CasterType::Pointer caster = CasterType::New();
caster->SetInput(realComplexInputImage);
caster->UpdateOutputInformation();
m_Image = caster->GetOutput();
m_Caster = caster;
return caster->GetOutput();
}
template <class TComplexInputImage, class TOutputImage>
TOutputImage*
ComplexInputImageParameter::CastVectorImageFromImage()
{
TComplexInputImage* realComplexInputImage = dynamic_cast<TComplexInputImage*>(m_Image.GetPointer());
typedef ImageToVectorImageCastFilter<TComplexInputImage, TOutputImage> CasterType;
typename CasterType::Pointer caster = CasterType::New();
caster->SetInput(realComplexInputImage);
caster->UpdateOutputInformation();
m_Image = caster->GetOutput();
m_Caster = caster;
return caster->GetOutput();
}
#define otbCastImageMacro(ComplexInputImageType, OutputImageType, theMethod) \ #define otbCastImageMacro(ComplexInputImageType, OutputImageType, theMethod) \
template<> OutputImageType * \ template<> OutputImageType * \
......
...@@ -74,11 +74,7 @@ public: ...@@ -74,11 +74,7 @@ public:
/** Generic cast method that will be specified for each image type. */ /** Generic cast method that will be specified for each image type. */
template <class TComplexInputImage, class TOutputImage> template <class TComplexInputImage, class TOutputImage>
TOutputImage* CastImage() TOutputImage* CastImage();
{
itkExceptionMacro("Cast from "<<typeid(TComplexInputImage).name()
<<" to "<<typeid(TOutputImage).name()<<" not authorized.");
}
/** Cast an image to an image of the same type /** Cast an image to an image of the same type
* Image to Image, VectorImage to VectorImage, RGBAImage to RGBAImage. */ * Image to Image, VectorImage to VectorImage, RGBAImage to RGBAImage. */
...@@ -127,7 +123,38 @@ private: ...@@ -127,7 +123,38 @@ private:
}; // End class ComplexInputImage Parameter }; // End class ComplexInputImage Parameter
// template specializations of CastImage<> should be declared in header
// so that the linker knows they exist when building OTB Applications
#define otbDefineCastImageMacro(ComplexInputImageType, OutputImageType) \
template<> OutputImageType * \
ComplexInputImageParameter::CastImage<ComplexInputImageType , OutputImageType>(); \
#define otbGenericDefineCastImageMacro(ComplexInputImageType, prefix) \
otbDefineCastImageMacro(ComplexInputImageType, ComplexFloat##prefix##ImageType) \
otbDefineCastImageMacro(ComplexInputImageType, ComplexDouble##prefix##ImageType)
/*********************************************************************
********************** Image -> Image
**********************************************************************/
otbGenericDefineCastImageMacro(ComplexFloatImageType, )
otbGenericDefineCastImageMacro(ComplexDoubleImageType, )
/*********************************************************************
********************** VectorImage -> VectorImage
**********************************************************************/
otbGenericDefineCastImageMacro(ComplexFloatVectorImageType, Vector)
otbGenericDefineCastImageMacro(ComplexDoubleVectorImageType, Vector)
} // End namespace Wrapper } // End namespace Wrapper
} // End namespace otb } // End namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbWrapperComplexInputImageParameter.txx"
#endif
#endif #endif
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbWrapperComplexInputImageParameter_txx
#define __otbWrapperComplexInputImageParameter_txx
#include "otbWrapperComplexInputImageParameter.h"
#include "otbImageFileReader.h"
#include "itkCastImageFilter.h"
#include "otbImageToVectorImageCastFilter.h"
namespace otb
{
namespace Wrapper
{
template <class TOutputImage>
TOutputImage *
ComplexInputImageParameter::GetImage()
{
// Used m_PreviousFileName because if not, when the user call twice GetImage,
// it without changing the filename, it returns 2 different
// image pointers
// Only one image type can be used
// 2 cases : the user set a filename vs. the user set an image
if (m_UseFilename)
{
if( m_PreviousFileName!=m_FileName && !m_FileName.empty() )
{
//////////////////////// Filename case:
// A new valid filename has been given : a reader is created
m_PreviousFileName = m_FileName;
typedef otb::ImageFileReader<TOutputImage> ReaderType;
typename ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(m_FileName);
try
{
reader->UpdateOutputInformation();
}
catch(itk::ExceptionObject &)
{
this->ClearValue();
}
m_Image = reader->GetOutput();
m_Reader = reader;
// Pay attention, don't return m_Image because it is a ImageBase...
return reader->GetOutput();
}
else
{
// In this case, the reader and the image should already be there
if (m_Image.IsNull())
{
itkExceptionMacro("No input image or filename detected...");
}
else
{
// Check if the image type asked here is the same as the one used for the reader
if (dynamic_cast<TOutputImage*> (m_Image.GetPointer()))
{
return dynamic_cast<TOutputImage*> (m_Image.GetPointer());
}
else
{
itkExceptionMacro("Cannot ask a different image type");
}
}
}
}
else
{
//////////////////////// Image case:
if( m_Image.IsNull() )
{
itkExceptionMacro("No input image or filename detected...");
}
else
{
if (dynamic_cast<ComplexFloatVectorImageType*>(m_Image.GetPointer()))
{
return CastImage<ComplexFloatVectorImageType, TOutputImage>();
}
else if (dynamic_cast<ComplexDoubleVectorImageType*>(m_Image.GetPointer()))
{
return CastImage<ComplexDoubleVectorImageType, TOutputImage>();
}
else if (dynamic_cast<ComplexFloatImageType*>(m_Image.GetPointer()))
{
return CastImage<ComplexFloatImageType, TOutputImage>();
}
else if (dynamic_cast<ComplexDoubleImageType*>(m_Image.GetPointer()))
{
return CastImage<ComplexDoubleImageType, TOutputImage>();
}
else
{
itkExceptionMacro("Unknown image type");
}
}
}
}
template <class TComplexInputImage, class TOutputImage>
TOutputImage*
ComplexInputImageParameter::CastImage()
{
itkExceptionMacro("Cast from "<<typeid(TComplexInputImage).name()
<<" to "<<typeid(TOutputImage).name()<<" not authorized.");
}
template <class TComplexInputImage, class TOutputImage>
TOutputImage*
ComplexInputImageParameter::SimpleCastImage()
{
TComplexInputImage* realComplexInputImage = dynamic_cast<TComplexInputImage*>(m_Image.GetPointer());
typedef itk::CastImageFilter<TComplexInputImage, TOutputImage> CasterType;
typename CasterType::Pointer caster = CasterType::New();
caster->SetInput(realComplexInputImage);
caster->UpdateOutputInformation();
m_Image = caster->GetOutput();
m_Caster = caster;
return caster->GetOutput();
}
template <class TComplexInputImage, class TOutputImage>
TOutputImage*
ComplexInputImageParameter::CastVectorImageFromImage()
{
TComplexInputImage* realComplexInputImage = dynamic_cast<TComplexInputImage*>(m_Image.GetPointer());
typedef ImageToVectorImageCastFilter<TComplexInputImage, TOutputImage> CasterType;
typename CasterType::Pointer caster = CasterType::New();
caster->SetInput(realComplexInputImage);
caster->UpdateOutputInformation();
m_Image = caster->GetOutput();
m_Caster = caster;
return caster->GetOutput();
}
} // End namespace Wrapper
} // End namespace otb
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment