OTB  10.0.0
Orfeo Toolbox
otbDecisionTree.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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 otbDecisionTree_h
22 #define otbDecisionTree_h
23 
24 #include <map>
25 #include "itkObjectFactory.h"
26 #include "itkDataObject.h"
27 
28 namespace otb
29 {
30 
60 template <class AttributeValueType, class LabelType>
61 class ITK_EXPORT DecisionTree : public itk::DataObject
62 {
63 public:
65  {
66  MIN,
67  LT = MIN,
68  LE,
69  EQ,
70  GE,
71  GT,
72  MAX = GT
73  };
75  typedef DecisionTree Self;
76  typedef itk::DataObject Superclass;
77  typedef itk::SmartPointer<Self> Pointer;
78  typedef itk::SmartPointer<const Self> ConstPointer;
79 
81  itkNewMacro(Self);
82 
84  itkTypeMacro(DecisionTree, DataObject);
85 
86  typedef typename std::pair<AttributeValueType, DecisionTreeTestType> KeyType;
87  typedef typename std::map<KeyType, Pointer> TreeMapType;
88  typedef typename std::map<KeyType, LabelType> LabelMapType;
89  typedef std::vector<AttributeValueType> ExampleType;
90 
91  itkSetMacro(Attribute, unsigned int);
92  itkGetMacro(Attribute, unsigned int);
93 
95  void AddBranch(AttributeValueType attr, DecisionTreeTestType testType, Pointer branch);
96 
99  void AddBranch(AttributeValueType attr, Pointer branch);
100 
102  void AddBranch(AttributeValueType attr, DecisionTreeTestType testType, LabelType label);
103 
106  void AddBranch(AttributeValueType attr, LabelType label);
107 
108  LabelType Decide(const ExampleType& example);
109 
110 protected:
112  DecisionTree();
113 
115  ~DecisionTree() override;
116 
120  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
121 
122 private:
123  DecisionTree(const Self&) = delete;
124  void operator=(const Self&) = delete;
125 
128 
131 
133  unsigned int m_Attribute;
134 
136  bool m_IsFinal;
137 
138  LabelType m_Label;
139 };
140 } // end namespace otb
141 
142 #ifndef OTB_MANUAL_INSTANTIATION
143 #include "otbDecisionTree.hxx"
144 #endif
145 
146 #endif
Models a decision tree.
itk::SmartPointer< Self > Pointer
std::map< KeyType, Pointer > TreeMapType
TreeMapType * m_TreeMap
void operator=(const Self &)=delete
std::pair< AttributeValueType, DecisionTreeTestType > KeyType
itk::DataObject Superclass
unsigned int m_Attribute
DecisionTree(const Self &)=delete
DecisionTree Self
std::vector< AttributeValueType > ExampleType
std::map< KeyType, LabelType > LabelMapType
LabelMapType m_LabelMap
itk::SmartPointer< const Self > ConstPointer
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.