diff --git a/Octree/include/CGAL/Octree.h b/Octree/include/CGAL/Octree.h index 64f186c06ef..cd3d26b4dd7 100644 --- a/Octree/include/CGAL/Octree.h +++ b/Octree/include/CGAL/Octree.h @@ -23,8 +23,7 @@ #define CGAL_OCTREE_3_H #include -#include -#include +#include #include #include @@ -129,7 +128,7 @@ namespace CGAL { m_root.unsplit(); } - void refine(std::function stop_criterion) { + void refine(std::function stop_criterion) { // create a side length map for (int i = 0; i <= (int) 10; i++) @@ -164,47 +163,8 @@ namespace CGAL { } } - void refine(size_t max_depth, size_t max_pts_num) { - - refine([&](Node *n) -> bool { - return (n->num_points() <= max_pts_num || n->depth() == max_depth); - }); - - /* - - // 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 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 bucket_size) { + refine(Stop_at_max_depth_or_bucket_size(max_depth, bucket_size)); } Node &root() { return m_root; } @@ -223,7 +183,6 @@ namespace CGAL { // If all else is equal, recursively compare the trees themselves return rhs.m_root == m_root; - } diff --git a/Octree/include/CGAL/Octree/Criterion.h b/Octree/include/CGAL/Octree/Criterion.h deleted file mode 100644 index 2f6b84d5240..00000000000 --- a/Octree/include/CGAL/Octree/Criterion.h +++ /dev/null @@ -1,64 +0,0 @@ - -#ifndef OCTREE_CRITERION_H -#define OCTREE_CRITERION_H - -#include -#include - - -// Possible criterions -template -struct Stop_at_max_depth { - - std::size_t max_depth; - - Stop_at_max_depth(std::size_t max_depth) : max_depth(max_depth) {} - - 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; - - Stop_at_max_number_of_points(const std::size_t &max_nb_points) - : max_nb_points(max_nb_points) {} - - bool operator()(const Node &n) const { - return n.number_of_points() // internally, the node can use std::distance(begin, end) - < max_nb_points; - } -}; - -// Just for an example using outside info (like a normal map) -// The normals remain unknown to the octree but are used for construction -struct Stop_at_normal_deviation { - Normal_map normal_map; - FT max_dev; - - Stop_at_normal_deviation(Normal_map normal_map, - FT max_dev) - : normal_map(normal_map), max_dev(max_dev) {} - - bool operator()(const Node &n) const { - FT dev = 0; - - for (Iterator it = n.begin(); it != n.end(); ++it) - dev += compute_deviation(get(normal_map, *it)); // whatever compute_deviation is :) - - // if your node defines begin() and end(), you can also use a C++11 loop: - // for (const Range_type& r : n) - // dev += compute_deviation(get (normal_map, r)); - - return dev < max_dev; - } -}; - -*/ - -#endif //OCTREE_CRITERION_H diff --git a/Octree/include/CGAL/Octree/Stop_criterion.h b/Octree/include/CGAL/Octree/Stop_criterion.h new file mode 100644 index 00000000000..42410e41bfe --- /dev/null +++ b/Octree/include/CGAL/Octree/Stop_criterion.h @@ -0,0 +1,74 @@ + +#ifndef OCTREE_STOP_CRITERION_H +#define OCTREE_STOP_CRITERION_H + +namespace CGAL { + + struct Stop_at_max_depth_or_bucket_size { + + std::size_t m_max_depth, m_bucket_size; + + Stop_at_max_depth_or_bucket_size(std::size_t max_depth, std::size_t bucket_size) : + m_max_depth(max_depth), m_bucket_size(bucket_size) {} + + template + bool operator()(Node n) const { + return (n->num_points() <= m_bucket_size || n->depth() == m_max_depth); + } + }; + + struct Stop_at_max_depth { + + std::size_t m_max_depth; + + Stop_at_max_depth(std::size_t max_depth) : m_max_depth(max_depth) {} + + template + bool operator()(Node n) const { + return n->depth() == m_max_depth; + } + }; + +} + +/* + +struct Stop_at_max_number_of_points { + std::size_t max_nb_points; + + Stop_at_max_number_of_points(const std::size_t &max_nb_points) + : max_nb_points(max_nb_points) {} + + bool operator()(const Node &n) const { + return n.number_of_points() // internally, the node can use std::distance(begin, end) + < max_nb_points; + } +}; + +// Just for an example using outside info (like a normal map) +// The normals remain unknown to the octree but are used for construction +struct Stop_at_normal_deviation { + Normal_map normal_map; + FT max_dev; + + Stop_at_normal_deviation(Normal_map normal_map, + FT max_dev) + : normal_map(normal_map), max_dev(max_dev) {} + + bool operator()(const Node &n) const { + FT dev = 0; + + for (Iterator it = n.begin(); it != n.end(); ++it) + dev += compute_deviation(get(normal_map, *it)); // whatever compute_deviation is :) + + // if your node defines begin() and end(), you can also use a C++11 loop: + // for (const Range_type& r : n) + // dev += compute_deviation(get (normal_map, r)); + + return dev < max_dev; + } +}; + +*/ + +#endif //OCTREE_STOP_CRITERION_H