diff --git a/Code/FeatureExtraction/otbImageFunctionAdaptor.h b/Code/FeatureExtraction/otbImageFunctionAdaptor.h new file mode 100644 index 0000000000000000000000000000000000000000..bf392fddfc0a78416ab371fecffbe7685544a6ff --- /dev/null +++ b/Code/FeatureExtraction/otbImageFunctionAdaptor.h @@ -0,0 +1,122 @@ +/*========================================================================= + + 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 __otbImageFunctionAdaptor_h +#define __otbImageFunctionAdaptor_h + +#include "itkImageFunction.h" +#include "itkNumericTraits.h" + +#include "otbVariableLengthVectorConverter.h" + + +#include <complex> + +namespace otb +{ + + +template< class TInternalImageFunctionType > +class ITK_EXPORT ImageFunctionAdaptor : + public itk::ImageFunction< typename TInternalImageFunctionType::InputImageType, + itk::VariableLengthVector< + ITK_TYPENAME itk::NumericTraits<typename TInternalImageFunctionType::InputImageType::PixelType> + ::RealType >, + typename TInternalImageFunctionType::CoordRepType > +{ + public: + // Standard class typedefs. // + typedef ImageFunctionAdaptor Self; + typedef itk::ImageFunction< typename TInternalImageFunctionType::InputImageType, + itk::VariableLengthVector< + ITK_TYPENAME itk::NumericTraits<typename TInternalImageFunctionType::InputImageType::PixelType> + ::RealType >, + typename TInternalImageFunctionType::CoordRepType > + Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + // Run-time type information (and related methods). // + itkTypeMacro(ImageFunctionAdaptor, ImageFunction); + + // Method for creation through the object factory. // + itkNewMacro(Self); + + // InputImageType typedef support. // + typedef typename TInternalImageFunctionType::InputImageType InputImageType; + typedef typename TInternalImageFunctionType::CoordRepType CoordRepType; + typedef typename Superclass::IndexType IndexType; + typedef typename Superclass::ContinuousIndexType ContinuousIndexType; + typedef typename Superclass::PointType PointType; + typedef typename Superclass::OutputType OutputType; + typedef typename OutputType::ValueType OutputValueType; + + // InternalImageFunction related typedefs // + typedef TInternalImageFunctionType InternalImageFunctionType; + typedef typename InternalImageFunctionType::OutputType InternalImageFunctionOutputType; + + // Converter related typedefs // + typedef VariableLengthVectorConverter<InternalImageFunctionOutputType, double> ConverterType; + + + // Dimension of the underlying image. // + itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension); + + // Evalulate the function at specified index // + virtual OutputType EvaluateAtIndex(const IndexType& index) const; + + // Evaluate the function at non-integer positions // + virtual OutputType Evaluate(const PointType& point) const + { + IndexType index; + this->ConvertPointToNearestIndex(point, index); + return this->EvaluateAtIndex(index); + } + virtual OutputType EvaluateAtContinuousIndex( + const ContinuousIndexType& cindex) const + { + IndexType index; + this->ConvertContinuousIndexToNearestIndex(cindex, index); + return this->EvaluateAtIndex(index); + } + + // Accessors // + itkGetConstMacro(InternalImageFunction, typename InternalImageFunctionType::Pointer); + itkSetMacro(InternalImageFunction, typename InternalImageFunctionType::Pointer); + +protected: + ImageFunctionAdaptor(); + virtual ~ImageFunctionAdaptor() {} + void PrintSelf(std::ostream& os, itk::Indent indent) const; + +private: + ImageFunctionAdaptor(const Self &); //purposely not implemented + void operator =(const Self&); //purposely not implemented + + // Internal Image Function // + typename InternalImageFunctionType::Pointer m_InternalImageFunction; + // Converter // + typename ConverterType::Pointer m_Converter; +}; + +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbImageFunctionAdaptor.txx" +#endif + +#endif diff --git a/Code/FeatureExtraction/otbImageFunctionAdaptor.txx b/Code/FeatureExtraction/otbImageFunctionAdaptor.txx new file mode 100644 index 0000000000000000000000000000000000000000..62a1437d1419ee56559017189bba046b0e1feb1b --- /dev/null +++ b/Code/FeatureExtraction/otbImageFunctionAdaptor.txx @@ -0,0 +1,58 @@ +/*========================================================================= + + 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 __otbImageFunctionAdaptor_txx +#define __otbImageFunctionAdaptor_txx + +#include "otbImageFunctionAdaptor.h" + +namespace otb +{ +template< class TInternalImageFunctionType > +ImageFunctionAdaptor< TInternalImageFunctionType > +::ImageFunctionAdaptor() +{ + m_InternalImageFunction = InternalImageFunctionType::New(); + m_Converter = ConverterType::New(); +} + +template< class TInternalImageFunctionType > +void +ImageFunctionAdaptor< TInternalImageFunctionType > +::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + Superclass::PrintSelf(os, indent); + os << indent << "Internal Image Function: " << m_InternalImageFunction << std::endl; +} + +template< class TInternalImageFunctionType > +typename ImageFunctionAdaptor< TInternalImageFunctionType >::OutputType +ImageFunctionAdaptor< TInternalImageFunctionType > +::EvaluateAtIndex(const IndexType& index) const +{ + OutputType result; + this->GetInternalImageFunction()->SetInputImage(this->GetInputImage()); + InternalImageFunctionOutputType tmpResult = this->GetInternalImageFunction()->EvaluateAtIndex(index); + result = m_Converter->Convert(tmpResult); + + return result; +} + + +} // end namespace otb + +#endif diff --git a/Testing/Code/FeatureExtraction/CMakeLists.txt b/Testing/Code/FeatureExtraction/CMakeLists.txt index 560bcf869530627cf44fba8f1214cefa96728ca2..12b13c2b26f4b4e0cb5355e71882cd2c5119a5bb 100644 --- a/Testing/Code/FeatureExtraction/CMakeLists.txt +++ b/Testing/Code/FeatureExtraction/CMakeLists.txt @@ -1504,12 +1504,12 @@ ADD_TEST(feTuLocalHistogramImageFunctionTest ${FEATUREEXTRACTION_TESTS16} # ------- otb::ImageFunctionAdapter ------------- -ADD_TEST(feTuImageFunctionAdapterNew ${FEATUREEXTRACTION_TESTS16} - otbImageFunctionAdapterNew +ADD_TEST(feTuImageFunctionAdaptorNew ${FEATUREEXTRACTION_TESTS16} + otbImageFunctionAdaptorNew ) -ADD_TEST(feTvImageFunctionAdapter ${FEATUREEXTRACTION_TESTS16} - otbImageFunctionAdapter +ADD_TEST(feTvImageFunctionAdaptor ${FEATUREEXTRACTION_TESTS16} + otbImageFunctionAdaptor ${INPUTDATA}/poupees.png ) @@ -1722,7 +1722,7 @@ otbFeatureExtractionTests16.cxx otbFourierMellinDescriptors.cxx otbLocalHistogramImageFunctionNew.cxx otbLocalHistogramImageFunctionTest.cxx -otbImageFunctionAdapter.cxx +otbImageFunctionAdaptor.cxx otbMetaImageFunction.cxx ) diff --git a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests16.cxx b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests16.cxx index 0b1ddb8e18db845756e4f2828bbf52142cf9ec51..4ce2d662b6c6c19970ed23327ab6483f78fe0892 100644 --- a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests16.cxx +++ b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests16.cxx @@ -32,8 +32,8 @@ void RegisterTests() REGISTER_TEST(otbFourierMellinDescriptorsRotationInvariant); REGISTER_TEST(otbLocalHistogramImageFunctionNew); REGISTER_TEST(otbLocalHistogramImageFunctionTest); - REGISTER_TEST(otbImageFunctionAdapterNew); - REGISTER_TEST(otbImageFunctionAdapter); + REGISTER_TEST(otbImageFunctionAdaptorNew); + REGISTER_TEST(otbImageFunctionAdaptor); REGISTER_TEST(otbMetaImageFunctionNew); REGISTER_TEST(otbMetaImageFunction); }