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
|
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Performance Test
// Copyright (c) 2012-2015 Barend Gehrels, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/geometry.hpp>
#include <boost/geometry/multi/geometries/multi_geometries.hpp>
#include <boost/foreach.hpp>
#include <boost/timer.hpp>
#include <fstream>
namespace bg = boost::geometry;
template
<
typename GeometryOut,
typename Geometry
>
double test_growth(Geometry const& geometry, int n, int d, double distance)
{
typedef typename bg::coordinate_type<Geometry>::type coordinate_type;
typedef typename bg::point_type<Geometry>::type point_type;
// extern int point_buffer_count;
std::ostringstream complete;
complete
<< "point_growth"
<< "_" << "r"
<< "_" << n
<< "_" << d
// << "_" << point_buffer_count
;
//std::cout << complete.str() << std::endl;
std::ostringstream filename;
filename << "buffer_" << complete.str() << ".svg";
std::ofstream svg(filename.str().c_str());
#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
bg::svg_mapper<point_type> mapper(svg, 500, 500);
{
bg::model::box<point_type> box;
bg::envelope(geometry, box);
bg::buffer(box, box, distance * 1.01);
mapper.add(box);
}
#endif
bg::strategy::buffer::join_round join_strategy(100);
bg::strategy::buffer::end_flat end_strategy;
bg::strategy::buffer::point_circle point_strategy;
bg::strategy::buffer::side_straight side_strategy;
typedef bg::strategy::buffer::distance_symmetric<coordinate_type> distance_strategy_type;
distance_strategy_type distance_strategy(distance);
std::vector<GeometryOut> buffered;
bg::buffer(geometry, buffered,
distance_strategy, side_strategy,
join_strategy, end_strategy, point_strategy);
typename bg::default_area_result<GeometryOut>::type area = 0;
BOOST_FOREACH(GeometryOut const& polygon, buffered)
{
area += bg::area(polygon);
}
#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
// Map input geometry in green
mapper.map(geometry, "opacity:0.5;fill:rgb(0,128,0);stroke:rgb(0,128,0);stroke-width:10");
BOOST_FOREACH(GeometryOut const& polygon, buffered)
{
mapper.map(polygon, "opacity:0.4;fill:rgb(255,255,128);stroke:rgb(0,0,0);stroke-width:3");
}
#endif
return area;
}
template <typename P>
void test_growth(int n, int distance_count)
{
srand(int(time(NULL)));
//std::cout << typeid(bg::coordinate_type<P>::type).name() << std::endl;
boost::timer t;
namespace buf = bg::strategy::buffer;
typedef bg::model::polygon<P> polygon;
typedef bg::model::multi_point<P> multi_point_type;
multi_point_type multi_point;
for (int i = 0; i < n; i++)
{
P point(rand() % 100, rand() % 100);
multi_point.push_back(point);
}
//std::cout << bg::wkt(multi_point) << std::endl;
double previous_area = 0;
double epsilon = 0.1;
double distance = 15.0;
for (int d = 0; d < distance_count; d++, distance += epsilon)
{
double area = test_growth<polygon>(multi_point, n, d, distance);
if (area < previous_area)
{
std::cout << "Error: " << area << " < " << previous_area << std::endl
<< " n=" << n << " distance=" << distance
<< bg::wkt(multi_point) << std::endl;
}
previous_area = area;
}
std::cout << "n=" << n << " time=" << t.elapsed() << std::endl;
}
int main(int, char* [])
{
for (int i = 5; i <= 50; i++)
{
test_growth<bg::model::point<double, 2, bg::cs::cartesian> >(i, 20);
}
return 0;
}
|