All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
TiledGraphCell.h
1 #pragma once
2 
3 #include "Graphs.h"
4 #include "Types.h"
5 #include "MortonKey.h"
6 #include "VectorMath.h"
7 #include "TiledGraphNode.h"
8 #include "TiledGraphEdge.h"
9 
10 #include <vector>
11 
12 
13 #define EEGEO_GRAPHS_TILED_GRAPH_VALIDATION 0
14 
15 namespace Eegeo
16 {
17  namespace Graphs
18  {
20  {
21  public:
22  static TiledGraphCell* CreateEmpty(
23  const Eegeo::Streaming::MortonKey& key,
24  const dv3& originEcef
25  );
26 
27  static TiledGraphCell* Create(
28  const Eegeo::Streaming::MortonKey& key,
29  const dv3& originEcef,
30  const std::vector<TiledGraphNode>& nodes,
31  const std::vector<TiledGraphEdge>& edges,
32  const std::vector<int>& incidentEdges,
33  const std::vector<int>& edgesWithExternalNodesForward,
34  const std::vector<int>& edgesWithExternalNodesReversed
35  );
36 
37  const Eegeo::Streaming::MortonKey& GetKey() const { return m_key; }
38  const dv3& GetOriginEcef() const { return m_originEcef; }
39 
40  bool ContainsNode(const TiledGraphNodeId& nodeId) const;
41  bool ContainsEdge(const TiledGraphEdgeId& edgeId) const;
42 
43  const TiledGraphNode& GetNode(const TiledGraphNodeId& nodeId) const;
44  const TiledGraphEdge& GetEdge(const TiledGraphEdgeId& edgeId) const;
45  const std::vector<int>& GetIncidentEdges() const;
46 
47  TiledGraphNodeId BuildNodeId(int localIndex) const;
48  TiledGraphEdgeId BuildEdgeId(int localIndex) const;
49 
50  dv3 GetNodePoint(const TiledGraphNodeId& nodeId) const;
51 
52  void GetIncidentEdgeIds(const TiledGraphNodeId& nodeId, std::vector<TiledGraphEdgeId>& out_incidentEdgeIds) const;
53 
54  bool FindEdgeId(const TiledGraphNodeId& nodeIdA, const TiledGraphNodeId& nodeIdB, TiledGraphEdgeId& out_edgeId) const;
55 
56  bool FindEdgeWithAttributes(const int attributesId, const bool attributesDirectionReversed, TiledGraphEdgeId& out_edgeId) const;
57 
58  bool FindExternalEdgeWithAttributes(const int attributesId, const bool attributesDirectionReversed, TiledGraphEdgeId& out_edgeId) const;
59 
60  void GetEdgeIdsToLink(std::vector<TiledGraphEdgeId>& out_edgeIds) const;
61 
62  void GetCellKeysToUnlink(std::vector<Streaming::MortonKey>& out_keys) const;
63 
64  bool ValidateAllUnlinked(const Streaming::MortonKey& cellKey) const;
65 
66  bool ValidateExternalNodesExist() const;
67 
68  bool ValidateAllExternalNodesUnlinked() const;
69 
70  const std::vector<TiledGraphNode>& GetNodes() const { return m_nodes; }
71 
72  const std::vector<TiledGraphEdge>& GetEdges() const { return m_edges; }
73 
74  const TiledGraph* GetGraphOrNull() const { return m_pTiledGraph; }
75 
76 
77  // mutable
78  void Link(const TiledGraph& tiledGraph);
79 
80  void Unlink(const TiledGraph& tiledGraph);
81 
82  void LinkEdge(const TiledGraphEdgeId& edgeId, const TiledGraphNodeId& externalNodeId);
83 
84  void UnlinkFromCellWithKey(const Streaming::MortonKey& key);
85 
86  private:
88  const Eegeo::Streaming::MortonKey& key,
89  const dv3& originEcef);
90 
92  const Eegeo::Streaming::MortonKey& key,
93  const dv3& originEcef,
94  const std::vector<TiledGraphNode>& nodes,
95  const std::vector<TiledGraphEdge>& edges,
96  const std::vector<int>& incidentEdges,
97  const std::vector<int>& edgesWithExternalNodesForward,
98  const std::vector<int>& edgesWithExternalNodesReversed
99  );
100 
101  void AppendEdgeIdsToLink(const std::vector<int>& edgesWithExternalNodes, std::vector<TiledGraphEdgeId>& out_edgeIds) const;
102 
103  void AppendKeysToUnlink(const std::vector<int>& edgesWithExternalNodes, std::vector<Streaming::MortonKey>& out_keys) const;
104 
105  void UnlinkEdgeNodesWithKey(TiledGraphEdge& edge, const Streaming::MortonKey& key);
106 
107  void UnlinkExternalEdgeNode(TiledGraphEdge& edge);
108 
109  void UnlinkExternalEdgeNodes();
110 
111  bool ValidateNodeIsInternalOrUnlinked(const TiledGraphNodeId& nodeId) const;
112 
113  const TiledGraph* m_pTiledGraph;
115  dv3 m_originEcef;
116  std::vector<TiledGraphNode> m_nodes;
117  std::vector<TiledGraphEdge> m_edges;
118  std::vector<int> m_incidentEdges;
119  std::vector<int> m_edgesWithExternalNodesForward;
120  std::vector<int> m_edgesWithExternalNodesReversed;
121  };
122 
124  {
126  const std::vector<TiledGraphEdge>& edges
127  )
128  : m_edges(edges)
129  {}
130 
131  bool operator() (const int edgeIndexA, const int edgeIndexB) const
132  {
133  const auto& edgeA = m_edges.at(edgeIndexA);
134  const auto& edgeB = m_edges.at(edgeIndexB);
135  return edgeA.AttributesId < edgeB.AttributesId;
136  }
137 
138  private:
139  const std::vector<TiledGraphEdge>& m_edges;
140  };
141 
143  {
145  const std::vector<TiledGraphEdge>& edges
146  )
147  : m_edges(edges)
148  {}
149 
150  bool operator() (const int edgeIndexA, const int edgeIndexB) const
151  {
152  const auto& edgeA = m_edges.at(edgeIndexA);
153  const auto& edgeB = m_edges.at(edgeIndexB);
154  return edgeA.AttributesId == edgeB.AttributesId;
155  }
156 
157  private:
158  const std::vector<TiledGraphEdge>& m_edges;
159  };
160  }
161 }