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