OTB  10.0.0
Orfeo Toolbox
otbUnaryImageFunctorWithVectorImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbUnaryImageFunctorWithVectorImageFilter_hxx
22 #define otbUnaryImageFunctorWithVectorImageFilter_hxx
23 
25 #include "itkImageRegionIterator.h"
26 #include "itkProgressReporter.h"
27 
28 namespace otb
29 {
30 
34 template <class TInputImage, class TOutputImage, class TFunction>
36 {
37  this->SetNumberOfRequiredInputs(1);
38  this->InPlaceOff();
39  this->DynamicMultiThreadingOn();
40 }
42 
52 template <class TInputImage, class TOutputImage, class TFunction>
54 {
55  Superclass::GenerateOutputInformation();
56 
57  // get pointers to the input and output
58  typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
59  typename Superclass::InputImageConstPointer inputPtr = this->GetInput();
60 
61  if (!outputPtr || !inputPtr)
62  {
63  return;
64  }
65  outputPtr->SetNumberOfComponentsPerPixel( // propagate vector length info
66  inputPtr->GetNumberOfComponentsPerPixel());
67 
68  // TODO: Check this
69  // The Functor vector is not initialised !
70  for (unsigned int i = 0; i < inputPtr->GetNumberOfComponentsPerPixel(); ++i)
71  {
72  FunctorType functor;
73  m_FunctorVector.push_back(functor);
74  }
75 }
76 
80 template <class TInputImage, class TOutputImage, class TFunction>
82 {
83  typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
84  typename Superclass::InputImageConstPointer inputPtr = this->GetInput();
86 
87  // Define the iterators
88  itk::ImageRegionConstIterator<InputImageType> inputIt(inputPtr, outputRegionForThread);
89  itk::ImageRegionIterator<OutputImageType> outputIt(outputPtr, outputRegionForThread);
90 
91  inputIt.GoToBegin();
92  outputIt.GoToBegin();
93 
94  // Null pixel construction
95  InputPixelType nullPixel;
96  nullPixel.SetSize(inputPtr->GetNumberOfComponentsPerPixel());
97  nullPixel.Fill(itk::NumericTraits<OutputInternalPixelType>::Zero);
98 
99  while (!inputIt.IsAtEnd())
100  {
101  InputPixelType inPixel = inputIt.Get();
102  OutputPixelType outPixel;
103  outPixel.SetSize(inputPtr->GetNumberOfComponentsPerPixel());
104  outPixel.Fill(itk::NumericTraits<OutputInternalPixelType>::Zero);
105  // if the input pixel in null, the output is considered as null ( no sensor information )
106  if (inPixel != nullPixel)
107  {
108  for (unsigned int j = 0; j < inputPtr->GetNumberOfComponentsPerPixel(); ++j)
109  {
110  outPixel[j] = m_FunctorVector[j](inPixel[j]);
111  }
112  }
113  outputIt.Set(outPixel);
114  ++inputIt;
115  ++outputIt;
116  }
117 }
118 
119 template <class TInputImage, class TOutputImage, class TFunction>
121 {
122  this->Superclass::PrintSelf(os, indent);
123 }
124 
125 } // end namespace otb
126 
127 #endif
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
void PrintSelf(std::ostream &os, itk::Indent indent) const override
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.