<commit_before>/*=========================================================================

  Program:   OTB
  Module:    $otbStokesToMCLImageFilter.h$
  Language:  C++
  Date:      $Date: 24/10/2006 $
  Version:   $Revision: 1.0 $

 

=========================================================================*/
#ifndef __CoherencyToMuellerImageFilter_h
#define __CoherencyToMuellerImageFilter_h

#include "itkImageToImageFilter.h"
#include "itkImage.h"
#include "itkNumericTraits.h"
#include "itkImageRegionIterator.h"
#include "itkImageRegionConstIterator.h"
#include "itkImageRegionConstIteratorWithIndex.h"
#include "itkVector.h"

#include "otbImage.h"

namespace otb
 {
/** \class otbCoherencyToMuellerImageFilter
 * \brief Compute the Coherency image (9 channels) from the MLC image (9 channels)
 */
template <class TPixel>
class  CoherencyToMuellerImageFilter :
   public itk::ImageToImageFilter< otb::Image<itk::Vector<TPixel,9>,2>, otb::Image<itk::Vector<TPixel,10>,2> >
{
public:
  /** Convenient typedefs for simplifying declarations. */
  typedef TPixel InputPixelType;
  typedef otb::Image<itk::Vector<TPixel,9>,2> InputImageType;
  typedef otb::Image<itk::Vector<TPixel,10>,2> OutputImageType;

  /** Extract dimension from input and output image. */
  itkStaticConstMacro(InputImageDimension, unsigned int,
                      InputImageType::ImageDimension);
  itkStaticConstMacro(OutputImageDimension, unsigned int,
                      OutputImageType::ImageDimension);

  
  /** Standard class typedefs. */
  typedef CoherencyToMuellerImageFilter Self;
  typedef itk::ImageToImageFilter< InputImageType, OutputImageType> 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(CoherencyToMuellerImageFilter, ImageToImageFilter);
  
  /** Image typedef support. */
  typedef typename InputImageType::PixelType InputPixelType;
  typedef typename OutputImageType::PixelType OutputPixelType;
  
  typedef typename InputImageType::RegionType InputImageRegionType;
  typedef typename OutputImageType::RegionType OutputImageRegionType;

  typedef typename InputImageType::SizeType InputSizeType;
  typedef typename InputImageType::IndexType IndexType ;

  /** Coherency type **/
  typedef itk::Vector<float,9> CoherencyType;
  /** Mueller Type **/
  typedef itk::Vector<float,10> MuellerType;
  
  
  /** CoherencyToMuellerImageFilter needs a larger input requested region than
   * the output requested region.  As such, CoherencyToMuellerImageFilter needs
   * to provide an implementation for GenerateInputRequestedRegion()
   * in order to inform the pipeline execution model.
   *
   * \sa ImageToImageFilter::GenerateInputRequestedRegion() */
  virtual void GenerateInputRequestedRegion() throw(itk::InvalidRequestedRegionError);

protected:
  CoherencyToMuellerImageFilter();
  virtual ~CoherencyToMuellerImageFilter() {}
  void PrintSelf(std::ostream& os, itk::Indent indent) const;

  /** CoherencyToMuellerImageFilter can be implemented as a multithreaded filter.
   * Therefore, this implementation provides a ThreadedGenerateData()
   * routine which is called for each processing thread. The output
   * image data is allocated automatically by the superclass prior to
   * calling ThreadedGenerateData().  ThreadedGenerateData can only
   * write to the portion of the output image specified by the
   * parameter "outputRegionForThread"
   *
   * \sa ImageToImageFilter::ThreadedGenerateData(),
   *     ImageToImageFilter::GenerateData() */
  void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
                            int threadId );

private:
  CoherencyToMuellerImageFilter(const Self&); //purposely not implemented
  void operator=(const Self&); //purposely not implemented

 
 

};
  
} // end namespace otb

#ifndef ITK_MANUAL_INSTANTIATION
#include "otbCoherencyToMuellerImageFilter.txx"
#endif

#endif<commit_msg>ENH: CoherencyToMuellerImageFilter class inherite from an UnaryFunctorImageFilter<commit_after>/*=========================================================================

  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 __CoherencyToMuellerImageFilter_h
