Merge pull request #4244 from maxGimeno/AABB_tree-Make_accelerate_distance_queries_default-maxGimeno

AABB_tree: make accelerate distance queries default
This commit is contained in:
Laurent Rineau 2019-12-05 11:05:35 +01:00
commit 0fa0c4fbb9
25 changed files with 28 additions and 39 deletions

View File

@ -806,7 +806,6 @@ void Scene::build_facet_tree()
timer.start();
std::cout << "Construct Facet AABB tree...";
m_facet_tree.rebuild(faces(*m_pPolyhedron).first, faces(*m_pPolyhedron).second,*m_pPolyhedron);
m_facet_tree.accelerate_distance_queries();
std::cout << "done (" << timer.time() << " s)" << std::endl;
}
@ -826,7 +825,6 @@ void Scene::build_edge_tree()
timer.start();
std::cout << "Construct Edge AABB tree...";
m_edge_tree.rebuild(edges(*m_pPolyhedron).first,edges(*m_pPolyhedron).second,*m_pPolyhedron);
m_edge_tree.accelerate_distance_queries();
std::cout << "done (" << timer.time() << " s)" << std::endl;
}

View File

@ -77,7 +77,6 @@ void Scene::benchmark_distances(const double duration)
timer.start();
std::cout << "Construct AABB tree and internal KD tree...";
Facet_tree tree(faces(*m_pPolyhedron).first, faces(*m_pPolyhedron).second,*m_pPolyhedron);
tree.accelerate_distance_queries();
std::cout << "done (" << timer.time() << " s)" << std::endl;
// benchmark
@ -123,7 +122,7 @@ void Scene::bench_memory()
typedef CGAL::Memory_sizer::size_type size_type;
size_type before = CGAL::Memory_sizer().virtual_size();
Facet_tree tree(faces(*m_pPolyhedron).first, faces(*m_pPolyhedron).second,*m_pPolyhedron);
// tree.accelerate_distance_queries(); // 150 vs 61 bytes per primitive!
tree.do_not_accelerate_distance_queries(); // 150 vs 61 bytes per primitive!
size_type after = CGAL::Memory_sizer().virtual_size();
size_type bytes = after - before; // in Bytes
@ -165,7 +164,6 @@ void Scene::bench_construction()
CGAL::Timer time2;
time2.start();
Facet_tree tree2(faces(*m_pPolyhedron).first, faces(*m_pPolyhedron).second,*m_pPolyhedron);
tree2.accelerate_distance_queries();
double duration_construction_and_kdtree = time2.time();
std::cout << m_pPolyhedron->size_of_facets() << "\t"
@ -248,7 +246,6 @@ void Scene::bench_distances_vs_nbt()
// constructs tree (out of timing)
Facet_tree tree(faces(*m_pPolyhedron).first, faces(*m_pPolyhedron).second, *m_pPolyhedron);
tree.accelerate_distance_queries();
// calls queries
CGAL::Timer timer;

View File

