diff --git a/Code/FeatureExtraction/otbImageToModulusAndDirectionImageFilter.h b/Code/FeatureExtraction/otbImageToModulusAndDirectionImageFilter.h new file mode 100755 index 0000000000000000000000000000000000000000..6085aafe9fc07dcee5506160f71b8b47450ef223 --- /dev/null +++ b/Code/FeatureExtraction/otbImageToModulusAndDirectionImageFilter.h @@ -0,0 +1,90 @@ +/*========================================================================= + + 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 __otbImageToModulusAndDirectionImageFilter_h +#define __otbImageToModulusAndDirectionImageFilter_h + +#include "itkImageToImageFilter.h" + + +namespace otb +{ + +/** \class ImageToModulusAndDirectionImageFilter + * + * \brief Base class for modulus and direction image filters. + * + * This is the base class for alls class' generate modulus and + * directions outputs. + * GetOutput() method return the output image modulus and + * GetOutputDirection() return the output image direction + * + */ +template <class TInputImage, + class TOutputImage, + class TOutputImageDirection = TOutputImage > +class ITK_EXPORT ImageToModulusAndDirectionImageFilter : public itk::ImageToImageFilter< TInputImage, TOutputImage > +{ +public: + /** Extract dimensions as well of the images of entry of exit. */ + itkStaticConstMacro( InputImageDimension, + unsigned int, + TInputImage::ImageDimension); + itkStaticConstMacro( OutputImageDimension, + unsigned int, + TOutputImage::ImageDimension); + + typedef TInputImage InputImageType; + typedef TOutputImage OutputImageType; + typedef TOutputImageDirection OutputImageDirectionType; + + /** typedef for the classes standards. */ + typedef ImageToModulusAndDirectionImageFilter Self; + typedef itk::ImageToImageFilter< InputImageType, OutputImageType> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Method for management of the object factory. */ + itkNewMacro(Self); + + /** Return the name of the class. */ + itkTypeMacro(ImageToModulusAndDirectionImageFilter, itk::ImageToImageFilter); + + /** Return the output image modulus */ + const OutputImageType * GetOutput(); + + /** Return the output image direction */ + const OutputImageDirectionType * GetOutputDirection(); + +protected: + ImageToModulusAndDirectionImageFilter(); + virtual ~ImageToModulusAndDirectionImageFilter() {}; + void PrintSelf(std::ostream& os, itk::Indent indent) const; + +private: + ImageToModulusAndDirectionImageFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + +}; +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbImageToModulusAndDirectionImageFilter.txx" +#endif + + +#endif diff --git a/Code/FeatureExtraction/otbImageToModulusAndDirectionImageFilter.txx b/Code/FeatureExtraction/otbImageToModulusAndDirectionImageFilter.txx new file mode 100755 index 0000000000000000000000000000000000000000..d3b0ba31cb100abe7a5a30ebc7d9722222338e4e --- /dev/null +++ b/Code/FeatureExtraction/otbImageToModulusAndDirectionImageFilter.txx @@ -0,0 +1,86 @@ +/*========================================================================= + + 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 __otbImageToModulusAndDirectionImageFilter_txx +#define __otbImageToModulusAndDirectionImageFilter_txx + +#include "otbImageToModulusAndDirectionImageFilter.h" +#include "itkProcessObject.h" + +namespace otb +{ + +/** + * + */ +template <class TInputImage, class TOutputImage, class TOutputImageDirection > +ImageToModulusAndDirectionImageFilter<TInputImage, TOutputImage, TOutputImageDirection>:: +ImageToModulusAndDirectionImageFilter() +{ + this->SetNumberOfInputs(1); + this->SetNumberOfRequiredInputs(1); + this->SetNumberOfOutputs(2); + this->SetNumberOfRequiredOutputs(2); + + this->SetNthOutput(0,OutputImageType::New()); + this->SetNthOutput(1,OutputImageDirectionType::New()); +} + + +/** Return the output image modulus */ +template <class TInputImage, class TOutputImage, class TOutputImageDirection > +const typename ImageToModulusAndDirectionImageFilter<TInputImage, TOutputImage, TOutputImageDirection>::OutputImageType * +ImageToModulusAndDirectionImageFilter<TInputImage, TOutputImage, TOutputImageDirection>:: +GetOutput() +{ + if (this->GetNumberOfOutputs() < 1) + { + return 0; + } + return static_cast<const OutputImageType * > + (this->itk::ProcessObject::GetOutput(0) ); +} + +/** Return the output image direction */ +template <class TInputImage, class TOutputImage, class TOutputImageDirection > +const typename ImageToModulusAndDirectionImageFilter<TInputImage, TOutputImage, TOutputImageDirection>::OutputImageDirectionType * +ImageToModulusAndDirectionImageFilter<TInputImage, TOutputImage, TOutputImageDirection>:: +GetOutputDirection() +{ + if (this->GetNumberOfOutputs() < 2) + { + return 0; + } + return static_cast<const OutputImageDirectionType * > + (this->itk::ProcessObject::GetOutput(1) ); +} + +/** + * Standard "PrintSelf" method + */ +template <class TInputImage, class TOutputImage, class TOutputImageDirection > +void +ImageToModulusAndDirectionImageFilter<TInputImage, TOutputImage, TOutputImageDirection>:: +PrintSelf(std::ostream& os, itk::Indent indent) const +{ + Superclass::PrintSelf( os, indent ); + +} + +} // end namespace otb + +#endif diff --git a/Code/FeatureExtraction/otbModulusAndDirectionImageToImageFilter.h b/Code/FeatureExtraction/otbModulusAndDirectionImageToImageFilter.h new file mode 100755 index 0000000000000000000000000000000000000000..cfbbe226270160761481e4668d98fca2d8c42491 --- /dev/null +++ b/Code/FeatureExtraction/otbModulusAndDirectionImageToImageFilter.h @@ -0,0 +1,91 @@ +/*========================================================================= + + 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 __otbModulusAndDirectionImageToImageFilter_h +#define __otbModulusAndDirectionImageToImageFilter_h + +#include "itkImageToImageFilter.h" + + +namespace otb +{ + +/** \class ModulusAndDirectionImageToImageFilter + * + * \brief Base class for modulus and direction image filters. + * + * This is the base class for alls class' generate an image dulus and + * by using an modulus and a direction images intputs. + * SetInput() method set the modulus image input and + * SetInputDirection() set the image direction input. + * + */ +template <class TInputImage, + class TInputImageDirection, + class TOutputImage > +class ITK_EXPORT ModulusAndDirectionImageToImageFilter : public itk::ImageToImageFilter< TInputImage, TOutputImage > +{ +public: + /** Extract dimensions as well of the images of entry of exit. */ + itkStaticConstMacro( InputImageDimension, + unsigned int, + TInputImage::ImageDimension); + itkStaticConstMacro( OutputImageDimension, + unsigned int, + TOutputImage::ImageDimension); + + typedef TInputImage InputImageType; + typedef TInputImageDirection InputImageDirectionType; + typedef TOutputImage OutputImageType; + + /** typedef for the classes standards. */ + typedef ModulusAndDirectionImageToImageFilter Self; + typedef itk::ImageToImageFilter< InputImageType, OutputImageType> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Method for management of the object factory. */ + itkNewMacro(Self); + + /** Return the name of the class. */ + itkTypeMacro(ModulusAndDirectionImageToImageFilter, itk::ImageToImageFilter); + + + /** Set/Get the image input of this process object. */ + virtual void SetInput( const InputImageType *input); + virtual void SetInputDirection( const InputImageDirectionType *direction); + const InputImageType * GetInput(void); + const InputImageDirectionType * GetInputDirection(void); + +protected: + ModulusAndDirectionImageToImageFilter(); + virtual ~ModulusAndDirectionImageToImageFilter() {}; + void PrintSelf(std::ostream& os, itk::Indent indent) const; + +private: + ModulusAndDirectionImageToImageFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + +}; +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbModulusAndDirectionImageToImageFilter.txx" +#endif + + +#endif diff --git a/Code/FeatureExtraction/otbModulusAndDirectionImageToImageFilter.txx b/Code/FeatureExtraction/otbModulusAndDirectionImageToImageFilter.txx new file mode 100755 index 0000000000000000000000000000000000000000..03950a847203ab83023cff500e3aad76dbc72e79 --- /dev/null +++ b/Code/FeatureExtraction/otbModulusAndDirectionImageToImageFilter.txx @@ -0,0 +1,108 @@ +/*========================================================================= + + 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 __otbModulusAndDirectionImageToImageFilter_txx +#define __otbModulusAndDirectionImageToImageFilter_txx + +#include "otbModulusAndDirectionImageToImageFilter.h" +#include "itkProcessObject.h" + +namespace otb +{ + +/** + * + */ +template <class TInputImage, class TOutputImage, class TOutputImageDirection > +ModulusAndDirectionImageToImageFilter<TInputImage, TOutputImage, TOutputImageDirection>:: +ModulusAndDirectionImageToImageFilter() +{ + this->SetNumberOfInputs(2); + this->SetNumberOfRequiredInputs(2); + this->SetNumberOfOutputs(1); + this->SetNumberOfRequiredOutputs(1); + + this->SetNthOutput(0,OutputImageType::New()); +} + + +template <class TInputImage, class TInputImageDirection, class TOutputImage > +void +ModulusAndDirectionImageToImageFilter<TInputImage, TInputImageDirection, TOutputImage>:: +SetInput( const InputImageType *input) +{ + // Process object is not const-correct so the const_cast is required here + this->itk::ProcessObject::SetNthInput(0, + const_cast< InputImageType * >( input ) ); +} + +template <class TInputImage, class TInputImageDirection, class TOutputImage > +void +ModulusAndDirectionImageToImageFilter<TInputImage, TInputImageDirection, TOutputImage>:: +SetInputDirection( const InputImageDirectionType *direction) +{ + // Process object is not const-correct so the const_cast is required here + this->itk::ProcessObject::SetNthInput(1, + const_cast< InputImageDirectionType * >( direction ) ); +} + +/** Return the input image modulus */ +template <class TInputImage, class TInputImageDirection, class TOutputImage > +const typename ModulusAndDirectionImageToImageFilter<TInputImage, TInputImageDirection, TOutputImage>::InputImageType * +ModulusAndDirectionImageToImageFilter<TInputImage, TInputImageDirection, TOutputImage>:: +GetInput(void) +{ + if (this->GetNumberOfInputs() < 1) + { + return 0; + } + + return static_cast<const TInputImage * > + (this->itk::ProcessObject::GetInput(0) ); +} + +/** Return the intput image direction */ +template <class TInputImage, class TInputImageDirection, class TOutputImage > +const typename ModulusAndDirectionImageToImageFilter<TInputImage, TInputImageDirection, TOutputImage>::InputImageDirectionType * +ModulusAndDirectionImageToImageFilter<TInputImage, TInputImageDirection, TOutputImage>:: +GetInputDirection(void) +{ + if (this->GetNumberOfInputs() < 1) + { + return 0; + } + + return static_cast<const TInputImageDirection * > + (this->itk::ProcessObject::GetInput(1) ); + +} + +/** + * Standard "PrintSelf" method + */ +template <class TInputImage, class TInputImageDirection, class TOutputImage > +void +ModulusAndDirectionImageToImageFilter<TInputImage, TInputImageDirection, TOutputImage>:: +PrintSelf(std::ostream& os, itk::Indent indent) const +{ + Superclass::PrintSelf( os, indent ); + +} + +} // end namespace otb + +#endif diff --git a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests.cxx b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests.cxx index ffccd4dadc0eaff5dab24d2f9bf84c81e292a8df..ab03deb9bfb137d7fa78a0b27412533da5bac7b0 100755 --- a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests.cxx +++ b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests.cxx @@ -79,4 +79,5 @@ REGISTER_TEST(otbFourierMellinImageFilterTestFFT); REGISTER_TEST(otbFourierMellinImageFilter); REGISTER_TEST(otbImageToEdgePathFilterNew); REGISTER_TEST(otbImageToEdgePathFilter); +REGISTER_TEST(otbModulusAndDirectionImageFiltersNew); } diff --git a/Testing/Code/FeatureExtraction/otbModulusAndDirectionImageFiltersNew.cxx b/Testing/Code/FeatureExtraction/otbModulusAndDirectionImageFiltersNew.cxx new file mode 100644 index 0000000000000000000000000000000000000000..1584898435065bf74ff8a85bc507c957be510b98 --- /dev/null +++ b/Testing/Code/FeatureExtraction/otbModulusAndDirectionImageFiltersNew.cxx @@ -0,0 +1,74 @@ +/*========================================================================= + + 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. + +=========================================================================*/ +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "itkExceptionObject.h" +#include "otbImage.h" +#include <iostream> + +#include "otbImageToModulusAndDirectionImageFilter.h" +#include "otbModulusAndDirectionImageToImageFilter.h" + +int otbModulusAndDirectionImageFiltersNew( int argc, char* argv[] ) +{ + try + { + typedef unsigned char InputPixelType; + typedef double OutputPixelType; + const unsigned int Dimension = 2; + + typedef otb::Image< InputPixelType, Dimension > InputImageType; + typedef otb::Image< OutputPixelType, Dimension > InputImageDirectionType; + typedef otb::Image< OutputPixelType, Dimension > OutputImageType; + typedef otb::Image< OutputPixelType, Dimension > OutputImageDirectionType; + + typedef otb::ImageToModulusAndDirectionImageFilter< InputImageType, OutputImageType> FilterType; + typedef otb::ImageToModulusAndDirectionImageFilter< InputImageType, OutputImageType, OutputImageDirectionType> Filter2Type; + + FilterType::Pointer Filter = FilterType::New(); + Filter2Type::Pointer Filter2 = Filter2Type::New(); + + typedef otb::ModulusAndDirectionImageToImageFilter< InputImageType, InputImageDirectionType, OutputImageType> Filter3Type; + Filter3Type::Pointer Filter3 = Filter3Type::New(); + + } + catch( itk::ExceptionObject & err ) + { + std::cout << "Exception itk::ExceptionObject levee !" << std::endl; + std::cout << err << std::endl; + return EXIT_FAILURE; + } + catch( std::bad_alloc & err ) + { + std::cout << "Exception bad_alloc : "<<(char*)err.what()<< std::endl; + return EXIT_FAILURE; + } + catch( ... ) + { + std::cout << "Exception levee inconnue !" << std::endl; + return EXIT_FAILURE; + } + // Software Guide : EndCodeSnippet + +//#endif + return EXIT_SUCCESS; +} + +