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