summaryrefslogtreecommitdiff
path: root/include/gudhi_patches/CGAL/Regular_triangulation_traits_adapter.h
blob: 78bb95a60aa48c75d37d2ee0d27a34f14f643c8c (plain)
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
// Copyright (c) 2014 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$
// $Id$
//
// Author(s)     : Clement Jamin

#ifndef CGAL_REGULAR_TRIANGULATION_TRAITS_ADAPTER_H
#define CGAL_REGULAR_TRIANGULATION_TRAITS_ADAPTER_H

#include <CGAL/basic.h>

#include <boost/iterator/transform_iterator.hpp>

namespace CGAL {

// Wrapper class to make a model of `RegularTriangulationTraits` easily usable
// by the `Regular_triangulation` class. By using this class:
// - Point_d (used by `Triangulation` and the TDS) becomes a weighted point
// - Predicates and functors such as Less_coordinate_d or Orientation_d
//   can be called using weighted points instead of bare points (this is
//   needed because `Weighted_point_d` is not convertible to `Point_d`)
// This way, `Triangulation` works perfectly well with weighted points.

template <class K>
class Regular_triangulation_traits_adapter
  : public K
{
public:
  typedef K                                         Base;

  // Required by TriangulationTraits
  typedef typename K::Dimension                     Dimension;
  typedef typename K::FT                            FT;
  typedef typename K::Flat_orientation_d            Flat_orientation_d;
  typedef typename K::Weighted_point_d              Point_d;

  // Required by RegularTriangulationTraits
  typedef typename K::Point_d                       Bare_point_d;
  typedef typename K::Weighted_point_d              Weighted_point_d;
  typedef typename K::Construct_point_d             Construct_point_d;
  typedef typename K::Compute_weight_d              Compute_weight_d;
  typedef typename K::Power_side_of_power_sphere_d  Power_side_of_power_sphere_d;
  typedef typename K::In_flat_power_side_of_power_sphere_d 
                                                    In_flat_power_side_of_power_sphere_d;

  //===========================================================================
  // Custom types
  //===========================================================================

  // Required by SpatialSortingTraits_d
  class Less_coordinate_d
  {
    const K &m_kernel;

  public:
    typedef bool result_type;

    Less_coordinate_d(const K &kernel)
      : m_kernel(kernel) {}

    result_type operator()(
      Weighted_point_d const& p, Weighted_point_d const& q, int i) const
    {
      Construct_point_d cp = m_kernel.construct_point_d_object();
      return m_kernel.less_coordinate_d_object() (cp(p), cp(q), i);
    }
  };

  //===========================================================================

  // Required by TriangulationTraits
  class Orientation_d
  {
    const K &m_kernel;

  public:
    typedef Orientation result_type;

    Orientation_d(const K &kernel)
      : m_kernel(kernel) {}

    template <typename ForwardIterator> 
    result_type operator()(ForwardIterator start, ForwardIterator end) const
    {
      Construct_point_d cp = m_kernel.construct_point_d_object();
      return m_kernel.orientation_d_object() (
        boost::make_transform_iterator(start, cp),
        boost::make_transform_iterator(end, cp)
      );
    }
  };

  //===========================================================================

  // Required by TriangulationTraits
  class Construct_flat_orientation_d
  {
    const K &m_kernel;

  public:
    typedef Flat_orientation_d result_type;
    
    Construct_flat_orientation_d(const K &kernel)
      : m_kernel(kernel) {}

    template <typename ForwardIterator> 
    result_type operator()(ForwardIterator start, ForwardIterator end) const
    {
      Construct_point_d cp = m_kernel.construct_point_d_object();
      return m_kernel.construct_flat_orientation_d_object() (
        boost::make_transform_iterator(start, cp),
        boost::make_transform_iterator(end, cp)
      );
    }
  };


  //===========================================================================

  // Required by TriangulationTraits
  class In_flat_orientation_d
  {
    const K &m_kernel;

  public:
    typedef Orientation result_type;
    
    In_flat_orientation_d(const K &kernel)
      : m_kernel(kernel) {}

    template <typename ForwardIterator> 
    result_type operator()(Flat_orientation_d orient, 
      ForwardIterator start, ForwardIterator end) const
    {
      Construct_point_d cp = m_kernel.construct_point_d_object();
      return m_kernel.in_flat_orientation_d_object() (
        orient,
        boost::make_transform_iterator(start, cp),
        boost::make_transform_iterator(end, cp)
      );
    }
  };

  //===========================================================================
  
  // Required by TriangulationTraits
  class Contained_in_affine_hull_d
  {
    const K &m_kernel;

  public:
    typedef bool result_type;
    
    Contained_in_affine_hull_d(const K &kernel)
      : m_kernel(kernel) {}

    template <typename ForwardIterator> 
    result_type operator()(ForwardIterator start, ForwardIterator end, 
                           const Weighted_point_d & p) const
    {
      Construct_point_d cp = m_kernel.construct_point_d_object();
      return m_kernel.contained_in_affine_hull_d_object() (
        boost::make_transform_iterator(start, cp),
        boost::make_transform_iterator(end, cp),
        cp(p)
      );
    }
  };

  //===========================================================================

  // Required by TriangulationTraits
  class Compare_lexicographically_d
  {
    const K &m_kernel;

  public:
    typedef Comparison_result result_type;
    
    Compare_lexicographically_d(const K &kernel)
      : m_kernel(kernel) {}

    result_type operator()(
      const Weighted_point_d & p, const Weighted_point_d & q) const
    {
      Construct_point_d cp = m_kernel.construct_point_d_object();
      return m_kernel.compare_lexicographically_d_object()(cp(p), cp(q));
    }
  };
  
  //===========================================================================

  // Only for Triangulation_off_ostream.h (undocumented)
  class Compute_coordinate_d
  {
    const K &m_kernel;

  public:
    typedef FT result_type;
    
    Compute_coordinate_d(const K &kernel)
      : m_kernel(kernel) {}

    result_type operator()(
      const Weighted_point_d & p, const int i) const
    {
      Construct_point_d cp = m_kernel.construct_point_d_object();
      return m_kernel.compute_coordinate_d_object()(cp(p), i);
    }
  };

  //===========================================================================

  // To satisfy SpatialSortingTraits_d
  // and also for Triangulation_off_ostream.h (undocumented)
  class Point_dimension_d
  {
    const K &m_kernel;

  public:
    typedef int result_type;
    
    Point_dimension_d(const K &kernel)
      : m_kernel(kernel) {}

    result_type operator()(
      const Weighted_point_d & p) const
    {
      Construct_point_d cp = m_kernel.construct_point_d_object();
      return m_kernel.point_dimension_d_object()(cp(p));
    }
  };
  
  //===========================================================================
  // Object creation
  //===========================================================================

  Less_coordinate_d less_coordinate_d_object() const
  {
    return Less_coordinate_d(*this);
  }
  Contained_in_affine_hull_d contained_in_affine_hull_d_object() const
  { 
    return Contained_in_affine_hull_d(*this); 
  }
  Orientation_d orientation_d_object() const
  {
    return Orientation_d(*this); 
  }
  Construct_flat_orientation_d construct_flat_orientation_d_object() const
  { 
    return Construct_flat_orientation_d(*this);
  }
  In_flat_orientation_d in_flat_orientation_d_object() const
  { 
    return In_flat_orientation_d(*this);
  }
  Compare_lexicographically_d compare_lexicographically_d_object() const
  { 
    return Compare_lexicographically_d(*this);
  }
  Compute_coordinate_d compute_coordinate_d_object() const
  { 
    return Compute_coordinate_d(*this);
  }
  Point_dimension_d point_dimension_d_object() const
  { 
    return Point_dimension_d(*this);
  }
};


} //namespace CGAL

#endif // CGAL_REGULAR_TRIANGULATION_TRAITS_ADAPTER_H