Orfeo Toolbox  4.0
otbQuaternaryFunctorImageFilter.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  Some parts of this code are derived from ITK. See ITKCopyright.txt
13  for details.
14 
15 
16  This software is distributed WITHOUT ANY WARRANTY; without even
17  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18  PURPOSE. See the above copyright notices for more information.
19 
20 =========================================================================*/
21 #ifndef __otbQuaternaryFunctorImageFilter_txx
22 #define __otbQuaternaryFunctorImageFilter_txx
23 
25 #include "itkImageRegionIterator.h"
27 #include "itkProgressReporter.h"
28 
29 namespace otb
30 {
31 
35 template <class TInputImage1, class TInputImage2, class TInputImage3,
36  class TInputImage4, class TOutputImage, class TFunction>
39 {
40  this->InPlaceOff();
41 }
42 
46 template <class TInputImage1, class TInputImage2, class TInputImage3,
47  class TInputImage4, class TOutputImage, class TFunction>
48 void
50 ::SetInput1(const TInputImage1 *image1)
51 {
52  // The ProcessObject is not const-correct so the const_cast is required here
53  this->SetNthInput(0, const_cast<TInputImage1 *>(image1));
54 }
55 
59 template <class TInputImage1, class TInputImage2, class TInputImage3,
60  class TInputImage4, class TOutputImage, class TFunction>
61 void
63 ::SetInput2(const TInputImage2 *image2)
64 {
65  // The ProcessObject is not const-correct so the const_cast is required here
66  this->SetNthInput(1, const_cast<TInputImage2 *>(image2));
67 }
68 
72 template <class TInputImage1, class TInputImage2, class TInputImage3,
73  class TInputImage4, class TOutputImage, class TFunction>
74 void
76 ::SetInput3(const TInputImage3 *image3)
77 {
78  // The ProcessObject is not const-correct so the const_cast is required here
79  this->SetNthInput(2, const_cast<TInputImage3 *>(image3));
80 }
81 
85 template <class TInputImage1, class TInputImage2, class TInputImage3,
86  class TInputImage4, class TOutputImage, class TFunction>
87 void
89 ::SetInput4(const TInputImage4 *image4)
90 {
91  // The ProcessObject is not const-correct so the const_cast is required here
92  this->SetNthInput(3, const_cast<TInputImage4 *>(image4));
93 }
94 
98 template <class TInputImage1, class TInputImage2, class TInputImage3,
99  class TInputImage4, class TOutputImage, class TFunction>
100 void
103 {
104  Input1ImagePointer inputPtr1
105  = dynamic_cast<const TInputImage1*>((itk::ProcessObject::GetInput(0)));
106  Input2ImagePointer inputPtr2
107  = dynamic_cast<const TInputImage2*>((itk::ProcessObject::GetInput(1)));
108  Input3ImagePointer inputPtr3
109  = dynamic_cast<const TInputImage3*>((itk::ProcessObject::GetInput(2)));
110  Input4ImagePointer inputPtr4
111  = dynamic_cast<const TInputImage4*>((itk::ProcessObject::GetInput(3)));
112  if (inputPtr1.IsNull() || inputPtr2.IsNull() || inputPtr3.IsNull() || inputPtr4.IsNull())
113  {
114  itkExceptionMacro(<< "At least one input is missing."
115  << " Input1 is " << inputPtr1.GetPointer() << ", "
116  << " Input2 is " << inputPtr2.GetPointer() << ", "
117  << " Input3 is " << inputPtr3.GetPointer() << ", "
118  << " Input4 is " << inputPtr4.GetPointer());
119 
120  }
121 }
122 
126 template <class TInputImage1, class TInputImage2, class TInputImage3,
127  class TInputImage4, class TOutputImage, class TFunction>
128 void
130 ::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
131  itk::ThreadIdType threadId)
132 {
133  // We use dynamic_cast since inputs are stored as DataObjects. The
134  // ImageToImageFilter::GetInput(int) always returns a pointer to a
135  // TInputImage1 so it cannot be used for the second or third input.
136  Input1ImagePointer inputPtr1
137  = dynamic_cast<const TInputImage1*>((itk::ProcessObject::GetInput(0)));
138  Input2ImagePointer inputPtr2
139  = dynamic_cast<const TInputImage2*>((itk::ProcessObject::GetInput(1)));
140  Input3ImagePointer inputPtr3
141  = dynamic_cast<const TInputImage3*>((itk::ProcessObject::GetInput(2)));
142  Input4ImagePointer inputPtr4
143  = dynamic_cast<const TInputImage4*>((itk::ProcessObject::GetInput(3)));
144  OutputImagePointer outputPtr = this->GetOutput(0);
145 
146  itk::ImageRegionConstIterator<TInputImage1> inputIt1(inputPtr1, outputRegionForThread);
147  itk::ImageRegionConstIterator<TInputImage2> inputIt2(inputPtr2, outputRegionForThread);
148  itk::ImageRegionConstIterator<TInputImage3> inputIt3(inputPtr3, outputRegionForThread);
149  itk::ImageRegionConstIterator<TInputImage4> inputIt4(inputPtr4, outputRegionForThread);
150  itk::ImageRegionIterator<TOutputImage> outputIt(outputPtr, outputRegionForThread);
151 
152  itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
153 
154  inputIt1.GoToBegin();
155  inputIt2.GoToBegin();
156  inputIt3.GoToBegin();
157  outputIt.GoToBegin();
158 
159  while (!inputIt1.IsAtEnd())
160  {
161  outputIt.Set(m_Functor(inputIt1.Get(), inputIt2.Get(), inputIt3.Get(), inputIt4.Get()));
162  ++inputIt1;
163  ++inputIt2;
164  ++inputIt3;
165  ++inputIt4;
166  ++outputIt;
167  progress.CompletedPixel(); // potential exception thrown here
168  }
169 }
170 } // end namespace otb
171 
172 #endif

Generated at Sat Mar 8 2014 16:14:26 for Orfeo Toolbox with doxygen 1.8.3.1