1 // Copyright (c) 2003-2007  INRIA Sophia-Antipolis (France).
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/Surface_mesher/include/CGAL/Surface_mesh_cell_base_3.h $
7 // $Id: Surface_mesh_cell_base_3.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot
8 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
9 //
10 // Author(s)     : Steve Oudot, David Rey, Mariette Yvinec, Laurent Rineau, Andreas Fabri
11 
12 #ifndef CGAL_SURFACE_MESH_CELL_BASE_3_H
13 #define CGAL_SURFACE_MESH_CELL_BASE_3_H
14 
15 #include <CGAL/license/Surface_mesher.h>
16 
17 #include <CGAL/Complex_2_in_triangulation_cell_base_3.h>
18 #include <CGAL/Delaunay_triangulation_cell_base_3.h>
19 
20 #ifdef CGAL_MESH_3_IO_H
21 #include <string>
22 #endif
23 
24 #ifdef CGAL_SURFACE_MESHER_TAG_BAD
25 #include <bitset>
26 #endif // CGAL_SURFACE_MESHER_TAG_BAD
27 
28 namespace CGAL {
29 
30   template < class GT, class Cb = Delaunay_triangulation_cell_base_3<GT> >
31   class Surface_mesh_cell_base_3 :
32     public Complex_2_in_triangulation_cell_base_3<GT, Cb>
33   {
34     typedef Complex_2_in_triangulation_cell_base_3<GT, Cb> Base;
35   public:
36     typedef Surface_mesh_cell_base_3 <GT, Cb> Self;
37 
38     template < class TDS3 >
39     struct Rebind_TDS {
40       typedef typename Cb::template Rebind_TDS<TDS3>::Other  Cb3;
41       typedef Surface_mesh_cell_base_3 <GT, Cb3> Other;
42     };
43 
44 
45     typedef typename GT::Point_3 Point;
46 
47     typedef typename Base::Triangulation_data_structure Tds;
48     typedef typename Tds::Vertex_handle Vertex_handle;
49     typedef typename Tds::Cell_handle Cell_handle;
50 
51 
52   private:
53 
54     // -- fields added to this class --
55     Point tab_surface_center_facets [4];
56 #ifdef CGAL_SURFACE_MESHER_TAG_BAD
57     std::bitset<12> bits;
58 #else
59     char bits; // the lower 4 bits for 'facet_visited',
60                // the higher 4 bits for 'visits'
61 #endif
62 
63   public:
64 
65     // Constructors
66 
Surface_mesh_cell_base_3()67     Surface_mesh_cell_base_3()
68       : Base(), bits()// c_visited(0)
69     {}
70 
Surface_mesh_cell_base_3(Vertex_handle v0,Vertex_handle v1,Vertex_handle v2,Vertex_handle v3)71     Surface_mesh_cell_base_3 (Vertex_handle v0,
72                               Vertex_handle v1,
73                               Vertex_handle v2,
74                               Vertex_handle v3)
75       : Base (v0, v1, v2, v3), bits()// c_visited(0)
76     {}
77 
Surface_mesh_cell_base_3(Vertex_handle v0,Vertex_handle v1,Vertex_handle v2,Vertex_handle v3,Cell_handle n0,Cell_handle n1,Cell_handle n2,Cell_handle n3)78     Surface_mesh_cell_base_3 (Vertex_handle v0,
79                               Vertex_handle v1,
80                               Vertex_handle v2,
81                               Vertex_handle v3,
82                               Cell_handle n0,
83                               Cell_handle n1,
84                               Cell_handle n2,
85                               Cell_handle n3)
86       : Base (v0, v1, v2, v3, n0, n1, n2, n3), bits()// c_visited(0)
87     {}
88 
89 
90 
91     // Access functions
92 
93     // Facets
94 
is_facet_visited(const int facet)95     bool is_facet_visited (const int facet) const {
96       CGAL_assertion (facet>=0 && facet <4);
97 #ifdef CGAL_SURFACE_MESHER_TAG_BAD
98       return bits[facet];
99 #else
100       return (bits & (1 << facet)) != 0;
101 #endif
102     }
103 
visited(const int facet)104     bool visited (const int facet) const {
105       CGAL_assertion (facet>=0 && facet <4);
106 #ifdef CGAL_SURFACE_MESHER_TAG_BAD
107       return bits[facet+4];
108 #else
109       return (bits & (1 << (facet+4))) != 0;
110 #endif
111     }
112 
get_facet_surface_center(const int facet)113     const Point& get_facet_surface_center(const int facet) const {
114       CGAL_assertion (facet>=0 && facet <4);
115       return(tab_surface_center_facets[facet]);
116   }
117 
118     // Setting functions
119 
120     // Facets
121 
set_facet_visited(const int facet)122     void set_facet_visited (const int facet) {
123       CGAL_assertion (facet>=0 && facet <4);
124 #ifdef CGAL_SURFACE_MESHER_TAG_BAD
125       bits[facet] = true;
126 #else
127       bits |= (1 << facet);
128 #endif
129     }
130 
set_visited(const int facet)131     void set_visited (const int facet) {
132       CGAL_assertion (facet>=0 && facet <4);
133 #ifdef CGAL_SURFACE_MESHER_TAG_BAD
134       bits[facet+4] = true;
135 #else
136       bits |= (1 << (4+facet));
137 #endif
138     }
139 
140 #ifdef CGAL_SURFACE_MESHER_TAG_BAD
set_bad(const int facet)141     void set_bad(const int facet) {
142       bits[facet+8] = true;
143     }
144 
is_bad(const int facet)145     bool is_bad(const int facet) const {
146       return bits[facet+8];
147     }
148 #endif
149 
reset_visited(const int facet)150     void reset_visited (const int facet) {
151       CGAL_assertion (facet>=0 && facet <4);
152 #ifdef CGAL_SURFACE_MESHER_TAG_BAD
153       bits &= ~((1 | (1 << 4) | (1 << 8)) << facet);
154 //       bits[facet+8] = false;
155 //       bits[facet+4] = false;
156 //       bits[facet] = false;
157 #else
158       bits &= (15 & ~(1 << facet));
159       bits &= ((15 | (15<<4)) & ~(1 << (4+facet)));
160 #endif
161     }
162 
set_facet_surface_center(const int facet,const Point & p)163     void set_facet_surface_center(const int facet,
164                           const Point& p) {
165       CGAL_assertion (facet>=0 && facet <4);
166       tab_surface_center_facets[facet]=p;
167     }
168 
169 #ifdef CGAL_MESH_3_IO_H
170     static
io_signature()171     std::string io_signature()
172     {
173       return
174         Get_io_signature<Complex_2_in_triangulation_cell_base_3<GT, Cb> >()();
175     }
176 #endif
177   };  // end Surface_mesh_cell_base_3
178 
179 template < class GT, class Cb >
180 std::istream&
181 operator>>(std::istream &is,
182            Surface_mesh_cell_base_3<GT, Cb> &v)
183 {
184   return is >>
185     static_cast<Complex_2_in_triangulation_cell_base_3<GT, Cb>&>(v);
186 }
187 
188 template < class GT, class Cb >
189 std::ostream&
190 operator<<(std::ostream &os,
191            const Surface_mesh_cell_base_3<GT, Cb> &v)
192 {
193   return os <<
194     static_cast<const Complex_2_in_triangulation_cell_base_3<GT, Cb>&>(v);
195 }
196 
197 }  // namespace CGAL
198 
199 
200 #endif  // CGAL_SURFACE_MESH_CELL_BASE_3_H
201