OTB  9.0.0
Orfeo Toolbox
otbShiftScaleSampleListFilter.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 otbShiftScaleSampleListFilter_hxx
22 #define otbShiftScaleSampleListFilter_hxx
23 
25 #include "itkProgressReporter.h"
26 
27 namespace otb
28 {
29 namespace Statistics
30 {
31 
32 template <class TInputSampleList, class TOutputSampleList>
34 {
35 }
36 
37 template <class TInputSampleList, class TOutputSampleList>
39 {
40  // Retrieve input and output pointers
41  InputSampleListConstPointer inputSampleListPtr = this->GetInput();
42 
43  OutputSampleListPointer outputSampleListPtr = this->GetOutput();
44  outputSampleListPtr->SetMeasurementVectorSize(inputSampleListPtr->GetMeasurementVectorSize());
45 
46  // Check if the inputSampleList is not empty
47  if (inputSampleListPtr->Size() == 0)
48  itkExceptionMacro(<< "Input Sample List is empty");
49 
50  // Check if the size of the scale and the shift measurement vectors
51  // are the same than the input vector
52  if (inputSampleListPtr->GetMeasurementVectorSize() != m_Scales.Size() || inputSampleListPtr->GetMeasurementVectorSize() != m_Shifts.Size())
53  itkExceptionMacro(<< "Inconsistent measurement vector size : Input Sample List size " << inputSampleListPtr->GetMeasurementVectorSize()
54  << " Scale measurement vector size " << m_Scales.Size() << " Shift measurement vector size " << m_Shifts.Size());
55 
56  // Compute the 1/(sigma) vector
57  InputMeasurementVectorType invertedScales = m_Scales;
58  for (unsigned int idx = 0; idx < invertedScales.Size(); ++idx)
59  {
60  if (m_Scales[idx] - 1e-10 < 0.)
61  invertedScales[idx] = 0.;
62  else
63  invertedScales[idx] = 1 / m_Scales[idx];
64  }
65 
66  // Clear any previous output
67  outputSampleListPtr->Clear();
68 
69  typename InputSampleListType::ConstIterator inputIt = inputSampleListPtr->Begin();
70 
71  // Set-up progress reporting
72  itk::ProgressReporter progress(this, 0, inputSampleListPtr->Size());
73 
74  // Iterate on the InputSampleList
75  while (inputIt != inputSampleListPtr->End())
76  {
77  // Retrieve current input sample
78  InputMeasurementVectorType currentInputMeasurement = inputIt.GetMeasurementVector();
79 
80  // Build current output sample
81  OutputMeasurementVectorType currentOutputMeasurement;
82  currentOutputMeasurement.SetSize(currentInputMeasurement.GetSize());
83 
84  // Center and reduce each component
85  for (unsigned int idx = 0; idx < invertedScales.Size(); ++idx)
86  {
87  currentOutputMeasurement[idx] = static_cast<OutputValueType>((currentInputMeasurement[idx] - m_Shifts[idx]) * invertedScales[idx]);
88  }
89 
90  // Add the current output sample to the output SampleList
91  outputSampleListPtr->PushBack(currentOutputMeasurement);
92 
93  // Update progress
94  progress.CompletedPixel();
95 
96  ++inputIt;
97  }
98 }
99 
100 template <class TInputSampleList, class TOutputSampleList>
102 {
103  // Call superclass implementation
104  Superclass::PrintSelf(os, indent);
105 }
106 
107 } // End namespace Statistics
108 } // End namespace otb
109 
110 #endif
otb::Statistics::ShiftScaleSampleListFilter::ShiftScaleSampleListFilter
ShiftScaleSampleListFilter()
Definition: otbShiftScaleSampleListFilter.hxx:33
otb::Statistics::ShiftScaleSampleListFilter::GenerateData
void GenerateData() override
Definition: otbShiftScaleSampleListFilter.hxx:38
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Statistics::ShiftScaleSampleListFilter::OutputSampleListPointer
OutputSampleListType::Pointer OutputSampleListPointer
Definition: otbShiftScaleSampleListFilter.h:75
otb::Statistics::ShiftScaleSampleListFilter::InputSampleListConstPointer
InputSampleListType::ConstPointer InputSampleListConstPointer
Definition: otbShiftScaleSampleListFilter.h:69
otb::Statistics::ShiftScaleSampleListFilter::InputMeasurementVectorType
InputSampleListType::MeasurementVectorType InputMeasurementVectorType
Definition: otbShiftScaleSampleListFilter.h:70
otb::Statistics::ShiftScaleSampleListFilter::OutputValueType
OutputMeasurementVectorType::ValueType OutputValueType
Definition: otbShiftScaleSampleListFilter.h:78
otb::Statistics::ShiftScaleSampleListFilter::OutputMeasurementVectorType
OutputSampleListType::MeasurementVectorType OutputMeasurementVectorType
Definition: otbShiftScaleSampleListFilter.h:77
otb::Statistics::ShiftScaleSampleListFilter::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbShiftScaleSampleListFilter.hxx:101
otbShiftScaleSampleListFilter.h