OTB  9.0.0
Orfeo Toolbox
grmGraph.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Generic Region Merging Library
4  Language: C++
5  author: Lassalle Pierre
6  contact: lassallepierre34@gmail.com
7 
8 
9 
10  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef GRM_GRAPH_H
19 #define GRM_GRAPH_H
20 #include "grmDataStructures.h"
21 #include "lpContour.h"
22 
23 namespace grm
24 {
25  struct BaseNode
26  {
27  /* Node already merged. */
28  bool m_Valid;
29 
30  /* Node has to be removed from the graph. */
31  bool m_Expired;
32 
33  /* Does the node merge at the previous iteration */
34  bool m_IsMerged;
35 
36  /* Perimeter of the region */
37  unsigned int m_Perimeter;
38 
39  /* Area (number of inner pixels) of the region */
40  unsigned int m_Area;
41 
42  /*
43  Node is identified by the location
44  of the first pixel of the region.
45  */
46  long unsigned int m_Id;
47 
48  /*
49  Bounding box of the region
50  in the image.
51  */
53 
54  /* Contour of the shape */
56  };
57 
58  template<class DerivedNode>
59  struct NeighborType
60  {
61  typedef std::weak_ptr<DerivedNode> WeakDerived;
62  typedef std::shared_ptr<DerivedNode> SharedDerived;
63 
65  float m_Cost;
66  unsigned int m_Boundary;
68 
69  NeighborType(WeakDerived ptr, double w, unsigned int c) :
70  m_Target(ptr), m_Cost(w), m_Boundary(c), m_CostUpdated(false) {}
71 
73  {
74  SharedDerived ptr(m_Target.lock());
75  if(!ptr)
76  throw std::runtime_error("NeighborType::GetRegion - Region pointer is not valid");
77  return ptr;
78  }
79  };
80 
81 
82  template<class DerivedNode>
83  struct Node : BaseNode
84  {
86  std::vector<CRPTNeighborType> m_Edges;
87  };
88 
89  template<class TNode>
90  struct Graph
91  {
92  typedef TNode NodeType;
93  typedef std::shared_ptr<NodeType> NodePointerType;
94  typedef typename NodeType::CRPTNeighborType EdgeType;
95  typedef std::vector<NodePointerType> NodeListType;
96  typedef typename NodeListType::iterator NodeIteratorType;
97  typedef typename NodeListType::const_iterator NodeConstIteratorType;
98  typedef std::vector<EdgeType> EdgeListType;
99  typedef typename EdgeListType::iterator EdgeIteratorType;
100  typedef typename EdgeListType::const_iterator EdgeConstIteratorType;
101 
102  std::vector< NodePointerType > m_Nodes;
103  };
104 
105 } // end of namespace grm
106 #endif
grm::Graph::EdgeIteratorType
EdgeListType::iterator EdgeIteratorType
Definition: grmGraph.h:99
grm::NeighborType::m_Cost
float m_Cost
Definition: grmGraph.h:65
grm
Definition: grmBaatzSegmenter.h:22
grm::Graph::NodeConstIteratorType
NodeListType::const_iterator NodeConstIteratorType
Definition: grmGraph.h:97
grm::BaseNode::m_Id
long unsigned int m_Id
Definition: grmGraph.h:46
grm::BaseNode
Definition: grmGraph.h:25
grm::NeighborType::m_Boundary
unsigned int m_Boundary
Definition: grmGraph.h:66
grm::Graph::EdgeType
NodeType::CRPTNeighborType EdgeType
Definition: grmGraph.h:94
grm::BaseNode::m_Valid
bool m_Valid
Definition: grmGraph.h:28
grm::NeighborType::WeakDerived
std::weak_ptr< DerivedNode > WeakDerived
Definition: grmGraph.h:61
grm::NeighborType::SharedDerived
std::shared_ptr< DerivedNode > SharedDerived
Definition: grmGraph.h:62
grm::BaseNode::m_IsMerged
bool m_IsMerged
Definition: grmGraph.h:34
grm::BaseNode::m_Perimeter
unsigned int m_Perimeter
Definition: grmGraph.h:37
grm::BaseNode::m_Expired
bool m_Expired
Definition: grmGraph.h:31
grm::Graph::EdgeConstIteratorType
EdgeListType::const_iterator EdgeConstIteratorType
Definition: grmGraph.h:100
grm::NeighborType::m_Target
WeakDerived m_Target
Definition: grmGraph.h:64
grm::BaseNode::m_Area
unsigned int m_Area
Definition: grmGraph.h:40
grmDataStructures.h
grm::BaseNode::m_Contour
lp::Contour m_Contour
Definition: grmGraph.h:55
grm::Node::CRPTNeighborType
NeighborType< DerivedNode > CRPTNeighborType
Definition: grmGraph.h:85
lp::BoundingBox
Definition: lpContour.h:47
grm::Node
Definition: grmGraph.h:83
grm::Graph::NodeListType
std::vector< NodePointerType > NodeListType
Definition: grmGraph.h:95
grm::Graph::EdgeListType
std::vector< EdgeType > EdgeListType
Definition: grmGraph.h:98
lp::Contour
boost::dynamic_bitset<> Contour
Definition: lpContour.h:37
grm::BaseNode::m_Bbox
lp::BoundingBox m_Bbox
Definition: grmGraph.h:52
grm::Graph
Definition: grmGraph.h:90
grm::Graph::m_Nodes
std::vector< NodePointerType > m_Nodes
Definition: grmGraph.h:102
grm::NeighborType::m_CostUpdated
bool m_CostUpdated
Definition: grmGraph.h:67
grm::Graph::NodeType
TNode NodeType
Definition: grmGraph.h:92
grm::NeighborType
Definition: grmGraph.h:59
grm::Graph::NodeIteratorType
NodeListType::iterator NodeIteratorType
Definition: grmGraph.h:96
lpContour.h
grm::NeighborType::NeighborType
NeighborType(WeakDerived ptr, double w, unsigned int c)
Definition: grmGraph.h:69
grm::Graph::NodePointerType
std::shared_ptr< NodeType > NodePointerType
Definition: grmGraph.h:93
grm::NeighborType::GetRegion
SharedDerived GetRegion()
Definition: grmGraph.h:72
grm::Node::m_Edges
std::vector< CRPTNeighborType > m_Edges
Definition: grmGraph.h:86