mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-06 12:28:34 -06:00
Add regular BFS to ChunkNodes
This commit is contained in:
@@ -106,6 +106,25 @@ void ChunkNode::depthFirst(const std::function<void(const ChunkNode&)>& f) const
|
||||
}
|
||||
}
|
||||
|
||||
void ChunkNode::breadthFirst(const std::function<void(const ChunkNode&)>& f) const {
|
||||
std::queue<const ChunkNode*> Q;
|
||||
|
||||
// Loop through nodes in breadths first order
|
||||
Q.push(this);
|
||||
while (Q.size() > 0) {
|
||||
const ChunkNode* node = Q.front();
|
||||
Q.pop();
|
||||
|
||||
f(*node);
|
||||
|
||||
// Add children to queue, if any
|
||||
if (!node->isLeaf()) {
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
Q.push(node->_children[i].get());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ChunkNode::reverseBreadthFirst(const std::function<void(const ChunkNode&)>& f) const {
|
||||
std::stack<const ChunkNode*> S;
|
||||
@@ -126,10 +145,9 @@ void ChunkNode::reverseBreadthFirst(const std::function<void(const ChunkNode&)>&
|
||||
Q.push(node->_children[i].get());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Loop through all nodes in stack, this this will be reversed breadth first
|
||||
// Loop through all nodes in stack, this will be reversed breadth first
|
||||
while (S.size() > 0) {
|
||||
f(*S.top());
|
||||
S.pop();
|
||||
|
||||
@@ -63,6 +63,7 @@ public:
|
||||
bool isLeaf() const;
|
||||
|
||||
void depthFirst(const std::function<void(const ChunkNode&)>& f) const;
|
||||
void breadthFirst(const std::function<void(const ChunkNode&)>& f) const;
|
||||
void reverseBreadthFirst(const std::function<void(const ChunkNode&)>& f) const;
|
||||
|
||||
const ChunkNode& getChild(Quad quad) const;
|
||||
|
||||
Reference in New Issue
Block a user