1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2010-2015 Barend Gehrels, Amsterdam, the Netherlands.
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)
10 #ifndef BOOST_GEOMETRY_TEST_BUFFER_SVG_PER_TURN_HPP
11 #define BOOST_GEOMETRY_TEST_BUFFER_SVG_PER_TURN_HPP
16 #include <test_buffer_svg.hpp>
17 #include <boost/ptr_container/ptr_vector.hpp>
19 template <typename Point>
20 class save_turns_visitor
23 typedef std::vector<std::pair<Point, int> > vector_type;
25 template <typename Turns>
26 inline void get_turns(Turns const& turns)
28 for (typename boost::range_iterator<Turns const>::type it =
29 boost::begin(turns); it != boost::end(turns); ++it)
31 m_points.push_back(std::make_pair(it->point, it->turn_index));
35 template <typename PieceCollection>
36 inline void apply(PieceCollection const& collection, int phase)
40 get_turns(collection.m_turns);
44 vector_type const& get_points() { return m_points; }
52 template <typename Point>
56 mapper_visitor(std::string const& complete, int index, Point const& point)
57 : m_filename(get_filename(complete, index))
58 , m_svg(m_filename.c_str())
59 , m_mapper(m_svg, 1000, 800)
61 , m_buffer_mapper(m_filename)
64 double half_size = 75.0; // specific for multi_point buffer
65 bg::set<bg::min_corner, 0>(box, bg::get<0>(point) - half_size);
66 bg::set<bg::min_corner, 1>(box, bg::get<1>(point) - half_size);
67 bg::set<bg::max_corner, 0>(box, bg::get<0>(point) + half_size);
68 bg::set<bg::max_corner, 1>(box, bg::get<1>(point) + half_size);
71 m_visitor.set_alternate_box(box);
72 m_buffer_mapper.set_alternate_box(box);
75 // It is used in a ptr vector
76 virtual ~mapper_visitor()
80 template <typename PieceCollection>
81 inline void apply(PieceCollection const& collection, int phase)
83 m_visitor.apply(collection, phase);
86 template <typename Geometry, typename GeometryBuffer>
87 void map_input_output(Geometry const& geometry,
88 GeometryBuffer const& buffered, bool negative)
90 m_buffer_mapper.map_input_output(m_mapper, geometry, buffered, negative);
94 std::string get_filename(std::string const& complete, int index)
96 std::ostringstream filename;
97 filename << "buffer_per_turn_" << complete << "_" << index << ".svg";
98 return filename.str();
101 typedef bg::svg_mapper<Point> mapper_type;
102 typedef bg::model::box<Point> box_type;
104 std::string m_filename;
106 mapper_type m_mapper;
107 svg_visitor<mapper_type, box_type> m_visitor;
108 buffer_svg_mapper<Point> m_buffer_mapper;
111 template <typename Point>
112 class per_turn_visitor
114 // Both fstreams and svg mappers are non-copyable,
115 // therefore we need to use dynamic memory
116 typedef boost::ptr_vector<mapper_visitor<Point> > container_type;
117 container_type mappers;
121 typedef std::pair<Point, int> pair_type;
122 typedef std::vector<pair_type> vector_type;
124 per_turn_visitor(std::string const& complete_caseid,
125 vector_type const& points)
127 namespace bg = boost::geometry;
129 if (points.size() > 100u)
131 // Defensive check. Too much intersections. Don't create anything
135 BOOST_FOREACH(pair_type const& p, points)
137 mappers.push_back(new mapper_visitor<Point>(complete_caseid, p.second, p.first));
141 template <typename PieceCollection>
142 inline void apply(PieceCollection const& collection, int phase)
144 for(typename container_type::iterator it = mappers.begin();
145 it != mappers.end(); ++it)
147 it->apply(collection, phase);
151 template <typename Geometry, typename GeometryBuffer>
152 void map_input_output(Geometry const& geometry,
153 GeometryBuffer const& buffered, bool negative)
155 for(typename container_type::iterator it = mappers.begin();
156 it != mappers.end(); ++it)
158 it->map_input_output(geometry, buffered, negative);
164 #endif // BOOST_GEOMETRY_TEST_BUFFER_SVG_PER_TURN_HPP