Skip to content

Commit

Permalink
Implement adjacent for direct siblings
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonCampolattaro committed Aug 13, 2020
1 parent adf6b74 commit a8daae7
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Octree/include/CGAL/Octree/Node.h
Expand Up @@ -336,11 +336,15 @@ class Node {
return !operator==(rhs);
}

Node<Point_index> *adjacent(std::bitset<3> direction) {
const Node<Point_index> *adjacent(std::bitset<3> direction) const {

// Nodes only have up to 6 different adjacent nodes (since cubes have 6 sides)
assert(direction.to_ulong() < 6);

// The root node has no adjacent nodes!
if (is_root())
return nullptr;

// Direction: LEFT RIGHT DOWN UP BACK FRONT
// direction: 000 001 010 011 100 101

Expand All @@ -356,8 +360,15 @@ class Node {
// Finally, apply the sign to the offset
offset = (sign ? -offset : offset);

// Check if this child has the opposite sign along the direction's axis
if ((index() >> dimension)[0] != sign) {

// This means the adjacent node is a direct sibling, the offset can be applied easily!
return &(*parent())[index().to_ulong() + offset];
}

// Determine if the adjacent node is a direct sibling (same parent)
//
return nullptr;
}

/// @}
Expand Down

0 comments on commit a8daae7

Please sign in to comment.