|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r60609 - in sandbox/geometry/boost/geometry: core extensions/algorithms extensions/io/svg
From: barend.gehrels_at_[hidden]
Date: 2010-03-15 05:34:09
Author: barendgehrels
Date: 2010-03-15 05:34:08 EDT (Mon, 15 Mar 2010)
New Revision: 60609
URL: http://svn.boost.org/trac/boost/changeset/60609
Log:
Some stylistic changes, added optional SameScale paramter to mapper, added policy for remove_spikes
Text files modified:
sandbox/geometry/boost/geometry/core/point_type.hpp | 23 ++++++++----
sandbox/geometry/boost/geometry/extensions/algorithms/remove_spikes.hpp | 75 +++++++++++++++++++++++++++++++++++++--
sandbox/geometry/boost/geometry/extensions/io/svg/svg_mapper.hpp | 4 +-
3 files changed, 88 insertions(+), 14 deletions(-)
Modified: sandbox/geometry/boost/geometry/core/point_type.hpp
==============================================================================
--- sandbox/geometry/boost/geometry/core/point_type.hpp (original)
+++ sandbox/geometry/boost/geometry/core/point_type.hpp 2010-03-15 05:34:08 EDT (Mon, 15 Mar 2010)
@@ -17,9 +17,11 @@
#include <boost/geometry/core/tag.hpp>
#include <boost/geometry/core/tags.hpp>
-namespace boost { namespace geometry {
+namespace boost { namespace geometry
+{
-namespace traits {
+namespace traits
+{
/*!
\brief Traits class indicating the type of contained points
@@ -60,6 +62,7 @@
typedef Point type;
};
+
// Specializations for linestring/linear ring, via boost::range
template <typename Linestring>
struct point_type<linestring_tag, Linestring>
@@ -67,12 +70,14 @@
typedef typename boost::range_value<Linestring>::type type;
};
+
template <typename Ring>
struct point_type<ring_tag, Ring>
{
typedef typename boost::range_value<Ring>::type type;
};
+
// Specialization for polygon: the point-type is the point-type of its rings
template <typename Polygon>
struct point_type<polygon_tag, Polygon>
@@ -84,6 +89,7 @@
>::type type;
};
+
} // namespace core_dispatch
#endif // DOXYGEN_NO_DISPATCH
@@ -96,14 +102,15 @@
struct point_type
{
typedef typename boost::remove_const<Geometry>::type ncg;
- typedef typename core_dispatch::point_type<
- typename tag<Geometry>::type, ncg>::type type;
-
-
-
-
+ typedef typename core_dispatch::point_type
+ <
+ typename tag<Geometry>::type,
+ ncg
+ >::type type;
};
+
}} // namespace boost::geometry
+
#endif // BOOST_GEOMETRY_CORE_POINT_TYPE_HPP
Modified: sandbox/geometry/boost/geometry/extensions/algorithms/remove_spikes.hpp
==============================================================================
--- sandbox/geometry/boost/geometry/extensions/algorithms/remove_spikes.hpp (original)
+++ sandbox/geometry/boost/geometry/extensions/algorithms/remove_spikes.hpp 2010-03-15 05:34:08 EDT (Mon, 15 Mar 2010)
@@ -23,6 +23,10 @@
#include <boost/geometry/geometries/concepts/check.hpp>
#include <boost/geometry/strategies/side.hpp>
+#include <boost/geometry/algorithms/area.hpp>
+#include <boost/geometry/algorithms/distance.hpp>
+#include <boost/geometry/algorithms/perimeter.hpp>
+
#include <boost/geometry/iterators/ever_circling_iterator.hpp>
/*
@@ -33,7 +37,7 @@
| +--+
| | ^this "spike" is removed, can be located outside/inside the ring
+------+
-(the actualy determination if it is removed is done by a strategy, TODO)
+(the actualy determination if it is removed is done by a strategy)
*/
@@ -58,7 +62,6 @@
typedef typename coordinate_type<Range>::type coordinate_type;
-
static inline void apply(Range& range, Policy const& policy)
{
std::size_t n = boost::size(range);
@@ -83,7 +86,7 @@
std::deque<std::size_t> vertices;
for (std::size_t i = 0;
i < n;
- ++i, ++prev, ++it, ++next)
+ ++i, ++it, ++next)
{
if (policy(*prev, *it, *next))
{
@@ -95,6 +98,10 @@
close = true;
}
}
+ else
+ {
+ prev = it;
+ }
}
for (std::deque<std::size_t>::reverse_iterator rit = vertices.rbegin();
rit != vertices.rend(); ++rit)
@@ -287,7 +294,6 @@
*/
return remove;
-
}
}
return false;
@@ -295,6 +301,67 @@
};
+template <typename Point>
+struct remove_by_normalized
+{
+ typedef typename coordinate_type<Point>::type coordinate_type;
+ coordinate_type m_zero;
+
+ inline remove_by_normalized()
+ : m_zero(coordinate_type())
+ {}
+
+ inline bool operator()(Point const& prev,
+ Point const& current, Point const& next) const
+ {
+ coordinate_type x1 = get<0>(prev);
+ coordinate_type y1 = get<1>(prev);
+ coordinate_type x2 = get<0>(current);
+ coordinate_type y2 = get<1>(current);
+
+ coordinate_type dx1 = x2 - x1;
+ coordinate_type dy1 = y2 - y1;
+
+ // Duplicate points (can be created by removing spikes)
+ // can be removed as well. (Can be seen as a spike without length)
+ if (geometry::math::equals(dx1, 0) && geometry::math::equals(dy1, 0))
+ {
+ return true;
+ }
+
+ coordinate_type dx2 = get<0>(next) - x2;
+ coordinate_type dy2 = get<1>(next) - y2;
+
+ // If middle point is duplicate with next, also.
+ if (geometry::math::equals(dx2, 0) && geometry::math::equals(dy2, 0))
+ {
+ return true;
+ }
+
+ // Normalize the vectors -> this results in points+direction
+ // and is comparible between geometries
+ coordinate_type magnitude1 = sqrt(dx1 * dx1 + dy1 * dy1);
+ coordinate_type magnitude2 = sqrt(dx2 * dx2 + dy2 * dy2);
+
+ if (magnitude1 > m_zero && magnitude2 > m_zero)
+ {
+ dx1 /= magnitude1;
+ dy1 /= magnitude1;
+ dx2 /= magnitude2;
+ dy2 /= magnitude2;
+
+ // If the directions are opposite, it can be removed
+ //if (geometry::math::equals(dx1, -dx2) && geometry::math::equals(dy1, -dy2))
+ coordinate_type small(1e-7);
+ if (abs(dx1 + dx2) < small && abs(dy1 + dy2) < small)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+};
+
}} // namespace boost::geometry
Modified: sandbox/geometry/boost/geometry/extensions/io/svg/svg_mapper.hpp
==============================================================================
--- sandbox/geometry/boost/geometry/extensions/io/svg/svg_mapper.hpp (original)
+++ sandbox/geometry/boost/geometry/extensions/io/svg/svg_mapper.hpp 2010-03-15 05:34:08 EDT (Mon, 15 Mar 2010)
@@ -173,7 +173,7 @@
}
-template <typename P>
+template <typename P, bool SameScale = true>
class svg_mapper
{
typedef boost::geometry::strategy::transform::map_transformer
@@ -181,7 +181,7 @@
P,
boost::geometry::point_xy<int>,
true,
- true
+ SameScale
> transformer_type;
boost::geometry::box<P> bbox;
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