OTB  10.0.0
Orfeo Toolbox
otbVectorImageToIntensityImageFilter.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 otbVectorImageToIntensityImageFilter_hxx
22 #define otbVectorImageToIntensityImageFilter_hxx
23 
25 #include "itkImageRegionIterator.h"
26 #include "itkProgressReporter.h"
27 #include "otbMath.h"
28 
29 namespace otb
30 {
34 template <class TInputImage, class TOutputImage>
36 {
37  this->DynamicMultiThreadingOn();
38 }
39 
40 template <class TInputImage, class TOutputImage>
41 void VectorImageToIntensityImageFilter<TInputImage, TOutputImage>::DynamicThreadedGenerateData(const OutputImageRegionType& outputRegionForThread)
42 {
43 
44  InputImageConstPointerType inputPtr = this->GetInput();
45  OutputImagePointerType outputPtr = this->GetOutput();
46 
47  // Define the portion of the input to walk for this thread, using
48  // the CallCopyOutputRegionToInputRegion method allows for the input
49  // and output images to be different dimensions
50  InputImageRegionType inputRegionForThread;
51  this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread);
52 
53  // Define the iterators
54  itk::ImageRegionConstIterator<InputImageType> inputIt(inputPtr, inputRegionForThread);
55  itk::ImageRegionIterator<OutputImageType> outputIt(outputPtr, outputRegionForThread);
56 
57  inputIt.GoToBegin();
58  outputIt.GoToBegin();
59 
60  while (!inputIt.IsAtEnd() && !outputIt.IsAtEnd())
61  {
62  double sum = 0.0;
63  InputPixelType pixel = inputIt.Get();
64  for (unsigned int i = 0; i < pixel.Size(); ++i)
65  {
66  sum += pixel[i];
67  }
68  sum /= pixel.Size();
69 
70  outputIt.Set(static_cast<OutputPixelType>(sum));
71  ++inputIt;
72  ++outputIt;
73  }
74 }
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.