OTB  9.0.0
Orfeo Toolbox
otbMinMaxAttributesLabelMapFilter.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 otbMinMaxAttributesLabelMapFilter_hxx
22 #define otbMinMaxAttributesLabelMapFilter_hxx
23 
25 #include "itkNumericTraits.h"
26 
27 namespace otb
28 {
29 
30 template <class TInputImage>
32 {
33  this->Superclass::SetNumberOfRequiredOutputs(3);
34  this->itk::ProcessObject::SetNthOutput(1, this->MakeOutput(1).GetPointer());
35  this->itk::ProcessObject::SetNthOutput(2, this->MakeOutput(2).GetPointer());
36 }
37 
38 template <class TInputImage>
41 {
43  switch (i)
44  {
45  case 0:
46  ret = InputImageType::New();
47  break;
48  case 1:
49  case 2:
50  ret = AttributesMapObjectType::New();
51  break;
52  }
53  return ret;
54 }
55 
56 
57 template <class TInputImage>
59 {
60  return static_cast<AttributesMapObjectType*>(this->itk::ProcessObject::GetOutput(1));
61 }
62 
63 template <class TInputImage>
65 {
66  return static_cast<const AttributesMapObjectType*>(this->itk::ProcessObject::GetOutput(1));
67 }
68 
69 template <class TInputImage>
71 {
72  return static_cast<AttributesMapObjectType*>(this->itk::ProcessObject::GetOutput(2));
73 }
74 
75 template <class TInputImage>
77 {
78  return static_cast<const AttributesMapObjectType*>(this->itk::ProcessObject::GetOutput(2));
79 }
80 
81 template <class TInputImage>
83 {
84  std::vector<std::string> attributes = this->GetLabelMap()->GetLabelObject(0)->GetAvailableAttributes();
85 
86  AttributesMapType& minAttr = this->GetMinimumOutput()->Get();
87  AttributesMapType& maxAttr = this->GetMaximumOutput()->Get();
88 
89  // create an entry in the output maps for each attribute
90  std::vector<std::string>::const_iterator valueIt;
91  for (valueIt = attributes.begin(); valueIt != attributes.end(); ++valueIt)
92  {
93  minAttr[*valueIt] = itk::NumericTraits<AttributesValueType>::max();
94  maxAttr[*valueIt] = itk::NumericTraits<AttributesValueType>::NonpositiveMin();
95  }
96 
97 
98  for (unsigned int i = 0; i < this->GetLabelMap()->GetNumberOfLabelObjects(); ++i)
99  {
100  LabelObjectType* labelObject = this->GetLabelMap()->GetNthLabelObject(i);
101  std::vector<std::string>::const_iterator it;
102  for (it = attributes.begin(); it != attributes.end(); ++it)
103  {
104  AttributesValueType val = labelObject->GetAttribute((*it).c_str());
105  // Update min
106  if (val < minAttr[*it])
107  minAttr[*it] = val;
108  // Update max
109  if (val > maxAttr[*it])
110  maxAttr[*it] = val;
111  }
112  ++it;
113  }
114 }
115 
116 } // end namespace otb
117 #endif
otb::MinMaxAttributesLabelMapFilter::AttributesMapType
LabelObjectType::AttributesMapType AttributesMapType
Definition: otbMinMaxAttributesLabelMapFilter.h:58
otb::MinMaxAttributesLabelMapFilter::MakeOutput
DataObjectPointerType MakeOutput(DataObjectPointerArraySizeType idx) override
Definition: otbMinMaxAttributesLabelMapFilter.hxx:40
otb::MinMaxAttributesLabelMapFilter::DataObjectPointerType
DataObjectType::Pointer DataObjectPointerType
Definition: otbMinMaxAttributesLabelMapFilter.h:62
otb::MinMaxAttributesLabelMapFilter::LabelObjectType
InputImageType::LabelObjectType LabelObjectType
Definition: otbMinMaxAttributesLabelMapFilter.h:54
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::MinMaxAttributesLabelMapFilter::GenerateData
void GenerateData() override
Definition: otbMinMaxAttributesLabelMapFilter.hxx:82
otb::MinMaxAttributesLabelMapFilter::GetMinimumOutput
AttributesMapObjectType * GetMinimumOutput()
Definition: otbMinMaxAttributesLabelMapFilter.hxx:58
otbMinMaxAttributesLabelMapFilter.h
otb::MinMaxAttributesLabelMapFilter::DataObjectPointerArraySizeType
itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
Definition: otbMinMaxAttributesLabelMapFilter.h:48
otb::MinMaxAttributesLabelMapFilter::AttributesValueType
LabelObjectType::AttributesValueType AttributesValueType
Definition: otbMinMaxAttributesLabelMapFilter.h:57
otb::MinMaxAttributesLabelMapFilter::MinMaxAttributesLabelMapFilter
MinMaxAttributesLabelMapFilter()
Definition: otbMinMaxAttributesLabelMapFilter.hxx:31
otb::MinMaxAttributesLabelMapFilter::AttributesMapObjectType
itk::SimpleDataObjectDecorator< AttributesMapType > AttributesMapObjectType
Definition: otbMinMaxAttributesLabelMapFilter.h:59
otb::MinMaxAttributesLabelMapFilter::GetMaximumOutput
AttributesMapObjectType * GetMaximumOutput()
Definition: otbMinMaxAttributesLabelMapFilter.hxx:70