Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
cgal_kernel.h
Go to the documentation of this file.
1#ifndef _RHEO_CGAL_KERNEL_H
2#define _RHEO_CGAL_KERNEL_H
23//
24// defines a cutsom CGAL kernel by using rheolef::point_basic<T>
25// => avoid copy of coordinates
26//
27// Pierre.Saramito@imag.fr
28//
29// 12 march 2012
30//
31// References:
32// https://lists-sop.inria.fr/sympa/arc/cgal-discuss/2010-08/msg00205.html
33// examples/Kernel_23/MyKernel.h
34//
35// https://doc.cgal.org/latest/Kernel_23/index.html#Section_11.5
36
37// cicumvents debian bug #683975 in boost-1.49 (fixed in boost-1.50 or 1.53)
38#ifndef CGAL_HAS_NO_THREADS
39#define CGAL_HAS_NO_THREADS
40#endif
41
42#pragma GCC diagnostic push
43#pragma GCC diagnostic ignored "-Weffc++"
44#pragma GCC diagnostic ignored "-Wignored-attributes"
45#include <CGAL/Cartesian.h>
46#pragma GCC diagnostic pop
47
48#include "rheolef/point.h"
49
50namespace rheolef { namespace custom_cgal {
51
52// -------------------------------------------------------------------------
53// 1) segment
54// -------------------------------------------------------------------------
55
56template <class R_>
58{
59 typedef typename R_::FT FT;
60 typedef typename R_::Point_2 Point_2;
61 typedef typename R_::Vector_2 Vector_2;
62 typedef typename R_::Direction_2 Direction_2;
63 typedef typename R_::Line_2 Line_2;
64 typedef typename R_::Segment_2 Segment_2;
65 typedef typename R_::Aff_transformation_2 Aff_transformation_2;
66
67 Point_2 sp_, tp_;
68public:
69 typedef R_ R;
70
72
73 MySegmentC2(const Point_2 &sp, const Point_2 &tp)
74 : sp_(sp), tp_(tp) {}
75
76 bool is_horizontal() const;
77 bool is_vertical() const;
78 bool has_on(const Point_2 &p) const;
79 bool collinear_has_on(const Point_2 &p) const;
80
81 bool operator==(const MySegmentC2 &s) const;
82 bool operator!=(const MySegmentC2 &s) const;
83
84 const Point_2 & source() const
85 {
86 return sp_;
87 }
88
89 const Point_2 & target() const
90 {
91 return tp_;
92 }
93 const Point_2 & start() const;
94 const Point_2 & end() const;
95
96 const Point_2 & min () const;
97 const Point_2 & max () const;
98 const Point_2 & vertex(int i) const;
99 const Point_2 & point(int i) const;
100 const Point_2 & operator[](int i) const;
101
102 FT squared_length() const;
103
104 Direction_2 direction() const;
105 Vector_2 to_vector() const;
106 Line_2 supporting_line() const;
107 Segment_2 opposite() const;
108
109 Segment_2 transform(const Aff_transformation_2 &t) const
110 {
111 return Segment_2(t.transform(source()), t.transform(target()));
112 }
113
114 bool is_degenerate() const;
115 CGAL::Bbox_2 bbox() const;
116};
117template < class R >
118inline
119bool
121{
122 return source() == s.source() && target() == s.target();
123}
124template < class R >
125inline
126bool
128{
129 return !(*this == s);
130}
131template < class R >
132inline
133const typename MySegmentC2<R>::Point_2 &
135{
136 typename R::Less_xy_2 less_xy;
137 return less_xy(source(),target()) ? source() : target();
138}
139template < class R >
140inline
141const typename MySegmentC2<R>::Point_2 &
143{
144 typename R::Less_xy_2 less_xy;
145 return less_xy(source(),target()) ? target() : source();
146}
147template < class R >
148inline
149const typename MySegmentC2<R>::Point_2 &
151{
152 return (i%2 == 0) ? source() : target();
153}
154template < class R >
155inline
156const typename MySegmentC2<R>::Point_2 &
158{
159 return (i%2 == 0) ? source() : target();
160}
161template < class R >
162inline
163const typename MySegmentC2<R>::Point_2 &
165{
166 return vertex(i);
167}
168template < class R >
169inline
170typename MySegmentC2<R>::FT
172{
173 typename R::Compute_squared_distance_2 squared_distance;
174 return squared_distance(source(), target());
175}
176template < class R >
177inline
178typename MySegmentC2<R>::Direction_2
180{
181 typename R::Construct_vector_2 construct_vector;
182 return Direction_2( construct_vector( source(), target()));
183}
184template < class R >
185inline
186typename MySegmentC2<R>::Vector_2
188{
189 typename R::Construct_vector_2 construct_vector;
190 return construct_vector( source(), target());
191}
192template < class R >
193inline
194typename MySegmentC2<R>::Line_2
196{
197 typename R::Construct_line_2 construct_line;
198
199 return construct_line(*this);
200}
201template < class R >
202inline
203typename MySegmentC2<R>::Segment_2
205{
206 return MySegmentC2<R>(target(), source());
207}
208template < class R >
209inline
210CGAL::Bbox_2
212{
213 return source().bbox() + target().bbox();
214}
215template < class R >
216inline
217bool
219{
220 return R().equal_y_2_object()(source(), target());
221}
222template < class R >
223inline
224bool
226{
227 return R().equal_y_2_object()(source(), target());
228}
229template < class R >
230inline
231bool
233{
234 return R().equal_x_2_object()(source(), target());
235}
236template < class R >
237inline
238bool
240has_on(const typename MySegmentC2<R>::Point_2 &p) const
241{
242 return R().collinear_are_ordered_along_line_2_object()(source(), p, target());
243}
244template < class R >
245inline
246bool
248collinear_has_on(const typename MySegmentC2<R>::Point_2 &p) const
249{
250 return R().collinear_has_on_2_object()(*this, p);
251}
252template < class R >
253std::ostream &
254operator<<(std::ostream &os, const MySegmentC2<R> &s)
255{
256#if CGAL_VERSION_NR >= 1041101000
257 switch(CGAL::get_mode(os)) {
258#elif CGAL_VERSION_NR >= 1040801000
259 switch(os.iword(CGAL::IO::get_static_mode())) {
260#else
261 switch(os.iword(CGAL::IO::mode)) {
262#endif
263 case CGAL::IO::ASCII :
264 return os << s.source() << ' ' << s.target();
265 case CGAL::IO::BINARY :
266 return os << s.source() << s.target();
267 default:
268 return os << "MySegmentC2(" << s.source() << ", " << s.target() << ")";
269 }
270}
271template < class R >
272std::istream &
273operator>>(std::istream &is, MySegmentC2<R> &s)
274{
275 typename R::Point_2 p, q;
276
277 is >> p >> q;
278
279 if (is)
280 s = MySegmentC2<R>(p, q);
281 return is;
282}
283// -------------------------------------------------------------------------
284// 2) bbox
285// -------------------------------------------------------------------------
286template <class ConstructBbox_2>
287class MyConstruct_bbox_2 : public ConstructBbox_2 {
288public:
289 using ConstructBbox_2::operator();
290 CGAL::Bbox_2 operator()(const point_basic<Float>& p) const {
291 return CGAL::Bbox_2(p.x(), p.y(), p.x(), p.y());
292 }
293};
294// -------------------------------------------------------------------------
295// 3) coordinate iterator
296// -------------------------------------------------------------------------
297template <class T>
299public:
300 const T* operator() (const point_basic<T>& p) { return &p.x(); }
301 const T* operator() (const point_basic<T>& p, int) {
302 const T* pyptr = &p.y();
303 pyptr++;
304 return pyptr;
305 }
306};
307// -------------------------------------------------------------------------
308// 4) construct point
309// -------------------------------------------------------------------------
310template <typename K, typename OldK>
312{
313 typedef typename K::RT RT;
314 typedef typename K::Point_2 Point_2;
315 typedef typename K::Line_2 Line_2;
316 typedef typename Point_2::Rep Rep;
317public:
318 typedef Point_2 result_type;
319
320 // Note : the CGAL::Return_base_tag is really internal CGAL stuff.
321 // Unfortunately it is needed for optimizing away copy-constructions,
322 // due to current lack of delegating constructors in the C++ standard.
323 Rep // Point_2
324 operator() (CGAL::Return_base_tag, CGAL::Origin o) const
325 { return Rep(o); }
326
327 Rep // Point_2
328 operator() (CGAL::Return_base_tag, const RT& x, const RT& y) const
329 { return Rep(x, y); }
330
331#ifdef TO_CLEAN
332 Rep // Point_2
333 operator() (CGAL::Return_base_tag, const RT& x, const RT& y, const RT& w) const
334 { return Rep(x, y); }
335#endif // TO_CLEAN
336
337 Point_2
338 operator()(const CGAL::Origin& o) const
339 { return point_basic<RT>(0, 0); }
340
341 Point_2
342 operator()(const RT& x, const RT& y) const
343 {
344 return point_basic<RT>(x, y);
345 }
346
347 const Point_2&
348 operator()(const Point_2 & p) const
349 {
350 return p;
351 }
352
353 Point_2
354 operator()(const Line_2& l) const
355 {
356 typename OldK::Construct_point_2 base_operator;
357 Point_2 p = base_operator(l);
358 return p;
359 }
360
361 Point_2
362 operator()(const Line_2& l, int i) const
363 {
364 typename OldK::Construct_point_2 base_operator;
365 return base_operator(l, i);
366 }
367
368 // We need this one, as such a functor is in the Filtered_kernel
369 Point_2
370 operator() (const RT& x, const RT& y, const RT& w) const
371 {
372 if(w != 1){
373 return point_basic<RT>(x/w, y/w);
374 } else {
375 return point_basic<RT>(x,y);
376 }
377 }
378};
379// -------------------------------------------------------------------------
380// cartesian kernel
381// -------------------------------------------------------------------------
382template <typename NewKernel, typename BaseKernel>
383class my_cartesian2d_base : public BaseKernel::template Base<NewKernel>::Type {
384 typedef typename BaseKernel::template Base<NewKernel>::Type OldKernel;
385public:
386 typedef typename BaseKernel::FT FT;
387 typedef NewKernel Kernel;
389#ifdef TODO
390 typedef point_basic<FT> Point_1;
391 typedef point_basic<FT> Point_3;
392#endif // TODO
398
403
404 template <typename Kernel2>
408};
409template <typename FT_>
411 : public CGAL::Type_equality_wrapper<
412 my_cartesian2d_base<kernel_2d<FT_>, CGAL::Cartesian<FT_> >,
413 kernel_2d<FT_> >
414{};
415template <typename NewKernel, typename BaseKernel>
416class my_cartesian3d_base : public BaseKernel::template Base<NewKernel>::Type {
417 typedef typename BaseKernel::template Base<NewKernel>::Type OldKernel;
418public:
419 typedef typename BaseKernel::FT FT;
420 typedef NewKernel Kernel;
421#ifdef TODO
422 typedef point_basic<FT> Point_2;
423 typedef point_basic<FT> Point_1;
424#endif // TODO
426#ifdef TODO
427 typedef MySegmentC2<Kernel> Segment_2;
429 typedef MyConstruct_coord_iterator<FT> Construct_cartesian_const_iterator_2;
430 typedef const FT* Cartesian_const_iterator_2;
431 typedef MyConstruct_point_2<Kernel, OldKernel> Construct_point_2;
432
433 Construct_point_2 construct_point_2_object() const { return Construct_point_2(); }
434 Construct_bbox_2 construct_bbox_2_object() const { return Construct_bbox_2(); }
435 Construct_cartesian_const_iterator_2 construct_cartesian_const_iterator_2_object() const
436 { return Construct_cartesian_const_iterator_2(); }
437#endif // TODO
438
439 template <typename Kernel2>
443};
444template <typename FT_>
446 : public CGAL::Type_equality_wrapper<
447 my_cartesian3d_base<kernel_3d<FT_>, CGAL::Cartesian<FT_> >,
448 kernel_3d<FT_> >
449{};
450
451}} // namespace rheolef::custom_cgal
452#endif // _RHEO_CGAL_KERNEL_H
see the point page for the full documentation
CGAL::Bbox_2 operator()(const point_basic< Float > &p) const
const T * operator()(const point_basic< T > &p)
Point_2 operator()(const CGAL::Origin &o) const
const Point_2 & operator()(const Point_2 &p) const
Point_2 operator()(const Line_2 &l, int i) const
Point_2 operator()(const RT &x, const RT &y) const
Point_2 operator()(const Line_2 &l) const
Rep operator()(CGAL::Return_base_tag, CGAL::Origin o) const
bool has_on(const Point_2 &p) const
Segment_2 transform(const Aff_transformation_2 &t) const
const Point_2 & end() const
bool operator!=(const MySegmentC2 &s) const
MySegmentC2(const Point_2 &sp, const Point_2 &tp)
Definition cgal_kernel.h:73
const Point_2 & max() const
const Point_2 & start() const
bool collinear_has_on(const Point_2 &p) const
const Point_2 & source() const
Definition cgal_kernel.h:84
const Point_2 & target() const
Definition cgal_kernel.h:89
const Point_2 & min() const
const Point_2 & point(int i) const
const Point_2 & operator[](int i) const
bool operator==(const MySegmentC2 &s) const
const Point_2 & vertex(int i) const
MyConstruct_bbox_2< typename OldKernel::Construct_bbox_2 > Construct_bbox_2
MyConstruct_point_2< Kernel, OldKernel > Construct_point_2
Construct_bbox_2 construct_bbox_2_object() const
Construct_cartesian_const_iterator_2 construct_cartesian_const_iterator_2_object() const
MyConstruct_coord_iterator< FT > Construct_cartesian_const_iterator_2
Construct_point_2 construct_point_2_object() const
const point vertex[n_vertex]
Definition edge.icc:67
Expr1::float_type T
Definition field_expr.h:230
std::istream & operator>>(std::istream &is, MySegmentC2< R > &s)
std::ostream & operator<<(std::ostream &os, const MySegmentC2< R > &s)
This file is part of Rheolef.
Definition sphere.icc:25
my_cartesian2d_base< Kernel2, BaseKernel > Type
my_cartesian3d_base< Kernel2, BaseKernel > Type