OTB  10.0.0
Orfeo Toolbox
otbUnaryFunctorObjectListFilter.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 otbUnaryFunctorObjectListFilter_hxx
22 #define otbUnaryFunctorObjectListFilter_hxx
23 
25 #include "itkProgressReporter.h"
26 #include "otbMath.h"
27 
28 namespace otb
29 {
30 
34 template <class TInputList, class TOutputList, class TFunction>
36 {
37 }
38 
39 template <class TInputList, class TOutputList, class TFunction>
41  itk::ThreadIdType threadId)
42 {
43 
44  InputListPointer inputPtr = this->GetInput();
45  this->m_ObjectListPerThread[threadId] = OutputListType::New();
46 
47  itk::ProgressReporter progress(this, threadId, stopIndex - startIndex);
48 
49  // Define the iterators
50  InputListIterator it = inputPtr->Begin();
51  unsigned int count = 0;
52  while ((count < startIndex) && (it != inputPtr->End()))
53  {
54  ++it;
55  ++count;
56  }
57 
58  while ((count < stopIndex) && (it != inputPtr->End()))
59  {
60  this->m_ObjectListPerThread[threadId]->PushBack(m_Functor(it.Get()));
61 
62  progress.CompletedPixel();
63  ++it;
64  ++count;
65  }
66 }
67 
68 template <class TInputList, class TOutputList, class TFunction>
70 {
71  // copy the lists to the output
72  OutputListPointer outputPtr = this->GetOutput();
73  for (unsigned int i = 0; i < this->m_ObjectListPerThread.size(); ++i)
74  {
75  if (this->m_ObjectListPerThread[i].IsNotNull())
76  {
77  for (OutputListIterator it = this->m_ObjectListPerThread[i]->Begin(); it != this->m_ObjectListPerThread[i]->End(); ++it)
78  {
79  outputPtr->PushBack(it.Get());
80  }
81  }
82  }
83 }
84 
85 } // end namespace otb
86 
87 #endif
TOutputList::Pointer OutputListPointer
void ThreadedGenerateData(unsigned int startIndex, unsigned int stopIndex, itk::ThreadIdType threadId) override
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.