Skip to content

Commit

Permalink
Add method for an octree node to determine what its index is.
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonCampolattaro committed Jun 24, 2020
1 parent 2e1adcb commit dcfeb0a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Octree/include/CGAL/Octree/Octree_node.h
Expand Up @@ -143,6 +143,17 @@ namespace CGAL {

const uint8_t &depth() const { return m_depth; }

std::bitset<3> index() const {

std::bitset<3> result {};

result[0] = location()[0] & 1;
result[1] = location()[1] & 1;
result[2] = location()[2] & 1;

return result;
}

bool is_sibling(Node *neighbor) const {
return (m_parent == neighbor->parent());
}
Expand Down
3 changes: 2 additions & 1 deletion Octree/test/Octree/CMakeLists.txt
Expand Up @@ -7,5 +7,6 @@ project( Octree )
find_package(CGAL REQUIRED QUIET OPTIONAL_COMPONENTS Core )

create_single_source_cgal_program( "octree_test.cpp" )
create_single_source_cgal_program( "test_equality.cpp" )
create_single_source_cgal_program( "test_octree_equality.cpp" )
create_single_source_cgal_program( "test_node_index.cpp" )

46 changes: 46 additions & 0 deletions Octree/test/Octree/test_node_index.cpp
@@ -0,0 +1,46 @@
#define CGAL_TRACE_STREAM std::cerr

#include <CGAL/Octree.h>
#include <CGAL/Octree/IO.h>

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Point_set_3.h>

typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_3 Point;
typedef CGAL::Point_set_3<Point> Point_set;
typedef CGAL::Octree
<Point_set, typename Point_set::Point_map>
Octree;

int main(void) {

Point_set points;
points.insert({-1, -1, -1});
points.insert({1, -1, -1});
points.insert({-1, 1, -1});
points.insert({1, 1, -1});
points.insert({-1, -1, 1});
points.insert({1, -1, 1});
points.insert({-1, 1, 1});
points.insert({1, 1, 1});

points.insert({-1, -1, -1.1});
points.insert({-1, -1, -1.2});
points.insert({-1, -1, -1.3});
points.insert({-1, -1, -1.4});
points.insert({-1, -1, -1.5});
points.insert({-1, -1, -1.6});
points.insert({-1, -1, -1.7});
points.insert({-1, -1, -1.8});
points.insert({-1, -1, -1.9});

auto point_map = points.point_map();

Octree octree(points, point_map);
octree.refine(10, 1);

std::cout << octree.root()[4].index();

return 0;
}
File renamed without changes.

0 comments on commit dcfeb0a

Please sign in to comment.