Skip to content

Commit

Permalink
Reverse negation by sign
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonCampolattaro committed Aug 13, 2020
1 parent 60b79a4 commit cb4f2ae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
12 changes: 9 additions & 3 deletions Octree/include/CGAL/Octree/Node.h
Expand Up @@ -20,6 +20,7 @@
#include <memory>
#include <bitset>
#include <cassert>
#include <iostream>

namespace CGAL {
namespace Octree {
Expand Down Expand Up @@ -75,6 +76,8 @@ class Node {

/// @}

// TODO: There's probably a better name for this
// TODO: Should I use an enum class?
enum Child {
LEFT_BOTTOM_FRONT,
RIGHT_BOTTOM_FRONT,
Expand Down Expand Up @@ -378,17 +381,20 @@ class Node {
bool sign = direction[0];

// The first two bits indicate the dimension/axis (x, y, z)
uint8_t dimension = (direction >> 2).to_ulong();
uint8_t dimension = (direction >> 1).to_ulong();

// Create an offset so that the bit-significance lines up with the dimension (e.g. 1, 2, 4 --> 001, 010, 100)
int8_t offset = 1 << dimension;
int8_t offset = (uint8_t) 1 << dimension;
std::cout << (int)offset << std::endl;

// Finally, apply the sign to the offset
offset = (sign ? -offset : offset);
offset = (sign ? offset : -offset);

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

std::cout << index().to_ulong() << std::endl;

// This means the adjacent node is a direct sibling, the offset can be applied easily!
return &(*parent())[index().to_ulong() + offset];
}
Expand Down
15 changes: 9 additions & 6 deletions Octree/test/Octree/test_node_adjacent.cpp
Expand Up @@ -51,12 +51,15 @@ int main(void) {
assert(nullptr == octree.root().adjacent(5));

// Left Top Front node should have siblings to the Right, Down, and Back
auto &left_top_front = octree.root()[2];
assert(nullptr != left_top_front.adjacent(Node::Direction::RIGHT));
assert(nullptr != left_top_front.adjacent(Node::Direction::DOWN));
assert(nullptr != left_top_front.adjacent(Node::Direction::BACK));

std::cout << left_top_front;
auto &left_top_front = octree.root()[Node::LEFT_TOP_FRONT];
assert(nullptr != left_top_front.adjacent(Node::RIGHT));
assert(nullptr != left_top_front.adjacent(Node::DOWN));
std::cout << left_top_front << std::endl;
std::cout << *left_top_front.adjacent(Node::RIGHT) << std::endl;
assert(nullptr != left_top_front.adjacent(Node::BACK));
assert(nullptr == left_top_front.adjacent(Node::LEFT));
assert(nullptr == left_top_front.adjacent(Node::UP));
assert(nullptr == left_top_front.adjacent(Node::FRONT));

return 0;
}

0 comments on commit cb4f2ae

Please sign in to comment.