OTB  7.4.0
Orfeo Toolbox
otbDataNode.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2020 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,
50 } NodeType;
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 
143  PolygonPointerType GetPolygonExteriorRing() const;
144 
149  PolygonListPointerType GetPolygonInteriorRings() const;
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 
310 protected:
312  DataNode();
313 
315  ~DataNode() override
316  {
317  }
318 
320  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
321 
322  OGRGeometry* ConvertDataNodeToOGRGeometry(const DataNode* dataNode);
323 
324 private:
325  DataNode(const Self&) = delete;
326  void operator=(const Self&) = delete;
327 
329  typedef struct
330  {
331  bool valid;
332  PointType point;
333  LinePointerType line;
334  PolygonPointerType exteriorRing;
335  PolygonListPointerType interiorRings;
336  } DataType;
337 
340 
342  std::string m_NodeId;
343 
346 
348  // FieldMapType m_FieldMap;
349 };
350 } // end namespace
351 
352 #ifndef OTB_MANUAL_INSTANTIATION
353 #include "otbDataNode.hxx"
354 #endif
355 
356 #endif
bool IsPolygonFeature() const
Polygon< ValuePrecisionType > PolygonType
Definition: otbDataNode.h:97
PolygonListType::ConstPointer PolygonListConstPointerType
Definition: otbDataNode.h:104
std::vector< std::string > GetFieldList() const
PolygonType::ConstPointer PolygonConstPointerType
Definition: otbDataNode.h:101
std::string m_NodeId
Definition: otbDataNode.h:342
itk::SmartPointer< Self > Pointer
Definition: otbDataNode.h:79
~DataNode() override
Definition: otbDataNode.h:315
bool Within(const DataNode *node)
void SetPolygonInteriorRings(PolygonListType *polygonList)
Definition: otbDataNode.hxx:72
bool IsLineFeature() const
DataType m_Data
Definition: otbDataNode.h:345
PolygonListPointerType GetPolygonInteriorRings() const
double EuclideanDistanceMetric(const DataNode *node)
OGRGeometry * ConvertDataNodeToOGRGeometry(const DataNode *dataNode)
This class implement a PolyLineParametricPath for which a value can be set. The value is stored in th...
PolygonPointerType GetPolygonExteriorRing() const
bool IsMultiLineFeature() const
int GetFieldAsInt(const std::string &key) const
NodeType
Definition: otbDataNode.h:39
This class represents a node of data in a vector data hierarchy.
Definition: otbDataNode.h:73
itk::SmartPointer< const Self > ConstPointer
Definition: otbPolygon.h:51
void SetPoint(PointType point)
Definition: otbDataNode.hxx:45
This class represent a 2D polygon.
Definition: otbPolygon.h:44
PolygonPointerType exteriorRing
Definition: otbDataNode.h:334
PolygonType::VertexListType VertexListType
Definition: otbDataNode.h:98
TPrecision PrecisionType
Definition: otbDataNode.h:84
VertexListType::ConstPointer VertexListConstPointerType
Definition: otbDataNode.h:99
LinePointerType line
Definition: otbDataNode.h:333
bool IsMultiPointFeature() const
LinePointerType GetLine() const
Definition: otbDataNode.hxx:97
bool IsCollectionFeature() const
This class is a generic all-purpose wrapping around an std::vector<itk::SmartPointer<ObjectType> >...
Definition: otbObjectList.h:40
otb::PolyLineParametricPathWithValue< ValuePrecisionType, VDimension > LineType
Definition: otbDataNode.h:94
itk::SmartPointer< const Self > ConstPointer
Definition: otbDataNode.h:80
bool IsPointFeature() const
double GetFieldAsDouble(const std::string &key) const
void SetFieldAsDouble(const std::string &key, double value)
bool Intersects(const DataNode *node)
void SetPolygonExteriorRing(PolygonType *polygon)
Definition: otbDataNode.hxx:60
PointType GetPoint() const
Definition: otbDataNode.hxx:84
void SetNodeType(NodeType type)
Definition: otbDataNode.hxx:38
bool IsDocument() const
std::string GetFieldAsString(const std::string &key) const
DataNode Self
Definition: otbDataNode.h:77
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
void SetLine(LineType *line)
Definition: otbDataNode.hxx:53
itk::SmartPointer< const Self > ConstPointer
Definition: otbObjectList.h:47
bool IsRoot() const
itk::SmartPointer< Self > Pointer
Definition: otbObjectList.h:46
ObjectList< PolygonType > PolygonListType
Definition: otbDataNode.h:102
LineType::ConstPointer LineConstPointerType
Definition: otbDataNode.h:96
bool HasField(const std::string &key) const
static constexpr GLenum value() noexcept
bool IsMultiPolygonFeature() const
PolygonListPointerType interiorRings
Definition: otbDataNode.h:335
void operator=(const Self &)=delete
Superclass::VertexListType VertexListType
Definition: otbPolygon.h:62
void SetFieldAsString(const std::string &key, const std::string &value)
LineType::Pointer LinePointerType
Definition: otbDataNode.h:95
PolygonType::Pointer PolygonPointerType
Definition: otbDataNode.h:100
itk::SmartPointer< Self > Pointer
Definition: otbPolygon.h:50
PolygonListType::Pointer PolygonListPointerType
Definition: otbDataNode.h:103
std::string GetNodeTypeAsString() const
TValuePrecision ValuePrecisionType
Definition: otbDataNode.h:89
void PrintSelf(std::ostream &os, itk::Indent indent) const override
itk::Object Superclass
Definition: otbDataNode.h:78
void SetFieldAsInt(const std::string &key, int value)
OTBMetadata_EXPORT char const * DataType
static const unsigned int Dimension
Definition: otbDataNode.h:90
bool IsFolder() const
void CopyFieldList(const DataNode *dataNode)
itk::Point< PrecisionType, VDimension > PointType
Definition: otbDataNode.h:93
NodeType m_NodeType
Definition: otbDataNode.h:339