Skip to content

Commit

Permalink
Add sequential refinement method
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonCampolattaro committed Jun 20, 2020
1 parent 40ac8d9 commit 72aa220
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Octree/benchmark/Octree/bench.cpp
Expand Up @@ -40,7 +40,7 @@ std::chrono::duration<double> benchmark(Point_set points) {
auto start = std::chrono::high_resolution_clock::now();

Octree octree(points, point_map);
octree.refine(MAX_DEPTH, BUCKET_SIZE);
octree._refine(MAX_DEPTH, BUCKET_SIZE);

auto end = std::chrono::high_resolution_clock::now();

Expand Down
17 changes: 17 additions & 0 deletions Octree/benchmark/Octree/results/2020-06-19~2.txt
@@ -0,0 +1,17 @@
Fri Jun 19 21:08:01 2020

Benchmark Configuration
~~~~~~~~~~~~~~~~~~~~~~~
Bucket Size: 20
Max Depth: 10
Dataset Source: ../data/archer_statue_scan.ply
Point Count: 380306
Number of Runs: 40

Results
~~~~~~~~~~~~~~~~~~~~~~~
Tree construction time: 13096 us

Notes
~~~~~~~~~~~~~~~~~~~~~~~
Switch to sequential refinement method.
45 changes: 40 additions & 5 deletions Octree/include/CGAL/Octree.h
Expand Up @@ -22,13 +22,9 @@
#ifndef CGAL_OCTREE_3_H
#define CGAL_OCTREE_3_H

/*
* Not present or relevant for benchmarking
*/
//#include <CGAL/license/Implicit_surface_reconstruction_3.h>

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

#include <CGAL/bounding_box.h>
#include <boost/iterator/transform_iterator.hpp>
Expand All @@ -47,6 +43,7 @@
#include <boost/bind.hpp>
#include <iostream>
#include <fstream>
#include <ostream>

#include <stack>
#include <queue>
Expand Down Expand Up @@ -132,6 +129,42 @@ namespace CGAL {
m_root.unsplit();
}

void _refine(size_t max_depth, size_t max_pts_num) {

// create a side length map
for (int i = 0; i <= (int) 10; i++)
m_side_per_depth.push_back(m_bbox_side / (FT) (1 << i));

// Initialize a queue of nodes that need to be refined
std::queue<Node*> todo;
todo.push(&m_root);

// Process items in the queue until it's consumed fully
while (!todo.empty()) {

// Get the next element
auto current = todo.front();
todo.pop();
int depth = current->depth();

// Check if this node needs to be processed
if (current->num_points() > max_pts_num && current->depth() < max_depth) {

// Split this node
current->split();

// Redistribute its points
reassign_points((*current));

// Process each of its children
for (int i = 0; i < 8; ++i)
todo.push(&(*current)[i]);

}
}

}

void refine(size_t max_depth, size_t max_pts_num) {

// Make sure arguments are valid
Expand All @@ -147,6 +180,7 @@ namespace CGAL {

for (int i = 0; i <= (int) m_max_depth_reached; i++)
m_unit_per_depth.push_back(1 << (m_max_depth_reached - i));

}

Node &root() { return m_root; }
Expand All @@ -165,6 +199,7 @@ namespace CGAL {

// If all else is equal, recursively compare the trees themselves
return rhs.m_root == m_root;

}


Expand Down
14 changes: 8 additions & 6 deletions Octree/include/CGAL/Octree/Criterion.h
Expand Up @@ -2,25 +2,27 @@
#ifndef OCTREE_CRITERION_H
#define OCTREE_CRITERION_H

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

/*
typedef Octree_node<Kernel, PointRange> Node;

// Possible criterions
template <class Node>
struct Stop_at_max_depth {

std::size_t max_depth;

Stop_at_max_depth(const std::size_t &max_depth) : max_depth(max_depth) {}
Stop_at_max_depth(std::size_t max_depth) : max_depth(max_depth) {}

bool operator()(const Node &n) const {
return n.depth() == max_depth; // not sure you can know that from node only,
bool operator()(Node n) const {
return n->depth() == max_depth; // not sure you can know that from node only,
// otherwise your criterion could also take a
// reference to the full octree as parameter
}
};

/*
struct Stop_at_max_number_of_points {
std::size_t max_nb_points;
Expand Down
2 changes: 1 addition & 1 deletion Octree/test/Octree/octree_test.cpp
Expand Up @@ -39,7 +39,7 @@ int main(void) {
auto point_map = points.point_map();

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

std::cout << octree.root();

Expand Down

0 comments on commit 72aa220

Please sign in to comment.