Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
ArrayGraph.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Graph.h>
37
38#include <cstdint>
39#include <functional>
40
41namespace ogdf {
42class GraphAttributes;
43
44namespace fast_multipole_embedder {
45
47public:
50
52 ArrayGraph(uint32_t maxNumNodes, uint32_t maxNumEdges);
53
55 ArrayGraph(const GraphAttributes& GA, const EdgeArray<float>& edgeLength,
57
60
62 inline uint32_t numNodes() const { return m_numNodes; }
63
65 inline uint32_t numEdges() const { return m_numEdges; }
66
68
74 void readFrom(const GraphAttributes& GA, const EdgeArray<float>& edgeLength,
76
78
89 template<typename CoordinateType, typename LengthType, typename SizeType>
91 const EdgeArray<LengthType>& edgeLength, const NodeArray<SizeType>& nodeSize) {
92 m_numNodes = 0;
93 m_numEdges = 0;
94 NodeArray<uint32_t> nodeIndex(G);
95 m_numNodes = 0;
96 m_numEdges = 0;
98 m_avgNodeSize = 0;
99 for (node v : G.nodes) {
100 m_nodeXPos[m_numNodes] = (float)xPos[v];
101 m_nodeYPos[m_numNodes] = (float)yPos[v];
102 m_nodeSize[m_numNodes] = (float)nodeSize[v];
104 nodeIndex[v] = m_numNodes;
105 m_numNodes++;
106 }
108
109 for (edge e : G.edges) {
110 pushBackEdge(nodeIndex[e->source()], nodeIndex[e->target()], (float)edgeLength[e]);
111 }
113 }
114
116
122
124
133 template<typename CoordinateType>
135 uint32_t i = 0;
136 for (node v : G.nodes) {
137 xPos[v] = m_nodeXPos[i];
138 yPos[v] = m_nodeYPos[i];
139 i++;
140 }
141 }
142
144 inline NodeAdjInfo& nodeInfo(uint32_t i) { return m_nodeAdj[i]; }
145
147 inline const NodeAdjInfo& nodeInfo(uint32_t i) const { return m_nodeAdj[i]; }
148
150 inline EdgeAdjInfo& edgeInfo(uint32_t i) { return m_edgeAdj[i]; }
151
153 inline const EdgeAdjInfo& edgeInfo(uint32_t i) const { return m_edgeAdj[i]; }
154
156 inline NodeAdjInfo* nodeInfo() { return m_nodeAdj; }
157
159 inline const NodeAdjInfo* nodeInfo() const { return m_nodeAdj; }
160
162 inline EdgeAdjInfo* edgeInfo() { return m_edgeAdj; }
163
165 inline const EdgeAdjInfo* edgeInfo() const { return m_edgeAdj; }
166
168 inline float* nodeXPos() { return m_nodeXPos; }
169
171 inline const float* nodeXPos() const { return m_nodeXPos; }
172
174 inline float* nodeYPos() { return m_nodeYPos; }
175
177 inline const float* nodeYPos() const { return m_nodeYPos; }
178
180 inline float* nodeSize() { return m_nodeSize; }
181
183 inline const float* nodeSize() const { return m_nodeSize; }
184
186 inline float* nodeMoveRadius() { return m_nodeMoveRadius; }
187
189 inline float* desiredEdgeLength() { return m_desiredEdgeLength; }
190
192 inline const float* desiredEdgeLength() const { return m_desiredEdgeLength; }
193
195 inline uint32_t firstEdgeAdjIndex(uint32_t nodeIndex) const {
196 return nodeInfo(nodeIndex).firstEntry;
197 };
198
200 inline uint32_t nextEdgeAdjIndex(uint32_t currEdgeAdjIndex, uint32_t nodeIndex) const {
201 return edgeInfo(currEdgeAdjIndex).nextEdgeAdjIndex(nodeIndex);
202 }
203
205 inline uint32_t twinNodeIndex(uint32_t currEdgeAdjIndex, uint32_t nodeIndex) const {
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 for (uint32_t i = begin; i <= end; i++) {
212 func(i);
213 }
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
227
228private:
230 void pushBackEdge(uint32_t a, uint32_t b, float desiredEdgeLength);
231
233 void allocate(uint32_t numNodes, uint32_t numEdges);
234
237
239 void clear() {
240 for (uint32_t i = 0; i < m_numNodes; i++) {
241 nodeInfo(i).degree = 0;
242 }
243
244 m_numNodes = 0;
245 m_numEdges = 0;
246 }
247
248 uint32_t m_numNodes;
249 uint32_t m_numEdges;
250
251 float* m_nodeXPos;
252 float* m_nodeYPos;
253
254 float* m_nodeSize;
256
258
261
264};
265
266}
267}
Datastructures for edge chains itself and the edge chains of nodes.
Includes declaration of graph class.
Decralation of GraphElement and GraphList classes.
Class for the representation of edges.
Definition Graph_d.h:364
Stores additional attributes of a graph (like layout information).
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
Class for the representation of nodes.
Definition Graph_d.h:241
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:205
const float * nodeSize() const
Returns the node size array for all nodes.
Definition ArrayGraph.h:183
float * m_nodeYPos
The y coordinates.
Definition ArrayGraph.h:252
float * nodeMoveRadius()
Returns the node movement radius array for all nodes.
Definition ArrayGraph.h:186
float * nodeXPos()
Returns the x coord array for all nodes.
Definition ArrayGraph.h:168
uint32_t numEdges() const
Returns the number of edges.
Definition ArrayGraph.h:65
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:134
~ArrayGraph()
Destructor. Deallocates the memory via OGDF_FREE_16 if needed.
EdgeAdjInfo & edgeInfo(uint32_t i)
Returns the adjacency information for the edge at index i in m_edgeAdj.
Definition ArrayGraph.h:150
void transform(float translate, float scale)
Transforms all positions via shifting them by translate and afterwards scaling by scale.
float * nodeYPos()
Returns the y coord array for all nodes.
Definition ArrayGraph.h:174
void writeTo(GraphAttributes &GA)
Store the data back in GraphAttributes.
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
void allocate(uint32_t numNodes, uint32_t numEdges)
Allocate all arrays.
uint32_t m_numEdges
Number of edges in the graph.
Definition ArrayGraph.h:249
NodeAdjInfo * m_nodeAdj
Information about adjacent edges.
Definition ArrayGraph.h:262
ArrayGraph()
Constructor. Does not allocate memory for the members.
const float * desiredEdgeLength() const
Returns the edge length array for all edges.
Definition ArrayGraph.h:192
const float * nodeYPos() const
Returns the y coord array for all nodes.
Definition ArrayGraph.h:177
const float * nodeXPos() const
Returns the x coord array for all nodes.
Definition ArrayGraph.h:171
NodeAdjInfo & nodeInfo(uint32_t i)
Returns the adjacency information for the node at index i in m_nodeAdj.
Definition ArrayGraph.h:144
EdgeAdjInfo * edgeInfo()
Returns the EdgeAdjInfo array for all edges.
Definition ArrayGraph.h:162
float * nodeSize()
Returns the node size array for all nodes.
Definition ArrayGraph.h:180
const NodeAdjInfo * nodeInfo() const
Returns the NodeAdjInfo array for all nodes.
Definition ArrayGraph.h:159
void centerGraph()
Transforming all positions such that the new center is at (0,0).
NodeAdjInfo * nodeInfo()
Returns the NodeAdjInfo array for all nodes.
Definition ArrayGraph.h:156
uint32_t m_numNodes
Number of nodes in the graph.
Definition ArrayGraph.h:248
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...
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:90
const NodeAdjInfo & nodeInfo(uint32_t i) const
Returns the adjacency information for the node at index i in m_nodeAdj.
Definition ArrayGraph.h:147
uint32_t numNodes() const
Returns the number of nodes.
Definition ArrayGraph.h:62
const EdgeAdjInfo & edgeInfo(uint32_t i) const
Returns the adjacency information for the edge at index i in m_edgeAdj.
Definition ArrayGraph.h:153
ArrayGraph(const GraphAttributes &GA, const EdgeArray< float > &edgeLength, const NodeArray< float > &nodeSize)
Constructor.
float * desiredEdgeLength()
Returns the edge length array for all edges.
Definition ArrayGraph.h:189
float avgDesiredEdgeLength() const
Average edge length.
Definition ArrayGraph.h:217
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:200
float * m_nodeXPos
The x coordinates.
Definition ArrayGraph.h:251
float avgNodeSize() const
Average node size.
Definition ArrayGraph.h:220
void deallocate()
Deallocate all arrays.
const EdgeAdjInfo * edgeInfo() const
Returns the EdgeAdjInfo array for all edges.
Definition ArrayGraph.h:165
float * m_nodeMoveRadius
Maximum node movement lengths.
Definition ArrayGraph.h:257
void pushBackEdge(uint32_t a, uint32_t b, float desiredEdgeLength)
Internal function used by readFrom.
float * m_nodeSize
Sizes of the nodes.
Definition ArrayGraph.h:254
ArrayGraph(uint32_t maxNumNodes, uint32_t maxNumEdges)
Constructor. Allocates memory via OGDF_MALLOC_16.
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:195
EdgeAdjInfo * m_edgeAdj
Information about adjacent nodes.
Definition ArrayGraph.h:263
Information about an edge (16 bytes).
Definition EdgeChain.h:53
uint32_t nextEdgeAdjIndex(uint32_t index) const
Returns the index of the next pair of index.
Definition EdgeChain.h:67
uint32_t twinNode(uint32_t index) const
Returns the other node (not index).
Definition EdgeChain.h:61
Information about incident edges (16 bytes).
Definition EdgeChain.h:44
uint32_t firstEntry
The first pair in the edges chain.
Definition EdgeChain.h:47
uint32_t degree
Total count of pairs where is either the first or second node.
Definition EdgeChain.h:46
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
The namespace for all OGDF objects.
HypergraphRegistry< HypernodeElement >::iterator begin(const HypergraphRegistry< HypernodeElement > &self)
HypergraphRegistry< HypernodeElement >::iterator end(const HypergraphRegistry< HypernodeElement > &self)