OTB  10.0.0
Orfeo Toolbox
otbDataNode.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 otbDataNode_h
22 #define otbDataNode_h
23 
24 #include "itkPoint.h"
25 #include "otbPolygon.h"
26 #include "otbObjectList.h"
28 
29 
30 #include "ogrsf_frmts.h"
31 #include <string>
32 
33 namespace otb
34 {
39 typedef enum {
40  ROOT = 0,
41  DOCUMENT = 1,
42  FOLDER = 2,
51 
72 template <class TPrecision = double, unsigned VDimension = 2, class TValuePrecision = double>
73 class DataNode : public itk::Object
74 {
75 public:
77  typedef DataNode Self;
78  typedef itk::Object Superclass;
79  typedef itk::SmartPointer<Self> Pointer;
80  typedef itk::SmartPointer<const Self> ConstPointer;
81 
83  itkNewMacro(Self);
84  itkTypeMacro(DataNode, Object);
86 
88  typedef TPrecision PrecisionType;
89  typedef TValuePrecision ValuePrecisionType;
90  itkStaticConstMacro(Dimension, unsigned int, VDimension);
91 
93  typedef itk::Point<PrecisionType, VDimension> PointType;
99  typedef typename VertexListType::ConstPointer VertexListConstPointerType;
105 
107  // typedef std::map<std::string, std::string> FieldMapType;
108  // typedef std::pair<std::string, std::string> FieldType;
109 
111  itkGetConstMacro(NodeType, NodeType);
112  itkGetStringMacro(NodeId);
113  itkSetStringMacro(NodeId);
115 
120  void SetNodeType(NodeType type);
121 
125  std::string GetNodeTypeAsString() const;
126 
131  PointType GetPoint() const;
132 
137  LinePointerType GetLine() const;
138 
144 
150 
155  void SetPoint(PointType point);
156 
161  void SetLine(LineType* line);
162 
167  void SetPolygonExteriorRing(PolygonType* polygon);
168 
173  void SetPolygonInteriorRings(PolygonListType* polygonList);
174 
178  bool IsDocument() const;
179 
183  bool IsRoot() const;
184 
188  bool IsFolder() const;
189 
193  bool IsPointFeature() const;
194 
198  bool IsLineFeature() const;
199 
203  bool IsPolygonFeature() const;
204 
208  bool IsMultiPointFeature() const;
209 
213  bool IsMultiLineFeature() const;
214 
218  bool IsMultiPolygonFeature() const;
219 
223  bool IsCollectionFeature() const;
224 
230  void SetFieldAsString(const std::string& key, const std::string& value);
231 
237  std::string GetFieldAsString(const std::string& key) const;
238 
244  void SetFieldAsInt(const std::string& key, int value);
245 
251  int GetFieldAsInt(const std::string& key) const;
252 
258  void SetFieldAsDouble(const std::string& key, double value);
259 
265  double GetFieldAsDouble(const std::string& key) const;
266 
271  // void RemoveField(const std::string& key);
272 
277  bool HasField(const std::string& key) const;
278 
283  void CopyFieldList(const DataNode* dataNode);
284 
288  std::vector<std::string> GetFieldList() const;
289 
291  double EuclideanDistanceMetric(const DataNode* node);
292 
293  double EuclideanDistanceMetric(const PointType point);
294 
298  bool Intersects(const DataNode* node);
299 
303  bool Within(const DataNode* node);
304 
308  // void ClearFields();
309 
316  void Reset(const DataNode& inputNode)
317  {
318  this->SetNodeType(inputNode.GetNodeType());
319  this->SetNodeId(inputNode.GetNodeId());
320  CopyFieldList(&inputNode);
321  this->m_Data = inputNode.m_Data;
322  }
323 protected:
324 
326  DataNode();
327 
329  ~DataNode() override
330  {
331  }
332 
334  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
335 
336  OGRGeometry* ConvertDataNodeToOGRGeometry(const DataNode* dataNode);
337 
338 private:
339  DataNode(const Self&) = delete;
340  void operator=(const Self&) = delete;
341 //TODO Refactor modern cpp
343  typedef struct
344  {
345  bool valid;
350  } DataType;
351 
354 
356  std::string m_NodeId;
357 
360 
362  // FieldMapType m_FieldMap;
363 };
364 } // end namespace
365 
366 #ifndef OTB_MANUAL_INSTANTIATION
367 #include "otbDataNode.hxx"
368 #endif
369 
370 #endif
This class represents a node of data in a vector data hierarchy.
Definition: otbDataNode.h:74
Polygon< ValuePrecisionType > PolygonType
Definition: otbDataNode.h:97
bool IsMultiLineFeature() const
int GetFieldAsInt(const std::string &key) const
OGRGeometry * ConvertDataNodeToOGRGeometry(const DataNode *dataNode)
LineType::Pointer LinePointerType
Definition: otbDataNode.h:95
itk::Object Superclass
Definition: otbDataNode.h:78
NodeType m_NodeType
Definition: otbDataNode.h:353
PolygonListPointerType GetPolygonInteriorRings() const
std::string GetFieldAsString(const std::string &key) const
void SetFieldAsString(const std::string &key, const std::string &value)
bool IsLineFeature() const
~DataNode() override
Definition: otbDataNode.h:329
PolygonType::Pointer PolygonPointerType
Definition: otbDataNode.h:100
otb::PolyLineParametricPathWithValue< ValuePrecisionType, VDimension > LineType
Definition: otbDataNode.h:94
bool IsPointFeature() const
double GetFieldAsDouble(const std::string &key) const
std::string GetNodeTypeAsString() const
bool IsMultiPointFeature() const
bool IsRoot() const
PolygonListType::Pointer PolygonListPointerType
Definition: otbDataNode.h:103
static const unsigned int Dimension
Definition: otbDataNode.h:90
TValuePrecision ValuePrecisionType
Definition: otbDataNode.h:89
std::vector< std::string > GetFieldList() const
DataType m_Data
Definition: otbDataNode.h:359
bool HasField(const std::string &key) const
TPrecision PrecisionType
Definition: otbDataNode.h:84
void SetFieldAsDouble(const std::string &key, double value)
ObjectList< PolygonType > PolygonListType
Definition: otbDataNode.h:102
itk::SmartPointer< Self > Pointer
Definition: otbDataNode.h:79
bool IsCollectionFeature() const
void SetLine(LineType *line)
Definition: otbDataNode.hxx:53
itk::Point< PrecisionType, VDimension > PointType
Definition: otbDataNode.h:93
std::string m_NodeId
Definition: otbDataNode.h:356
itk::SmartPointer< const Self > ConstPointer
Definition: otbDataNode.h:80
double EuclideanDistanceMetric(const DataNode *node)
void PrintSelf(std::ostream &os, itk::Indent indent) const override
PointType GetPoint() const
Definition: otbDataNode.hxx:84
LinePointerType GetLine() const
Definition: otbDataNode.hxx:97
VertexListType::ConstPointer VertexListConstPointerType
Definition: otbDataNode.h:99
bool IsDocument() const
virtual const char * GetNodeId() const
PolygonType::VertexListType VertexListType
Definition: otbDataNode.h:98
bool IsPolygonFeature() const
void SetFieldAsInt(const std::string &key, int value)
virtual void SetNodeId(const char *_arg)
void SetPoint(PointType point)
Definition: otbDataNode.hxx:45
bool Within(const DataNode *node)
PolygonListType::ConstPointer PolygonListConstPointerType
Definition: otbDataNode.h:104
void Reset(const DataNode &inputNode)
Perform a reset of all fields of a datanode using an input node.
Definition: otbDataNode.h:316
bool IsMultiPolygonFeature() const
PolygonPointerType GetPolygonExteriorRing() const
void SetPolygonInteriorRings(PolygonListType *polygonList)
Definition: otbDataNode.hxx:72
void SetPolygonExteriorRing(PolygonType *polygon)
Definition: otbDataNode.hxx:60
LineType::ConstPointer LineConstPointerType
Definition: otbDataNode.h:96
DataNode(const Self &)=delete
void operator=(const Self &)=delete
bool Intersects(const DataNode *node)
PolygonType::ConstPointer PolygonConstPointerType
Definition: otbDataNode.h:101
DataNode Self
Definition: otbDataNode.h:77
bool IsFolder() const
void CopyFieldList(const DataNode *dataNode)
void SetNodeType(NodeType type)
Definition: otbDataNode.hxx:38
virtual NodeType GetNodeType() const
This class is a generic all-purpose wrapping around an std::vector<itk::SmartPointer<ObjectType> >.
Definition: otbObjectList.h:41
itk::SmartPointer< const Self > ConstPointer
Definition: otbObjectList.h:47
itk::SmartPointer< Self > Pointer
Definition: otbObjectList.h:46
This class implement a PolyLineParametricPath for which a value can be set. The value is stored in th...
This class represent a 2D polygon.
Definition: otbPolygon.h:45
itk::SmartPointer< const Self > ConstPointer
Definition: otbPolygon.h:51
itk::SmartPointer< Self > Pointer
Definition: otbPolygon.h:50
Superclass::VertexListType VertexListType
Definition: otbPolygon.h:62
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
NodeType
Definition: otbDataNode.h:39
@ FEATURE_POLYGON
Definition: otbDataNode.h:45
@ FEATURE_MULTIPOINT
Definition: otbDataNode.h:46
@ FEATURE_MULTIPOLYGON
Definition: otbDataNode.h:48
@ FOLDER
Definition: otbDataNode.h:42
@ FEATURE_MULTILINE
Definition: otbDataNode.h:47
@ DOCUMENT
Definition: otbDataNode.h:41
@ ROOT
Definition: otbDataNode.h:40
@ FEATURE_POINT
Definition: otbDataNode.h:43
@ FEATURE_COLLECTION
Definition: otbDataNode.h:49
@ FEATURE_LINE
Definition: otbDataNode.h:44
PolygonListPointerType interiorRings
Definition: otbDataNode.h:349
PolygonPointerType exteriorRing
Definition: otbDataNode.h:348
LinePointerType line
Definition: otbDataNode.h:347