#define __CoherencyToMuellerImageFilter_h

#include "itkUnaryFunctorImageFilter.h"

namespace otb
 {

namespace Functor {

/** \class otbCoherencyToMuellerFunctor
 * \brief Evaluate the Mueller matrix from the coherency matrix image
 *
 */
template< class TInput, class TOutput>
class CoherencyToMuellerFunctor
{
public:
  typedef double                                   RealType;
  typedef typename std::complex <RealType>         ComplexType;
  typedef typename TOutput::ValueType              OutputValueType;

  inline TOutput operator()( const TInput & Coherency ) const
    {
    TOutput result;
    result.SetSize(m_NumberOfComponentsPerPixel);

    RealType T1 = static_cast<RealType>(Coherency[0].real());
    RealType T2 = static_cast<RealType>(Coherency[3].real());
    RealType T3 = static_cast<RealType>(Coherency[5].real());
    RealType T4 = static_cast<RealType>(Coherency[1].real());
    RealType T5 = static_cast<RealType>(Coherency[1].imag());
    RealType T6 = static_cast<RealType>(Coherency[2].real());
    RealType T7 = static_cast<RealType>(Coherency[2].imag());
    RealType T8 = static_cast<RealType>(Coherency[4].real());
    RealType T9 = static_cast<RealType>(Coherency[4].imag());

    result[0] = static_cast<RealType>( (T1+T2+T3)/2. );  //A0+B0
    result[1] = static_cast<RealType>( (T1+T2-T3)/2. );  //A0+B
    result[2] = static_cast<RealType>( (T1-T2+T3)/2. );  //A0-B
    result[3] = static_cast<RealType>( (-T1+T2+T3)/2.); //-A0+B0
    result[4] = static_cast<RealType>( T4 );             //C
    result[5] = static_cast<RealType>( T6 );             //H
    result[6] = static_cast<RealType>( T9 );             //F
    result[7] = static_cast<RealType>( T8 );             //E
    result[8] = static_cast<RealType>( T7 );             //G
    result[9] = static_cast<RealType>(-T5 );             //D

    return result;
    }

   unsigned int GetOutputSize()
   {
     return m_NumberOfComponentsPerPixel;
   }

   /** Constructor */
   CoherencyToMuellerFunctor() : m_NumberOfComponentsPerPixel(9)  {}

   /** Destructor */
   ~CoherencyToMuellerFunctor() {}

private:
    unsigned int m_NumberOfComponentsPerPixel;
};
}


/** \class otbCoherencyToMuellerImageFilter
 * \brief Compute the Mueller matrix image (9 real channels)
 * from the coherency image (6 complex channels)
 */
template <class TInputImage, class TOutputImage, class TFunction = Functor::CoherencyToMuellerFunctor<
    ITK_TYPENAME TInputImage::PixelType, ITK_TYPENAME TOutputImage::PixelType> >
class ITK_EXPORT CoherencyToMuellerImageFilter :
   public itk::UnaryFunctorImageFilter<TInputImage,TOutputImage, TFunction>
{
public:
   /** Standard class typedefs. */
   typedef CoherencyToMuellerImageFilter  Self;
   typedef itk::UnaryFunctorImageFilter<TInputImage,TOutputImage, TFunction> Superclass;
   typedef itk::SmartPointer<Self>        Pointer;
   typedef itk::SmartPointer<const Self>  ConstPointer;

   /** Method for creation through the object factory. */
   itkNewMacro(Self);

   /** Runtime information support. */
   itkTypeMacro(CoherencyToMuellerImageFilter,itk::UnaryFunctorImageFilter);


protected:
   CoherencyToMuellerImageFilter() {}
  virtual ~CoherencyToMuellerImageFilter() {}

private:
  CoherencyToMuellerImageFilter(const Self&); //purposely not implemented
  void operator=(const Self&);            //purposely not implemented

};
  
} // end namespace otb

#endif
{'fraction_non_alphanumeric': 0.13323572474377746, 'fraction_numerical': 0.010248901903367497, 'mean_word_length': 4.490288010716678, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '251513', 'n_tokens_mistral': 2492, 'n_tokens_neox': 2406, 'n_words': 564}