Orfeo Toolbox  3.16
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();
102  maxAttr[*valueIt] = itk::NumericTraits<AttributesValueType>::NonpositiveMin();
103  }
104 
105  LabelObjectContainerConstIterator it = this->GetLabelMap()->GetLabelObjectContainer().begin();
106  LabelObjectContainerConstIterator end = this->GetLabelMap()->GetLabelObjectContainer().end();
107  for (; it != end; ++it)
108  {
109  // get the label object
110  LabelObjectType * labelObject = it->second;
111 
112  std::vector<std::string>::const_iterator it;
113  for (it = attributes.begin(); it != attributes.end(); ++it)
114  {
115  AttributesValueType val = labelObject->GetAttribute((*it).c_str());
116  // Update min
117  if (val < minAttr[*it])
118  minAttr[*it] = val;
119  //Update max
120  if (val > maxAttr[*it])
121  maxAttr[*it] = val;
122  }
123  }
124 }
125 
126 }// end namespace otb
127 #endif

Generated at Sun Feb 3 2013 00:37:02 for Orfeo Toolbox with doxygen 1.8.1.1