OTB  9.0.0
Orfeo Toolbox
otbSummingFilter.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  * Copyright (C) 2016-2019 IRSTEA
5  *
6  * This file is part of Orfeo Toolbox
7  *
8  * https://www.orfeo-toolbox.org/
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 #ifndef __SummingFilter_hxx
23 #define __SummingFilter_hxx
24 
25 #include "otbSummingFilter.h"
26 #include "itkProgressReporter.h"
27 
28 namespace otb
29 {
30 
34 template <class TInputImage, class TOutputImage>
36 {
37  itkDebugMacro(<< "Generate output information");
38  Superclass::GenerateOutputInformation();
39 }
41 
45 template <class TInputImage, class TOutputImage>
46 void SummingFilter<TInputImage, TOutputImage>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId)
47 {
48 
49  // Debug info
50  itkDebugMacro(<< "Actually executing thread " << threadId << " in region " << outputRegionForThread);
51 
52  // Support progress methods/callbacks
53  itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
54 
55  // Iterate through the thread region
56  OutputIteratorType outputIt(this->GetOutput(), outputRegionForThread);
57 
58  // Prepare input iterators
59  unsigned int nbInputImages = this->GetNumberOfInputs();
60  unsigned int nbInputBands;
61 
62  InputIteratorType inputIt[nbInputImages];
63  for (unsigned int i = 0; i < nbInputImages; i++)
64  {
65  InputImageType* currentImage = const_cast<InputImageType*>(this->GetInput(i));
66  inputIt[i] = InputIteratorType(currentImage, outputRegionForThread);
67  nbInputBands = currentImage->GetNumberOfComponentsPerPixel();
68  }
69 
71  pix.SetSize(nbInputBands);
72 
73  // Sum images
74  for (outputIt.GoToBegin(); !outputIt.IsAtEnd(); ++outputIt)
75  {
76  pix.Fill(0.0);
77  for (unsigned int i = 0; i < nbInputImages; i++)
78  {
79 
80  for (unsigned int band = 0; band < nbInputBands; band++)
81  {
82  pix[band] += inputIt[i].Get()[band];
83  }
84  ++inputIt[i];
85  }
86  outputIt.Set(pix);
87 
88  // Update process
89  progress.CompletedPixel();
90  }
91 }
92 }
93 
94 #endif
otb::SummingFilter::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbSummingFilter.h:68
otbSummingFilter.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::SummingFilter::ThreadedGenerateData
virtual void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId)
Definition: otbSummingFilter.hxx:46
otb::SummingFilter::InputImageType
TInputImage InputImageType
Definition: otbSummingFilter.h:53
otb::SummingFilter::InputIteratorType
itk::ImageRegionConstIterator< InputImageType > InputIteratorType
Definition: otbSummingFilter.h:78
otb::SummingFilter::OutputImagePixelType
OutputImageType::PixelType OutputImagePixelType
Definition: otbSummingFilter.h:73
otb::SummingFilter::GenerateOutputInformation
virtual void GenerateOutputInformation(void)
Definition: otbSummingFilter.hxx:35
otb::SummingFilter::OutputIteratorType
itk::ImageRegionIterator< OutputImageType > OutputIteratorType
Definition: otbSummingFilter.h:77