File: properties_Triangulation_data_structure_2.h

package info (click to toggle)
cgal 5.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 121,084 kB
  • sloc: cpp: 742,056; ansic: 182,102; sh: 647; python: 411; makefile: 280; javascript: 110
file content (353 lines) | stat: -rw-r--r-- 11,472 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
// Copyright (c) 2019  GeometryFactory (France).  All rights reserved.
//
// This file is part of CGAL (www.cgal.org)
//
// $URL: https://github.com/CGAL/cgal/blob/v5.2/Triangulation_2/include/CGAL/boost/graph/properties_Triangulation_data_structure_2.h $
// $Id: properties_Triangulation_data_structure_2.h 0903946 2020-03-17T17:53:21+01:00 Sébastien Loriot
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
//
// Author(s)     : Mael Rouxel-Labbé

#ifndef CGAL_PROPERTIES_TRIANGULATION_DATA_STRUCTURE_2_H
#define CGAL_PROPERTIES_TRIANGULATION_DATA_STRUCTURE_2_H

#include <CGAL/Triangulation_data_structure_2.h>
#include <CGAL/boost/graph/internal/graph_traits_2D_triangulation_helper.h>
#include <CGAL/boost/graph/internal/Has_member_id.h>

#include <CGAL/boost/graph/Named_function_parameters.h>

#include <boost/graph/properties.hpp>

namespace CGAL {
namespace internal {

// property maps
template <class VB, class FB>
class TDS2_vertex_point_map
{
public:
  typedef boost::lvalue_property_map_tag                                      category;
  typedef typename VB::Point                                                  value_type;
  typedef value_type&                                                         reference;
  typedef typename CGAL::Triangulation_data_structure_2<VB,FB>::Vertex_handle key_type;

