OTB  9.0.0
Orfeo Toolbox
otbAttributesMapLabelObjectWithClassLabel.h
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 otbAttributesMapLabelObjectWithClassLabel_h
22 #define otbAttributesMapLabelObjectWithClassLabel_h
23 
25 
26 namespace otb
27 {
28 
53 template <class TLabel, unsigned int VImageDimension, class TAttributesValue, class TClassLabel>
54 class ITK_EXPORT AttributesMapLabelObjectWithClassLabel : public AttributesMapLabelObject<TLabel, VImageDimension, TAttributesValue>
55 {
56 public:
60  typedef itk::LabelObject<TLabel, VImageDimension> LabelObjectType;
61  typedef itk::SmartPointer<Self> Pointer;
62  typedef itk::SmartPointer<const Self> ConstPointer;
63  typedef itk::WeakPointer<const Self> ConstWeakPointer;
64 
66  itkNewMacro(Self);
67 
70 
71  itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
72 
74  typedef TClassLabel ClassLabelType;
75 
77  void SetClassLabel(const ClassLabelType& label)
78  {
79  m_ClassLabel = label;
80  m_HasClassLabel = true;
81  }
82 
86  {
87  if (!m_HasClassLabel)
88  {
89  itkExceptionMacro(<< "LabelObject has no class label!");
90  }
91  return m_ClassLabel;
92  }
94 
96  bool HasClassLabel() const
97  {
98  return m_HasClassLabel;
99  }
100 
103  {
104  m_ClassLabel = itk::NumericTraits<ClassLabelType>::Zero;
105  m_HasClassLabel = false;
106  }
107 
108  void CopyAttributesFrom(const LabelObjectType* lo) override
109  {
110  Superclass::CopyAttributesFrom(lo);
111 
112  // copy the data of the current type if possible
113  const Self* src = dynamic_cast<const Self*>(lo);
114  if (src == nullptr)
115  {
116  return;
117  }
118 
119  m_ClassLabel = src->m_ClassLabel;
120  m_HasClassLabel = src->m_HasClassLabel;
121  }
122 
123 protected:
125  AttributesMapLabelObjectWithClassLabel() : m_ClassLabel(itk::NumericTraits<ClassLabelType>::Zero), m_HasClassLabel(false)
126  {
127  }
128 
131  {
132  }
133 
135  void PrintSelf(std::ostream& os, itk::Indent indent) const override
136  {
137  Superclass::PrintSelf(os, indent);
138  if (m_HasClassLabel)
139  {
140  os << indent << "Class Label: " << m_ClassLabel << std::endl;
141  }
142  else
143  {
144  os << indent << "No class label available." << std::endl;
145  }
146  }
148 
149 private:
150  AttributesMapLabelObjectWithClassLabel(const Self&) = delete;
151  void operator=(const Self&) = delete;
152 
155 
158 };
159 
160 } // end namespace otb
161 #endif
otbAttributesMapLabelObject.h
otb::AttributesMapLabelObjectWithClassLabel::m_ClassLabel
ClassLabelType m_ClassLabel
Definition: otbAttributesMapLabelObjectWithClassLabel.h:154
otb::AttributesMapLabelObject::LabelObjectType
Superclass::LabelObjectType LabelObjectType
Definition: otbAttributesMapLabelObject.h:183
otb::AttributesMapLabelObjectWithClassLabel::Superclass
AttributesMapLabelObject< TLabel, VImageDimension, TAttributesValue > Superclass
Definition: otbAttributesMapLabelObjectWithClassLabel.h:59
otb::AttributesMapLabelObject
A LabelObject with a generic attributes map.
Definition: otbAttributesMapLabelObject.h:177
otb::AttributesMapLabelObjectWithClassLabel::ConstWeakPointer
itk::WeakPointer< const Self > ConstWeakPointer
Definition: otbAttributesMapLabelObjectWithClassLabel.h:63
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::AttributesMapLabelObjectWithClassLabel::GetClassLabel
const ClassLabelType & GetClassLabel() const
Definition: otbAttributesMapLabelObjectWithClassLabel.h:85
otb::AttributesMapLabelObjectWithClassLabel::LabelObjectType
itk::LabelObject< TLabel, VImageDimension > LabelObjectType
Definition: otbAttributesMapLabelObjectWithClassLabel.h:60
otb::AttributesMapLabelObjectWithClassLabel::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbAttributesMapLabelObjectWithClassLabel.h:61
otb::AttributesMapLabelObjectWithClassLabel::RemoveClassLabel
void RemoveClassLabel()
Definition: otbAttributesMapLabelObjectWithClassLabel.h:102
otb::AttributesMapLabelObjectWithClassLabel::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbAttributesMapLabelObjectWithClassLabel.h:62
otb::AttributesMapLabelObjectWithClassLabel::AttributesMapLabelObjectWithClassLabel
AttributesMapLabelObjectWithClassLabel()
Definition: otbAttributesMapLabelObjectWithClassLabel.h:125
otb::AttributesMapLabelObjectWithClassLabel::Self
AttributesMapLabelObjectWithClassLabel Self
Definition: otbAttributesMapLabelObjectWithClassLabel.h:58
otb::AttributesMapLabelObjectWithClassLabel::HasClassLabel
bool HasClassLabel() const
Definition: otbAttributesMapLabelObjectWithClassLabel.h:96
otb::AttributesMapLabelObjectWithClassLabel
An AttributesMapLabelObject with an optional class label.
Definition: otbAttributesMapLabelObjectWithClassLabel.h:54
otb::AttributesMapLabelObjectWithClassLabel::ClassLabelType
TClassLabel ClassLabelType
Definition: otbAttributesMapLabelObjectWithClassLabel.h:74
itk
Definition: otbNoDataHelper.h:31
otb::AttributesMapLabelObjectWithClassLabel::~AttributesMapLabelObjectWithClassLabel
~AttributesMapLabelObjectWithClassLabel() override
Definition: otbAttributesMapLabelObjectWithClassLabel.h:130
otb::AttributesMapLabelObjectWithClassLabel::CopyAttributesFrom
void CopyAttributesFrom(const LabelObjectType *lo) override
Definition: otbAttributesMapLabelObjectWithClassLabel.h:108
otb::AttributesMapLabelObjectWithClassLabel::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbAttributesMapLabelObjectWithClassLabel.h:135
otb::AttributesMapLabelObjectWithClassLabel::m_HasClassLabel
bool m_HasClassLabel
Definition: otbAttributesMapLabelObjectWithClassLabel.h:157
otb::AttributesMapLabelObjectWithClassLabel::SetClassLabel
void SetClassLabel(const ClassLabelType &label)
Definition: otbAttributesMapLabelObjectWithClassLabel.h:77