[buffer] create documentation about PointStrategy (buffer_circle)

add buffer_square as alternative
This commit is contained in:
Barend Gehrels 2014-07-19 14:36:39 +02:00
parent cebad2e20c
commit 46068123b9
13 changed files with 265 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -114,5 +114,8 @@
[import src/examples/io/wkt.cpp]
[import src/examples/io/read_wkt.cpp]
[import src/examples/strategies/buffer_circle.cpp]
[import src/examples/strategies/buffer_square.cpp]
[import src/examples/views/box_view.cpp]
[import src/examples/views/segment_view.cpp]

View File

@ -115,6 +115,7 @@ strategies = ["distance::pythagoras", "distance::pythagoras_box_box"
, "distance::cross_track", "distance::projected_point"
, "within::winding", "within::franklin", "within::crossings_multiply"
, "area::surveyor", "area::huiller"
, "buffer::buffer_circle", "buffer::buffer_square"
, "centroid::bashein_detmer", "centroid::average"
, "convex_hull::graham_andrew"
, "simplify::douglas_peucker"

View File

@ -300,6 +300,8 @@
[include generated/distance_cross_track.qbk]
[include generated/area_surveyor.qbk]
[include generated/area_huiller.qbk]
[include generated/buffer_buffer_circle.qbk]
[include generated/buffer_buffer_square.qbk]
[include generated/centroid_average.qbk]
[include generated/centroid_bashein_detmer.qbk]
[include generated/convex_hull_graham_andrew.qbk]

View File

@ -15,7 +15,6 @@
[heading Examples]
[buffer_with_strategies]
[heading The linestring case]
[$img/algorithms/buffer_linestring.png]
@ -24,3 +23,7 @@
[heading The multi_polygon case]
[$img/algorithms/buffer_multi_polygon.png]
[heading Available Strategies]
* PointStrategy: [link geometry.reference.strategies.strategy_buffer_buffer_circle Circle (cartesian)]
* PointStrategy: [link geometry.reference.strategies.strategy_buffer_buffer_square Square (cartesian)]

View File

@ -19,4 +19,5 @@ build-project algorithms ;
build-project core ;
build-project geometries ;
build-project io ;
build-project strategies ;
build-project views ;

View File

@ -0,0 +1,15 @@
# Boost.Geometry (aka GGL, Generic Geometry Library)
#
# Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
# Use, modification and distribution is subject to the Boost Software License,
# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
project boost-geometry-doc-example-strategies
: # requirements
;
exe buffer_circle : buffer_circle.cpp ;
exe buffer_square : buffer_square.cpp ;

View File

@ -0,0 +1,53 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// QuickBook Example
// Copyright (c) 2014 Barend Gehrels, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//[buffer_circle
//` Shows how the buffer_circle strategy can be used as a PointStrategy to create circular buffers around points
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/geometries.hpp>
/*<-*/ #include "../examples_utils/create_svg_buffer.hpp" /*->*/
int main()
{
typedef double coordinate_type;
typedef boost::geometry::model::d2::point_xy<coordinate_type> point;
typedef boost::geometry::model::polygon<point> polygon;
// Declare the buffer_circle strategy
const int points_per_circle = 360;
boost::geometry::strategy::buffer::buffer_circle circle_strategy(points_per_circle);
// Declare other strategies
const double buffer_distance = 0.7;
boost::geometry::strategy::buffer::distance_symmetric<coordinate_type> distance_strategy(buffer_distance);
boost::geometry::strategy::buffer::join_round join_strategy(points_per_circle);
boost::geometry::strategy::buffer::end_round end_strategy(points_per_circle);
boost::geometry::strategy::buffer::buffer_side side_strategy;
// Declare output
boost::geometry::model::multi_polygon<polygon> result;
// Declare/fill of a multi point
boost::geometry::model::multi_point<point> mp;
boost::geometry::read_wkt("MULTIPOINT((3 3),(3 4),(4 4),(7 3))", mp);
// Create the buffer of a multi point
boost::geometry::buffer(mp, result,
distance_strategy, side_strategy,
join_strategy, end_strategy, circle_strategy);
/*<-*/ create_svg_buffer("buffer_circle.svg", mp, result); /*->*/
return 0;
}
//]

View File

@ -0,0 +1,53 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// QuickBook Example
// Copyright (c) 2014 Barend Gehrels, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//[buffer_square
//` Shows how the buffer_square strategy can be used as a PointStrategy to create square buffers where the original point lies in the center
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/geometries.hpp>
/*<-*/ #include "../examples_utils/create_svg_buffer.hpp" /*->*/
int main()
{
typedef double coordinate_type;
typedef boost::geometry::model::d2::point_xy<coordinate_type> point;
typedef boost::geometry::model::polygon<point> polygon;
// Declare the buffer_square strategy
boost::geometry::strategy::buffer::buffer_square square_strategy;
// Declare other strategies
const int points_per_circle = 36;
const double buffer_distance = 0.5;
boost::geometry::strategy::buffer::distance_symmetric<coordinate_type> distance_strategy(buffer_distance);
boost::geometry::strategy::buffer::join_round join_strategy(points_per_circle);
boost::geometry::strategy::buffer::end_round end_strategy(points_per_circle);
boost::geometry::strategy::buffer::buffer_side side_strategy;
// Declare output
boost::geometry::model::multi_polygon<polygon> result;
// Declare/fill of a multi point
boost::geometry::model::multi_point<point> mp;
boost::geometry::read_wkt("MULTIPOINT((3 3),(3 4),(4 4),(7 3))", mp);
// Create the buffer of a multi point
boost::geometry::buffer(mp, result,
distance_strategy, side_strategy,
join_strategy, end_strategy, square_strategy);
/*<-*/ create_svg_buffer("buffer_square.svg", mp, result); /*->*/
return 0;
}
//]

View File

@ -22,14 +22,38 @@ namespace boost { namespace geometry
namespace strategy { namespace buffer
{
// Strategy to create a buffer around a point using a specified amount of points
/*!
\brief Create a circular buffer around a point
\ingroup strategies
\details This strategy can be used as PointStrategy for the buffer algorithm.
It creates a circular buffer around a point. It can be applied
for points and multi_points, but also for a linestring (if it is degenerate,
so consisting of only one point) and for polygons (if it is degenerate).
This strategy is only applicable for Cartesian coordinate systems.
\qbk{
[heading Example]
[buffer_circle]
[heading Output]
[$img/strategies/buffer_circle.png]
[heading See also]
\* [link geometry.reference.algorithms.buffer.buffer_7_with_strategies buffer (with strategies)]
}
*/
class buffer_circle
{
public :
//! Constructs the strategy with default number of points (90)
buffer_circle()
: m_count(90)
{}
//! Constructs the strategy specifying the nuber of points
explicit buffer_circle(std::size_t count)
: m_count(count)
{}
//! Fills output_range with a circle around point using distance_strategy
template
<
typename Point,

View File

@ -0,0 +1,107 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2012-2014 Barend Gehrels, Amsterdam, the Netherlands.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_SQUARE_HPP
#define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_SQUARE_HPP
#include <cstddef>
#include <boost/range.hpp>
#include <boost/geometry/util/math.hpp>
#include <boost/geometry/strategies/buffer.hpp>
namespace boost { namespace geometry
{
namespace strategy { namespace buffer
{
/*!
\brief Create a squared form buffer around a point
\ingroup strategies
\details This strategy can be used as PointStrategy for the buffer algorithm.
It creates a square from each point, where the point lies in the center.
It can be applied for points and multi_points, but also for a linestring (if it is degenerate,
so consisting of only one point) and for polygons (if it is degenerate).
This strategy is only applicable for Cartesian coordinate systems.
\qbk{
[heading Example]
[buffer_square]
[heading Output]
[$img/strategies/buffer_square.png]
[heading See also]
\* [link geometry.reference.algorithms.buffer.buffer_7_with_strategies buffer (with strategies)]
}
*/
class buffer_square
{
private :
template
<
typename Point,
typename DistanceType,
typename OutputRange
>
inline void add_point(Point const& point,
DistanceType const& distance,
DistanceType const& x,
DistanceType const& y,
OutputRange& output_range) const
{
typename boost::range_value<OutputRange>::type p;
set<0>(p, get<0>(point) + x * distance);
set<1>(p, get<1>(point) + y * distance);
output_range.push_back(p);
}
template
<
typename Point,
typename DistanceType,
typename OutputRange
>
inline void add_points(Point const& point,
DistanceType const& distance,
OutputRange& output_range) const
{
add_point(point, distance, -1.0, -1.0, output_range);
add_point(point, distance, -1.0, +1.0, output_range);
add_point(point, distance, +1.0, +1.0, output_range);
add_point(point, distance, +1.0, -1.0, output_range);
// Close it:
output_range.push_back(output_range.front());
}
public :
//! Fills output_range with a square around point using distance_strategy
template
<
typename Point,
typename DistanceStrategy,
typename OutputRange
>
inline void apply(Point const& point,
DistanceStrategy const& distance_strategy,
OutputRange& output_range) const
{
add_points(point, distance_strategy.apply(point, point,
strategy::buffer::buffer_side_left), output_range);
}
};
}} // namespace strategy::buffer
}} // namespace boost::geometry
#endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_BUFFER_SQUARE_HPP

View File

@ -42,6 +42,7 @@
#include <boost/geometry/strategies/cartesian/buffer_join_round.hpp>
#include <boost/geometry/strategies/cartesian/buffer_join_round_by_divide.hpp>
#include <boost/geometry/strategies/cartesian/buffer_side.hpp>
#include <boost/geometry/strategies/cartesian/buffer_square.hpp>
#include <boost/geometry/strategies/cartesian/centroid_average.hpp>
#include <boost/geometry/strategies/cartesian/centroid_bashein_detmer.hpp>
#include <boost/geometry/strategies/cartesian/centroid_weighted_length.hpp>