  friend reference get(TDS2_vertex_point_map<VB,FB>, key_type vh) { return vh->point(); }
  friend void put(TDS2_vertex_point_map<VB,FB>, key_type vh, reference v) { vh->point() = v; }
  reference operator[](key_type vh) const { return vh->point(); }
};

template <class VB, class FB>
class TDS2_edge_weight_map
  : public boost::put_get_helper<typename VB::FT, TDS2_edge_weight_map<VB, FB> >
{
public:
  typedef boost::readable_property_map_tag                           category;
  typedef typename VB::FT                                            value_type;
  typedef value_type                                                 reference;
  typedef typename CGAL::Triangulation_data_structure_2<VB,FB>::Edge key_type;

  TDS2_edge_weight_map(const CGAL::Triangulation_data_structure_2<VB,FB>& tds_) : tds(tds_) { }

  value_type operator[](key_type e) const { return approximate_sqrt(tds.segment(e).squared_length()); }

private:
  const CGAL::Triangulation_data_structure_2<VB,FB>& tds;
};

template <class VB, class FB>
class TDS2_vertex_id_map
  : public boost::put_get_helper<int, TDS2_vertex_id_map<VB, FB> >
{
public:
  typedef boost::readable_property_map_tag                                    category;
  typedef int                                                                 value_type;
  typedef int                                                                 reference;
  typedef typename CGAL::Triangulation_data_structure_2<VB,FB>::Vertex_handle key_type;

  TDS2_vertex_id_map() {}

  long operator[](key_type vh) const { return vh->id(); }
};

template <class VB, class FB>
class TDS2_halfedge_id_map
  : public boost::put_get_helper<int, TDS2_halfedge_id_map<VB, FB> >
{
  typedef typename CGAL::Triangulation_data_structure_2<VB,FB>     TDS;

public:
  typedef boost::readable_property_map_tag                         category;
  typedef int                                                      value_type;
  typedef int                                                      reference;
  typedef CGAL::internal::T2_halfedge_descriptor<TDS>              key_type;

  typedef typename TDS::Face_handle                                face_descriptor;

  TDS2_halfedge_id_map() { }

  // Halfedge id is twice the edge id, and +0/+1 depending whether
  // h.first is such that h.first < opposite(h).first --> different ids
  value_type operator[](key_type h) const
  {
    const face_descriptor f1 = h.first;
    const face_descriptor f2 = f1->neighbor(h.second);

    if(f1->id() < f2->id())
      return 2*(3 * f1->id() + h.second);
    else
      return 2*(3 * f2->id() + f2->index(f1)) + 1;
  }
};

template <class VB, class FB>
class TDS2_edge_id_map
  : public boost::put_get_helper<int, TDS2_edge_id_map<VB, FB> >
{
  typedef typename CGAL::Triangulation_data_structure_2<VB,FB>       TDS;

public:
  typedef boost::readable_property_map_tag                           category;
  typedef int                                                        value_type;
  typedef int                                                        reference;
  typedef CGAL::internal::T2_edge_descriptor<TDS>                    key_type;

  typedef typename TDS::Face_handle                                  Face_handle;

  TDS2_edge_id_map() {}

  value_type operator[](key_type h) const
  {
    const Face_handle f1 = h.first;
    const Face_handle f2 = f1->neighbor(h.second);

    if(f1->id() < f2->id())
      return 3 * f1->id() + h.second;
    else
      return 3 * f2->id() + f2->index(f1);
  }
};

template <class VB, class FB>
class TDS2_face_id_map
  : public boost::put_get_helper<int, TDS2_face_id_map<VB, FB> >
{
  typedef typename CGAL::Triangulation_data_structure_2<VB,FB>     TDS;

public:
  typedef boost::readable_property_map_tag                         category;
  typedef int                                                      value_type;
  typedef int                                                      reference;
  typedef typename TDS::Face_handle                                key_type;

  TDS2_face_id_map() { }

  value_type operator[](key_type f) const { return f->id(); }
};

template <class VB, class FB, class Tag>
struct TDS2_property_map { };

template <class VB, class FB>
struct TDS2_property_map<VB, FB, boost::vertex_point_t>
{
  typedef internal::TDS2_vertex_point_map<VB,FB> type;
  typedef internal::TDS2_vertex_point_map<VB,FB> const_type;
};

template <class VB, class FB>
struct TDS2_property_map<VB, FB, boost::edge_weight_t>
{
  typedef internal::TDS2_edge_weight_map<VB,FB> type;
  typedef internal::TDS2_edge_weight_map<VB,FB> const_type;
};

template <class VB, class FB>
struct TDS2_property_map<VB, FB, boost::vertex_index_t>
{
  typedef internal::TDS2_vertex_id_map<VB,FB> type;
  typedef internal::TDS2_vertex_id_map<VB,FB> const_type;
};

template <class VB, class FB>
struct TDS2_property_map<VB, FB, boost::halfedge_index_t>
{
  typedef internal::TDS2_vertex_id_map<VB,FB> type;
  typedef internal::TDS2_vertex_id_map<VB,FB> const_type;
};

template <class VB, class FB>
struct TDS2_property_map<VB, FB, boost::edge_index_t>
{
  typedef internal::TDS2_edge_id_map<VB,FB> type;
  typedef internal::TDS2_edge_id_map<VB,FB> const_type;
};

template <class VB, class FB>
struct TDS2_property_map<VB, FB, boost::face_index_t>
{
  typedef internal::TDS2_vertex_id_map<VB,FB> type;
  typedef internal::TDS2_vertex_id_map<VB,FB> const_type;
};

} // end namespace internal

template <class VB, class FB >
struct graph_has_property<CGAL::Triangulation_data_structure_2<VB, FB>, boost::vertex_point_t>
  : CGAL::Tag_true{};
template<class VB, class FB >
struct graph_has_property<CGAL::Triangulation_data_structure_2<VB, FB>, boost::edge_weight_t>
  : CGAL::Tag_true{};

template<class VB, class FB >
struct graph_has_property<CGAL::Triangulation_data_structure_2<VB, FB>, boost::vertex_index_t>
  : CGAL::Boolean_tag<
      CGAL::internal::Has_member_id<
        typename CGAL::Triangulation_data_structure_2<VB, FB>::Vertex
      >::value
    >
{};
template<class VB, class FB >
struct graph_has_property<CGAL::Triangulation_data_structure_2<VB, FB>, boost::halfedge_index_t>
  : CGAL::Boolean_tag<
      CGAL::internal::Has_member_id<
        typename CGAL::Triangulation_data_structure_2<VB, FB>::Face
      >::value
    >
{};
template<class VB, class FB >
struct graph_has_property<CGAL::Triangulation_data_structure_2<VB, FB>, boost::edge_index_t>
  : CGAL::Boolean_tag<
      CGAL::internal::Has_member_id<
        typename CGAL::Triangulation_data_structure_2<VB, FB>::Face
      >::value
    >
{};
template<class VB, class FB >
struct graph_has_property<CGAL::Triangulation_data_structure_2<VB, FB>, boost::face_index_t>
  : CGAL::Boolean_tag<
      CGAL::internal::Has_member_id<
        typename CGAL::Triangulation_data_structure_2<VB, FB>::Face
      >::value
    >
{};

template <class VB, class FB>
inline internal::TDS2_vertex_point_map<VB,FB>
get(boost::vertex_point_t, const Triangulation_data_structure_2<VB,FB>&)
{
  internal::TDS2_vertex_point_map<VB,FB> m;
  return m;
}

template <class VB, class FB>
inline internal::TDS2_edge_weight_map<VB,FB>
get(boost::edge_weight_t, const Triangulation_data_structure_2<VB,FB>& g)
{
  internal::TDS2_edge_weight_map<VB,FB> m(g);
  return m;
}

template <class VB, class FB>
inline internal::TDS2_vertex_id_map<VB,FB>
get(boost::vertex_index_t, const Triangulation_data_structure_2<VB,FB>&)
{
  internal::TDS2_vertex_id_map<VB,FB> m;
  return m;
}

template <class VB, class FB>
inline internal::TDS2_halfedge_id_map<VB,FB>
get(boost::halfedge_index_t, const Triangulation_data_structure_2<VB,FB>&)
{
  internal::TDS2_halfedge_id_map<VB,FB> m;
  return m;
}

template <class VB, class FB>
inline internal::TDS2_edge_id_map<VB,FB>
get(boost::edge_index_t, const Triangulation_data_structure_2<VB,FB>&)
{
  internal::TDS2_edge_id_map<VB,FB> m;
  return m;
}

template <class VB, class FB>
inline internal::TDS2_face_id_map<VB,FB>
get(boost::face_index_t, const Triangulation_data_structure_2<VB,FB>&)
{
  internal::TDS2_face_id_map<VB,FB> m;
  return m;
}

} // namespace CGAL

