/Src/Dependencies/Boost/libs/geometry/doc/src/examples/algorithms/create_svg_overlay.hpp

http://hadesmem.googlecode.com/ · C++ Header · 53 lines · 31 code · 14 blank · 8 comment · 0 complexity · eb5c22bf87940bd60e8db587ad871eac MD5 · raw file

  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2011 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Use, modification and distribution is subject to the Boost Software License,
  4. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // Code to create SVG for examples
  7. #ifndef CREATE_SVG_OVERLAY_HPP
  8. #define CREATE_SVG_OVERLAY_HPP
  9. #include <fstream>
  10. #include <boost/algorithm/string.hpp>
  11. #if defined(HAVE_SVG)
  12. # include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
  13. #endif
  14. template <typename Geometry, typename Range>
  15. void create_svg(std::string const& filename, Geometry const& a, Geometry const& b, Range const& range)
  16. {
  17. #if defined(HAVE_SVG)
  18. std::cout << std::endl << "[$img/algorithms/" << boost::replace_all_copy(filename, ".svg", ".png") << "]" << std::endl << std::endl;
  19. typedef typename boost::geometry::point_type<Geometry>::type point_type;
  20. std::ofstream svg(filename.c_str());
  21. boost::geometry::svg_mapper<point_type> mapper(svg, 400, 400);
  22. mapper.add(a);
  23. mapper.add(b);
  24. mapper.map(a, "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:2");
  25. mapper.map(b, "fill-opacity:0.3;fill:rgb(51,51,153);stroke:rgb(51,51,153);stroke-width:2");
  26. int i = 0;
  27. BOOST_FOREACH(Geometry const& g, range)
  28. {
  29. mapper.map(g, "opacity:0.8;fill:none;stroke:rgb(255,128,0);stroke-width:4;stroke-dasharray:1,7;stroke-linecap:round");
  30. std::ostringstream out;
  31. out << i++;
  32. mapper.text(boost::geometry::return_centroid<point_type>(g), out.str(),
  33. "fill:rgb(0,0,0);font-family:Arial;font-size:10px");
  34. }
  35. #endif
  36. }
  37. // NOTE: convert manually from svg to png using Inkscape ctrl-shift-E
  38. // and copy png to html/img/algorithms/
  39. #endif // CREATE_SVG_OVERLAY_HPP