OTB  9.0.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-2022 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, class TInputImage4, class TOutputImage, class TFunction>
37 {
38  this->InPlaceOff();
39 }
40 
44 template <class TInputImage1, class TInputImage2, class TInputImage3, class TInputImage4, class TOutputImage, class TFunction>
46 {
47  // The ProcessObject is not const-correct so the const_cast is required here
48  this->SetNthInput(0, const_cast<TInputImage1*>(image1));
49 }
50 
54 template <class TInputImage1, class TInputImage2, class TInputImage3, class TInputImage4, class TOutputImage, class TFunction>
56 {
57  // The ProcessObject is not const-correct so the const_cast is required here
58  this->SetNthInput(1, const_cast<TInputImage2*>(image2));
59 }
60 
64 template <class TInputImage1, class TInputImage2, class TInputImage3, class TInputImage4, class TOutputImage, class TFunction>
66 {
67  // The ProcessObject is not const-correct so the const_cast is required here
68  this->SetNthInput(2, const_cast<TInputImage3*>(image3));
69 }
70 
74 template <class TInputImage1, class TInputImage2, class TInputImage3, class TInputImage4, class TOutputImage, class TFunction>
76 {
77  // The ProcessObject is not const-correct so the const_cast is required here
78  this->SetNthInput(3, const_cast<TInputImage4*>(image4));
79 }
80 
84 template <class TInputImage1, class TInputImage2, class TInputImage3, class TInputImage4, class TOutputImage, class TFunction>
86 {
87  Input1ImagePointer inputPtr1 = dynamic_cast<const TInputImage1*>((itk::ProcessObject::GetInput(0)));
88  Input2ImagePointer inputPtr2 = dynamic_cast<const TInputImage2*>((itk::ProcessObject::GetInput(1)));
89  Input3ImagePointer inputPtr3 = dynamic_cast<const TInputImage3*>((itk::ProcessObject::GetInput(2)));
90  Input4ImagePointer inputPtr4 = dynamic_cast<const TInputImage4*>((itk::ProcessObject::GetInput(3)));
91  if (inputPtr1.IsNull() || inputPtr2.IsNull() || inputPtr3.IsNull() || inputPtr4.IsNull())
92  {
93  itkExceptionMacro(<< "At least one input is missing."
94  << " Input1 is " << inputPtr1.GetPointer() << ", "
95  << " Input2 is " << inputPtr2.GetPointer() << ", "
96  << " Input3 is " << inputPtr3.GetPointer() << ", "
97  << " Input4 is " << inputPtr4.GetPointer());
98  }
99 }
101 
105 template <class TInputImage1, class TInputImage2, class TInputImage3, class TInputImage4, class TOutputImage, class TFunction>
107  const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId)
108 {
109  // We use dynamic_cast since inputs are stored as DataObjects. The
110  // ImageToImageFilter::GetInput(int) always returns a pointer to a
111  // TInputImage1 so it cannot be used for the second or third input.
112  Input1ImagePointer inputPtr1 = dynamic_cast<const TInputImage1*>((itk::ProcessObject::GetInput(0)));
113  Input2ImagePointer inputPtr2 = dynamic_cast<const TInputImage2*>((itk::ProcessObject::GetInput(1)));
114  Input3ImagePointer inputPtr3 = dynamic_cast<const TInputImage3*>((itk::ProcessObject::GetInput(2)));
115  Input4ImagePointer inputPtr4 = dynamic_cast<const TInputImage4*>((itk::ProcessObject::GetInput(3)));
116  OutputImagePointer outputPtr = this->GetOutput(0);
118 
119  itk::ImageRegionConstIterator<TInputImage1> inputIt1(inputPtr1, outputRegionForThread);
120  itk::ImageRegionConstIterator<TInputImage2> inputIt2(inputPtr2, outputRegionForThread);
121  itk::ImageRegionConstIterator<TInputImage3> inputIt3(inputPtr3, outputRegionForThread);
122  itk::ImageRegionConstIterator<TInputImage4> inputIt4(inputPtr4, outputRegionForThread);
123  itk::ImageRegionIterator<TOutputImage> outputIt(outputPtr, outputRegionForThread);
124 
125  itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
126 
127  inputIt1.GoToBegin();
128  inputIt2.GoToBegin();
129  inputIt3.GoToBegin();
130  outputIt.GoToBegin();
131 
132  while (!inputIt1.IsAtEnd())
133  {
134  outputIt.Set(m_Functor(inputIt1.Get(), inputIt2.Get(), inputIt3.Get(), inputIt4.Get()));
135  ++inputIt1;
136  ++inputIt2;
137  ++inputIt3;
138  ++inputIt4;
139  ++outputIt;
140  progress.CompletedPixel(); // potential exception thrown here
141  }
142 }
143 } // end namespace otb
144 
145 #endif
otb::QuaternaryFunctorImageFilter::OutputImagePointer
OutputImageType::Pointer OutputImagePointer
Definition: otbQuaternaryFunctorImageFilter.h:79
otb::QuaternaryFunctorImageFilter::Input1ImagePointer
Input1ImageType::ConstPointer Input1ImagePointer
Definition: otbQuaternaryFunctorImageFilter.h:63
otb::QuaternaryFunctorImageFilter::SetInput4
void SetInput4(const TInputImage4 *image4)
Definition: otbQuaternaryFunctorImageFilter.hxx:75
otb::QuaternaryFunctorImageFilter::SetInput2
void SetInput2(const TInputImage2 *image2)
Definition: otbQuaternaryFunctorImageFilter.hxx:55
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::QuaternaryFunctorImageFilter::ThreadedGenerateData
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId) override
Definition: otbQuaternaryFunctorImageFilter.hxx:106
otb::QuaternaryFunctorImageFilter::BeforeThreadedGenerateData
void BeforeThreadedGenerateData() override
Definition: otbQuaternaryFunctorImageFilter.hxx:85
otb::QuaternaryFunctorImageFilter::QuaternaryFunctorImageFilter
QuaternaryFunctorImageFilter()
Definition: otbQuaternaryFunctorImageFilter.hxx:36
otb::QuaternaryFunctorImageFilter::SetInput3
void SetInput3(const TInputImage3 *image3)
Definition: otbQuaternaryFunctorImageFilter.hxx:65
otb::QuaternaryFunctorImageFilter::Input4ImagePointer
Input4ImageType::ConstPointer Input4ImagePointer
Definition: otbQuaternaryFunctorImageFilter.h:75
otbQuaternaryFunctorImageFilter.h
otb::QuaternaryFunctorImageFilter::SetInput1
void SetInput1(const TInputImage1 *image1)
Definition: otbQuaternaryFunctorImageFilter.hxx:45
otb::QuaternaryFunctorImageFilter::Input3ImagePointer
Input3ImageType::ConstPointer Input3ImagePointer
Definition: otbQuaternaryFunctorImageFilter.h:71
otb::QuaternaryFunctorImageFilter::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbQuaternaryFunctorImageFilter.h:80
otb::QuaternaryFunctorImageFilter::Input2ImagePointer
Input2ImageType::ConstPointer Input2ImagePointer
Definition: otbQuaternaryFunctorImageFilter.h:67