Orfeo Toolbox  4.0
otbMinMaxAttributesLabelMapFilter.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 __otbMinMaxAttributesLabelMapFilter_txx
19 #define __otbMinMaxAttributesLabelMapFilter_txx
20 
22 #include "itkNumericTraits.h"
23 
24 namespace otb {
25 
26 template <class TInputImage>
29 {
30  this->Superclass::SetNumberOfRequiredOutputs(3);
31  this->itk::ProcessObject::SetNthOutput(1, this->MakeOutput(1).GetPointer());
32  this->itk::ProcessObject::SetNthOutput(2, this->MakeOutput(2).GetPointer());
33 }
34 
35 template<class TInputImage>
38 ::MakeOutput(unsigned int i)
39 {
41  switch (i)
42  {
43  case 0:
44  ret = InputImageType::New();
45  break;
46  case 1:
47  case 2:
48  ret = AttributesMapObjectType::New();
49  break;
50  }
51  return ret;
52 }
53 
54 
55 template<class TInputImage>
59 {
60  return static_cast<AttributesMapObjectType*>(this->itk::ProcessObject::GetOutput(1));
61 }
62 
63 template<class TInputImage>
67 {
68  return static_cast<const AttributesMapObjectType*>(this->itk::ProcessObject::GetOutput(1));
69 }
70 
71 template<class TInputImage>
75 {
76  return static_cast<AttributesMapObjectType*>(this->itk::ProcessObject::GetOutput(2));
77 }
78 
79 template<class TInputImage>
83 {
84  return static_cast<const AttributesMapObjectType*>(this->itk::ProcessObject::GetOutput(2));
85 }
86 
87 template<class TInputImage>
88 void
91 {
92  std::vector<std::string> attributes = this->GetLabelMap()->GetLabelObject(0)->GetAvailableAttributes();
93 
94  AttributesMapType& minAttr = this->GetMinimumOutput()->Get();
95  AttributesMapType& maxAttr = this->GetMaximumOutput()->Get();
96 
97  // create an entry in the output maps for each attribute
98  std::vector<std::string>::const_iterator valueIt;
99  for (valueIt = attributes.begin(); valueIt != attributes.end(); ++valueIt)
100  {
101  minAttr[*valueIt] = itk::NumericTraits<AttributesValueType>::max();
103  }
104 
105 
106  for(unsigned int i = 0; i < this->GetLabelMap()->GetNumberOfLabelObjects(); ++i)
107  {
108  LabelObjectType* labelObject =this->GetLabelMap()->GetNthLabelObject(i);
109  std::vector<std::string>::const_iterator it;
110  for (it = attributes.begin(); it != attributes.end(); ++it)
111  {
112  AttributesValueType val = labelObject->GetAttribute((*it).c_str());
113  // Update min
114  if (val < minAttr[*it])
115  minAttr[*it] = val;
116  //Update max
117  if (val > maxAttr[*it])
118  maxAttr[*it] = val;
119  }
120  ++it;
121  }
122 
123 
124 }
125 
126 }// end namespace otb
127 #endif

Generated at Sat Mar 8 2014 16:08:07 for Orfeo Toolbox with doxygen 1.8.3.1