1 // Copyright (c) 1997-2002,2005 Max-Planck-Institute Saarbruecken (Germany). 2 // All rights reserved. 3 // 4 // This file is part of CGAL (www.cgal.org). 5 // 6 // $URL: https://github.com/CGAL/cgal/blob/v5.3/Nef_3/include/CGAL/Nef_3/Nef_box.h $ 7 // $Id: Nef_box.h 458ecf1 2021-06-08T17:32:12+01:00 Giles Bathgate 8 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial 9 // 10 // Author(s) : Peter Hachenberger <hachenberger@mpi-sb.mpg.de> 11 #ifndef CGAL_NEF_BOX_H 12 #define CGAL_NEF_BOX_H 13 14 #include <CGAL/license/Nef_3.h> 15 16 17 #include <CGAL/box_intersection_d.h> 18 #include <CGAL/Box_intersection_d/box_limits.h> 19 #include <CGAL/internal/Static_filters/tools.h> 20 21 namespace CGAL { 22 23 template<class SNC_decorator> 24 class Nef_box : public Box_intersection_d::Box_d< double, 3 > { 25 26 typedef typename SNC_decorator::SNC_structure SNC_structure; 27 typedef typename CGAL::SNC_intersection<SNC_structure> SNC_intersection; 28 29 typedef typename SNC_decorator::Decorator_traits Decorator_traits; 30 typedef typename Decorator_traits::Vertex_handle Vertex_handle; 31 typedef typename Decorator_traits::Halfedge_handle Halfedge_handle; 32 typedef typename Decorator_traits::Halffacet_handle Halffacet_handle; 33 typedef typename Decorator_traits::Halffacet_cycle_iterator 34 Halffacet_cycle_iterator; 35 typedef typename SNC_decorator::Infi_box Infi_box; 36 typedef typename SNC_decorator::Kernel Kernel; 37 typedef typename SNC_decorator::Point_3 Point_3; 38 typedef typename Decorator_traits::SHalfedge_iterator SHalfedge_iterator; 39 typedef typename Decorator_traits::SHalfedge_around_facet_circulator 40 SHalfedge_around_facet_circulator; 41 42 typedef CGAL::SNC_const_decorator<SNC_structure> Const_decorator; 43 44 45 typedef std::pair<double, double> double_pair; 46 typedef Box_intersection_d::box_limits<double> box_limits; 47 48 Halffacet_handle f; 49 Halfedge_handle e; 50 Vertex_handle v; 51 enum Type { FACET, EDGE, VERTEX }; 52 Type type; 53 extend(const Point_3 & p,const Tag_false &)54 void extend( const Point_3& p, const Tag_false& ) { 55 internal::Static_filters_predicates::Get_approx<Point_3> get_approx; // Identity functor for all points 56 // but lazy points 57 std::pair<double, double> q[3]; 58 q[0] = CGAL::to_interval( get_approx(p).x() ); 59 q[1] = CGAL::to_interval( get_approx(p).y() ); 60 q[2] = CGAL::to_interval( get_approx(p).z() ); 61 Box_intersection_d::Box_d< double, 3 >::extend(q); 62 } 63 extend(const Point_3 & p,const Tag_true &)64 void extend( const Point_3& p, const Tag_true& ) { 65 double_pair q[3]; 66 if(Infi_box::degree(p.hx()) == 0) 67 q[0] = CGAL::to_interval(p.x()); 68 else 69 q[0] = p.x() > 0 ? double_pair(box_limits::sup(),box_limits::sup()) 70 : double_pair(box_limits::inf(),box_limits::inf()); 71 if(Infi_box::degree(p.hy()) == 0) 72 q[1] = CGAL::to_interval(p.y()); 73 else 74 q[1] = p.y() > 0 ? double_pair(box_limits::sup(),box_limits::sup()) 75 : double_pair(box_limits::inf(),box_limits::inf()); 76 if(Infi_box::degree(p.hz()) == 0) 77 q[2] = CGAL::to_interval(p.z()); 78 else 79 q[2] = p.z() > 0 ? double_pair(box_limits::sup(),box_limits::sup()) 80 : double_pair(box_limits::inf(),box_limits::inf()); 81 Box_intersection_d::Box_d< double, 3 >::extend(q); 82 } 83 84 public: Nef_box(Halffacet_handle f)85 Nef_box( Halffacet_handle f ) : f(f), type(FACET) { 86 if( !Const_decorator::is_standard( f ) ) { 87 init( true ); 88 } else { 89 init( false ); 90 Halffacet_cycle_iterator cycle_it = f->facet_cycles_begin(); 91 if( cycle_it.is_shalfedge() ) { 92 SHalfedge_iterator edge_it(cycle_it); 93 SHalfedge_around_facet_circulator 94 start( edge_it ), end( edge_it ); 95 CGAL_For_all( start, end ) { 96 const Point_3& p = start->prev()->source()->source()->point(); 97 extend( p, typename Is_extended_kernel<Kernel>::value_type()); 98 } 99 } else 100 CGAL_error_msg( "is facet first cycle a SHalfloop?"); 101 } 102 } 103 Nef_box(Halfedge_handle e)104 Nef_box( Halfedge_handle e ) : e(e), type(EDGE) { 105 106 if(!Const_decorator::is_standard(e->source() ) || 107 !Const_decorator::is_standard(e->twin()->source() ) ) { 108 init( true ); 109 } else { 110 init( false ); 111 extend( e->source()->point(), 112 typename Is_extended_kernel<Kernel>::value_type()); 113 extend( e->twin()->source()->point(), 114 typename Is_extended_kernel<Kernel>::value_type()); 115 } 116 } 117 Nef_box(Vertex_handle vin)118 Nef_box(Vertex_handle vin) : v(vin), type(VERTEX) { 119 120 if(!Const_decorator::is_standard(v)) 121 init(true); 122 else { 123 init(false); 124 extend(v->point(), 125 typename Is_extended_kernel<Kernel>::value_type()); 126 } 127 } 128 get_halffacet()129 Halffacet_handle get_halffacet() { 130 CGAL_assertion( type == FACET ); 131 return f; 132 } 133 get_halfedge()134 Halfedge_handle get_halfedge() { 135 CGAL_assertion( type == EDGE ); 136 return e; 137 } 138 get_vertex()139 Vertex_handle get_vertex() { 140 CGAL_assertion(type == VERTEX); 141 return v; 142 } 143 }; 144 145 } //namespace CGAL 146 147 #endif // CGAL_NEF_BOX_H 148