Orfeo Toolbox  4.2
otbLabelMapToSampleListFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbLabelMapToSampleListFilter_txx
19 #define __otbLabelMapToSampleListFilter_txx
20 
22 
23 namespace otb
24 {
25 
26 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
29 {
30  this->SetNumberOfRequiredInputs(1);
31  this->SetNumberOfRequiredOutputs(1);
32 
33  this->itk::ProcessObject::SetNthOutput(0, this->MakeOutput(0).GetPointer());
34 }
35 
36 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
39 {
40 }
41 
42 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
44 ::DataObjectPointerType
46 ::MakeOutput(unsigned int itkNotUsed(idx))
47 {
48  DataObjectPointerType output;
49  output = static_cast<itk::DataObject*>(OutputSampleListType::New().GetPointer());
50  return output;
51 }
52 
53 // Set the input labelMap
54 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
55 void
57 ::SetInputLabelMap(const InputLabelMapType * inputLabelMap )
58 {
59  // Process object is not const-correct so the const_cast is required here
61  const_cast<InputLabelMapType*>(inputLabelMap));
62 }
63 
64 //Get the input labelMap
65 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
67 ::InputLabelMapType *
70 {
71  if (this->GetNumberOfInputs() < 1)
72  {
73  return 0;
74  }
75 
76  return static_cast<const InputLabelMapType* >
77  (this->itk::ProcessObject::GetInput(0) );
78 }
79 
80 // Get the output SampleList
81 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
83 ::OutputSampleListType *
86 {
87  return dynamic_cast<OutputSampleListType*>(this->itk::ProcessObject::GetOutput(0));
88 }
89 
90 
91 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
92 void
95 {
96  // Get the input LabelMap
97  InputLabelMapConstPointerType inputLabelMap = this->GetInputLabelMap();
98 
99  // Get the output ListSample
100  OutputSampleListPointerType outputSampleList = const_cast<OutputSampleListType*>(this->GetOutputSampleList());
101 
102  ConstIteratorType it = ConstIteratorType( inputLabelMap );
103 
104  // iterate on label objects
105  bool isFirstIteration = true;
106  while( !it.IsAtEnd() )
107  {
108  // Get the measurement vector size of the output samplelist : once
109  // in the begining of the iterator
110  if( isFirstIteration )
111  {
112  typename OutputSampleListType::MeasurementVectorSizeType measurementSize;
113  measurementSize = m_MeasurementFunctor(it.GetLabelObject()).Size();
114  outputSampleList->SetMeasurementVectorSize(measurementSize);
115  isFirstIteration = false;
116  }
117  outputSampleList->PushBack(m_MeasurementFunctor(it.GetLabelObject()));
118  ++it;
119  }
120 }
121 
122 template <class TInputLabelMap, class TOutputListSample, class TMeasurementFunctor>
123 void
125 ::PrintSelf(std::ostream& os, itk::Indent indent) const
126 {
127  Superclass::PrintSelf(os, indent);
128 }
129 
130 } // end namespace otb
131 
132 #endif

Generated at Sat Aug 30 2014 16:10:31 for Orfeo Toolbox with doxygen 1.8.3.1