1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2011-2012 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 // Code to create SVG for examples
10
11 #ifndef CREATE_SVG_OVERLAY_HPP
12 #define CREATE_SVG_OVERLAY_HPP
13
14 #include <fstream>
15
16 #include <boost/foreach.hpp>
17 #include <boost/core/ignore_unused.hpp>
18 #include <boost/algorithm/string.hpp>
19
20 #if defined(HAVE_SVG)
21 # include <boost/geometry/io/svg/svg_mapper.hpp>
22 #endif
23
24 template <typename Geometry, typename Range>
create_svg(std::string const & filename,Geometry const & a,Geometry const & b,Range const & range)25 void create_svg(std::string const& filename, Geometry const& a, Geometry const& b, Range const& range)
26 {
27 #if defined(HAVE_SVG)
28 std::cout << std::endl << "[$img/algorithms/" << boost::replace_all_copy(filename, ".svg", ".png") << "]" << std::endl << std::endl;
29
30 typedef typename boost::geometry::point_type<Geometry>::type point_type;
31 std::ofstream svg(filename.c_str());
32
33 boost::geometry::svg_mapper<point_type> mapper(svg, 400, 400);
34 mapper.add(a);
35 mapper.add(b);
36
37 mapper.map(a, "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:2");
38 mapper.map(b, "fill-opacity:0.3;fill:rgb(51,51,153);stroke:rgb(51,51,153);stroke-width:2");
39 int i = 0;
40 BOOST_FOREACH(typename boost::range_value<Range>::type const& g, range)
41 {
42 mapper.map(g, "opacity:0.8;fill:none;stroke:rgb(255,128,0);stroke-width:4;stroke-dasharray:1,7;stroke-linecap:round");
43 std::ostringstream out;
44 out << i++;
45 mapper.text(boost::geometry::return_centroid<point_type>(g), out.str(),
46 "fill:rgb(0,0,0);font-family:Arial;font-size:10px");
47 }
48 #else
49 boost::ignore_unused(filename, a, b, range);
50 #endif
51 }
52
53 // NOTE: convert manually from svg to png using Inkscape ctrl-shift-E
54 // and copy png to html/img/algorithms/
55
56
57 #endif // CREATE_SVG_OVERLAY_HPP
58
59