|
Open Graph Drawing Framework |
v. 2023.09 (Elderberry)
|
|
|
Go to the documentation of this file.
36 namespace energybased {
40 template<
typename IntType,
int Dim>
106 void setPoint(
int i,
int d, IntType value);
166 template<
typename IntType,
int Dim>
169 m_points =
new Point[m_numPoints];
171 m_nodes =
new Node[m_numPoints * 2];
175 template<
typename IntType,
int Dim>
178 delete[] m_mortonOrder;
182 template<
typename IntType,
int Dim>
185 m_points[i].x[d] = value;
189 template<
typename IntType,
int Dim>
192 for (
int i = 0; i < m_numPoints; i++) {
194 m_mortonOrder[i].ref = i;
197 interleaveBits<IntType, Dim>(m_points[i].x, m_mortonOrder[i].mortonNr);
202 template<
typename IntType,
int Dim>
205 std::sort(m_mortonOrder, m_mortonOrder + m_numPoints);
209 template<
typename IntType,
int Dim>
211 Node* leafLayer = m_nodes;
212 Node* innerLayer = m_nodes + m_numPoints;
217 for (
int i = 0; i < m_numPoints;) {
218 Node& leaf = leafLayer[i];
219 Node& innerNode = innerLayer[i];
224 while ((j < m_numPoints) && (m_mortonOrder[i] == m_mortonOrder[j])) {
237 if (j < m_numPoints) {
244 innerNode.
child[0] = i;
245 innerNode.
child[1] = j;
247 innerNode.
level = lowestCommonAncestorLevel<IntType, Dim>(m_mortonOrder[i].mortonNr,
248 m_mortonOrder[j].mortonNr);
249 innerNode.
next = m_numPoints + j;
252 innerLayer[i].
next = 0;
254 innerLayer[i].
level = m_maxLevel + 1;
262 innerLayer[last].
next = 0;
267 template<
typename IntType,
int Dim>
269 int next =
node(curr).next;
272 node(curr).child[
node(curr).numChilds++] =
node(next).child[1];
280 template<
typename IntType,
int Dim>
283 node(curr).firstPoint =
node(
node(curr).child[0]).firstPoint;
286 const int lastChild =
node(curr).child[
node(curr).numChilds - 1];
289 node(curr).numPoints =
290 node(lastChild).firstPoint +
node(lastChild).numPoints -
node(curr).firstPoint;
294 template<
typename IntType,
int Dim>
297 while (
node(curr).next &&
node(
node(curr).next).level < maxLevel) {
299 int next =
node(curr).next;
301 if (
node(curr).level ==
node(next).level) {
303 }
else if (
node(curr).level <
node(next).level) {
306 node(next).child[0] = curr;
309 adjustPointInfo(curr);
314 int r = linkNodes(next,
node(curr).level);
315 node(curr).child[
node(curr).numChilds - 1] =
r;
320 adjustPointInfo(curr);
327 template<
typename IntType,
int Dim>
329 m_rootIndex = linkNodes(m_numPoints, m_maxLevel);
333 template<
typename IntType,
int Dim>
335 if (m_nodes[curr].numChilds) {
337 for (
int i = 0; i < m_nodes[curr].numChilds; i++) {
338 sum += countPoints(m_nodes[curr].child[i]);
343 return m_nodes[curr].numPoints;
348 template<
typename IntType,
int Dim>
351 prepareMortonOrder();
The namespace for all OGDF objects.
void adjustPointInfo(int curr)
used to update the first and numPoints of inner nodes by linkNodes
int child(int i, int j) const
returns the index of the j th child of node i
void mergeWithNext(int curr)
Merges curr with next node in the chain (used by linkNodes)
int numPoints() const
returns the number of points the quadtree contains
The entry in the sorted order for a point.
IntType mortonNr[Dim]
the morton number of the point
bool operator==(const MortonEntry &other) const
equal comparer for the construction algorithm
void prepareMortonOrder()
Prepares the morton numbers for sorting.
int m_rootIndex
The index of the root node.
int m_numPoints
Total number of points.
int countPoints() const
Just for fun: traverse the tree and count the points in the leaves.
void build()
Does all required steps except the allocate, deallocate, randomPoints.
int numChilds
number of children
void setPoint(int i, int d, IntType value)
sets the point to the given grid coords
const Node & node(int i) const
Just to access the nodes a little bit easier.
void sort(T *array, int size, LessThan lt)
DTree(int numPoints)
constructor
int numPoints
the number of points covered by this subtree
int next
the next node on the same layer (leaf or inner node layer)
Node * m_nodes
Memory for all nodes.
The point class with integer coords.
int maxNumNodes() const
returns the maximum number of nodes (and the max index of a node)
int level
the level of the node in a complete quadtree
NodeElement * node
The type of nodes.
int firstPoint
the first point in the sorted order covered by this subtree
Point * m_points
The input set.
const Point & point(int i) const
returns the ith point in the input sequence
int ref
index in the original point order
bool operator<(const MortonEntry &other) const
less comparator for sort
void allocate(int n)
Allocates memory for n points.
void linkNodes()
The Recursive Bottom-Up Construction (recursion start)
void sortMortonNumbers()
Sorts the points by morton number.
int rootIndex() const
returns the index of the root node
int numPoints(int i) const
returns the number of points covered by this subtree
MortonEntry * m_mortonOrder
The order to be sorted.
int point(int i, int j) const
returns the index of the jth point covered by i's subtree.
int numChilds(int i) const
returns the number of children of node i
Implentation of the reduced quadtree for Dim dimensions.
static constexpr int MaxNumChildrenPerNode
the maximum number of children per node = 2^d
void deallocate()
Releases memory.
Node & node(int i)
Just to access the nodes a little bit easier.
int child[MaxNumChildrenPerNode]
index of the children
void prepareNodeLayer()
Prepares both the leaf and inner node layer.