OTB  9.0.0
Orfeo Toolbox
otbUnaryImageFunctorWithVectorImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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 }
41 
51 template <class TInputImage, class TOutputImage, class TFunction>
53 {
54  Superclass::GenerateOutputInformation();
55 
56  // get pointers to the input and output
57  typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
58  typename Superclass::InputImageConstPointer inputPtr = this->GetInput();
59 
60  if (!outputPtr || !inputPtr)
61  {
62  return;
63  }
64  outputPtr->SetNumberOfComponentsPerPixel( // propagate vector length info
65  inputPtr->GetNumberOfComponentsPerPixel());
66 
67  // TODO: Check this
68  // The Functor vector is not initialised !
69  for (unsigned int i = 0; i < inputPtr->GetNumberOfComponentsPerPixel(); ++i)
70  {
71  FunctorType functor;
72  m_FunctorVector.push_back(functor);
73  }
74 }
75 
79 template <class TInputImage, class TOutputImage, class TFunction>
81  itk::ThreadIdType threadId)
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  itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
92 
93  inputIt.GoToBegin();
94  outputIt.GoToBegin();
95 
96  // Null pixel construction
97  InputPixelType nullPixel;
98  nullPixel.SetSize(inputPtr->GetNumberOfComponentsPerPixel());
99  nullPixel.Fill(itk::NumericTraits<OutputInternalPixelType>::Zero);
100 
101  while (!inputIt.IsAtEnd())
102  {
103  InputPixelType inPixel = inputIt.Get();
104  OutputPixelType outPixel;
105  outPixel.SetSize(inputPtr->GetNumberOfComponentsPerPixel());
106  outPixel.Fill(itk::NumericTraits<OutputInternalPixelType>::Zero);
107  // if the input pixel in null, the output is considered as null ( no sensor information )
108  if (inPixel != nullPixel)
109  {
110  for (unsigned int j = 0; j < inputPtr->GetNumberOfComponentsPerPixel(); ++j)
111  {
112  outPixel[j] = m_FunctorVector[j](inPixel[j]);
113  }
114  }
115  outputIt.Set(outPixel);
116  ++inputIt;
117  ++outputIt;
118  progress.CompletedPixel(); // potential exception thrown here
119  }
120 }
121 
122 template <class TInputImage, class TOutputImage, class TFunction>
124 {
125  this->Superclass::PrintSelf(os, indent);
126 }
127 
128 } // end namespace otb
129 
130 #endif
otb::UnaryImageFunctorWithVectorImageFilter::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbUnaryImageFunctorWithVectorImageFilter.hxx:123
otb::UnaryImageFunctorWithVectorImageFilter< TInputImage, TOutputImage, Functor::ImageToReflectanceImageFunctor< TInputImage::InternalPixelType, TOutputImage::InternalPixelType > >::OutputPixelType
OutputImageType::PixelType OutputPixelType
Definition: otbUnaryImageFunctorWithVectorImageFilter.h:73
otb::UnaryImageFunctorWithVectorImageFilter::GenerateOutputInformation
void GenerateOutputInformation() override
Definition: otbUnaryImageFunctorWithVectorImageFilter.hxx:52
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::UnaryImageFunctorWithVectorImageFilter< TInputImage, TOutputImage, Functor::ImageToReflectanceImageFunctor< TInputImage::InternalPixelType, TOutputImage::InternalPixelType > >::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbUnaryImageFunctorWithVectorImageFilter.h:75
otb::UnaryImageFunctorWithVectorImageFilter< TInputImage, TOutputImage, Functor::ImageToReflectanceImageFunctor< TInputImage::InternalPixelType, TOutputImage::InternalPixelType > >::InputPixelType
InputImageType::PixelType InputPixelType
Definition: otbUnaryImageFunctorWithVectorImageFilter.h:70
otb::UnaryImageFunctorWithVectorImageFilter::ThreadedGenerateData
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId) override
Definition: otbUnaryImageFunctorWithVectorImageFilter.hxx:80
otb::UnaryImageFunctorWithVectorImageFilter::UnaryImageFunctorWithVectorImageFilter
UnaryImageFunctorWithVectorImageFilter()
Definition: otbUnaryImageFunctorWithVectorImageFilter.hxx:35
otbUnaryImageFunctorWithVectorImageFilter.h
otb::Functor::ImageToReflectanceImageFunctor
Call the ImageToRadianceFunctor over the input and the RadianceToReflectanceFunctor to this result.
Definition: otbImageToReflectanceImageFilter.h:46