Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r70919 - in trunk/libs/geometry: doc/src/examples/algorithms example
From: barend.gehrels_at_[hidden]
Date: 2011-04-03 03:50:13


Author: barendgehrels
Date: 2011-04-03 03:50:11 EDT (Sun, 03 Apr 2011)
New Revision: 70919
URL: http://svn.boost.org/trac/boost/changeset/70919

Log:
Ifdefed some examples for release branch
Text files modified:
   trunk/libs/geometry/doc/src/examples/algorithms/assign_2d_point.cpp | 6 +++---
   trunk/libs/geometry/doc/src/examples/algorithms/create_svg_overlay.hpp | 7 ++++++-
   trunk/libs/geometry/doc/src/examples/algorithms/create_svg_two.hpp | 7 ++++++-
   trunk/libs/geometry/example/05_a_overlay_polygon_example.cpp | 12 ++++++++++--
   trunk/libs/geometry/example/05_b_overlay_linestring_polygon_example.cpp | 9 +++++++--
   trunk/libs/geometry/example/06_b_transformation_example.cpp | 11 ++++++++---
   trunk/libs/geometry/example/07_a_graph_route_example.cpp | 19 ++++++++++++++-----
   trunk/libs/geometry/example/07_b_graph_route_example.cpp | 18 +++++++++++++-----
   8 files changed, 67 insertions(+), 22 deletions(-)

Modified: trunk/libs/geometry/doc/src/examples/algorithms/assign_2d_point.cpp
==============================================================================
--- trunk/libs/geometry/doc/src/examples/algorithms/assign_2d_point.cpp (original)
+++ trunk/libs/geometry/doc/src/examples/algorithms/assign_2d_point.cpp 2011-04-03 03:50:11 EDT (Sun, 03 Apr 2011)
@@ -16,7 +16,7 @@
 #include <boost/geometry/geometry.hpp>
 #include <boost/geometry/geometries/geometries.hpp>
 
-#if defined(_MSC_VER)
+#if defined(HAVE_TTMATH)
 # include <boost/geometry/extensions/contrib/ttmath_stub.hpp>
 #endif
 
@@ -29,7 +29,7 @@
     boost::geometry::model::d2::point_xy<double> p1;
     assign(p1, 1.2345, 2.3456);
 