namespace boost {

#define CGAL_PM_SPECIALIZATION(TAG) \
template <class VB, class FB> \
struct property_map<CGAL::Triangulation_data_structure_2<VB,FB>, TAG> \
{ \
  typedef typename CGAL::internal::TDS2_property_map<VB, FB, TAG> map_gen; \
  typedef typename map_gen::type type; \
  typedef typename map_gen::const_type const_type; \
}; \
\
template <class VB, class FB> \
struct property_map<const CGAL::Triangulation_data_structure_2<VB,FB>, TAG> \
{ \
  typedef typename CGAL::internal::TDS2_property_map<VB, FB, TAG> map_gen; \
  typedef typename map_gen::type type; \
  typedef typename map_gen::const_type const_type; \
};

CGAL_PM_SPECIALIZATION(vertex_point_t)
CGAL_PM_SPECIALIZATION(edge_weight_t)
CGAL_PM_SPECIALIZATION(vertex_index_t)
CGAL_PM_SPECIALIZATION(halfedge_index_t)
CGAL_PM_SPECIALIZATION(edge_index_t)
CGAL_PM_SPECIALIZATION(face_index_t)

#undef CGAL_PM_SPECIALIZATION

} // namespace boost

namespace CGAL {

template <class VB, class FB, class PropertyTag, class Key>
inline
typename boost::property_traits<
typename boost::property_map<Triangulation_data_structure_2<VB,FB>,PropertyTag>::const_type>::value_type
get(PropertyTag p, const Triangulation_data_structure_2<VB,FB>& g, const Key& key)
{
  return get(get(p, g), key);
}

template <class VB, class FB, class PropertyTag, class Key,class Value>
inline void
put(PropertyTag p, Triangulation_data_structure_2<VB,FB>& g,
    const Key& key, const Value& value)
{
  typedef typename boost::property_map<Triangulation_data_structure_2<VB,FB>, PropertyTag>::type Map;
  Map pmap = get(p, g);
  put(pmap, key, value);
}

} // namespace CGAL

namespace boost {

// What are those needed for ???
template <typename VB, typename FB>
struct edge_property_type<CGAL::Triangulation_data_structure_2<VB,FB> > {
  typedef void type;
};

template <typename VB, typename FB>
struct vertex_property_type<CGAL::Triangulation_data_structure_2<VB,FB> > {
  typedef void type;
};

} // namespace boost

#endif /* CGAL_PROPERTIES_TRIANGULATION_DATA_STRUCTURE_2_H */