Stop criterion now provided in Stop_criterion.h

This commit is contained in:
Jackson Campolattaro 2020-06-20 12:01:06 -04:00
parent 3425f7a216
commit a46b3068f0
3 changed files with 78 additions and 109 deletions

View File

@ -23,8 +23,7 @@
#define CGAL_OCTREE_3_H
#include <CGAL/Octree/Octree_node.h>
#include <CGAL/Octree/Criterion.h>
#include <CGAL/Octree/IO.h>
#include <CGAL/Octree/Stop_criterion.h>
#include <CGAL/bounding_box.h>
#include <boost/iterator/transform_iterator.hpp>
@ -129,7 +128,7 @@ namespace CGAL {
m_root.unsplit();
}
void refine(std::function<bool(Node *)> stop_criterion) {
void refine(std::function<bool(const Node *)> 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<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 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;
}

View File

@ -1,64 +0,0 @@
#ifndef OCTREE_CRITERION_H
#define OCTREE_CRITERION_H
#include <CGAL/Octree.h>
#include <CGAL/Octree/Octree_node.h>
// Possible criterions
template <class Node>
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

View File

@ -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<class Node>
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<class Node>
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