Skip to content

Commit

Permalink
Implement visual grade() test
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonCampolattaro committed Aug 12, 2020
1 parent 110885e commit b70181c
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 1 deletion.
22 changes: 22 additions & 0 deletions Octree/include/CGAL/Octree.h
Expand Up @@ -272,6 +272,28 @@ class Octree {
refine(Split_criterion::Max_depth_or_bucket_size(max_depth, bucket_size));
}

void grade() {
std::queue<Node *> leaf_nodes;
fill_leaf_queue(&m_root, leaf_nodes);

while (!leaf_nodes.empty()) {
Node *node = leaf_nodes.front();
leaf_nodes.pop();
if (!node->is_leaf()) continue;

std::list<Node *> neighbors_to_split = node->find_unbalanced_neighbors_to_split();
if (!neighbors_to_split.empty()) leaf_nodes.push(node);
for (Node *neighbor : neighbors_to_split) {
neighbor->split();
reassign_points(neighbor);
for (int child_id = 0; child_id < 8; child_id++) {
Node *neighbor_child = neighbor->child(child_id);
leaf_nodes.push(neighbor_child);
}
}
}
}

/// @}

/// \name Accessors
Expand Down
104 changes: 103 additions & 1 deletion Octree/test/Octree/test_octree_grade.cpp
@@ -1 +1,103 @@
// TODO

#define CGAL_TRACE_STREAM std::cerr

#include <iostream>
#include <CGAL/Octree.h>
#include <CGAL/Octree/IO.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Point_set_3.h>

#include <cassert>

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

void test_1_point() {

// Define the dataset
Point_set points;
points.insert({-1, -1, -1});

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

std::cout << octree << std::endl;

std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << std::endl;
octree.grade();

std::cout << octree << std::endl;

std::cout << "\n\n\n" << std::endl;
}

void test_8_points() {

// Define the dataset
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});

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

std::cout << octree << std::endl;

std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << std::endl;
octree.grade();

std::cout << octree << std::endl;

std::cout << "\n\n\n" << std::endl;
}

void test_10_points() {

// Define the dataset
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({0.875, 1, -1});
points.insert({-1, -0.75, 1});

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

std::cout << octree << std::endl;

std::cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << std::endl;
octree.grade();

std::cout << octree << std::endl;

std::cout << "\n\n\n" << std::endl;
}

int main(void) {

test_1_point();
test_8_points();
test_10_points();

return EXIT_SUCCESS;
}

0 comments on commit b70181c

Please sign in to comment.