-#if defined(_MSC_VER)
+#if defined(HAVE_TTMATH)
     boost::geometry::model::d2::point_xy<ttmath::Big<1,4> > p2;
     assign(p2, "1.2345", "2.3456"); /*< It is possible to assign coordinates with other types than the coordinate type.
         For ttmath, you can e.g. conveniently use strings. The advantage is that it then has higher precision, because
@@ -40,7 +40,7 @@
     std::cout
         << std::setprecision(20)
         << boost::geometry::dsv(p1) << std::endl
-#if defined(_MSC_VER)
+#if defined(HAVE_TTMATH)
         << boost::geometry::dsv(p2) << std::endl
 #endif
         ;

Modified: trunk/libs/geometry/doc/src/examples/algorithms/create_svg_overlay.hpp
==============================================================================
--- trunk/libs/geometry/doc/src/examples/algorithms/create_svg_overlay.hpp (original)
+++ trunk/libs/geometry/doc/src/examples/algorithms/create_svg_overlay.hpp 2011-04-03 03:50:11 EDT (Sun, 03 Apr 2011)
@@ -13,11 +13,15 @@
 
 #include <fstream>
 #include <boost/algorithm/string.hpp>
-#include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
+
+#if defined(HAVE_SVG)
+# include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
+#endif
 
 template <typename Geometry, typename Range>
 void create_svg(std::string const& filename, Geometry const& a, Geometry const& b, Range const& range)
 {
+#if defined(HAVE_SVG)
     std::cout << std::endl << "[$img/algorithms/" << boost::replace_all_copy(filename, ".svg", ".png") << "]" << std::endl << std::endl;
 
     typedef typename boost::geometry::point_type<Geometry>::type point_type;
@@ -38,6 +42,7 @@
         mapper.text(boost::geometry::return_centroid<point_type>(g), out.str(),
                     "fill:rgb(0,0,0);font-family:Arial;font-size:10px");
     }
+#endif
 }
 
 // NOTE: convert manually from svg to png using Inkscape ctrl-shift-E

Modified: trunk/libs/geometry/doc/src/examples/algorithms/create_svg_two.hpp
==============================================================================
--- trunk/libs/geometry/doc/src/examples/algorithms/create_svg_two.hpp (original)
+++ trunk/libs/geometry/doc/src/examples/algorithms/create_svg_two.hpp 2011-04-03 03:50:11 EDT (Sun, 03 Apr 2011)
@@ -13,11 +13,15 @@
 
 #include <fstream>
 #include <boost/algorithm/string.hpp>
-#include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
+
+#if defined(HAVE_SVG)
+# include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
+#endif
 
 template <typename Geometry1, typename Geometry2>
 void create_svg(std::string const& filename, Geometry1 const& a, Geometry2 const& b)
 {
+#if defined(HAVE_SVG)
     std::cout << std::endl << "[$img/algorithms/" << boost::replace_all_copy(filename, ".svg", ".png") << "]" << std::endl << std::endl;
 
     typedef typename boost::geometry::point_type<Geometry1>::type point_type;
@@ -36,6 +40,7 @@
     {
         mapper.map(b, "opacity:0.8;fill:none;stroke:rgb(255,128,0);stroke-width:4;stroke-dasharray:1,7;stroke-linecap:round");
     }
+#endif
 }
 
 // NOTE: convert manually from svg to png using Inkscape ctrl-shift-E

Modified: trunk/libs/geometry/example/05_a_overlay_polygon_example.cpp
==============================================================================
--- trunk/libs/geometry/example/05_a_overlay_polygon_example.cpp (original)
+++ trunk/libs/geometry/example/05_a_overlay_polygon_example.cpp 2011-04-03 03:50:11 EDT (Sun, 03 Apr 2011)
@@ -21,7 +21,9 @@
 #include <boost/geometry/geometry.hpp>
 #include <boost/geometry/geometries/adapted/c_array_cartesian.hpp>
 
-#include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
+#if defined(HAVE_SVG)
+# include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
+#endif
 
 
 int main(void)
@@ -32,8 +34,10 @@
     typedef bg::model::polygon<point_2d> polygon_2d;
 
 
+#if defined(HAVE_SVG)
     std::ofstream stream("05_a_intersection_polygon_example.svg");
     bg::svg_mapper<point_2d> svg(stream, 500, 500);
+#endif
 
     // Define a polygons and fill the outer rings.
     polygon_2d a;
@@ -45,7 +49,6 @@
     }
     bg::correct(a);
     std::cout << "A: " << bg::dsv(a) << std::endl;
- svg.add(a);
 
     polygon_2d b;
     {
@@ -56,10 +59,13 @@
     }
     bg::correct(b);
     std::cout << "B: " << bg::dsv(b) << std::endl;
+#if defined(HAVE_SVG)
+ svg.add(a);
     svg.add(b);
 
     svg.map(a, "opacity:0.6;fill:rgb(0,255,0);");
     svg.map(b, "opacity:0.6;fill:rgb(0,0,255);");
+#endif
 
 
     // Calculate interesection(s)
@@ -70,7 +76,9 @@
     BOOST_FOREACH(polygon_2d const& polygon, intersection)
     {
         std::cout << bg::dsv(polygon) << std::endl;
+#if defined(HAVE_SVG)
         svg.map(polygon, "opacity:0.5;fill:none;stroke:rgb(255,0,0);stroke-width:6");
+#endif
     }
 
     return 0;

Modified: trunk/libs/geometry/example/05_b_overlay_linestring_polygon_example.cpp
==============================================================================
--- trunk/libs/geometry/example/05_b_overlay_linestring_polygon_example.cpp (original)
+++ trunk/libs/geometry/example/05_b_overlay_linestring_polygon_example.cpp 2011-04-03 03:50:11 EDT (Sun, 03 Apr 2011)
@@ -21,7 +21,9 @@
 #include <boost/geometry/geometry.hpp>
 #include <boost/geometry/geometries/adapted/c_array_cartesian.hpp>
 
-#include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
+#if defined(HAVE_SVG)
+# include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
+#endif
 
 
 int main(void)
@@ -43,6 +45,7 @@
     }
     bg::correct(p);
 
+#if defined(HAVE_SVG)
     // Create SVG-mapper
     std::ofstream stream("05_b_overlay_linestring_polygon_example.svg");
     bg::svg_mapper<point_2d> svg(stream, 500, 500);
@@ -52,7 +55,7 @@
     // Map geometries
     svg.map(ls, "opacity:0.6;stroke:rgb(255,0,0);stroke-width:2;");
     svg.map(p, "opacity:0.6;fill:rgb(0,0,255);");
-
+#endif
 
     // Calculate intersection points (turn points)
     typedef bg::detail::overlay::turn_info<point_2d> turn_info;
@@ -76,8 +79,10 @@
 
         }
         std::cout << action << " polygon at " << bg::dsv(turn.point) << std::endl;
+#if defined(HAVE_SVG)
         svg.map(turn.point, "fill:rgb(255,128,0);stroke:rgb(0,0,100);stroke-width:1");
         svg.text(turn.point, action, "fill:rgb(0,0,0);font-family:Arial;font-size:10px");
+#endif
     }
 
     return 0;

Modified: trunk/libs/geometry/example/06_b_transformation_example.cpp
==============================================================================
--- trunk/libs/geometry/example/06_b_transformation_example.cpp (original)
+++ trunk/libs/geometry/example/06_b_transformation_example.cpp 2011-04-03 03:50:11 EDT (Sun, 03 Apr 2011)
@@ -19,9 +19,12 @@
 #include <boost/geometry/algorithms/centroid.hpp>
 #include <boost/geometry/strategies/transform.hpp>
 #include <boost/geometry/strategies/transform/matrix_transformers.hpp>
-#include <boost/geometry/extensions/io/svg/write_svg.hpp>
 #include <boost/geometry/domains/gis/io/wkt/read_wkt.hpp>
 
+#if defined(HAVE_SVG)
+# include <boost/geometry/extensions/io/svg/write_svg.hpp>
+#endif
+
 #include <boost/bind.hpp>
 #include <boost/random.hpp>
 #include <boost/range.hpp>
@@ -84,8 +87,9 @@
     void put(G const& g, std::string const& label)
     {
         std::string style_str(style.fill(opacity) + style.stroke(5, opacity));
- os << ::boost::geometry::svg(g, style_str) << std::endl;
-
+#if defined(HAVE_SVG)
+ os << boost::geometry::svg(g, style_str) << std::endl;
+#endif
         if (!label.empty())
         {
             typename point_type<G>::type c;
@@ -101,6 +105,7 @@
     random_style style;
 };
 
+
 int main()
 {
     using namespace boost::geometry::strategy::transform;

Modified: trunk/libs/geometry/example/07_a_graph_route_example.cpp
==============================================================================
--- trunk/libs/geometry/example/07_a_graph_route_example.cpp (original)
+++ trunk/libs/geometry/example/07_a_graph_route_example.cpp 2011-04-03 03:50:11 EDT (Sun, 03 Apr 2011)
@@ -30,10 +30,12 @@
 // Yes, this example currently uses some extensions:
 
     // For output:
- #include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
+ #if defined(HAVE_SVG)
+ # include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
+ #endif
 
     // For distance-calculations over the Earth:
- #include <boost/geometry/extensions/gis/geographic/strategies/andoyer.hpp>
+ //#include <boost/geometry/extensions/gis/geographic/strategies/andoyer.hpp>
 
 
 
@@ -260,10 +262,11 @@
 
 int main()
 {
- // Define a point in the Geographic coordinate system
+ // Define a point in the Geographic coordinate system (currently Spherical)
+ // (geographic calculations are in an extension; for sample it makes no difference)
     typedef boost::geometry::model::point
         <
- double, 2, boost::geometry::cs::geographic<boost::geometry::degree>
+ double, 2, boost::geometry::cs::spherical<boost::geometry::degree>
> point_type;
 
     typedef boost::geometry::model::linestring<point_type> line_type;
@@ -302,8 +305,12 @@
     double const km = 1000.0;
     std::cout << "distances, all in KM" << std::endl
         << std::fixed << std::setprecision(0);
+
+ // To calculate distance, declare and construct a strategy with average earth radius
+ boost::geometry::strategy::distance::haversine<point_type> haversine(6372795.0);
 
     // Main functionality: calculate shortest routes from/to all cities
+
 
     // For the first one, the complete route is stored as a linestring
     bool first = true;
@@ -329,7 +336,7 @@
             if (! boost::equals(city1.get<1>(), city2.get<1>()))
             {
                 double distance = costs[city2.get<2>()] / km;
- double acof = boost::geometry::distance(city1.get<0>(), city2.get<0>()) / km;
+ double acof = boost::geometry::distance(city1.get<0>(), city2.get<0>(), haversine) / km;
 
                 std::cout
                     << std::setiosflags (std::ios_base::left) << std::setw(15)
@@ -351,6 +358,7 @@
         }
     }
 
+#if defined(HAVE_SVG)
     // Create the SVG
     std::ofstream stream("routes.svg");
     boost::geometry::svg_mapper<point_type> mapper(stream, 600, 600);
@@ -378,6 +386,7 @@
         mapper.text(city.get<0>(), city.get<1>(),
                 "fill:rgb(0,0,0);font-family:Arial;font-size:10px", 5, 5);
     }
+#endif
 
     return 0;
 }

Modified: trunk/libs/geometry/example/07_b_graph_route_example.cpp
==============================================================================
--- trunk/libs/geometry/example/07_b_graph_route_example.cpp (original)
+++ trunk/libs/geometry/example/07_b_graph_route_example.cpp 2011-04-03 03:50:11 EDT (Sun, 03 Apr 2011)
@@ -34,10 +34,12 @@
 // Yes, this example currently uses some extensions:
 
     // For output:
- #include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
+ #if defined(HAVE_SVG)
+ # include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
+ #endif
 
     // For distance-calculations over the Earth:
- #include <boost/geometry/extensions/gis/geographic/strategies/andoyer.hpp>
+ //#include <boost/geometry/extensions/gis/geographic/strategies/andoyer.hpp>
 
 
 
@@ -246,10 +248,11 @@
 
 int main()
 {
- // Define a point in the Geographic coordinate system
+ // Define a point in the Geographic coordinate system (currently Spherical)
+ // (geographic calculations are in an extension; for sample it makes no difference)
     typedef boost::geometry::model::point
         <
- double, 2, boost::geometry::cs::geographic<boost::geometry::degree>
+ double, 2, boost::geometry::cs::spherical<boost::geometry::degree>
> point_type;
 
     typedef boost::geometry::model::linestring<point_type> line_type;
@@ -291,6 +294,9 @@
     std::cout << "distances, all in KM" << std::endl
         << std::fixed << std::setprecision(0);
 
+ // To calculate distance, declare and construct a strategy with average earth radius
+ boost::geometry::strategy::distance::haversine<point_type> haversine(6372795.0);
+
     // Main functionality: calculate shortest routes from/to all cities
 
     // For the first one, the complete route is stored as a linestring
@@ -317,7 +323,7 @@
             if (! boost::equals(city1.get<1>(), city2.get<1>()))
             {
                 double distance = costs[city2.get<2>()] / km;
- double acof = boost::geometry::distance(city1.get<0>(), city2.get<0>()) / km;
+ double acof = boost::geometry::distance(city1.get<0>(), city2.get<0>(), haversine) / km;
 
                 std::cout
                     << std::setiosflags (std::ios_base::left) << std::setw(15)
@@ -339,6 +345,7 @@
         }
     }
 
+#if defined(HAVE_SVG)
     // Create the SVG
     std::ofstream stream("routes.svg");
     boost::geometry::svg_mapper<point_type> mapper(stream, 600, 600);
@@ -366,6 +373,7 @@
         mapper.text(city.get<0>(), city.get<1>(),
                 "fill:rgb(0,0,0);font-family:Arial;font-size:10px", 5, 5);
     }
+#endif
 
     return 0;
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk