Orfeo Toolbox  4.0
otbMatrixImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbMatrixImageFilter_txx
19 #define __otbMatrixImageFilter_txx
20 
21 #include "otbMatrixImageFilter.h"
23 #include "itkImageRegionIterator.h"
24 #include "itkProgressReporter.h"
25 
26 namespace otb
27 {
28 
32 template <class TInputImage, class TOutputImage, class TMatrix>
34 {
35 }
36 
37 template <class TInputImage, class TOutputImage, class TMatrix>
39 {
40  // call the superclass' implementation of this method
41  Superclass::GenerateOutputInformation();
42 
43  if ( m_MatrixByVector )
44  {
45  if( this->GetInput()->GetNumberOfComponentsPerPixel() != m_Matrix.cols() )
46  {
47  itkExceptionMacro("Invalid Matrix size. Number of columns must be the same as the image number of channels.");
48  }
49 
50  if( m_Matrix.rows() == 0 )
51  {
52  itkExceptionMacro("Invalid Matrix size. Number of rows can't be null.");
53  }
54  this->GetOutput()->SetNumberOfComponentsPerPixel( m_Matrix.rows() );
55  }
56 
57  if ( !m_MatrixByVector )
58  {
59  if( this->GetInput()->GetNumberOfComponentsPerPixel() != m_Matrix.rows() )
60  {
61  itkExceptionMacro("Invalid Matrix size. Number of rows must be the same as the image number of channels.");
62  }
63 
64  if( m_Matrix.cols() == 0 )
65  {
66  itkExceptionMacro("Invalid Matrix size. Number of columns can't be null.");
67  }
68  this->GetOutput()->SetNumberOfComponentsPerPixel( m_Matrix.cols() );
69  }
70 }
71 
72 template<class TInputImage, class TOutputImage, class TMatrix>
74  const OutputImageRegionType& outputRegionForThread,
75  itk::ThreadIdType threadId
76  )
77 {
78  // images pointer
79  typename OutputImageType::Pointer outputPtr = this->GetOutput();
80  typename InputImageType::ConstPointer inputPtr = this->GetInput();
81 
82  typename itk::ImageRegionConstIterator<InputImageType> inIt( inputPtr, outputRegionForThread);
83  itk::ImageRegionIterator<OutputImageType> outIt( outputPtr, outputRegionForThread);
84 
85 
86  // support progress methods/callbacks
87  itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
88 
89  inIt.GoToBegin();
90  outIt.GoToBegin();
91 
92  const unsigned int inSize = m_MatrixByVector ? m_Matrix.cols() : m_Matrix.rows();
93  const unsigned int outSize = m_MatrixByVector ? m_Matrix.rows() : m_Matrix.cols();
94 
95  VectorType inVect(inSize, InputRealType(0.));
96  VectorType outVect(outSize, InputRealType(0.));
97 
98  while (!outIt.IsAtEnd())
99  {
100  const InputPixelType & inPix = inIt.Get();
101  OutputPixelType outPix;
102  outPix.SetSize(outSize);
103 
104  for(unsigned int i=0; i<inSize; ++i)
105  {
106  inVect[i] = static_cast<InputRealType>(inPix[i]);
107  }
108 
109  outVect = m_MatrixByVector ? m_Matrix*inVect : inVect*m_Matrix;
110 
111  for(unsigned int i=0; i<outSize; ++i)
112  {
113  outPix[i] = static_cast<OutputInternalPixelType>(outVect[i]);
114  }
115  outIt.Set(outPix);
116 
117  ++inIt;
118  ++outIt;
119  progress.CompletedPixel();
120  }
121 }
122 
123 
127 template <class TInputImage, class TOutputImage, class TMatrix>
128 void
130 {
131  Superclass::PrintSelf(os, indent);
132  os << indent << "Matrix: " << m_Matrix << std::endl;
133  os << indent << "MatrixByVector: " << m_MatrixByVector << std::endl;
134 }
135 
136 } // end namespace otb
137 
138 #endif

Generated at Sat Mar 8 2014 16:07:02 for Orfeo Toolbox with doxygen 1.8.3.1