1 // Copyright (c) 2009 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/CGAL_ipelets/include/CGAL/grabbers.h $
7 // $Id: grabbers.h efc0c52 2021-01-15T10:02:00+01:00 Sébastien Loriot
8 // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
9 //
10 //
11 // Author(s) : Sebastien Loriot, Sylvain Pion
12
13
14 #ifndef CGAL_GRABBER_H
15 #define CGAL_GRABBER_H
16
17 #include <boost/iterator/function_output_iterator.hpp>
18
19 namespace CGAL{
20
21 template <class Kernel, class Container>
22 class Polygon_2;
23
24
25 namespace internal{
26
27 template <class Kernel, class output_iterator>
28 class Point_grabber{
29 output_iterator out;
30 public:
Point_grabber(output_iterator it)31 Point_grabber(output_iterator it):out(it){}
32
operator()33 void operator()(const typename Kernel::Point_2& p){
34 *out++=p;
35 }
36
operator()37 void operator()(const typename Kernel::Segment_2& s){
38 *out++=s[0];
39 *out++=s[1];
40 }
41
42 template<class Container>
operator()43 void operator()(const CGAL::Polygon_2<Kernel,Container>& p){
44 for(typename CGAL::Polygon_2<Kernel,Container>::Vertex_iterator it=
45 p.vertices_begin();it!=p.vertices_end();++it)
46 *out++= *it;
47 }
48 };
49
50 template<class Kernel,class output_iterator>
51 boost::function_output_iterator<Point_grabber<Kernel,output_iterator> >
point_grabber(output_iterator it)52 point_grabber(output_iterator it){
53 return boost::make_function_output_iterator(Point_grabber<Kernel,output_iterator>(it));
54 }
55
56
57 //Segments
58 template <class Kernel, class output_iterator>
59 class Segment_grabber{
60 output_iterator out;
61 public:
Segment_grabber(output_iterator it)62 Segment_grabber(output_iterator it):out(it){}
63
operator()64 void operator()(const typename Kernel::Segment_2& s){
65 *out++=s;
66 }
67
68 template<class Container>
operator()69 void operator()(const CGAL::Polygon_2<Kernel,Container>& p){
70 for(typename CGAL::Polygon_2<Kernel,Container>::Edge_const_iterator
71 it=p.edges_begin();it!=p.edges_end();++it)
72 *out++= *it;
73 }
74 };
75
76
77 template<class Kernel,class output_iterator>
78 boost::function_output_iterator<Segment_grabber<Kernel,output_iterator> >
segment_grabber(output_iterator it)79 segment_grabber(output_iterator it){
80 return boost::make_function_output_iterator(Segment_grabber<Kernel,output_iterator>(it));
81 }
82
83
84 //Weighted points
85 template <class Kernel,class output_iterator>
86 class Wpoint_grabber{
87 output_iterator out;
88 typedef typename Kernel::Weighted_point_2 Self;
89 public:
Wpoint_grabber(output_iterator it)90 Wpoint_grabber(output_iterator it):out(it){}
91
operator()92 void operator()(const Self& p){
93 *out++=p;
94 }
95
operator()96 void operator()(const typename Kernel::Point_2& p){
97 *out++=Self(p,0);
98 }
99
operator()100 void operator()(const typename Kernel::Circle_2& c){
101 *out++=Self(c.center(),c.squared_radius());
102 }
103
operator()104 void operator()(const typename Kernel::Segment_2& s){
105 *out++=Self(s[0],0);
106 *out++=Self(s[1],0);
107 }
108
109 template<class Container>
operator()110 void operator()(const CGAL::Polygon_2<Kernel,Container>& p){
111 for(typename CGAL::Polygon_2<Kernel,Container>::Vertex_iterator
112 it=p.vertices_begin();it!=p.vertices_end();++it)
113 *out++= Self(*it,0);
114 }
115 };
116
117 template<class Kernel,class output_iterator>
118 boost::function_output_iterator<Wpoint_grabber<Kernel,output_iterator> >
wpoint_grabber(output_iterator it)119 wpoint_grabber(output_iterator it){
120 return boost::make_function_output_iterator(Wpoint_grabber<Kernel,output_iterator>(it));
121 }
122
123 }//internal
124 }//CGAL
125 #endif //CGAL_GRABBER_H
126