Ifdefed some examples for release branch

[SVN r70919]
This commit is contained in:
Barend Gehrels 2011-04-03 07:50:11 +00:00
parent 85810e3132
commit 1431123722
8 changed files with 67 additions and 22 deletions

View File

@ -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 @@ int main()
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 @@ int main()
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
;

View File

@ -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 @@ void create_svg(std::string const& filename, Geometry const& a, Geometry const&
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

View File

@ -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 @@ void create_svg(std::string const& filename, Geometry1 const& a, Geometry2 const
{
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

View File

@ -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 @@ int main(void)
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 @@ int main(void)
}
bg::correct(a);
std::cout << "A: " << bg::dsv(a) << std::endl;
svg.add(a);
polygon_2d b;
{
@ -56,10 +59,13 @@ int main(void)
}
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 @@ int main(void)
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;

View File

@ -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 @@ int main(void)
}
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 @@ int main(void)
// 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 @@ int main(void)
}
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;

View File

@ -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 @@ struct svg_output
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 @@ private:
random_style style;
};
int main()
{
using namespace boost::geometry::strategy::transform;

View File

@ -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 @@ inline void build_route(Graph const& graph,
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 @@ int main()
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 @@ int main()
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 @@ int main()
}
}
#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 @@ int main()
mapper.text(city.get<0>(), city.get<1>(),
"fill:rgb(0,0,0);font-family:Arial;font-size:10px", 5, 5);
}
#endif
return 0;
}

View File

@ -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 @@ inline void build_route(Graph const& graph,
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 @@ int main()
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 @@ int main()
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 @@ int main()
}
}
#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 @@ int main()
mapper.text(city.get<0>(), city.get<1>(),
"fill:rgb(0,0,0);font-family:Arial;font-size:10px", 5, 5);
}
#endif
return 0;
}