From eed2074f7f523284a2876c8ab539e9bf3ba9e24f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Wed, 7 Sep 2011 09:55:59 +0000 Subject: [PATCH] Fix constness issues in AABB_tree *remove mutable data members *accelerate_distance_queries is not const *clear_search_tree is not const *root_node() const returns a const Node* *add root_note() non-const version *update documentation of AABB_tree class. function constness was not documented *update changes.html --- AABB_tree/doc_tex/AABB_tree_ref/AABB_tree.tex | 30 +++++++++---------- AABB_tree/include/CGAL/AABB_tree.h | 28 ++++++++++------- .../internal/AABB_tree/AABB_search_tree.h | 4 +-- Installation/changes.html | 12 ++++++++ 4 files changed, 46 insertions(+), 28 deletions(-) diff --git a/AABB_tree/doc_tex/AABB_tree_ref/AABB_tree.tex b/AABB_tree/doc_tex/AABB_tree_ref/AABB_tree.tex index 141419347af..3e30b0846f3 100644 --- a/AABB_tree/doc_tex/AABB_tree_ref/AABB_tree.tex +++ b/AABB_tree/doc_tex/AABB_tree_ref/AABB_tree.tex @@ -77,29 +77,29 @@ Class \ccRefName\ is a static data structure for efficient intersection and dist \ccGlue -\ccMethod{Bounding_box bbox();}{Returns the axis-aligned bounding box of the whole tree. } +\ccMethod{Bounding_box bbox() const;}{Returns the axis-aligned bounding box of the whole tree. } \ccGlue -\ccMethod{size_type size();}{Returns the number of primitives in the tree. } +\ccMethod{size_type size() const;}{Returns the number of primitives in the tree. } \ccGlue -\ccMethod{bool empty();}{Returns \ccc{true}, iff tree contains no primitive. } +\ccMethod{bool empty() const;}{Returns \ccc{true}, iff tree contains no primitive. } % INTERSECTION TESTS \ccHeading{Intersection Tests} \ccMethod{template - bool do_intersect(const Query& query);}{Returns \ccc{true}, iff the query intersects at least one of the input primitives. Type \ccc{Query} must be a type for which \ccHtmlNoLinksFrom{\ccc{do_intersect}} predicates are defined in the \ccc{AT} class.} + bool do_intersect(const Query& query) const;}{Returns \ccc{true}, iff the query intersects at least one of the input primitives. Type \ccc{Query} must be a type for which \ccHtmlNoLinksFrom{\ccc{do_intersect}} predicates are defined in the \ccc{AT} class.} \ccGlue \ccMethod{template - size_type number_of_intersected_primitives(const Query& query);}{Returns the number of primitives intersected by the query. Type \ccc{Query} must be a type for which \ccHtmlNoLinksFrom{\ccc{do_intersect}} predicates are defined in the \ccc{AT} class.} + size_type number_of_intersected_primitives(const Query& query) const;}{Returns the number of primitives intersected by the query. Type \ccc{Query} must be a type for which \ccHtmlNoLinksFrom{\ccc{do_intersect}} predicates are defined in the \ccc{AT} class.} \ccGlue \ccMethod{template OutputIterator all_intersected_primitives(const Query& query, - OutputIterator out);}{Outputs to the iterator the list of all intersected primitives ids. This function does not compute the intersection points and is hence faster than the function \ccc{all_intersections} function below. Type \ccc{Query} must be a type for which \ccHtmlNoLinksFrom{\ccc{do_intersect}} predicates are defined in the \ccc{AT} class.} + OutputIterator out) const;}{Outputs to the iterator the list of all intersected primitives ids. This function does not compute the intersection points and is hence faster than the function \ccc{all_intersections} function below. Type \ccc{Query} must be a type for which \ccHtmlNoLinksFrom{\ccc{do_intersect}} predicates are defined in the \ccc{AT} class.} \ccGlue \ccMethod{template boost::optional - any_intersected_primitive(const Query& query);}{Returns the first encountered intersected primitive id, iff the query intersects at least one of the input primitives. No particular order is guaranteed over the tree traversal, such that, e.g, the primitive returned is not necessarily the closest from the source point of a ray query. Type \ccc{Query} must be a type for which \ccHtmlNoLinksFrom{\ccc{do_intersect}} predicates are defined in the \ccc{AT} class.} + any_intersected_primitive(const Query& query) const;}{Returns the first encountered intersected primitive id, iff the query intersects at least one of the input primitives. No particular order is guaranteed over the tree traversal, such that, e.g, the primitive returned is not necessarily the closest from the source point of a ray query. Type \ccc{Query} must be a type for which \ccHtmlNoLinksFrom{\ccc{do_intersect}} predicates are defined in the \ccc{AT} class.} % INTERSECTIONS @@ -108,11 +108,11 @@ Class \ccRefName\ is a static data structure for efficient intersection and dist \ccMethod{template OutputIterator all_intersections(const Query& query, - OutputIterator out);}{Outputs to the iterator the list of all intersections between the query and input data, as objects of type \ccc{Object_and_primitive_id}. Type \ccc{Query} must be a type for which \ccHtmlNoLinksFrom{\ccc{do_intersect}} predicates and intersections are defined in the \ccc{AT} class.} + OutputIterator out) const;}{Outputs to the iterator the list of all intersections between the query and input data, as objects of type \ccc{Object_and_primitive_id}. Type \ccc{Query} must be a type for which \ccHtmlNoLinksFrom{\ccc{do_intersect}} predicates and intersections are defined in the \ccc{AT} class.} \ccGlue \ccMethod{template boost::optional - any_intersection(const Query& query);}{Returns the first encountered intersection, iff the query intersects at least one of the input primitives. No particular order is guaranteed over the tree traversal, such that, e.g, the primitive returned is not necessarily the closest from the source point of a ray query. Type \ccc{Query} must be a type for which \ccHtmlNoLinksFrom{\ccc{do_intersect}} predicates and intersections are defined in the \ccc{AT} class.} + any_intersection(const Query& query) const;}{Returns the first encountered intersection, iff the query intersects at least one of the input primitives. No particular order is guaranteed over the tree traversal, such that, e.g, the primitive returned is not necessarily the closest from the source point of a ray query. Type \ccc{Query} must be a type for which \ccHtmlNoLinksFrom{\ccc{do_intersect}} predicates and intersections are defined in the \ccc{AT} class.} @@ -120,13 +120,13 @@ Class \ccRefName\ is a static data structure for efficient intersection and dist \ccHeading{Distance Queries} \ccMethod{FT -squared_distance(const Point& query);}{Returns the minimum squared distance between the query point and all input primitives. Method \ccc{accelerate_distance_queries} should be called before the first distance query, so that an internal secondary search structure is build, for improving performance.} +squared_distance(const Point& query) const;}{Returns the minimum squared distance between the query point and all input primitives. Method \ccc{accelerate_distance_queries} should be called before the first distance query, so that an internal secondary search structure is build, for improving performance.} \ccGlue \ccMethod{Point -closest_point(const Point& query);}{Returns the point in the union of all input primitives which is closest to the query. In case there are several closest points, one arbitrarily chosen closest point is returned. Method \ccc{accelerate_distance_queries} should be called before the first distance query, so that an internal secondary search structure is build, for improving performance.} +closest_point(const Point& query) const;}{Returns the point in the union of all input primitives which is closest to the query. In case there are several closest points, one arbitrarily chosen closest point is returned. Method \ccc{accelerate_distance_queries} should be called before the first distance query, so that an internal secondary search structure is build, for improving performance.} \ccGlue \ccMethod{Point_and_primitive_id -closest_point_and_primitive(const Point& query);}{Returns a \ccc{Point_and_primitive_id} which realizes the smallest distance between the query point and all input primitives. Method \ccc{accelerate_distance_queries} should be called before the first distance query, so that an internal secondary search structure is build, for improving performance.} +closest_point_and_primitive(const Point& query) const;}{Returns a \ccc{Point_and_primitive_id} which realizes the smallest distance between the query point and all input primitives. Method \ccc{accelerate_distance_queries} should be called before the first distance query, so that an internal secondary search structure is build, for improving performance.} % ACCELERATING THE DISTANCE QUERIES @@ -162,13 +162,13 @@ Note that, in some cases, the user is not able to provide ids of the primitives As an alternative to using the KD-tree, the user can also provide the hints directly, by using the following methods: \ccMethod{FT -squared_distance(const Point& query, const Point& hint);}{Returns the minimum squared distance between the query point and all input primitives. The internal KD-tree is not used.} +squared_distance(const Point& query, const Point& hint) const;}{Returns the minimum squared distance between the query point and all input primitives. The internal KD-tree is not used.} \ccMethod{Point -closest_point(const Point& query, const Point& hint);}{Returns the point in the union of all input primitives which is closest to the query. In case there are several closest points, one arbitrarily chosen closest point is returned. The internal KD-tree is not used.} +closest_point(const Point& query, const Point& hint) const;}{Returns the point in the union of all input primitives which is closest to the query. In case there are several closest points, one arbitrarily chosen closest point is returned. The internal KD-tree is not used.} \ccMethod{Point_and_primitive_id -closest_point_and_primitive(const Point& query, const Point_and_primitive_id& hint);}{Returns a \ccc{Point_and_primitive_id} which realizes the smallest distance between the query point and all input primitives. The internal KD-tree is not used.} +closest_point_and_primitive(const Point& query, const Point_and_primitive_id& hint) const;}{Returns a \ccc{Point_and_primitive_id} which realizes the smallest distance between the query point and all input primitives. The internal KD-tree is not used.} \end{ccAdvanced} diff --git a/AABB_tree/include/CGAL/AABB_tree.h b/AABB_tree/include/CGAL/AABB_tree.h index 83fa98978ed..e0179404d76 100644 --- a/AABB_tree/include/CGAL/AABB_tree.h +++ b/AABB_tree/include/CGAL/AABB_tree.h @@ -1,4 +1,4 @@ -// Copyright (c) 2008 INRIA Sophia-Antipolis (France), ETH Zurich (Switzerland). +// Copyright (c) 2008,2011 INRIA Sophia-Antipolis (France), ETH Zurich (Switzerland). // All rights reserved. // // This file is part of CGAL (www.cgal.org); you may redistribute it under @@ -121,12 +121,12 @@ namespace CGAL { // returns true iff successful memory allocation template bool accelerate_distance_queries(ConstPointIterator first, - ConstPointIterator beyond) const; + ConstPointIterator beyond); /// Construct internal search tree from /// a point set taken on the internal primitives // returns true iff successful memory allocation - bool accelerate_distance_queries() const; + bool accelerate_distance_queries(); // intersection tests template @@ -165,7 +165,7 @@ namespace CGAL { } // clears internal KD tree - void clear_search_tree() const + void clear_search_tree() { delete m_p_search_tree; m_p_search_tree = NULL; @@ -213,16 +213,22 @@ namespace CGAL { // single root node Node* m_p_root_node; - Node* root_node() const { + const Node* root_node() const { if(m_need_build) - const_cast< AABB_tree* >(this)->build(); + const_cast< AABB_tree* >(this)->build(); //THIS IS NOT THREADSAFE + return m_p_root_node; + } + + Node* root_node() { + if(m_need_build) + build(); return m_p_root_node; } // search KD-tree - mutable Search_tree* m_p_search_tree; - mutable bool m_search_tree_constructed; - mutable bool m_default_search_tree_constructed; + const Search_tree* m_p_search_tree; + bool m_search_tree_constructed; + bool m_default_search_tree_constructed; bool m_need_build; private: @@ -329,7 +335,7 @@ namespace CGAL { template template bool AABB_tree::accelerate_distance_queries(ConstPointIterator first, - ConstPointIterator beyond) const + ConstPointIterator beyond) { // clears current KD tree clear_search_tree(); @@ -349,7 +355,7 @@ namespace CGAL { // constructs the search KD tree from internal primitives template - bool AABB_tree::accelerate_distance_queries() const + bool AABB_tree::accelerate_distance_queries() { CGAL_assertion(!m_primitives.empty()); diff --git a/AABB_tree/include/CGAL/internal/AABB_tree/AABB_search_tree.h b/AABB_tree/include/CGAL/internal/AABB_tree/AABB_search_tree.h index 370154f5339..91743d5e5bb 100644 --- a/AABB_tree/include/CGAL/internal/AABB_tree/AABB_search_tree.h +++ b/AABB_tree/include/CGAL/internal/AABB_tree/AABB_search_tree.h @@ -121,8 +121,8 @@ namespace CGAL delete m_p_tree; } - // TOFIX: make it const - Point_and_primitive_id closest_point(const Point& query) + + Point_and_primitive_id closest_point(const Point& query) const { typedef typename Add_decorated_point::Point_3 Decorated_point; Neighbor_search search(*m_p_tree, query, 1); diff --git a/Installation/changes.html b/Installation/changes.html index 11776392008..08dfd411be6 100644 --- a/Installation/changes.html +++ b/Installation/changes.html @@ -98,6 +98,18 @@ Number of lines of code of CGAL

+

Release 3.10

+
+

Release date: XXX 2011

+ +

+CGAL 3.10 offers the following improvements and new functionality :

+ +

AABB tree

+
    +
  • Fix constness issues in the AABB_tree class.
  • +
+

Release 3.9

Release date: XXX 2011