diff --git a/Code/CMakeLists.txt b/Code/CMakeLists.txt index fd4925b470128f76bd6a6250332684e352bc3b2a..3c5e456aebeafa595ee53f588006c56fcee613be 100644 --- a/Code/CMakeLists.txt +++ b/Code/CMakeLists.txt @@ -12,7 +12,7 @@ Projections Radiometry Fusion Markov -Radar +SARPolarimetry ) IF(OTB_USE_VISU_GUI) diff --git a/Code/SARPolarimetry/CMakeLists.txt b/Code/SARPolarimetry/CMakeLists.txt new file mode 100755 index 0000000000000000000000000000000000000000..331d19f379d869488a50227a9c8f5236dd4041cf --- /dev/null +++ b/Code/SARPolarimetry/CMakeLists.txt @@ -0,0 +1,18 @@ + +# Sources of non-templated classes. +FILE(GLOB OTBRADAR_SRCS "*.cxx" ) + +ADD_LIBRARY(OTBRadar ${OTBRADAR_SRCS}) +TARGET_LINK_LIBRARIES (OTBRadar OTBCommon OTBBasicFilters) + +INSTALL(TARGETS OTBRadar +RUNTIME DESTINATION ${OTB_INSTALL_BIN_DIR} COMPONENT RuntimeLibraries +LIBRARY DESTINATION ${OTB_INSTALL_LIB_DIR} COMPONENT RuntimeLibraries +ARCHIVE DESTINATION ${OTB_INSTALL_LIB_DIR} COMPONENT Development) + +FILE(GLOB __files1 "${CMAKE_CURRENT_SOURCE_DIR}/*.h") +FILE(GLOB __files2 "${CMAKE_CURRENT_SOURCE_DIR}/*.txx") + +INSTALL(FILES ${__files1} ${__files2} + DESTINATION ${OTB_INSTALL_INCLUDE_DIR}/RADAR + COMPONENT Development) diff --git a/Code/SARPolarimetry/foo.cxx b/Code/SARPolarimetry/foo.cxx new file mode 100644 index 0000000000000000000000000000000000000000..8b137891791fe96927ad78e64b0aad7bded08bdc --- /dev/null +++ b/Code/SARPolarimetry/foo.cxx @@ -0,0 +1 @@ + diff --git a/Code/SARPolarimetry/otbPolarimetricFunctor.h b/Code/SARPolarimetry/otbPolarimetricFunctor.h new file mode 100644 index 0000000000000000000000000000000000000000..da2be06c6903070fcd50b0b66d8fde48d3bd5409 --- /dev/null +++ b/Code/SARPolarimetry/otbPolarimetricFunctor.h @@ -0,0 +1,98 @@ +/*========================================================================= + + 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 __otbPolarimetricFunctor_h +#define __otbPolarimetricFunctor_h + + +namespace otb +{ +namespace Functor + { + /** \class PolarimetricFunctor2Channels + * \brief This functor calculate the + * + * + * + * \ingroup Functor + */ + template <class TInput1, class TInput2, class TOutput> + class PolarimetricFunctor2Channels + { + public: + PolarimetricFunctor2Channels() {}; + ~PolarimetricFunctor2Channels() {}; + inline TOutput operator()(const TInput1 &r, const TInput2 &nir) + { + + return ( static_cast<TOutput>(0) ); + } + }; + + /** \class PolarimetricSynthesis3Channels + * \brief This functor calculate the + * + * + * + * \ingroup Functor + */ +/* template <class TInput1, class TInput2, class TInput3, class TOutput> + class PolarimetricSynthesis3Channels + { + public: + PolarimetricSynthesis3Channels() {}; + ~PolarimetricSynthesis3Channels() {}; + inline TOutput operator()(const TInput1 &r, const TInput2 &nir) + { + double dr = static_cast<double>(r); + double dnir = static_cast<double>(nir); + if( r == 0 ) + { + return static_cast<TOutput>(0.); + } + return ( static_cast<TOutput>(dnir/dr)); + } + }; +*/ + /** \class PolarimetricSynthesis4Channels + * \brief This functor calculate the + * + * + * + * \ingroup Functor + */ +/* template <class TInput1, class TInput2, class TInput3, class TInput4, class TOutput> + class PolarimetricSynthesis4Channels + { + public: + PolarimetricSynthesis4Channels() {}; + ~PolarimetricSynthesis4Channels() {}; + inline TOutput operator()(const TInput1 &r, const TInput2 &nir) + { + double dnir = static_cast<double>(nir); + double dr = static_cast<double>(r); + return ( static_cast<TOutput>( (dnir - m_A*dr - m_B)*m_Coeff) ); + } + + private: +*/ + + } // namespace Functor +} // namespace otb + +#endif + diff --git a/Code/SARPolarimetry/otbPolarimetricSynthesisFilter.h b/Code/SARPolarimetry/otbPolarimetricSynthesisFilter.h new file mode 100755 index 0000000000000000000000000000000000000000..60014fdd49b5e12c94664dbde5670461a82ffb4c --- /dev/null +++ b/Code/SARPolarimetry/otbPolarimetricSynthesisFilter.h @@ -0,0 +1,143 @@ +/*========================================================================= + + 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 __otbPolarimetricSynthesisFilter_h +#define __otbPolarimetricSynthesisFilter_h + +#include "itkInPlaceImageFilter.h" +#include "otbPolarimetricFunctor.h" + +namespace otb +{ + +/** \class PolarimetricSynthesisFilter + * \brief Implements + * + * This class is parameterized over the type of the input image and + * the type of the output image. It is also parameterized by the + * operation to be applied, using a Functor style. + * + */ + + +template <class TInputImage, class TOutputImage, + class TFunction = Functor::PolarimetricFunctor2Channels< + typename TInputImage::InternalPixelType, + typename TInputImage::InternalPixelType, + typename TOutputImage::PixelType> > +class ITK_EXPORT PolarimetricSynthesisFilter : public itk::InPlaceImageFilter<TInputImage,TOutputImage> +{ +public: + /** Standard class typedefs. */ + typedef PolarimetricSynthesisFilter Self; + typedef itk::InPlaceImageFilter<TInputImage,TOutputImage> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(PolarimetricSynthesisFilter, InPlaceImageFilter); + + /** Some typedefs. */ + typedef TFunction FunctorType; + typedef TInputImage InputImageType; + typedef typename InputImageType::ConstPointer InputImagePointer; + typedef typename InputImageType::RegionType InputImageRegionType; + typedef typename InputImageType::PixelType InputImagePixelType; + typedef TOutputImage OutputImageType; + typedef typename OutputImageType::Pointer OutputImagePointer; + typedef typename OutputImageType::RegionType OutputImageRegionType; + typedef typename OutputImageType::PixelType OutputImagePixelType; + + /** Get the functor object. The functor is returned by reference. + * (Functors do not have to derive from itk::LightObject, so they do + * not necessarily have a reference count. So we cannot return a + * SmartPointer.) */ + FunctorType& GetFunctor() { return m_Functor; }; + const FunctorType& GetFunctor() const { return m_Functor; }; + + + /** Set the functor object. This replaces the current Functor with a + * copy of the specified Functor. This allows the user to specify a + * functor that has ivars set differently than the default functor. + * This method requires an operator!=() be defined on the functor + * (or the compiler's default implementation of operator!=() being + * appropriate). */ + void SetFunctor(const FunctorType& functor) + { + if (m_Functor != functor) + { + m_Functor = functor; + this->Modified(); + } + } + + /** Set/Get the Phi */ + itkSetMacro(PhiE,float); + itkGetMacro(PhiE,float); + /** Set/Get */ + itkSetMacro(KhiE,float); + itkGetMacro(KhiE,float); + /** Set/Get */ + itkSetMacro(PhiR,float); + itkGetMacro(PhiR,float); + /** Set/Get */ + itkSetMacro(KhiR,float); + itkGetMacro(KhiR,float); + +protected: + PolarimetricSynthesisFilter(); + virtual ~ PolarimetricSynthesisFilter(); + + /** PolarimetricSynthesisFilter + * + * + * \sa ProcessObject::GenerateOutputInformaton() */ + virtual void GenerateOutputInformation(); + + void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, + int threadId ); + + void PrintSelf(std::ostream& os, itk::Indent indent) const; + +private : + PolarimetricSynthesisFilter(const Self&); //purposely not implemented + //void operator=(const Self&); //purposely not implemented + + /** Phi Emission */ + float m_PhiE; + /** Khi Emission */ + float m_KhiE; + /** Phi Reception */ + float m_PhiR; + /** Khi Reception */ + float m_KhiR; + /** Channel indexes 0 1 2 3 on verra */ + //unsigned int m_RedIndex; + FunctorType m_Functor; + +}; + +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbPolarimetricSynthesisFilter.txx" +#endif + +#endif diff --git a/Code/SARPolarimetry/otbPolarimetricSynthesisFilter.txx b/Code/SARPolarimetry/otbPolarimetricSynthesisFilter.txx new file mode 100755 index 0000000000000000000000000000000000000000..df06362ba53644a2c630ad7646edbf65b2fcab32 --- /dev/null +++ b/Code/SARPolarimetry/otbPolarimetricSynthesisFilter.txx @@ -0,0 +1,194 @@ +/*========================================================================= + + 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 __otbPolarimetricSynthesisFilter_txx +#define __otbPolarimetricSynthesisFilter_txx + +#include "otbPolarimetricSynthesisFilter.h" +#include "itkImageRegionIterator.h" +#include "itkImageRegionConstIterator.h" +#include "itkProgressReporter.h" + +namespace otb +{ + +/** + * Constructor + */ +template <class TInputImage, class TOutputImage, class TFunction > +PolarimetricSynthesisFilter<TInputImage,TOutputImage,TFunction> +::PolarimetricSynthesisFilter() +{ + this->SetNumberOfRequiredInputs( 1 ); + this->InPlaceOff(); +} + + /** PolarimetricSynthesisFilter + * + * + * \sa ProcessObject::GenerateOutputInformaton() + */ +template <class TInputImage, class TOutputImage, class TFunction> +void +PolarimetricSynthesisFilter<TInputImage,TOutputImage,TFunction> +::GenerateOutputInformation() +{ + // do not call the superclass' implementation of this method since + // this filter allows the input the output to be of different dimensions + + // get pointers to the input and output + typename Superclass::OutputImagePointer outputPtr = this->GetOutput(); + typename Superclass::InputImageConstPointer inputPtr = this->GetInput(); + + if ( !outputPtr || !inputPtr) + { + return; + } + + // Set the output image largest possible region. Use a RegionCopier + // so that the input and output images can be different dimensions. + OutputImageRegionType outputLargestPossibleRegion; + this->CallCopyInputRegionToOutputRegion(outputLargestPossibleRegion, + inputPtr->GetLargestPossibleRegion()); + outputPtr->SetLargestPossibleRegion( outputLargestPossibleRegion ); + + // Set the output spacing and origin + const itk::ImageBase<Superclass::InputImageDimension> *phyData; + + phyData + = dynamic_cast<const itk::ImageBase<Superclass::InputImageDimension>*>(this->GetInput()); + + if (phyData) + { + // Copy what we can from the image from spacing and origin of the input + // This logic needs to be augmented with logic that select which + // dimensions to copy + unsigned int i, j; + const typename InputImageType::SpacingType& + inputSpacing = inputPtr->GetSpacing(); + const typename InputImageType::PointType& + inputOrigin = inputPtr->GetOrigin(); + const typename InputImageType::DirectionType& + inputDirection = inputPtr->GetDirection(); + + typename OutputImageType::SpacingType outputSpacing; + typename OutputImageType::PointType outputOrigin; + typename OutputImageType::DirectionType outputDirection; + + // copy the input to the output and fill the rest of the + // output with zeros. + for (i=0; i < Superclass::InputImageDimension; ++i) + { + outputSpacing[i] = inputSpacing[i]; + outputOrigin[i] = inputOrigin[i]; + for (j=0; j < Superclass::OutputImageDimension; j++) + { + if (j < Superclass::InputImageDimension) + { + outputDirection[j][i] = inputDirection[j][i]; + } + else + { + outputDirection[j][i] = 0.0; + } + } + } + for (; i < Superclass::OutputImageDimension; ++i) + { + outputSpacing[i] = 1.0; + outputOrigin[i] = 0.0; + for (j=0; j < Superclass::OutputImageDimension; j++) + { + if (j == i) + { + outputDirection[j][i] = 1.0; + } + else + { + outputDirection[j][i] = 0.0; + } + } + } + + // set the spacing and origin + outputPtr->SetSpacing( outputSpacing ); + outputPtr->SetOrigin( outputOrigin ); + outputPtr->SetDirection( outputDirection ); + outputPtr->SetNumberOfComponentsPerPixel( // propagate vector length info + inputPtr->GetNumberOfComponentsPerPixel()); + } + else + { + // pointer could not be cast back down + itkExceptionMacro(<< "otb::MultiChannelRAndNIRVegetationIndexImageFilter::GenerateOutputInformation " + << "cannot cast input to " + << typeid(itk::ImageBase<Superclass::InputImageDimension>*).name() ); + } +} + + +/** + * ThreadedGenerateData Performs the pixel-wise addition + */ +template <class TInputImage, class TOutputImage, class TFunction > +void +PolarimetricSynthesisFilter<TInputImage,TOutputImage,TFunction> +::ThreadedGenerateData( const OutputImageRegionType &outputRegionForThread, + int threadId) +{ + InputImagePointer inputPtr = this->GetInput(); + OutputImagePointer outputPtr = this->GetOutput(0); + + // Define the portion of the input to walk for this thread, using + // the CallCopyOutputRegionToInputRegion method allows for the input + // and output images to be different dimensions + InputImageRegionType inputRegionForThread; + this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread); + + // Define the iterators + itk::ImageRegionConstIterator<TInputImage> inputIt(inputPtr, inputRegionForThread); + itk::ImageRegionIterator<TOutputImage> outputIt(outputPtr, outputRegionForThread); + + itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels()); + + inputIt.GoToBegin(); + outputIt.GoToBegin(); + + while( !inputIt.IsAtEnd() ) + { + outputIt.Set( m_Functor( inputIt.Get()[0], inputIt.Get()[1]) ); + ++inputIt; + ++outputIt; + progress.CompletedPixel(); // potential exception thrown here + } +} + +template <class TInputImage, class TOutputImage, class TFunction > +void +PolarimetricSynthesisFilter<TInputImage,TOutputImage,TFunction> +::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + this->Superclass::PrintSelf(os,indent); + os << indent << "Phi E: "<<m_PhiE<<std::endl; + os << indent << "Khi E: "<<m_KhiE<<std::endl; + os << indent << "Phi R: "<<m_PhiR<<std::endl; + os << indent << "Khi R: "<<m_KhiR<<std::endl; +} + +} // end namespace otb + +#endif