diff --git a/Nef_3/include/CGAL/Nef_3/Bounding_box_3.h b/Nef_3/include/CGAL/Nef_3/Bounding_box_3.h index ea36e0ee34a..3cf3e2ae137 100644 --- a/Nef_3/include/CGAL/Nef_3/Bounding_box_3.h +++ b/Nef_3/include/CGAL/Nef_3/Bounding_box_3.h @@ -27,13 +27,14 @@ CGAL_BEGIN_NAMESPACE -template +template class Bounding_box_3; + +template class Bounding_box_3 : public Box_intersection_d::Box_d< double, 3> { typedef Box_intersection_d::Box_d< double, 3> Base; - - typedef typename Traits::Point_3 Point_3; + typedef typename Kernel::Point_3 Point_3; public: Bounding_box_3() : Base() {} @@ -43,9 +44,29 @@ public: q[0] = CGAL::to_interval( p.x() ); q[1] = CGAL::to_interval( p.y() ); q[2] = CGAL::to_interval( p.z() ); - Box_intersection_d::Box_d< double, 3 >::extend(q); + Base::extend(q); } }; +template +class Bounding_box_3 : +public Box_intersection_d::Box_d { + + typedef typename Kernel::FT FT; + typedef Box_intersection_d::Box_d Base; + typedef typename Kernel::Point_3 Point_3; + +public: + Bounding_box_3() : Base() {} + + void extend( const Point_3& p) { + FT q[3]; + q[0] = p.x(); + q[1] = p.y(); + q[2] = p.z(); + Base::extend(q); + } +}; + CGAL_END_NAMESPACE #endif // CGAL_BOUNDING_BOX_3_H diff --git a/Nef_3/include/CGAL/Nef_3/K3_tree.h b/Nef_3/include/CGAL/Nef_3/K3_tree.h index 9de45ba9c11..be19d22a6b8 100644 --- a/Nef_3/include/CGAL/Nef_3/K3_tree.h +++ b/Nef_3/include/CGAL/Nef_3/K3_tree.h @@ -283,6 +283,7 @@ typedef typename Traits::Objects_bbox Objects_bbox; typedef typename Traits::Kernel Kernel; typedef typename Kernel::RT RT; +typedef typename Kernel::FT FT; typedef Smaller_than< Kernel, @@ -624,8 +625,8 @@ void divide_segment_by_plane( Segment_3 s, Plane_3 pl, c = (CGAL::abs(vec[2]) > CGAL::abs(vec[c]) ? 2 : c); Point_3 pt_on_minus_x_plane = vec[c] < 0 ? - Point_3(RT(b.min_coord(0)), RT(b.min_coord(1)),RT(b.min_coord(2))) : - Point_3(RT(b.max_coord(0)), RT(b.max_coord(1)),RT(b.max_coord(2))); + Point_3(FT(b.min_coord(0)), FT(b.min_coord(1)),FT(b.min_coord(2))) : + Point_3(FT(b.max_coord(0)), FT(b.max_coord(1)),FT(b.max_coord(2))); // We compute the intersection between a plane with normal vector in // the minus x direction and located at the minimum point of the bounding box, and the input ray. When the ray does not intersect the bounding volume, there won't be any object hit, so it is safe to construct a segment that simply lay in the unbounded side of the bounding box. This approach is taken instead of somehow (efficiently) report that there was no hit object, in order to mantain a clear interface with the Iterator class. Plane_3 pl_on_minus_x; diff --git a/Nef_3/include/CGAL/Nef_3/SNC_k3_tree_traits.h b/Nef_3/include/CGAL/Nef_3/SNC_k3_tree_traits.h index 08fd805ed57..863aed6feb7 100644 --- a/Nef_3/include/CGAL/Nef_3/SNC_k3_tree_traits.h +++ b/Nef_3/include/CGAL/Nef_3/SNC_k3_tree_traits.h @@ -196,18 +196,77 @@ public: typedef typename Kernel::RT RT; typedef typename Kernel::Kernel_tag Kernel_tag; - typedef CGAL::Bounding_box_3 Bounding_box_3; + typedef CGAL::Bounding_box_3 + ::value_type, Kernel> + Bounding_box_3; - virtual Bounding_box_3 operator()(const Object_list& o) const; - virtual Bounding_box_3 operator()(Object_handle o) const; - virtual Bounding_box_3 operator()(Vertex_handle v) const; - virtual Bounding_box_3 operator()(Halfedge_handle e) const; - virtual Bounding_box_3 operator()(Halffacet_handle f) const; - virtual Bounding_box_3 operator()(Halffacet_triangle_handle f) const; + Bounding_box_3 operator()( const Object_list& O) const { + Bounding_box_3 b; + typename Object_list::const_iterator o; + for( o = O.begin(); o != O.end(); ++o) { + Vertex_handle v; + if( CGAL::assign( v, *o)) { + b.extend(v->point()); + } + } + return b; + } - virtual ~Objects_bbox() {} + Bounding_box_3 operator()(Object_handle o) const { + Vertex_handle v; + Halfedge_handle e; + Halffacet_handle f; + if( CGAL::assign( v, o)) + return operator()(v); + else if( CGAL::assign( e, o)) + return operator()(e); + else if( CGAL::assign( f, o)) + return operator()(f); + else { + Halffacet_triangle_handle t; + if( CGAL::assign( t, o)) + return operator()(t); + else + CGAL_assertion_msg( 0, "wrong handle"); + } + return Bounding_box_3(); // never reached + } - SNC_decorator D; + Bounding_box_3 operator()(Vertex_handle v) const { + Bounding_box_3 b; + b.extend(v->point()); + return b; + } + + Bounding_box_3 operator()(Halfedge_handle e) const { + Bounding_box_3 b; + b.extend(e->source()->point()); + b.extend(e->twin()->source()->point()); + return b; + } + + Bounding_box_3 operator()(Halffacet_triangle_handle t) const { + Bounding_box_3 bbox; + Triangle_3 tr(t.get_triangle()); + for( int i = 0; i < 3; ++i) + bbox.extend(tr[i]); + return bbox; + } + + Bounding_box_3 operator()(Halffacet_handle f) const { + CGAL_assertion( f->facet_cycles_begin() != + Halffacet_cycle_iterator()); + Halffacet_cycle_iterator fc(f->facet_cycles_begin()); + SHalfedge_handle e; + CGAL_assertion(fc.is_shalfedge()); + e = SHalfedge_handle(fc); + SHalfedge_around_facet_circulator sc(e), send(sc); + CGAL_assertion( !is_empty_range( sc, send)); + Bounding_box_3 b; + CGAL_For_all( sc, send) + b.extend(sc->source()->source()->point()); + return b; + } }; template @@ -244,7 +303,9 @@ public: typedef typename Kernel::RT RT; typedef typename Kernel::Kernel_tag Kernel_tag; - typedef CGAL::Bounding_box_3 Bounding_box_3; + typedef CGAL::Bounding_box_3 + ::value_type, Kernel> + Bounding_box_3; typedef typename Kernel::Intersect_3 Intersect; typedef CGAL::Objects_bbox Objects_bbox; @@ -549,91 +610,6 @@ Side_of_plane::operator() //#endif } -template -Bounding_box_3 -Objects_bbox::operator() - ( const Object_list& O) const { - Bounding_box_3 b; - typename Object_list::const_iterator o; - for( o = O.begin(); o != O.end(); ++o) { - Vertex_handle v; - if( CGAL::assign( v, *o)) { - b.extend(v->point()); - } - } - return b; -} - -template -Bounding_box_3 -Objects_bbox::operator() - (Object_handle o) const { - Vertex_handle v; - Halfedge_handle e; - Halffacet_handle f; - if( CGAL::assign( v, o)) - return operator()(v); - else if( CGAL::assign( e, o)) - return operator()(e); - else if( CGAL::assign( f, o)) - return operator()(f); - else { - Halffacet_triangle_handle t; - if( CGAL::assign( t, o)) - return operator()(t); - else - CGAL_assertion_msg( 0, "wrong handle"); - } - return Bounding_box_3(); // never reached -} - -template -Bounding_box_3 -Objects_bbox::operator() - (Vertex_handle v) const { - Bounding_box_3 b; - b.extend(v->point()); - return b; -} - -template -Bounding_box_3 -Objects_bbox::operator() - (Halfedge_handle e) const { - Bounding_box_3 b; - b.extend(e->source()->point()); - b.extend(e->twin()->source()->point()); - return b; -} - -template -Bounding_box_3 -Objects_bbox::operator() - (Halffacet_triangle_handle t) const { - Bounding_box_3 bbox; - Triangle_3 tr(t.get_triangle()); - for( int i = 0; i < 3; ++i) - bbox.extend(tr[i]); - return bbox; -} - -template -Bounding_box_3 -Objects_bbox::operator() - (Halffacet_handle f) const { - CGAL_assertion( f->facet_cycles_begin() != Halffacet_cycle_iterator()); - Halffacet_cycle_iterator fc(f->facet_cycles_begin()); - SHalfedge_handle e; - CGAL_assertion(fc.is_shalfedge()); - e = SHalfedge_handle(fc); - SHalfedge_around_facet_circulator sc(e), send(sc); - CGAL_assertion( !is_empty_range( sc, send)); - Bounding_box_3 b; - CGAL_For_all( sc, send) - b.extend(sc->source()->source()->point()); - return b; -} - CGAL_END_NAMESPACE #endif // CGAL_NEF_SNC_K3_TREE_TRAITS_H