OTB  6.7.0
Orfeo Toolbox
otbQuaternaryFunctorImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999-2011 Insight Software Consortium
3  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 #ifndef otbQuaternaryFunctorImageFilter_hxx
23 #define otbQuaternaryFunctorImageFilter_hxx
24 
26 #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());
120 
121  }
122 }
123 
127 template <class TInputImage1, class TInputImage2, class TInputImage3,
128  class TInputImage4, class TOutputImage, class TFunction>
129 void
131 ::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
132  itk::ThreadIdType threadId)
133 {
134  // We use dynamic_cast since inputs are stored as DataObjects. The
135  // ImageToImageFilter::GetInput(int) always returns a pointer to a
136  // TInputImage1 so it cannot be used for the second or third input.
137  Input1ImagePointer inputPtr1
138  = dynamic_cast<const TInputImage1*>((itk::ProcessObject::GetInput(0)));
139  Input2ImagePointer inputPtr2
140  = dynamic_cast<const TInputImage2*>((itk::ProcessObject::GetInput(1)));
141  Input3ImagePointer inputPtr3
142  = dynamic_cast<const TInputImage3*>((itk::ProcessObject::GetInput(2)));
143  Input4ImagePointer inputPtr4
144  = dynamic_cast<const TInputImage4*>((itk::ProcessObject::GetInput(3)));
145  OutputImagePointer outputPtr = this->GetOutput(0);
147 
148  itk::ImageRegionConstIterator<TInputImage1> inputIt1(inputPtr1, outputRegionForThread);
149  itk::ImageRegionConstIterator<TInputImage2> inputIt2(inputPtr2, outputRegionForThread);
150  itk::ImageRegionConstIterator<TInputImage3> inputIt3(inputPtr3, outputRegionForThread);
151  itk::ImageRegionConstIterator<TInputImage4> inputIt4(inputPtr4, outputRegionForThread);
152  itk::ImageRegionIterator<TOutputImage> outputIt(outputPtr, outputRegionForThread);
153 
154  itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
155 
156  inputIt1.GoToBegin();
157  inputIt2.GoToBegin();
158  inputIt3.GoToBegin();
159  outputIt.GoToBegin();
160 
161  while (!inputIt1.IsAtEnd())
162  {
163  outputIt.Set(m_Functor(inputIt1.Get(), inputIt2.Get(), inputIt3.Get(), inputIt4.Get()));
164  ++inputIt1;
165  ++inputIt2;
166  ++inputIt3;
167  ++inputIt4;
168  ++outputIt;
169  progress.CompletedPixel(); // potential exception thrown here
170  }
171 }
172 } // end namespace otb
173 
174 #endif
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId) override
Input3ImageType::ConstPointer Input3ImagePointer
void Set(const PixelType &value) const
Input2ImageType::ConstPointer Input2ImagePointer
Input4ImageType::ConstPointer Input4ImagePointer
OutputImageType::Pointer OutputImagePointer
Input1ImageType::ConstPointer Input1ImagePointer
unsigned int ThreadIdType
DataObject * GetInput(const DataObjectIdentifierType &key)
OutputImageType::RegionType OutputImageRegionType
bool IsAtEnd(void) const
PixelType Get(void) const