]>
Commit | Line | Data |
---|---|---|
b32b8144 FG |
1 | // Boost.Geometry |
2 | ||
3 | // Copyright (c) 2017 Barend Gehrels, Amsterdam, the Netherlands. | |
4 | ||
5 | // Use, modification and distribution is subject to the Boost Software License, | |
6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
7 | // http://www.boost.org/LICENSE_1_0.txt) | |
8 | ||
9 | #ifndef BOOST_GEOMETRY_TEST_DEBUG_SORT_BY_SIDE_SVG_HPP | |
10 | #define BOOST_GEOMETRY_TEST_DEBUG_SORT_BY_SIDE_SVG_HPP | |
11 | ||
12 | #include <fstream> | |
13 | #include <sstream> | |
14 | #include <set> | |
15 | ||
16 | #include <boost/geometry/io/svg/svg_mapper.hpp> | |
17 | #include <boost/geometry/algorithms/detail/overlay/debug_turn_info.hpp> | |
18 | #include <boost/geometry/algorithms/detail/overlay/sort_by_side.hpp> | |
19 | ||
20 | namespace boost { namespace geometry { namespace debug | |
21 | { | |
22 | ||
23 | ||
24 | template <typename Sbs, typename Point, typename Geometry1, typename Geometry2> | |
25 | inline void sorted_side_map(std::string const& case_id, | |
26 | Sbs const& sbs, Point const& point, | |
27 | Geometry1 const& geometry1, | |
28 | Geometry2 const& geometry2, | |
29 | int take_turn_index = -1, int take_operation_index = -1) | |
30 | { | |
31 | ||
32 | // Check number of sources (buffer has only one source) | |
33 | std::set<signed_size_type> sources; | |
34 | for (std::size_t i = 0; i < sbs.m_ranked_points.size(); i++) | |
35 | { | |
36 | const typename Sbs::rp& er = sbs.m_ranked_points[i]; | |
37 | sources.insert(er.seg_id.source_index); | |
38 | } | |
39 | std::size_t const source_count = sources.size(); | |
40 | ||
41 | std::ostringstream filename; | |
42 | filename << "sort_by_side_" << case_id << ".svg"; | |
43 | std::ofstream svg(filename.str().c_str()); | |
44 | ||
45 | typedef geometry::svg_mapper<Point> mapper_type; | |
46 | typedef geometry::model::referring_segment<Point const> seg; | |
47 | ||
48 | mapper_type mapper(svg, 500, 500); | |
49 | ||
50 | for (std::size_t i = 0; i < sbs.m_ranked_points.size(); i++) | |
51 | { | |
52 | const typename Sbs::rp& er = sbs.m_ranked_points[i]; | |
53 | mapper.add(er.point); | |
54 | } | |
55 | ||
56 | if (sources.count(0) > 0) | |
57 | { | |
58 | mapper.map(geometry1, "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:0"); | |
59 | } | |
60 | if (sources.count(1) > 0) | |
61 | { | |
62 | mapper.map(geometry2, "fill-opacity:0.3;fill:rgb(51,51,153);stroke:rgb(51,51,153);stroke-width:0"); | |
63 | } | |
64 | ||
65 | const std::string style = "fill:rgb(0,0,0);font-family:Arial;font-size:10px;"; | |
66 | for (std::size_t i = 0; i < sbs.m_ranked_points.size(); i++) | |
67 | { | |
68 | const typename Sbs::rp& er = sbs.m_ranked_points[i]; | |
69 | ||
70 | std::ostringstream out; | |
71 | out << er.rank | |
72 | << " (" << i << ")" | |
73 | << " z=" << er.zone | |
74 | << " " << (er.direction == detail::overlay::sort_by_side::dir_to ? "t" : "f") | |
75 | << " " << er.turn_index | |
76 | << "[" << er.operation_index << "]"; | |
77 | ||
78 | if (er.direction == detail::overlay::sort_by_side::dir_to) | |
79 | { | |
80 | out << " L=" << er.count_left << " R=" << er.count_right; | |
81 | } | |
82 | else | |
83 | { | |
84 | out << " l=" << er.count_left << " r=" << er.count_right; | |
85 | } | |
86 | out << " " << operation_char(er.operation); | |
87 | if (source_count > 1) | |
88 | { | |
89 | out << " s=" << er.seg_id.source_index; | |
90 | } | |
91 | ||
92 | bool left = (i / 2) % 2 == 1; | |
93 | int x_offset = left ? -6 : 6; | |
94 | int y_offset = i % 2 == 0 ? 0 : 10; | |
95 | const std::string align = left ? "text-anchor:end;" : ""; | |
96 | ||
97 | std::string const source_style | |
98 | = er.seg_id.source_index == 0 | |
99 | ? "opacity:0.7;stroke:rgb(0,255,0);stroke-width:4;" | |
100 | : "opacity:0.7;stroke:rgb(0,0,255);stroke-width:4;"; | |
101 | mapper.map(seg(point, er.point), source_style); | |
102 | ||
103 | if (er.direction == detail::overlay::sort_by_side::dir_to) | |
104 | { | |
105 | if (er.turn_index == take_turn_index | |
106 | && er.operation_index == take_operation_index) | |
107 | { | |
108 | mapper.map(er.point, "opacity:0.7;fill:rgb(255,0,255);", 3); | |
109 | } | |
110 | else | |
111 | { | |
112 | mapper.map(er.point, "opacity:0.7;fill:rgb(0,0,0);", 3); | |
113 | } | |
114 | } | |
115 | ||
116 | mapper.text(er.point, out.str(), style + align, x_offset, y_offset); | |
117 | } | |
118 | mapper.map(sbs.m_origin, "opacity:0.9;fill:rgb(255,0,0);", 5); | |
119 | } | |
120 | ||
121 | }}} // namespace boost::geometry::debug | |
122 | ||
123 | #endif // BOOST_GEOMETRY_TEST_DEBUG_SORT_BY_SIDE_SVG_HPP |