Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

ArrayGraph.h
Go to the documentation of this file.
1 
32 #pragma once
33 
36 
37 namespace ogdf {
38 namespace fast_multipole_embedder {
39 
41 {
42 public:
44  ArrayGraph();
45 
47  ArrayGraph(uint32_t maxNumNodes, uint32_t maxNumEdges);
48 
50  ArrayGraph(const GraphAttributes& GA, const EdgeArray<float>& edgeLength, const NodeArray<float>& nodeSize);
51 
53  ~ArrayGraph();
54 
56  inline uint32_t numNodes() const { return m_numNodes; }
57 
59  inline uint32_t numEdges() const { return m_numEdges; }
60 
62 
68  void readFrom(const GraphAttributes& GA, const EdgeArray<float>& edgeLength, const NodeArray<float>& nodeSize);
69 
71 
82  template<typename CoordinateType, typename LengthType, typename SizeType>
83  void readFrom(const Graph& G, NodeArray<CoordinateType>& xPos, NodeArray<CoordinateType>& yPos, const EdgeArray<LengthType>& edgeLength, const NodeArray<SizeType>& nodeSize)
84  {
85  m_numNodes = 0;
86  m_numEdges = 0;
87  NodeArray<uint32_t> nodeIndex(G);
88  m_numNodes = 0;
89  m_numEdges = 0;
91  m_avgNodeSize = 0;
92  for(node v : G.nodes)
93  {
94  m_nodeXPos[m_numNodes] = (float)xPos[v];
95  m_nodeYPos[m_numNodes] = (float)yPos[v];
96  m_nodeSize[m_numNodes] = (float)nodeSize[v];
97  m_avgNodeSize += nodeSize[v];
98  nodeIndex[v] = m_numNodes;
99  m_numNodes++;
100  }
102 
103  for(edge e : G.edges)
104  {
105  pushBackEdge(nodeIndex[e->source()], nodeIndex[e->target()], (float)edgeLength[e]);
106  }
108  }
109 
111 
116  void writeTo(GraphAttributes& GA);
117 
119 
128  template<typename CoordinateType>
130  {
131  uint32_t i = 0;
132  for(node v : G.nodes)
133  {
134  xPos[v] = m_nodeXPos[i];
135  yPos[v] = m_nodeYPos[i];
136  i++;
137  }
138  }
139 
141  inline NodeAdjInfo& nodeInfo(uint32_t i) { return m_nodeAdj[i]; }
142 
144  inline const NodeAdjInfo& nodeInfo(uint32_t i) const { return m_nodeAdj[i]; }
145 
147  inline EdgeAdjInfo& edgeInfo(uint32_t i) { return m_edgeAdj[i]; }
148 
150  inline const EdgeAdjInfo& edgeInfo(uint32_t i) const { return m_edgeAdj[i]; }
151 
153  inline NodeAdjInfo* nodeInfo() { return m_nodeAdj; }
154 
156  inline const NodeAdjInfo* nodeInfo() const { return m_nodeAdj; }
157 
159  inline EdgeAdjInfo* edgeInfo() { return m_edgeAdj; }
160 
162  inline const EdgeAdjInfo* edgeInfo() const { return m_edgeAdj; }
163 
165  inline float* nodeXPos() { return m_nodeXPos; }
166 
168  inline const float* nodeXPos() const { return m_nodeXPos; }
169 
171  inline float* nodeYPos() { return m_nodeYPos; }
172 
174  inline const float* nodeYPos() const { return m_nodeYPos; }
175 
177  inline float* nodeSize() { return m_nodeSize; }
178 
180  inline const float* nodeSize() const { return m_nodeSize; }
181 
183  inline float* nodeMoveRadius() { return m_nodeMoveRadius; }
184 
186  inline float* desiredEdgeLength() { return m_desiredEdgeLength; }
187 
189  inline const float* desiredEdgeLength() const { return m_desiredEdgeLength; }
190 
192  inline uint32_t firstEdgeAdjIndex(uint32_t nodeIndex) const
193  {
194  return nodeInfo(nodeIndex).firstEntry;
195  };
196 
198  inline uint32_t nextEdgeAdjIndex(uint32_t currEdgeAdjIndex, uint32_t nodeIndex) const
199  {
200  return edgeInfo(currEdgeAdjIndex).nextEdgeAdjIndex(nodeIndex);
201  }
202 
204  inline uint32_t twinNodeIndex(uint32_t currEdgeAdjIndex, uint32_t nodeIndex) const
205  {
206  return edgeInfo(currEdgeAdjIndex).twinNode(nodeIndex);
207  }
208 
210  void for_all_nodes(uint32_t begin, uint32_t end, std::function<void(uint32_t)> func)
211  {
212  for(uint32_t i=begin; i <=end; i++)
213  func(i);
214  }
215 
217  inline float avgDesiredEdgeLength() const { return (float)m_desiredAvgEdgeLength; }
218 
220  inline float avgNodeSize() const { return (float)m_avgNodeSize; }
221 
223  void transform(float translate, float scale);
224 
226  void centerGraph();
227 
228 private:
229 
231  void pushBackEdge(uint32_t a, uint32_t b, float desiredEdgeLength);
232 
234  void allocate(uint32_t numNodes, uint32_t numEdges);
235 
237  void deallocate();
238 
240  void clear()
241  {
242  for (uint32_t i=0; i < m_numNodes; i++)
243  nodeInfo(i).degree = 0;
244 
245  m_numNodes = 0;
246  m_numEdges = 0;
247  }
248 
249  uint32_t m_numNodes;
250  uint32_t m_numEdges;
251 
252  float* m_nodeXPos;
253  float* m_nodeYPos;
254 
255  float* m_nodeSize;
256  double m_avgNodeSize;
257 
259 
262 
265 };
266 
267 }
268 }
node target() const
Returns the target node of the edge.
Definition: Graph_d.h:328
float * m_nodeMoveRadius
Maximum node movement lengths.
Definition: ArrayGraph.h:258
uint32_t numEdges() const
Returns the number of edges.
Definition: ArrayGraph.h:59
Declaration of class GraphAttributes which extends a Graph by additional attributes.
float * desiredEdgeLength()
Returns the edge length array for all edges.
Definition: ArrayGraph.h:186
uint32_t twinNodeIndex(uint32_t currEdgeAdjIndex, uint32_t nodeIndex) const
Returns the other node (not nodeIndex) of the pair with index currEdgeAdjIndex.
Definition: ArrayGraph.h:204
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:492
EdgeAdjInfo * m_edgeAdj
Information about adjacent nodes.
Definition: ArrayGraph.h:264
uint32_t firstEdgeAdjIndex(uint32_t nodeIndex) const
Returns the index of the first pair of the node with index nodeIndex in m_nodeAdj.
Definition: ArrayGraph.h:192
void transform(float translate, float scale)
Transforms all positions via shifting them by translate and afterwards scaling by scale...
~ArrayGraph()
Destructor. Deallocates the memory via OGDF_FREE_16 if needed.
Information about incident edges (16 bytes).
Definition: EdgeChain.h:42
uint32_t twinNode(uint32_t index) const
Returns the other node (not index).
Definition: EdgeChain.h:59
NodeAdjInfo * m_nodeAdj
Information about adjacent edges.
Definition: ArrayGraph.h:263
void deallocate()
Deallocate all arrays.
NodeAdjInfo * nodeInfo()
Returns the NodeAdjInfo array for all nodes.
Definition: ArrayGraph.h:153
const float * nodeYPos() const
Returns the y coord array for all nodes.
Definition: ArrayGraph.h:174
uint32_t firstEntry
The first pair in the edges chain.
Definition: EdgeChain.h:45
EdgeAdjInfo * edgeInfo()
Returns the EdgeAdjInfo array for all edges.
Definition: ArrayGraph.h:159
ArrayGraph()
Constructor. Does not allocate memory for the members.
const NodeAdjInfo * nodeInfo() const
Returns the NodeAdjInfo array for all nodes.
Definition: ArrayGraph.h:156
void writeTo(GraphAttributes &GA)
Store the data back in GraphAttributes.
float * m_nodeYPos
The y coordinates.
Definition: ArrayGraph.h:253
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition: Graph_d.h:568
float * m_nodeSize
Sizes of the nodes.
Definition: ArrayGraph.h:255
NodeAdjInfo & nodeInfo(uint32_t i)
Returns the adjacency information for the node at index i in m_nodeAdj.
Definition: ArrayGraph.h:141
float * nodeXPos()
Returns the x coord array for all nodes.
Definition: ArrayGraph.h:165
void readFrom(const GraphAttributes &GA, const EdgeArray< float > &edgeLength, const NodeArray< float > &nodeSize)
Updates an ArrayGraph from GraphAttributes with the given edge lengths and node sizes and creates the...
Information about an edge (16 bytes).
Definition: EdgeChain.h:51
uint32_t m_numNodes
Number of nodes in the graph.
Definition: ArrayGraph.h:249
uint32_t numNodes() const
Returns the number of nodes.
Definition: ArrayGraph.h:56
Stores additional attributes of a graph (like layout information).
const float * desiredEdgeLength() const
Returns the edge length array for all edges.
Definition: ArrayGraph.h:189
const float * nodeXPos() const
Returns the x coord array for all nodes.
Definition: ArrayGraph.h:168
void writeTo(const Graph &G, NodeArray< CoordinateType > &xPos, NodeArray< CoordinateType > &yPos)
Store the data back to NodeArray arrays with the given coordinate type.
Definition: ArrayGraph.h:129
const EdgeAdjInfo * edgeInfo() const
Returns the EdgeAdjInfo array for all edges.
Definition: ArrayGraph.h:162
uint32_t degree
Total count of pairs where is either the first or second node.
Definition: EdgeChain.h:44
float avgNodeSize() const
Average node size.
Definition: ArrayGraph.h:220
Datastructures for edge chains itself and the edge chains of nodes.
Class for the representation of edges.
Definition: Graph_d.h:292
const NodeAdjInfo & nodeInfo(uint32_t i) const
Returns the adjacency information for the node at index i in m_nodeAdj.
Definition: ArrayGraph.h:144
void allocate(uint32_t numNodes, uint32_t numEdges)
Allocate all arrays.
float * nodeSize()
Returns the node size array for all nodes.
Definition: ArrayGraph.h:177
const float * nodeSize() const
Returns the node size array for all nodes.
Definition: ArrayGraph.h:180
Class for the representation of nodes.
Definition: Graph_d.h:169
EdgeAdjInfo & edgeInfo(uint32_t i)
Returns the adjacency information for the edge at index i in m_edgeAdj.
Definition: ArrayGraph.h:147
float * m_nodeXPos
The x coordinates.
Definition: ArrayGraph.h:252
uint32_t m_numEdges
Number of edges in the graph.
Definition: ArrayGraph.h:250
uint32_t nextEdgeAdjIndex(uint32_t index) const
Returns the index of the next pair of index.
Definition: EdgeChain.h:65
void centerGraph()
Transforming all positions such that the new center is at (0,0).
float * m_desiredEdgeLength
Edge lengths.
Definition: ArrayGraph.h:260
void pushBackEdge(uint32_t a, uint32_t b, float desiredEdgeLength)
Internal function used by readFrom.
node source() const
Returns the source node of the edge.
Definition: Graph_d.h:326
The namespace for all OGDF objects.
void for_all_nodes(uint32_t begin, uint32_t end, std::function< void(uint32_t)> func)
Calls func on all nodes with indices from begin to end.
Definition: ArrayGraph.h:210
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition: Graph_d.h:565
void readFrom(const Graph &G, NodeArray< CoordinateType > &xPos, NodeArray< CoordinateType > &yPos, const EdgeArray< LengthType > &edgeLength, const NodeArray< SizeType > &nodeSize)
Updates an ArrayGraph with the given positions, edge lengths and node sizes and creates the edges...
Definition: ArrayGraph.h:83
float * nodeYPos()
Returns the y coord array for all nodes.
Definition: ArrayGraph.h:171
float * nodeMoveRadius()
Returns the node movement radius array for all nodes.
Definition: ArrayGraph.h:183
uint32_t nextEdgeAdjIndex(uint32_t currEdgeAdjIndex, uint32_t nodeIndex) const
Returns the index of the next pair of currEdgeAdjIndex of the node with index nodeIndex.
Definition: ArrayGraph.h:198
float avgDesiredEdgeLength() const
Average edge length.
Definition: ArrayGraph.h:217
const EdgeAdjInfo & edgeInfo(uint32_t i) const
Returns the adjacency information for the edge at index i in m_edgeAdj.
Definition: ArrayGraph.h:150