@ -25,7 +25,6 @@ void run(const FaceGraph& graph){
// constructs the AABB tree and the internal search tree for
// efficient distance queries.
Tree tree( faces(graph).first, faces(graph).second, graph);
tree.accelerate_distance_queries();
// counts #intersections with a triangle query
Segment segment_query(p,q);

View File

@ -27,7 +27,6 @@ void run(const HalfedgeGraph& graph){
// efficient distance queries.
Tree tree( CGAL::edges(graph).first,
CGAL::edges(graph).second, graph);
tree.accelerate_distance_queries();
// counts #intersections with a triangle query
Triangle triangle_query(p,q,r);

View File

@ -37,8 +37,6 @@ int main()
// data structure to accelerate distance queries
Tree tree(faces(polyhedron1).first, faces(polyhedron1).second, polyhedron1);
tree.accelerate_distance_queries();
tree.insert(faces(polyhedron2).first, faces(polyhedron2).second, polyhedron2);
// query point

View File

@ -31,7 +31,6 @@ int main()
Tree tree( CGAL::edges(polyhedron).first,
CGAL::edges(polyhedron).second,
polyhedron);
tree.accelerate_distance_queries();
// counts #intersections with a triangle query
Triangle triangle_query(p,q,r);

View File

@ -31,7 +31,6 @@ int main()
// constructs AABB tree and computes internal KD-tree
// data structure to accelerate distance queries
Tree tree(faces(polyhedron).first, faces(polyhedron).second, polyhedron);
tree.accelerate_distance_queries();
// query point
Point query(0.0, 0.0, 3.0);

View File

@ -36,7 +36,6 @@ int main()
// constructs the AABB tree and the internal search tree for
// efficient distance computations.
Tree tree(segments.begin(),segments.end());
tree.accelerate_distance_queries();
// counts #intersections with a plane query
Plane plane_query(a,b,d);

View File

@ -176,7 +176,7 @@ namespace CGAL {
clear_nodes();
m_primitives.clear();
clear_search_tree();
m_default_search_tree_constructed = false;
m_default_search_tree_constructed = true;
}
/// Returns the axis-aligned bounding box of the whole tree.
@ -430,6 +430,8 @@ public:
/// a point set taken on the internal primitives
/// returns `true` iff successful memory allocation
bool accelerate_distance_queries() const;
///Turns off the lazy construction of the internal search tree.
void do_not_accelerate_distance_queries() const;
/// Constructs an internal KD-tree containing the specified point
/// set, to be used as the set of potential hints for accelerating
@ -601,7 +603,7 @@ public:
, m_p_root_node(nullptr)
, m_p_search_tree(nullptr)
, m_search_tree_constructed(false)
, m_default_search_tree_constructed(false)
, m_default_search_tree_constructed(true)
, m_need_build(false)
{}
@ -615,7 +617,7 @@ public:
, m_p_root_node(nullptr)
, m_p_search_tree(nullptr)
, m_search_tree_constructed(false)
, m_default_search_tree_constructed(false)
, m_default_search_tree_constructed(true)
, m_need_build(false)
{
// Insert each primitive into tree
@ -673,7 +675,6 @@ public:
void AABB_tree<Tr>::build()
{
clear_nodes();
if(m_primitives.size() > 1) {
// allocates tree nodes
@ -695,8 +696,9 @@ public:
// In case the users has switched on the accelerated distance query
// data structure with the default arguments, then it has to be
// /built/rebuilt.
if(m_default_search_tree_constructed)
if(m_default_search_tree_constructed && !empty()){
build_kd_tree();
}
m_need_build = false;
}
// constructs the search KD tree from given points
@ -741,6 +743,14 @@ public:
}
}
template<typename Tr>
void AABB_tree<Tr>::do_not_accelerate_distance_queries()const
{
clear_search_tree();
m_default_search_tree_constructed = false;
}
// constructs the search KD tree from internal primitives
template<typename Tr>
bool AABB_tree<Tr>::accelerate_distance_queries() const

View File

@ -34,7 +34,6 @@ int main()
// Test calls to all functions but those who have `!empty()` as
// precondition.
CGAL::Emptyset_iterator devnull;
tree.accelerate_distance_queries();
tree.all_intersections(triangle_query, devnull);
tree.all_intersected_primitives(triangle_query, devnull);
assert(!tree.any_intersected_primitive(triangle_query));

View File

@ -36,7 +36,6 @@ int main()
// Test calls to all functions
CGAL::Emptyset_iterator devnull;
tree.accelerate_distance_queries();
tree.all_intersections(triangle_query, devnull);
tree.all_intersected_primitives(triangle_query, devnull);
assert(tree.any_intersected_primitive(triangle_query));

View File

@ -1,5 +1,13 @@
Release History
===============
Release 5.1
-----------
Release date: March 2020
### 3D Fast Intersection and Distance Computation
- **Breaking change**: the internal search tree is now lazily constructed. To disable it, one must call
the new function `do_not_accelerate_distance_queries()` before the first distance query.
[Release 5.0](https://github.com/CGAL/cgal/releases/tag/releases%2FCGAL-5.0)
-----------

View File

@ -310,7 +310,6 @@ public:
m_own_ptree.reset(new Tree(triangles.begin(), triangles.end()));
m_own_ptree->build();
m_own_ptree->accelerate_distance_queries();
}
private:

View File

@ -131,7 +131,6 @@ public:
m_own_ptree.reset(new Tree(triangles.begin(), triangles.end()));
m_own_ptree->build();
m_own_ptree->accelerate_distance_queries();
}
private:

View File

@ -90,7 +90,7 @@ public:
, step_size_(step_size)
, first_level_(first_level)
{
tree_->accelerate_distance_queries();
}
// Default copy constructor and assignment operator are ok
@ -207,7 +207,6 @@ public:
, sq_tolerance_size_(tolerance_size*tolerance_size)
, hint_(p.facets_begin()->halfedge()->vertex()->point())
{
tree_->accelerate_distance_queries();
}
// Default copy constructor and assignment operator are ok
@ -283,7 +282,6 @@ public:
, sq_tolerance_size_(tolerance_size*tolerance_size)
, hint_(p.facets_begin()->halfedge()->vertex()->point())
{
tree_->accelerate_distance_queries();
}
// Default copy constructor and assignment operator are ok

View File

@ -360,7 +360,6 @@ int main(int argc, char * argv[])
// Constructs AABB tree and computes internal KD-tree
// data structure to accelerate distance queries
AABB_tree tree(faces(output_mesh).first, faces(output_mesh).second, output_mesh);
tree.accelerate_distance_queries();
// Computes distance from each input point to reconstructed mesh
double max_distance = DBL_MIN;

View File

@ -549,7 +549,6 @@ double approximate_Hausdorff_distance(
Tree tree( faces(tm).first, faces(tm).second, tm);
tree.build();
tree.accelerate_distance_queries();
Point_3 hint = get(vpm, *vertices(tm).first);
return internal::approximate_Hausdorff_distance_impl<Concurrency_tag, Kernel>

View File

@ -372,7 +372,6 @@ namespace internal {
}
for(std::size_t i=0; i < trees.size(); ++i){
trees[i]->build();
trees[i]->accelerate_distance_queries();
}
}

View File

@ -74,7 +74,6 @@ namespace internal {
if(do_project)
{
tree.rebuild(faces(tmesh).first, faces(tmesh).second, tmesh);
tree.accelerate_distance_queries();
}
typename GT::Construct_translated_point_3 translate
= gt.construct_translated_point_3_object();

View File

@ -221,7 +221,6 @@ void smooth_mesh(const FaceRange& faces,
}
Tree aabb_tree(input_triangles.begin(), input_triangles.end());
aabb_tree.accelerate_distance_queries();
// Setup the working ranges and check some preconditions
Angle_smoother angle_smoother(tmesh, vpmap, vcmap, gt);

View File

@ -133,7 +133,6 @@ private:
typedef CGAL::AABB_tree< Traits > Tree;
Tree tree( faces(m).first, faces(m).second, m);
tree.accelerate_distance_queries();
tree.build();
boost::graph_traits<Face_graph>::vertex_descriptor vd = *(vertices(m).first);
Traits::Point_3 hint = get(CGAL::vertex_point,m, vd);

View File

@ -77,7 +77,6 @@ double compute_distances(const Mesh& m,
typedef CGAL::AABB_tree< Traits > Tree;
Tree tree( faces(m).first, faces(m).second, m);
tree.accelerate_distance_queries();
tree.build();
typedef typename boost::property_map<Mesh, boost::vertex_point_t>::const_type VPMap;
VPMap vpmap = get(boost::vertex_point, m);

View File

@ -358,7 +358,6 @@ SMesh* poisson_reconstruct(Point_set& points,
// Constructs AABB tree and computes internal KD-tree
// data structure to accelerate distance queries
AABB_tree tree(faces(*mesh).first, faces(*mesh).second, *mesh);
tree.accelerate_distance_queries();
// Computes distance from each input point to reconstructed mesh
double max_distance = DBL_MIN;

View File

@ -58,7 +58,6 @@ public:
, m_is_closed( is_closed(tm) )
{
CGAL_assertion(!m_tree_ptr->empty());
m_tree_ptr->accelerate_distance_queries();
}
double operator()(const typename GeomTraits::Point_3& p) const
@ -188,7 +187,6 @@ public:
, m_offset_distance(offset_distance)
{
CGAL_assertion(! m_tree_ptr->empty() );
m_tree_ptr->accelerate_distance_queries();
}
double operator()(const EPICK::Point_3& p) const

View File

@ -163,11 +163,10 @@ public:
if(!test)
tree.insert(Primitive(it, mesh, vertex_point_map));
}
tree.build();
if(build_kd_tree) {
tree.accelerate_distance_queries();
if(!build_kd_tree) {
tree.do_not_accelerate_distance_queries();
}
tree.build();
if(use_diagonal) {
CGAL::Bbox_3 bbox = tree.bbox();