From b9c28d07aaffcbebaf25383ae967c5ea59f031ee Mon Sep 17 00:00:00 2001 From: Pierre Alliez Date: Sun, 26 Apr 2009 21:48:18 +0000 Subject: [PATCH] AABB tree: rename is_smaller to is_contained another code cleanup --- AABB_tree/include/CGAL/AABB_drawing_traits.h | 7 ++-- AABB_tree/include/CGAL/AABB_node.h | 21 ++++-------- .../CGAL/AABB_polyhedron_edge_primitive.h | 33 +++++++++---------- .../CGAL/AABB_polyhedron_triangle_primitive.h | 31 ++++++++--------- .../include/CGAL/AABB_segment_primitive.h | 4 +-- AABB_tree/include/CGAL/AABB_traits.h | 22 ++++++------- AABB_tree/include/CGAL/AABB_tree.h | 2 +- .../include/CGAL/AABB_triangle_primitive.h | 24 +++++++------- .../aabb_intersection_triangle_test.cpp | 5 +++ 9 files changed, 68 insertions(+), 81 deletions(-) diff --git a/AABB_tree/include/CGAL/AABB_drawing_traits.h b/AABB_tree/include/CGAL/AABB_drawing_traits.h index b01613b122a..75bc21e493d 100644 --- a/AABB_tree/include/CGAL/AABB_drawing_traits.h +++ b/AABB_tree/include/CGAL/AABB_drawing_traits.h @@ -24,17 +24,15 @@ #include namespace CGAL { -namespace AABB { template -struct Drawing_traits +struct AABB_drawing_traits { typedef CGAL::Bbox_3 Bbox; bool go_further() { return true; } bool intersection(const int&, const Primitive&) { - // gl_draw(m_psc.compute_bbox(i)); return true; } @@ -86,9 +84,8 @@ struct Drawing_traits ::glVertex3d(px,py,pz); ::glVertex3d(qx,qy,qz); } -}; // Drawing_traits +}; // AABB_drawing_traits -} // end namespace AABB_tree } // end namespace CGAL #endif // CGAL_AABB_DRAWING_TRAITS_H diff --git a/AABB_tree/include/CGAL/AABB_node.h b/AABB_tree/include/CGAL/AABB_node.h index 803811d7bd1..c76eb7500a2 100644 --- a/AABB_tree/include/CGAL/AABB_node.h +++ b/AABB_tree/include/CGAL/AABB_node.h @@ -16,7 +16,7 @@ // $Id$ // // -// Author(s) : Camille Wormser, Pierre Alliez, Laurent Rineau, Stephane Tayeb +// Author(s) : Camille Wormser, Pierre Alliez, Laurent Rineau, Stephane Tayeb #ifndef CGAL_AABB_NODE_H #define CGAL_AABB_NODE_H @@ -87,13 +87,10 @@ public: Traversal_traits& traits, const int nb_primitives) const; - private: typedef AABB_node Node; typedef typename AABBTraits::Primitive Primitive; - - /// Helper functions const Node& left_child() const { return *static_cast(m_p_left_child); } @@ -113,9 +110,8 @@ private: /// bounding box Bounding_box m_bbox; - /// children nodes: - /// either pointing towards children (if the children are not leaves) - /// or pointing toward input primitives (if the children are leaves). + /// children nodes, either pointing towards children (if children are not leaves), + /// or pointing toward input primitives (if children are leaves). void *m_p_left_child; void *m_p_right_child; @@ -154,10 +150,10 @@ AABB_node::expand(ConstPrimitiveIterator first, break; default: const int new_range = range/2; - m_p_left_child = static_cast(this)+1; - m_p_right_child = static_cast(this)+new_range; - left_child().expand(first, first+new_range, new_range); - right_child().expand(first+new_range, beyond, range-new_range); + m_p_left_child = static_cast(this) + 1; + m_p_right_child = static_cast(this) + new_range; + left_child().expand(first, first + new_range, new_range); + right_child().expand(first + new_range, beyond, range - new_range); } } @@ -169,9 +165,6 @@ AABB_node::traversal(const Query& query, Traversal_traits& traits, const int nb_primitives) const { -// CGAL_assertion(NULL!=m_p_left_child); -// CGAL_assertion(NULL!=m_p_right_child); - // Recursive traversal switch(nb_primitives) { diff --git a/AABB_tree/include/CGAL/AABB_polyhedron_edge_primitive.h b/AABB_tree/include/CGAL/AABB_polyhedron_edge_primitive.h index c3d4dbd2ea9..d8c00d6772c 100644 --- a/AABB_tree/include/CGAL/AABB_polyhedron_edge_primitive.h +++ b/AABB_tree/include/CGAL/AABB_polyhedron_edge_primitive.h @@ -32,7 +32,7 @@ namespace CGAL { * * */ - template + template class AABB_polyhedron_edge_primitive { public: @@ -40,16 +40,14 @@ namespace CGAL { typedef typename GeomTraits::FT FT; typedef typename GeomTraits::Point_3 Point; typedef typename GeomTraits::Segment_3 Datum; - typedef typename Polyhedron_::Edge_const_iterator Id; + typedef typename Polyhedron::Halfedge_handle Id; /// Self - typedef AABB_polyhedron_edge_primitive Self; - - /// Constructors - //AABB_polyhedron_triangle_primitive() { }; + typedef AABB_polyhedron_edge_primitive Self; + /// Constructor AABB_polyhedron_edge_primitive(const Id& handle) - : m_handle(handle) { }; + : m_halfedge_handle(handle) { }; // Default copy constructor and assignment operator are ok @@ -59,20 +57,20 @@ namespace CGAL { /// Returns by constructing on the fly the geometric datum wrapped by the primitive Datum datum() const; /// Returns the identifier - const Id id() const { return m_handle; } + const Id id() const { return m_halfedge_handle; } /// Returns a point on the primitive Point point_on() const; /// Returns the x/y/z reference coordinate for sorting /// here simply one vertex of the triangle - const FT xref() const { return m_handle->vertex()->point().x(); } - const FT yref() const { return m_handle->vertex()->point().y(); } - const FT zref() const { return m_handle->vertex()->point().z(); } + const FT xref() const { return m_halfedge_handle->vertex()->point().x(); } + const FT yref() const { return m_halfedge_handle->vertex()->point().y(); } + const FT zref() const { return m_halfedge_handle->vertex()->point().z(); } private: - /// Halfedge handle - Id m_handle; + /// Id, here a polyhedron halfedge handle + Id m_halfedge_handle; }; // end class AABB_polyhedron_edge_primitive @@ -81,17 +79,16 @@ namespace CGAL { AABB_polyhedron_edge_primitive::datum() const { typedef typename GT::Point_3 Point; - typedef typename GT::Segment_3 Segment; - const Point& a = m_handle->vertex()->point(); - const Point& b = m_handle->opposite()->vertex()->point(); - return Datum(a,b); + const Point& a = m_halfedge_handle->vertex()->point(); + const Point& b = m_halfedge_handle->opposite()->vertex()->point(); + return Datum(a,b); // returns a 3D segment } template typename AABB_polyhedron_edge_primitive::Point AABB_polyhedron_edge_primitive::point_on() const { - return m_handle->vertex()->point(); + return m_halfedge_handle->vertex()->point(); } diff --git a/AABB_tree/include/CGAL/AABB_polyhedron_triangle_primitive.h b/AABB_tree/include/CGAL/AABB_polyhedron_triangle_primitive.h index 19702459a21..a3f317f23e7 100644 --- a/AABB_tree/include/CGAL/AABB_polyhedron_triangle_primitive.h +++ b/AABB_tree/include/CGAL/AABB_polyhedron_triangle_primitive.h @@ -32,7 +32,7 @@ namespace CGAL { * * */ - template + template class AABB_polyhedron_triangle_primitive { public: @@ -40,16 +40,14 @@ namespace CGAL { typedef typename GeomTraits::FT FT; typedef typename GeomTraits::Point_3 Point; typedef typename GeomTraits::Triangle_3 Datum; - typedef typename Polyhedron_::Facet_const_iterator Id; + typedef typename Polyhedron::Facet_handle Id; /// Self - typedef AABB_polyhedron_triangle_primitive Self; + typedef AABB_polyhedron_triangle_primitive Self; /// Constructors - //AABB_polyhedron_triangle_primitive() { }; - AABB_polyhedron_triangle_primitive(const Id& handle) - : m_handle(handle) { }; + : m_facet_handle(handle) { }; // Default copy constructor and assignment operator are ok @@ -63,17 +61,17 @@ namespace CGAL { Point point_on() const; /// Returns the identifier - const Id id() const { return m_handle; } + const Id id() const { return m_facet_handle; } /// Returns the x/y/z reference coordinate for sorting /// here simply one vertex of the triangle - const FT xref() const { return m_handle->halfedge()->vertex()->point().x(); } - const FT yref() const { return m_handle->halfedge()->vertex()->point().y(); } - const FT zref() const { return m_handle->halfedge()->vertex()->point().z(); } + const FT xref() const { return m_facet_handle->halfedge()->vertex()->point().x(); } + const FT yref() const { return m_facet_handle->halfedge()->vertex()->point().y(); } + const FT zref() const { return m_facet_handle->halfedge()->vertex()->point().z(); } private: - /// The handle - Id m_handle; + /// The id, here a polyhedron facet handle + Id m_facet_handle; }; // end class AABB_polyhedron_triangle_primitive @@ -82,10 +80,9 @@ namespace CGAL { AABB_polyhedron_triangle_primitive::datum() const { typedef typename GT::Point_3 Point; - typedef typename GT::Triangle_3 Triangle; - const Point& a = m_handle->halfedge()->vertex()->point(); - const Point& b = m_handle->halfedge()->next()->vertex()->point(); - const Point& c = m_handle->halfedge()->next()->next()->vertex()->point(); + const Point& a = m_facet_handle->halfedge()->vertex()->point(); + const Point& b = m_facet_handle->halfedge()->next()->vertex()->point(); + const Point& c = m_facet_handle->halfedge()->next()->next()->vertex()->point(); return Datum(a,b,c); } @@ -93,7 +90,7 @@ namespace CGAL { typename AABB_polyhedron_triangle_primitive::Point AABB_polyhedron_triangle_primitive::point_on() const { - return m_handle->halfedge()->vertex()->point(); + return m_facet_handle->halfedge()->vertex()->point(); } } // end namespace CGAL diff --git a/AABB_tree/include/CGAL/AABB_segment_primitive.h b/AABB_tree/include/CGAL/AABB_segment_primitive.h index 44f87db00ba..11a4b98d4d6 100644 --- a/AABB_tree/include/CGAL/AABB_segment_primitive.h +++ b/AABB_tree/include/CGAL/AABB_segment_primitive.h @@ -50,9 +50,9 @@ public: m_datum = *it; // copy segment } public: - const Datum& datum() const { return m_datum; } - Datum& datum() { return m_datum; } Id id() { return m_it; } + Datum& datum() { return m_datum; } + const Datum& datum() const { return m_datum; } /// Returns the x/y/z reference coordinate for sorting /// here simply the source vertex of the segment diff --git a/AABB_tree/include/CGAL/AABB_traits.h b/AABB_tree/include/CGAL/AABB_traits.h index fc36f92ee11..1ebddc8bbd1 100644 --- a/AABB_tree/include/CGAL/AABB_traits.h +++ b/AABB_tree/include/CGAL/AABB_traits.h @@ -39,14 +39,12 @@ template class AABB_traits { public: - /// Ray query type + /// query types typedef typename GeomTraits::Ray_3 Ray_3; - /// Line query type typedef typename GeomTraits::Line_3 Line_3; - /// Segment query type typedef typename GeomTraits::Segment_3 Segment_3; - // TODO: delete once "inside..." disappears + // TOFIX: delete once "inside..." disappears typedef typename GeomTraits::Triangle_3 Triangle_3; /// AABBTraits concept types @@ -61,18 +59,18 @@ public: typedef typename GeomTraits::Point_3 Projection_query; // types for search tree - typedef typename GeomTraits::Cartesian_const_iterator_3 Cartesian_const_iterator_3; - typedef typename GeomTraits::Construct_cartesian_const_iterator_3 - Construct_cartesian_const_iterator_3; + // TOFIX: how can we avoid repeating those? + typedef typename GeomTraits::FT FT; typedef typename GeomTraits::Point_3 Point_3; - typedef typename GeomTraits::Iso_cuboid_3 Iso_cuboid_3; typedef typename GeomTraits::Sphere_3 Sphere_3; + typedef typename GeomTraits::Iso_cuboid_3 Iso_cuboid_3; + typedef typename GeomTraits::Construct_center_3 Construct_center_3; typedef typename GeomTraits::Construct_iso_cuboid_3 Construct_iso_cuboid_3; typedef typename GeomTraits::Construct_min_vertex_3 Construct_min_vertex_3; typedef typename GeomTraits::Construct_max_vertex_3 Construct_max_vertex_3; - typedef typename GeomTraits::Construct_center_3 Construct_center_3; typedef typename GeomTraits::Compute_squared_radius_3 Compute_squared_radius_3; - typedef typename GeomTraits::FT FT; + typedef typename GeomTraits::Cartesian_const_iterator_3 Cartesian_const_iterator_3; + typedef typename GeomTraits::Construct_cartesian_const_iterator_3 Construct_cartesian_const_iterator_3; /// Constructor AABB_traits() { }; @@ -136,7 +134,7 @@ public: const Primitive& pr, Projection& projection_return) const; - bool is_smaller(const Sphere& a, const Sphere& b) const; + bool is_contained(const Sphere& a, const Sphere& b) const; private: /// Private types @@ -290,7 +288,7 @@ AABB_traits::intersection(const Sphere& sphere, template bool -AABB_traits::is_smaller(const Sphere& a, const Sphere& b) const +AABB_traits::is_contained(const Sphere& a, const Sphere& b) const { CGAL_precondition(a.center() == b.center()); diff --git a/AABB_tree/include/CGAL/AABB_tree.h b/AABB_tree/include/CGAL/AABB_tree.h index 8659e99a9fb..4dd344f1b75 100644 --- a/AABB_tree/include/CGAL/AABB_tree.h +++ b/AABB_tree/include/CGAL/AABB_tree.h @@ -271,7 +271,7 @@ namespace CGAL { if ( AABBTraits().intersection(sphere_, primitive, projection) ) { const Sphere sphere = AABBTraits().sphere(center_, projection); - if ( AABBTraits().is_smaller(sphere, sphere_) ) + if ( AABBTraits().is_contained(sphere, sphere_) ) { projection_ = projection; sphere_ = sphere; diff --git a/AABB_tree/include/CGAL/AABB_triangle_primitive.h b/AABB_tree/include/CGAL/AABB_triangle_primitive.h index f1f5bd18944..5593dc7491f 100644 --- a/AABB_tree/include/CGAL/AABB_triangle_primitive.h +++ b/AABB_tree/include/CGAL/AABB_triangle_primitive.h @@ -27,32 +27,32 @@ namespace CGAL { -template -class AABB_triangle_primitive -{ -public: + template + class AABB_triangle_primitive + { + public: // types typedef Iterator Id; // Id type typedef typename GeomTraits::FT FT; // field number type typedef typename GeomTraits::Point_3 Point; // point type typedef typename GeomTraits::Triangle_3 Datum; // datum type -private: + private: // member data Id m_it; // iterator Datum m_datum; // 3D triangle // constructor -public: + public: AABB_triangle_primitive(Id it) - : m_it(it) + : m_it(it) { - m_datum = *it; // copy triangle + m_datum = *it; // copy triangle } -public: - const Datum& datum() const { return m_datum; } - Datum& datum() { return m_datum; } + public: Id id() { return m_it; } + Datum& datum() { return m_datum; } + const Datum& datum() const { return m_datum; } /// Returns the x/y/z reference coordinate for sorting /// here simply the first vertex of the triangle @@ -62,7 +62,7 @@ public: /// Returns a point on the primitive Point point_on() const { m_datum.vertex(0); } -}; + }; } // end namespace CGAL diff --git a/AABB_tree/test/AABB_tree/aabb_intersection_triangle_test.cpp b/AABB_tree/test/AABB_tree/aabb_intersection_triangle_test.cpp index cfa104813db..b1ba64a7a6f 100644 --- a/AABB_tree/test/AABB_tree/aabb_intersection_triangle_test.cpp +++ b/AABB_tree/test/AABB_tree/aabb_intersection_triangle_test.cpp @@ -144,18 +144,23 @@ void test_several_kernels(const char *filename) std::cout << std::endl; std::cout << "Polyhedron " << filename << std::endl; + std::cout << std::endl; std::cout << "Simple cartesian float kernel" << std::endl; test >(filename); + std::cout << std::endl; std::cout << "Cartesian float kernel" << std::endl; test >(filename); + std::cout << std::endl; std::cout << "Simple cartesian double kernel" << std::endl; test >(filename); + std::cout << std::endl; std::cout << "Cartesian double kernel" << std::endl; test >(filename); + std::cout << std::endl; std::cout << "Epic kernel" << std::endl; test(filename); }