File: Triangulation_ds_face_base_2.h

package info (click to toggle)
cgal 4.0-5
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 65,068 kB
  • sloc: cpp: 500,870; ansic: 102,544; sh: 321; python: 92; makefile: 75; xml: 2
file content (359 lines) | stat: -rw-r--r-- 8,412 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
// Copyright (c) 1997  INRIA Sophia-Antipolis (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
// You can redistribute it and/or modify it under the terms of the GNU
// General Public License as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/next/Triangulation_2/include/CGAL/Triangulation_ds_face_base_2.h $
// $Id: Triangulation_ds_face_base_2.h 67117 2012-01-13 18:14:48Z lrineau $
// 
//
// Author(s)     : Mariette Yvinec

#ifndef CGAL_TRIANGULATION_DS_FACE_BASE_2_H
#define CGAL_TRIANGULATION_DS_FACE_BASE_2_H

#include <CGAL/basic.h>
#include <CGAL/triangulation_assertions.h>
#include <CGAL/Triangulation_utils_2.h>
#include <CGAL/Dummy_tds_2.h>

namespace CGAL { 

template < typename TDS = void>
class Triangulation_ds_face_base_2 
{
public:
  typedef TDS                          Triangulation_data_structure;
  typedef typename TDS::Vertex_handle  Vertex_handle;
  typedef typename TDS::Face_handle    Face_handle;

  template <typename TDS2>
  struct Rebind_TDS { typedef Triangulation_ds_face_base_2<TDS2> Other; }; 

private:
  Vertex_handle V[3];
  Face_handle   N[3];

public:
  Triangulation_ds_face_base_2();
  Triangulation_ds_face_base_2(Vertex_handle v0, 
			       Vertex_handle v1, 
			       Vertex_handle v2);
  Triangulation_ds_face_base_2(Vertex_handle v0, 
			       Vertex_handle v1, 
			       Vertex_handle v2,
			       Face_handle n0, 
			       Face_handle n1, 
			       Face_handle n2);

  Vertex_handle vertex(int i) const;
  bool has_vertex(Vertex_handle v) const;
  bool has_vertex(Vertex_handle v, int& i) const ;
  int index(Vertex_handle v) const ;
 
  Face_handle neighbor(int i) const ;
  bool has_neighbor(Face_handle n) const;
  bool has_neighbor(Face_handle n, int& i) const;
  int index(Face_handle n) const;

  void set_vertex(int i, Vertex_handle v);
  void set_vertices();
  void set_vertices(Vertex_handle v0, Vertex_handle v1, Vertex_handle v2);
  void set_neighbor(int i, Face_handle n) ;
  void set_neighbors();
  void set_neighbors(Face_handle n0, Face_handle n1, Face_handle n2);
  void reorient();
  void ccw_permute();
  void cw_permute();
  
  int dimension() const;
  //the following trivial is_valid to allow
  // the user of derived face base classes 
  // to add their own purpose checking
  bool is_valid(bool /* verbose */ = false, int /* level */ = 0) const
  {return true;}
  
   // For use by Compact_container.
  void * for_compact_container() const {return N[0].for_compact_container(); }
  void * & for_compact_container()     { return N[0].for_compact_container();}


