/Src/Dependencies/Boost/libs/geometry/doc/src/examples/algorithms/assign_points.cpp

http://hadesmem.googlecode.com/ · C++ · 73 lines · 35 code · 19 blank · 19 comment · 1 complexity · 3e25a6ec5b480f9829fd7d28c38ed3e7 MD5 · raw file

  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // QuickBook Example
  3. // Copyright (c) 2011 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Use, modification and distribution is subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //[assign_points
  8. //` Shows usage of Boost.Geometry's assign, Boost.Assign, and Boost.Range to assign ranges of a linestring
  9. #include <iostream>
  10. #include <boost/geometry.hpp>
  11. #include <boost/geometry/geometries/linestring.hpp>
  12. #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
  13. #include <boost/assign.hpp>
  14. #include <boost/geometry/geometries/adapted/boost_range/filtered.hpp>
  15. BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
  16. template <typename T>
  17. struct x_between
  18. {
  19. x_between(T a, T b)
  20. : fa(a), fb(b)
  21. {}
  22. template <typename P>
  23. bool operator()(P const& p) const
  24. {
  25. return boost::geometry::get<0>(p) >= fa
  26. && boost::geometry::get<0>(p) <= fb;
  27. }
  28. private :
  29. T fa, fb;
  30. };
  31. int main()
  32. {
  33. using namespace boost::assign;
  34. typedef boost::geometry::model::linestring<boost::tuple<int, int> > ls;
  35. ls line1, line2, line3;
  36. line1 = tuple_list_of(0, 0)(2, 3)(4, 0)(6, 3)(8, 0)(10, 3)(12, 0); /*< tuple_list_of is part of Boost.Assign and can be used for Boost.Geometry if points are tuples >*/
  37. boost::geometry::assign_points(line2, tuple_list_of(0, 0)(2, 2)(4, 0)(6, 2)(8, 0)); /*< tuple_list_of delivers a range and can therefore be used in boost::geometry::assign >*/
  38. boost::geometry::assign_points(line3, line1 | boost::adaptors::filtered(x_between<int>(4, 8))); /*< Boost.Range adaptors can also be used in boost::geometry::assign >*/
  39. std::cout << "line 1: " << boost::geometry::dsv(line1) << std::endl;
  40. std::cout << "line 2: " << boost::geometry::dsv(line2) << std::endl;
  41. std::cout << "line 3: " << boost::geometry::dsv(line3) << std::endl;
  42. return 0;
  43. }
  44. //]
  45. //[assign_points_output
  46. /*`
  47. Output:
  48. [pre
  49. line 1: ((0, 0), (2, 3), (4, 0), (6, 3), (8, 0), (10, 3), (12, 0))
  50. line 2: ((0, 0), (2, 2), (4, 0), (6, 2), (8, 0))
  51. line 3: ((4, 0), (6, 3), (8, 0))
  52. ]
  53. */
  54. //]