OTB  9.0.0
Orfeo Toolbox
otbLabelMapToSampleListFilter.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 otbLabelMapToSampleListFilter_hxx
22 #define otbLabelMapToSampleListFilter_hxx
23 
25 
26 namespace otb
27 {
28 
29 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
31 {
32  this->SetNumberOfRequiredInputs(1);
33  this->SetNumberOfRequiredOutputs(1);
34 
35  this->itk::ProcessObject::SetNthOutput(0, this->MakeOutput(0).GetPointer());
36 }
37 
38 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
40 {
41 }
42 
43 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
46 {
47  DataObjectPointerType output;
48  output = static_cast<itk::DataObject*>(OutputSampleListType::New().GetPointer());
49  return output;
50 }
51 
52 // Set the input labelMap
53 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
55 {
56  // Process object is not const-correct so the const_cast is required here
57  this->itk::ProcessObject::SetNthInput(0, const_cast<InputLabelMapType*>(inputLabelMap));
58 }
59 
60 // Get the input labelMap
61 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
64 {
65  if (this->GetNumberOfInputs() < 1)
66  {
67  return nullptr;
68  }
69 
70  return static_cast<const InputLabelMapType*>(this->itk::ProcessObject::GetInput(0));
71 }
72 
73 // Get the output SampleList
74 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
77 {
78  return dynamic_cast<OutputSampleListType*>(this->itk::ProcessObject::GetOutput(0));
79 }
80 
81 
82 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
84 {
85  // Get the input LabelMap
86  InputLabelMapConstPointerType inputLabelMap = this->GetInputLabelMap();
87 
88  // Get the output ListSample
89  OutputSampleListPointerType outputSampleList = const_cast<OutputSampleListType*>(this->GetOutputSampleList());
90 
91  ConstIteratorType it = ConstIteratorType(inputLabelMap);
92 
93  // iterate on label objects
94  bool isFirstIteration = true;
95  while (!it.IsAtEnd())
96  {
97  // Get the measurement vector size of the output samplelist : once
98  // in the beginning of the iterator
99  if (isFirstIteration)
100  {
101  typename OutputSampleListType::MeasurementVectorSizeType measurementSize;
102  measurementSize = m_MeasurementFunctor(it.GetLabelObject()).Size();
103  outputSampleList->SetMeasurementVectorSize(measurementSize);
104  isFirstIteration = false;
105  }
106  outputSampleList->PushBack(m_MeasurementFunctor(it.GetLabelObject()));
107  ++it;
108  }
109 }
110 
111 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
113 {
114  Superclass::PrintSelf(os, indent);
115 }
116 
117 } // end namespace otb
118 
119 #endif
otb::LabelMapToSampleListFilter< TInputLabelMap, TOutputSampleList, Functor::AttributesMapMeasurementFunctor< typename TInputLabelMap::LabelObjectType, typename TOutputSampleList::MeasurementVectorType > >::ConstIteratorType
InputLabelMapType::ConstIterator ConstIteratorType
Definition: otbLabelMapToSampleListFilter.h:66
otb::LabelMapToSampleListFilter::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbLabelMapToSampleListFilter.hxx:112
otb::LabelMapToSampleListFilter< TInputLabelMap, TOutputSampleList, Functor::AttributesMapMeasurementFunctor< typename TInputLabelMap::LabelObjectType, typename TOutputSampleList::MeasurementVectorType > >::DataObjectPointerArraySizeType
itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
Definition: otbLabelMapToSampleListFilter.h:76
otb::LabelMapToSampleListFilter::GetInputLabelMap
const InputLabelMapType * GetInputLabelMap() const
Definition: otbLabelMapToSampleListFilter.hxx:63
otb::LabelMapToSampleListFilter::OutputSampleListType
TOutputSampleList OutputSampleListType
Definition: otbLabelMapToSampleListFilter.h:68
otb::LabelMapToSampleListFilter::LabelMapToSampleListFilter
LabelMapToSampleListFilter()
Definition: otbLabelMapToSampleListFilter.hxx:30
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::LabelMapToSampleListFilter::DataObjectPointerType
Superclass::DataObjectPointer DataObjectPointerType
Definition: otbLabelMapToSampleListFilter.h:75
otb::LabelMapToSampleListFilter::GetOutputSampleList
const OutputSampleListType * GetOutputSampleList()
Definition: otbLabelMapToSampleListFilter.hxx:76
otb::LabelMapToSampleListFilter< TInputLabelMap, TOutputSampleList, Functor::AttributesMapMeasurementFunctor< typename TInputLabelMap::LabelObjectType, typename TOutputSampleList::MeasurementVectorType > >::OutputSampleListPointerType
OutputSampleListType::Pointer OutputSampleListPointerType
Definition: otbLabelMapToSampleListFilter.h:69
otb::LabelMapToSampleListFilter< TInputLabelMap, TOutputSampleList, Functor::AttributesMapMeasurementFunctor< typename TInputLabelMap::LabelObjectType, typename TOutputSampleList::MeasurementVectorType > >::InputLabelMapType
TInputLabelMap InputLabelMapType
Definition: otbLabelMapToSampleListFilter.h:59
otb::LabelMapToSampleListFilter::~LabelMapToSampleListFilter
~LabelMapToSampleListFilter() override
Definition: otbLabelMapToSampleListFilter.hxx:39
otb::LabelMapToSampleListFilter::MakeOutput
DataObjectPointerType MakeOutput(DataObjectPointerArraySizeType idx) override
Definition: otbLabelMapToSampleListFilter.hxx:45
otb::LabelMapToSampleListFilter::SetInputLabelMap
void SetInputLabelMap(const InputLabelMapType *inputLabelMap)
Definition: otbLabelMapToSampleListFilter.hxx:54
otbLabelMapToSampleListFilter.h
otb::LabelMapToSampleListFilter< TInputLabelMap, TOutputSampleList, Functor::AttributesMapMeasurementFunctor< typename TInputLabelMap::LabelObjectType, typename TOutputSampleList::MeasurementVectorType > >::InputLabelMapConstPointerType
InputLabelMapType::ConstPointer InputLabelMapConstPointerType
Definition: otbLabelMapToSampleListFilter.h:63
otb::LabelMapToSampleListFilter::GenerateData
void GenerateData() override
Definition: otbLabelMapToSampleListFilter.hxx:83