OTB  6.1.0
Orfeo Toolbox
otbLabelMapToSampleListFilter.txx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2017 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_txx
22 #define otbLabelMapToSampleListFilter_txx
23 
25 
26 namespace otb
27 {
28 
29 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
32 {
33  this->SetNumberOfRequiredInputs(1);
34  this->SetNumberOfRequiredOutputs(1);
35 
36  this->itk::ProcessObject::SetNthOutput(0, this->MakeOutput(0).GetPointer());
37 }
38 
39 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
42 {
43 }
44 
45 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
47 ::DataObjectPointerType
50 {
51  DataObjectPointerType output;
52  output = static_cast<itk::DataObject*>(OutputSampleListType::New().GetPointer());
53  return output;
54 }
55 
56 // Set the input labelMap
57 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
58 void
60 ::SetInputLabelMap(const InputLabelMapType * inputLabelMap )
61 {
62  // Process object is not const-correct so the const_cast is required here
64  const_cast<InputLabelMapType*>(inputLabelMap));
65 }
66 
67 //Get the input labelMap
68 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
70 ::InputLabelMapType *
73 {
74  if (this->GetNumberOfInputs() < 1)
75  {
76  return ITK_NULLPTR;
77  }
78 
79  return static_cast<const InputLabelMapType* >
80  (this->itk::ProcessObject::GetInput(0) );
81 }
82 
83 // Get the output SampleList
84 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
86 ::OutputSampleListType *
89 {
90  return dynamic_cast<OutputSampleListType*>(this->itk::ProcessObject::GetOutput(0));
91 }
92 
93 
94 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
95 void
98 {
99  // Get the input LabelMap
100  InputLabelMapConstPointerType inputLabelMap = this->GetInputLabelMap();
101 
102  // Get the output ListSample
103  OutputSampleListPointerType outputSampleList = const_cast<OutputSampleListType*>(this->GetOutputSampleList());
104 
105  ConstIteratorType it = ConstIteratorType( inputLabelMap );
106 
107  // iterate on label objects
108  bool isFirstIteration = true;
109  while( !it.IsAtEnd() )
110  {
111  // Get the measurement vector size of the output samplelist : once
112  // in the beginning of the iterator
113  if( isFirstIteration )
114  {
115  typename OutputSampleListType::MeasurementVectorSizeType measurementSize;
116  measurementSize = m_MeasurementFunctor(it.GetLabelObject()).Size();
117  outputSampleList->SetMeasurementVectorSize(measurementSize);
118  isFirstIteration = false;
119  }
120  outputSampleList->PushBack(m_MeasurementFunctor(it.GetLabelObject()));
121  ++it;
122  }
123 }
124 
125 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
126 void
128 ::PrintSelf(std::ostream& os, itk::Indent indent) const
129 {
130  Superclass::PrintSelf(os, indent);
131 }
132 
133 } // end namespace otb
134 
135 #endif
This class converts a LabelObjectMap to a SampleList for learning and classification.
DataObjectPointerType MakeOutput(DataObjectPointerArraySizeType idx) ITK_OVERRIDE
InputLabelMapType::ConstPointer InputLabelMapConstPointerType
const OutputSampleListType * GetOutputSampleList()
DataObjectPointerArray::size_type DataObjectPointerArraySizeType
DataObject * GetInput(const DataObjectIdentifierType &key)
InputLabelMapType::ConstIterator ConstIteratorType
virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input)
virtual void SetNthOutput(DataObjectPointerArraySizeType num, DataObject *output)
const InputLabelMapType * GetInputLabelMap() const
void PrintSelf(std::ostream &os, itk::Indent indent) const ITK_OVERRIDE
OutputSampleListType::Pointer OutputSampleListPointerType
void SetInputLabelMap(const InputLabelMapType *inputLabelMap)
DataObject * GetOutput(const DataObjectIdentifierType &key)