OTB  6.7.0
Orfeo Toolbox
otbConcatenateSampleListFilter.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 otbConcatenateSampleListFilter_hxx
22 #define otbConcatenateSampleListFilter_hxx
23 
25 #include "itkProgressReporter.h"
26 
27 namespace otb {
28 namespace Statistics {
29 
30 template < class TSampleList>
33  {}
34 
35 template <class TSampleList>
36 void
38 ::AddInput( const SampleListType * inputPtr )
39  {
40  // Process object is not const-correct so the const_cast is required here
41  Superclass::ProcessObject::AddInput(const_cast< SampleListType* >( inputPtr ) );
42  }
43 
44 
45 template <class TSampleList>
46 void
49  {
50  // Retrieve output pointers
51  SampleListPointer outputSampleListPtr = this->GetOutput();
52 
53  // Clear any previous output
54  outputSampleListPtr->Clear();
55 
56  // Set the measurement vector size (based on the first listsample)
57  outputSampleListPtr->SetMeasurementVectorSize(static_cast<SampleListType *>(
58  Superclass::ProcessObject::GetInput(0))->GetMeasurementVectorSize());
59 
60  // Evaluate the total number of samples for progress reporting
61  unsigned long totalNumberOfSamples = 0;
62 
63  for(unsigned int inputIndex = 0; inputIndex<this->GetNumberOfInputs(); ++inputIndex)
64  {
65  // Retrieve the ListSample
66  typename SampleListType::ConstPointer inputPtr = static_cast<SampleListType *>
67  (Superclass::ProcessObject::GetInput(inputIndex));
68 
69  totalNumberOfSamples += inputPtr->Size();
70  }
71 
72  // Set-up progress reporting
73  itk::ProgressReporter progress(this, 0, totalNumberOfSamples);
74 
75  for(unsigned int inputIndex = 0; inputIndex<this->GetNumberOfInputs(); ++inputIndex)
76  {
77  // Retrieve the ListSample
78  typename SampleListType::ConstPointer inputSampleListPtr = static_cast<SampleListType *>
79  (Superclass::ProcessObject::GetInput(inputIndex));
80 
81  typename SampleListType::ConstIterator inputIt = inputSampleListPtr->Begin();
82 
83  // Iterate on the InputSampleList
84  while(inputIt != inputSampleListPtr->End())
85  {
86  // Add the current output sample to the output SampleList
87  outputSampleListPtr->PushBack(inputIt.GetMeasurementVector());
88 
89  // Update progress
90  progress.CompletedPixel();
91 
92  ++inputIt;
93  }
94  }
95  }
96 
97 template <class TSampleList>
98 void
100 ::PrintSelf(std::ostream& os, itk::Indent indent) const
101  {
102  // Call superclass implementation
103  Superclass::PrintSelf(os, indent);
104  os<<indent<<"Number of input SampleList: "<<this->GetNumberOfInputs();
105  }
106 
107 
108 } // End namespace Statistics
109 } // End namespace otb
110 
111 #endif
void PrintSelf(std::ostream &os, itk::Indent indent) const override