36namespace energybased {
40template<
typename IntType,
int Dim>
106 void setPoint(
int i,
int d, IntType value);
166template<
typename IntType,
int Dim>
169 m_points =
new Point[m_numPoints];
171 m_nodes =
new Node[m_numPoints * 2];
175template<
typename IntType,
int Dim>
178 delete[] m_mortonOrder;
182template<
typename IntType,
int Dim>
185 m_points[i].x[
d] = value;
189template<
typename IntType,
int Dim>
192 for (
int i = 0; i < m_numPoints; i++) {
194 m_mortonOrder[i].ref = i;
202template<
typename IntType,
int Dim>
205 std::sort(m_mortonOrder, m_mortonOrder + m_numPoints);
209template<
typename IntType,
int Dim>
217 for (
int i = 0; i < m_numPoints;) {
224 while ((
j < m_numPoints) && (m_mortonOrder[i] == m_mortonOrder[
j])) {
237 if (
j < m_numPoints) {
248 m_mortonOrder[
j].mortonNr);
267template<
typename IntType,
int Dim>
280template<
typename IntType,
int Dim>
294template<
typename IntType,
int Dim>
309 adjustPointInfo(
curr);
314 int r = linkNodes(next,
node(
curr).level);
320 adjustPointInfo(
curr);
327template<
typename IntType,
int Dim>
329 m_rootIndex = linkNodes(m_numPoints, m_maxLevel);
333template<
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;
348template<
typename IntType,
int Dim>
351 prepareMortonOrder();
Implentation of the reduced quadtree for Dim dimensions.
const Point & point(int i) const
returns the ith point in the input sequence
int point(int i, int j) const
returns the index of the jth point covered by i's subtree.
void sortMortonNumbers()
Sorts the points by morton number.
int m_rootIndex
The index of the root node.
int countPoints() const
Just for fun: traverse the tree and count the points in the leaves.
void adjustPointInfo(int curr)
used to update the first and numPoints of inner nodes by linkNodes
Point * m_points
The input set.
static constexpr int MaxNumChildrenPerNode
the maximum number of children per node = 2^d
void prepareNodeLayer()
Prepares both the leaf and inner node layer.
int maxNumNodes() const
returns the maximum number of nodes (and the max index of a node)
Node * m_nodes
Memory for all nodes.
void deallocate()
Releases memory.
void mergeWithNext(int curr)
Merges curr with next node in the chain (used by linkNodes)
int numChilds(int i) const
returns the number of children of node i
int numPoints() const
returns the number of points the quadtree contains
int numPoints(int i) const
returns the number of points covered by this subtree
int m_numPoints
Total number of points.
int child(int i, int j) const
returns the index of the j th child of node i
void allocate(int n)
Allocates memory for n points.
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.
DTree(int numPoints)
constructor
void prepareMortonOrder()
Prepares the morton numbers for sorting.
void build()
Does all required steps except the allocate, deallocate, randomPoints.
Node & node(int i)
Just to access the nodes a little bit easier.
MortonEntry * m_mortonOrder
The order to be sorted.
void linkNodes()
The Recursive Bottom-Up Construction (recursion start)
int rootIndex() const
returns the index of the root node
NodeElement * node
The type of nodes.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
The entry in the sorted order for a point.
int ref
index in the original point order
IntType mortonNr[Dim]
the morton number of the point
bool operator<(const MortonEntry &other) const
less comparator for sort
bool operator==(const MortonEntry &other) const
equal comparer for the construction algorithm
int numChilds
number of children
int next
the next node on the same layer (leaf or inner node layer)
int firstPoint
the first point in the sorted order covered by this subtree
int child[MaxNumChildrenPerNode]
index of the children
int level
the level of the node in a complete quadtree
int numPoints
the number of points covered by this subtree
The point class with integer coords.