OTB  6.7.0
Orfeo Toolbox
otbUnaryFunctorObjectListBooleanFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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 otbUnaryFunctorObjectListBooleanFilter_hxx
22 #define otbUnaryFunctorObjectListBooleanFilter_hxx
23 
25 #include "itkProgressReporter.h"
26 
27 namespace otb
28 {
29 
33 template <class TInputList, class TOutputList, class TFunction>
36 {
37 }
38 
39 template <class TInputList, class TOutputList, class TFunction>
40 void
42 ::ThreadedGenerateData(unsigned int startIndex, unsigned int stopIndex, itk::ThreadIdType threadId)
43 {
44 
45  InputListPointer inputPtr = this->GetInput();
46  this->m_ObjectListPerThread[threadId] = OutputListType::New();
47 
48  itk::ProgressReporter progress(this, threadId, stopIndex - startIndex);
49 
50  // Define the iterators
51  InputListIterator it = inputPtr->Begin();
52  unsigned int count = 0;
53  while ((count < startIndex) && (it != inputPtr->End()))
54  {
55  ++it;
56  ++count;
57  }
58 
59  while ((count < stopIndex) && (it != inputPtr->End()))
60  {
61  if (m_Functor(it.Get()))
62  {
63  this->m_ObjectListPerThread[threadId]->PushBack(it.Get());
64  }
65 
66  progress.CompletedPixel();
67  ++it;
68  ++count;
69  }
70 
71 }
72 
73 template <class TInputList, class TOutputList, class TFunction>
74 void
77 {
78  // copy the lists to the output
79  OutputListPointer outputPtr = this->GetOutput();
80  for (unsigned int i = 0; i < this->m_ObjectListPerThread.size(); ++i)
81  {
82  if (this->m_ObjectListPerThread[i].IsNotNull())
83  {
84  for (OutputListIterator it = this->m_ObjectListPerThread[i]->Begin();
85  it != this->m_ObjectListPerThread[i]->End();
86  ++it)
87  {
88  outputPtr->PushBack(it.Get());
89  }
90  }
91  }
92 
93 }
94 
95 } // end namespace otb
96 
97 #endif
void ThreadedGenerateData(unsigned int startIndex, unsigned int stopIndex, itk::ThreadIdType threadId) override
unsigned int ThreadIdType
TOutputList::Pointer OutputListPointer