  static int ccw(int i) {return Triangulation_cw_ccw_2::ccw(i);}
  static int  cw(int i) {return Triangulation_cw_ccw_2::cw(i);}
};

template <class TDS>
Triangulation_ds_face_base_2<TDS> ::
Triangulation_ds_face_base_2()
{
  set_vertices();
  set_neighbors();
}

template <class TDS>
Triangulation_ds_face_base_2<TDS> ::
Triangulation_ds_face_base_2( Vertex_handle v0, 
			      Vertex_handle v1, 
			      Vertex_handle v2)
{
  set_vertices(v0, v1, v2);
  set_neighbors();
}

template <class TDS>
Triangulation_ds_face_base_2<TDS> ::
Triangulation_ds_face_base_2(Vertex_handle v0, 
			     Vertex_handle v1, 
			     Vertex_handle v2,
			     Face_handle n0, 
			     Face_handle n1, 
			     Face_handle n2)
{
  set_vertices(v0, v1, v2);
  set_neighbors(n0, n1, n2);
}


template <class TDS>
inline 
typename Triangulation_ds_face_base_2<TDS>::Vertex_handle
Triangulation_ds_face_base_2<TDS>::
vertex(int i) const
{
  CGAL_triangulation_precondition( i == 0 || i == 1 || i == 2);
  return V[i];
} 


template <class TDS>
inline bool
Triangulation_ds_face_base_2<TDS> ::
has_vertex(Vertex_handle v) const
{
  return (V[0] == v) || (V[1] == v) || (V[2]== v);
}
    
template <class TDS>
inline bool
Triangulation_ds_face_base_2<TDS> ::    
has_vertex(Vertex_handle v, int& i) const
{
  if (v == V[0]) {
    i = 0;
    return true;
  }
  if (v == V[1]) {
    i = 1;
    return true;
  }
  if (v == V[2]) {
    i = 2;
    return true;
  }
  return false;
}
    
template <class TDS>    
inline int
Triangulation_ds_face_base_2<TDS> :: 
index(Vertex_handle v) const
{
  if (v == V[0]) return 0;
  if (v == V[1]) return 1;
  CGAL_triangulation_assertion( v == V[2] );
  return 2;
}

template <class TDS>    
inline 
typename Triangulation_ds_face_base_2<TDS>::Face_handle 
Triangulation_ds_face_base_2<TDS>::
neighbor(int i) const
{
  CGAL_triangulation_precondition( i == 0 || i == 1 || i == 2);
  return N[i];
}
    
template <class TDS>      
inline bool 
Triangulation_ds_face_base_2<TDS> ::
has_neighbor(Face_handle n) const
{
  return (N[0] == n) || (N[1] == n) || (N[2] == n);
}
    
    
template <class TDS>      
inline bool 
Triangulation_ds_face_base_2<TDS> ::
has_neighbor(Face_handle n, int& i) const
{
  if(n == N[0]){
    i = 0;
    return true;
  }
  if(n == N[1]){
    i = 1;
    return true;
  }
  if(n == N[2]){
    i = 2;
    return true;
  }
  return false;
}

    
    
template <class TDS>      
inline int 
Triangulation_ds_face_base_2<TDS> ::
index(Face_handle n) const
{
  if (n == N[0]) return 0;
  if (n == N[1]) return 1;
  CGAL_triangulation_assertion( n == N[2] );
  return 2;
}
    
template <class TDS>      
inline void
Triangulation_ds_face_base_2<TDS> :: 
set_vertex(int i, Vertex_handle v)
{
  CGAL_triangulation_precondition( i == 0 || i == 1 || i == 2);
  V[i] = v;
}
    
template <class TDS>      
inline void
Triangulation_ds_face_base_2<TDS> ::     
set_neighbor(int i, Face_handle n)
{
  CGAL_triangulation_precondition( i == 0 || i == 1 || i == 2);
  CGAL_triangulation_precondition( this != &*n );
  N[i] = n;
}

template <class TDS>      
inline void
Triangulation_ds_face_base_2<TDS> :: 
set_vertices()
{
  V[0] = V[1] = V[2] = Vertex_handle();
}
    
template <class TDS>      
inline void
Triangulation_ds_face_base_2<TDS> ::     
set_vertices(Vertex_handle v0,  Vertex_handle v1, Vertex_handle v2)
{
  V[0] = v0;
  V[1] = v1;
  V[2] = v2;
}
    
template <class TDS>      
inline void
Triangulation_ds_face_base_2<TDS> :: 
set_neighbors()
{
  N[0] = N[1] = N[2] = Face_handle();
}
    
template <class TDS>      
inline void
Triangulation_ds_face_base_2<TDS> :: 
set_neighbors(Face_handle n0,Face_handle n1, Face_handle n2)
{
  CGAL_triangulation_precondition( this != &*n0 );
  CGAL_triangulation_precondition( this != &*n1 );
  CGAL_triangulation_precondition( this != &*n2 );
  N[0] = n0;
  N[1] = n1;
  N[2] = n2;
}

template <class TDS>
void
Triangulation_ds_face_base_2<TDS> :: 
reorient()
{
  //exchange the vertices 0 and 1
  set_vertices (V[1],V[0],V[2]);
  set_neighbors(N[1],N[0],N[2]);
}

template <class TDS>
inline void 
Triangulation_ds_face_base_2<TDS> ::
ccw_permute()
{
  set_vertices (V[2],V[0],V[1]);
  set_neighbors(N[2],N[0],N[1]);
}


template <class TDS>
inline void 
Triangulation_ds_face_base_2<TDS> ::
cw_permute()
{
  set_vertices (V[1],V[2],V[0]);
  set_neighbors(N[1],N[2],N[0]);
}


template < class TDS>
inline  int 
Triangulation_ds_face_base_2<TDS> ::
dimension() const
{
  if (V[2] != Vertex_handle()) {return 2;}
  else return( V[1] != Vertex_handle() ? 1 : 0);
}

template < class TDS >
inline
std::istream&
operator>>(std::istream &is, Triangulation_ds_face_base_2<TDS> &)
  // non combinatorial information. Default = nothing
{
  return is;
}

template < class TDS >
inline
std::ostream&
operator<<(std::ostream &os, const Triangulation_ds_face_base_2<TDS> &)
  // non combinatorial information. Default = nothing
{
  return os;
}

// Specialisation for void.
template <>
class Triangulation_ds_face_base_2<void>
{
public:
  typedef Dummy_tds_2                       Triangulation_data_structure;
  typedef Triangulation_data_structure::Vertex_handle   Vertex_handle;
  typedef Triangulation_data_structure::Face_handle     Face_handle;
  template <typename TDS2>
  struct Rebind_TDS { typedef Triangulation_ds_face_base_2<TDS2> Other; };
};



} //namespace CGAL 

#endif //CGAL_DS_TRIANGULATION_FACE_BASE_2_H