Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r68755 - in sandbox-branches/geometry/index_080/boost/geometry/extensions/index: filters rtree translator
From: adam.wulkiewicz_at_[hidden]
Date: 2011-02-09 18:23:21


Author: awulkiew
Date: 2011-02-09 18:23:19 EST (Wed, 09 Feb 2011)
New Revision: 68755
URL: http://svn.boost.org/trac/boost/changeset/68755

Log:
types changed in rtree, filters added, translators added
Added:
   sandbox-branches/geometry/index_080/boost/geometry/extensions/index/filters/
   sandbox-branches/geometry/index_080/boost/geometry/extensions/index/filters/nearest_filter.hpp (contents, props changed)
   sandbox-branches/geometry/index_080/boost/geometry/extensions/index/filters/spacial_filter.hpp (contents, props changed)
   sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/filters.hpp (contents, props changed)
   sandbox-branches/geometry/index_080/boost/geometry/extensions/index/translator/
   sandbox-branches/geometry/index_080/boost/geometry/extensions/index/translator/def.hpp (contents, props changed)
   sandbox-branches/geometry/index_080/boost/geometry/extensions/index/translator/helpers.hpp (contents, props changed)
   sandbox-branches/geometry/index_080/boost/geometry/extensions/index/translator/index.hpp (contents, props changed)
Text files modified:
   sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/helpers.hpp | 59 ++++++++++++++++++++++-----------------
   sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/rtree.hpp | 23 ++++++++++----
   sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/rtree_node.hpp | 18 ++++++++----
   3 files changed, 61 insertions(+), 39 deletions(-)

Added: sandbox-branches/geometry/index_080/boost/geometry/extensions/index/filters/nearest_filter.hpp
==============================================================================
--- (empty file)
+++ sandbox-branches/geometry/index_080/boost/geometry/extensions/index/filters/nearest_filter.hpp 2011-02-09 18:23:19 EST (Wed, 09 Feb 2011)
@@ -0,0 +1,78 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+//
+// Boost.SpatialIndex - nearest neighbour filter implementation
+//
+// Copyright 2011 Adam Wulkiewicz.
+// 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_EXTENSIONS_INDEX_FILTERS_NEAREST_FILTER_HPP
+#define BOOST_GEOMETRY_EXTENSIONS_INDEX_FILTERS_NEAREST_FILTER_HPP
+
+namespace boost { namespace geometry { namespace index { namespace filters {
+
+template <typename SpacialIndex>
+class nearest_filter
+{
+public:
+ typedef int* iterator;
+ typedef const int* const_iterator;
+
+ template <typename Point>
+ nearest_filter(
+ SpacialIndex const&,
+ Point const&,
+ typename traits::coordinate_type<Point>::type const&
+ )
+ {}
+
+ iterator begin() { return 0; }
+ iterator end() { return 0; }
+ const_iterator begin() const { return 0; }
+ const_iterator end() const { return 0; }
+};
+
+namespace detail {
+
+template<typename Point>
+class nearest_filtered
+{
+public:
+ explicit nearest_filtered(
+ Point const& p,
+ typename traits::coordinate_type<Point>::type const& distance)
+ : m_point(p), m_distance(distance) {}
+
+ Point const& point() const { return m_point; }
+
+ typename traits::coordinate_type<Point>::type const&
+ distance() const { return m_distance; }
+
+private:
+ Point m_point;
+ typename traits::coordinate_type<Point>::type m_distance;
+};
+
+} // namespace detail
+
+template <typename Point>
+detail::nearest_filtered<Point> nearest_filtered(
+ Point const& p,
+ typename traits::coordinate_type<Point>::type const& distance)
+{
+ return detail::nearest_filtered<Point>(p, distance);
+}
+
+}}}} // namespace boost::geometry::index::filters
+
+template<typename SpacialIndex, typename Point>
+boost::geometry::index::filters::nearest_filter<SpacialIndex>
+ operator|(
+ SpacialIndex const& si,
+ boost::geometry::index::filters::detail::nearest_filtered<Point> const& f)
+{
+ return boost::geometry::index::filters::nearest_filter<SpacialIndex>(si, f.point(), f.distance());
+}
+
+#endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_FILTERS_NEAREST_FILTER_HPP

Added: sandbox-branches/geometry/index_080/boost/geometry/extensions/index/filters/spacial_filter.hpp
==============================================================================
--- (empty file)
+++ sandbox-branches/geometry/index_080/boost/geometry/extensions/index/filters/spacial_filter.hpp 2011-02-09 18:23:19 EST (Wed, 09 Feb 2011)
@@ -0,0 +1,63 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+//
+// Boost.SpatialIndex - box query filter implementation
+//
+// Copyright 2011 Adam Wulkiewicz.
+// 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_EXTENSIONS_INDEX_FILTERS_SPACIAL_FILTER_HPP
+#define BOOST_GEOMETRY_EXTENSIONS_INDEX_FILTERS_SPACIAL_FILTER_HPP
+
+namespace boost { namespace geometry { namespace index { namespace filters {
+
+template <typename SpacialIndex>
+class spatial_filter
+{
+public:
+ typedef int* iterator;
+ typedef const int* const_iterator;
+
+ template <typename Box>
+ spatial_filter(SpacialIndex const&, Box const&) {}
+
+ iterator begin() { return 0; }
+ iterator end() { return 0; }
+ const_iterator begin() const { return 0; }
+ const_iterator end() const { return 0; }
+};
+
+namespace detail {
+
+template<typename Box>
+class spatially_filtered
+{
+public:
+ explicit spatially_filtered(Box const& b) : m_box(b) {}
+ Box const& box() const { return m_box; }
+
+private:
+ Box m_box;
+};
+
+} // namespace detail
+
+template <typename Box>
+detail::spatially_filtered<Box> spatially_filtered(Box const& b)
+{
+ return detail::spatially_filtered<Box>(b);
+}
+
+}}}} // namespace boost::geometry::index::filters
+
+template<typename SpacialIndex, typename Box>
+boost::geometry::index::filters::spatial_filter<SpacialIndex>
+operator|(
+ SpacialIndex const& si,
+ boost::geometry::index::filters::detail::spatially_filtered<Box> const& f)
+{
+ return boost::geometry::index::filters::spatial_filter<SpacialIndex>(si, f.box());
+}
+
+#endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_FILTERS_SPACIAL_FILTER_HPP

Added: sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/filters.hpp
==============================================================================
--- (empty file)
+++ sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/filters.hpp 2011-02-09 18:23:19 EST (Wed, 09 Feb 2011)
@@ -0,0 +1,118 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+//
+// Boost.SpatialIndex - rtree queries filters implementation
+//
+// Copyright 2011 Adam Wulkiewicz.
+// 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_EXTENSIONS_INDEX_RTREE_FILTERS_HPP
+#define BOOST_GEOMETRY_EXTENSIONS_INDEX_RTREE_FILTERS_HPP
+
+#include <boost/static_assert.hpp>
+
+#include <boost/geometry/extensions/index/rtree/rtree.hpp>
+#include <boost/geometry/extensions/index/filters/spacial_filter.hpp>
+#include <boost/geometry/extensions/index/filters/nearest_filter.hpp>
+
+namespace boost { namespace geometry { namespace index { namespace filters {
+
+template <typename Box, typename Value>
+class spatial_filter< index::rtree<Box, Value> >
+{
+public:
+ typedef typename std::deque<Value>::iterator iterator;
+ typedef typename std::deque<Value>::const_iterator const_iterator;
+
+ spatial_filter(index::rtree<Box, Value> const& rtree, Box const& b)
+ {
+ m_result = rtree.find(b);
+ }
+
+ iterator begin() { return m_result.begin(); }
+ iterator end() { return m_result.end(); }
+ const_iterator begin() const { return m_result.begin(); }
+ const_iterator end() const { return m_result.end(); }
+
+private:
+ std::deque<Value> m_result;
+};
+
+namespace detail {
+
+template <typename Box, size_t D>
+struct sphere_to_min_max
+{
+ BOOST_STATIC_ASSERT(0 < D);
+
+ static void apply(
+ typename traits::point_type<Box>::type & min_point,
+ typename traits::point_type<Box>::type & max_point,
+ typename traits::point_type<Box>::type const& centre,
+ typename traits::coordinate_type<typename traits::point_type<Box>::type>::type const& radius
+ )
+ {
+ geometry::set<D - 1>(min_point, geometry::get<D - 1>(centre) - radius);
+ geometry::set<D - 1>(max_point, geometry::get<D - 1>(centre) + radius);
+
+ sphere_to_min_max<Box, D - 1>::apply(min_point, max_point, centre, radius);
+ }
+};
+
+template <typename Box>
+struct sphere_to_min_max<Box, 1>
+{
+ static void apply(
+ typename traits::point_type<Box>::type & min_point,
+ typename traits::point_type<Box>::type & max_point,
+ typename traits::point_type<Box>::type const& centre,
+ typename traits::coordinate_type<typename traits::point_type<Box>::type>::type const& radius
+ )
+ {
+ geometry::set<0>(min_point, geometry::get<0>(centre) - radius);
+ geometry::set<0>(max_point, geometry::get<0>(centre) + radius);
+ }
+};
+
+} // namespace detail
+
+// TODO
+// implement final version of nearest filter
+// range should be sorted (for Boxes - by closest corner)
+
+template <typename Box, typename Value>
+class nearest_filter< index::rtree<Box, Value> >
+{
+public:
+ typedef typename std::deque<Value>::iterator iterator;
+ typedef typename std::deque<Value>::const_iterator const_iterator;
+
+ template <typename Point>
+ nearest_filter(
+ index::rtree<Box, Value> const& rtree,
+ Point const& box_centre,
+ typename traits::coordinate_type<Point>::type const& radius
+ )
+ {
+ typename traits::point_type<Box>::type pmin, pmax;
+ detail::sphere_to_min_max<
+ Box,
+ traits::dimension<typename traits::point_type<Box>::type>::value
+ >::apply(pmin, pmax, box_centre, radius);
+
+ m_result = rtree.find(Box(pmin, pmax));
+ }
+
+ iterator begin() { return m_result.begin(); }
+ iterator end() { return m_result.end(); }
+ const_iterator begin() const { return m_result.begin(); }
+ const_iterator end() const { return m_result.end(); }
+
+private:
+ std::deque<Value> m_result;
+};
+
+}}}} // namespace boost::geometry::index::filters
+
+#endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_RTREE_FILTERS_HPP

Modified: sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/helpers.hpp
==============================================================================
--- sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/helpers.hpp (original)
+++ sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/helpers.hpp 2011-02-09 18:23:19 EST (Wed, 09 Feb 2011)
@@ -7,41 +7,45 @@
 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
-#ifndef BOOST_GEOMETRY_GGL_INDEX_RTREE_HELPERS_HPP
-#define BOOST_GEOMETRY_GGL_INDEX_RTREE_HELPERS_HPP
+#ifndef BOOST_GEOMETRY_EXTENSIONS_INDEX_RTREE_HELPERS_HPP
+#define BOOST_GEOMETRY_EXTENSIONS_INDEX_RTREE_HELPERS_HPP
 
 #include <boost/geometry/algorithms/area.hpp>
 #include <boost/geometry/algorithms/disjoint.hpp>
 #include <boost/geometry/core/point_type.hpp>
 
+// awulkiew - added
+#include <boost/geometry/algorithms/combine.hpp>
+
 namespace boost { namespace geometry { namespace index {
 
 /**
  * \brief Given two boxes, returns the minimal box that contains them
  */
 // TODO: use geometry::combine
-template <typename Box>
-inline Box enlarge_box(Box const& b1, Box const& b2)
-{
- // TODO: mloskot - Refactor to readable form. Fix VC++8.0 min/max warnings:
- // warning C4002: too many actual parameters for macro 'min
-
- typedef typename geometry::point_type<Box>::type point_type;
-
- point_type pmin(
- geometry::get<min_corner, 0>(b1) < geometry::get<min_corner, 0>(b2)
- ? geometry::get<min_corner, 0>(b1) : geometry::get<min_corner, 0>(b2),
- geometry::get<min_corner, 1>(b1) < geometry::get<min_corner, 1>(b2)
- ? geometry::get<min_corner, 1>(b1) : geometry::get<min_corner, 1>(b2));
-
- point_type pmax(
- geometry::get<max_corner, 0>(b1) > geometry::get<max_corner, 0>(b2)
- ? geometry::get<max_corner, 0>(b1) : geometry::get<max_corner, 0>(b2),
- geometry::get<max_corner, 1>(b1) > geometry::get<max_corner, 1>(b2)
- ? geometry::get<max_corner, 1>(b1) : geometry::get<max_corner, 1>(b2));
-
- return Box(pmin, pmax);
-}
+// awulkiew - geometry::combine used
+//template <typename Box>
+//inline Box enlarge_box(Box const& b1, Box const& b2)
+//{
+// // TODO: mloskot - Refactor to readable form. Fix VC++8.0 min/max warnings:
+// // warning C4002: too many actual parameters for macro 'min
+//
+// typedef typename geometry::point_type<Box>::type point_type;
+//
+// point_type pmin(
+// geometry::get<min_corner, 0>(b1) < geometry::get<min_corner, 0>(b2)
+// ? geometry::get<min_corner, 0>(b1) : geometry::get<min_corner, 0>(b2),
+// geometry::get<min_corner, 1>(b1) < geometry::get<min_corner, 1>(b2)
+// ? geometry::get<min_corner, 1>(b1) : geometry::get<min_corner, 1>(b2));
+//
+// point_type pmax(
+// geometry::get<max_corner, 0>(b1) > geometry::get<max_corner, 0>(b2)
+// ? geometry::get<max_corner, 0>(b1) : geometry::get<max_corner, 0>(b2),
+// geometry::get<max_corner, 1>(b1) > geometry::get<max_corner, 1>(b2)
+// ? geometry::get<max_corner, 1>(b1) : geometry::get<max_corner, 1>(b2));
+//
+// return Box(pmin, pmax);
+//}
 
 /**
  * \brief Compute the area of the union of b1 and b2
@@ -49,7 +53,10 @@
 template <typename Box>
 inline typename area_result<Box>::type compute_union_area(Box const& b1, Box const& b2)
 {
- Box enlarged_box = enlarge_box(b1, b2);
+ //Box enlarged_box = enlarge_box(b1, b2);
+ // awulkiew - changed to geometry::combine
+ Box enlarged_box(b1);
+ geometry::combine(enlarged_box, b2);
     return geometry::area(enlarged_box);
 }
 
@@ -65,4 +72,4 @@
 
 }}} // namespace boost::geometry::index
 
-#endif // BOOST_GEOMETRY_GGL_INDEX_RTREE_HELPERS_HPP
+#endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_RTREE_HELPERS_HPP

Modified: sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/rtree.hpp
==============================================================================
--- sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/rtree.hpp (original)
+++ sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/rtree.hpp 2011-02-09 18:23:19 EST (Wed, 09 Feb 2011)
@@ -467,9 +467,14 @@
                     b2 = n2->compute_box();
 
                     /// areas
- typedef typename coordinate_type<Box>::type coordinate_type;
- coordinate_type b1_area, b2_area;
- coordinate_type eb1_area, eb2_area;
+ // awulkiew - areas types changed
+ //typedef typename coordinate_type<Box>::type coordinate_type;
+ //coordinate_type b1_area, b2_area;
+ //coordinate_type eb1_area, eb2_area;
+ typedef typename area_result<Box>::type area_type;
+ area_type b1_area, b2_area;
+ area_type eb1_area, eb2_area;
+
                     b1_area = geometry::area(b1);
                     b2_area = geometry::area(b2);
                     eb1_area = compute_union_area(b1, it->first);
@@ -543,12 +548,16 @@
                     b2 = n2->compute_box();
 
                     /// areas
- typedef typename coordinate_type<Box>::type coordinate_type;
- coordinate_type b1_area, b2_area;
- coordinate_type eb1_area, eb2_area;
+ // awulkiew - areas types changed
+ //typedef typename coordinate_type<Box>::type coordinate_type;
+ //coordinate_type b1_area, b2_area;
+ //coordinate_type eb1_area, eb2_area;
+ typedef typename area_result<Box>::type area_type;
+ area_type b1_area, b2_area;
+ area_type eb1_area, eb2_area;
+
                     b1_area = geometry::area(b1);
                     b2_area = geometry::area(b2);
-
                     eb1_area = compute_union_area(b1, it->first);
                     eb2_area = compute_union_area(b2, it->first);
 

Modified: sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/rtree_node.hpp
==============================================================================
--- sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/rtree_node.hpp (original)
+++ sandbox-branches/geometry/index_080/boost/geometry/extensions/index/rtree/rtree_node.hpp 2011-02-09 18:23:19 EST (Wed, 09 Feb 2011)
@@ -289,19 +289,25 @@
             throw std::logic_error("Empty node trying to choose the least enlargement node.");
         }
 
- typedef typename coordinate_type<Box>::type coordinate_type;
+ // awulkiew - areas types changed
+ //typedef typename coordinate_type<Box>::type coordinate_type;
+ typedef typename area_result<Box>::type area_type;
 
         bool first = true;
- coordinate_type min_area = 0;
- coordinate_type min_diff_area = 0;
+ //coordinate_type min_area = 0;
+ area_type min_area = 0;
+ //coordinate_type min_diff_area = 0;
+ area_type min_diff_area = 0;
         node_pointer chosen_node;
 
         // check for the least enlargement
         for (typename node_map::const_iterator it = m_nodes.begin(); it != m_nodes.end(); ++it)
         {
- coordinate_type const
- diff_area = coordinate_type(compute_union_area(box, it->first))
- - geometry::area(it->first);
+ // awulkiew - areas types changed
+ //coordinate_type const
+ // diff_area = coordinate_type(compute_union_area(box, it->first))
+ // - geometry::area(it->first);
+ area_type const diff_area = compute_union_area(box, it->first) - geometry::area(it->first);
 
             if (first)
             {

Added: sandbox-branches/geometry/index_080/boost/geometry/extensions/index/translator/def.hpp
==============================================================================
--- (empty file)
+++ sandbox-branches/geometry/index_080/boost/geometry/extensions/index/translator/def.hpp 2011-02-09 18:23:19 EST (Wed, 09 Feb 2011)
@@ -0,0 +1,83 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+//
+// Boost.SpatialIndex - default value to bounding object translation
+//
+// Copyright 2011 Adam Wulkiewicz.
+// 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_EXTENSIONS_INDEX_TRANSLATOR_DEF_HPP
+#define BOOST_GEOMETRY_EXTENSIONS_INDEX_TRANSLATOR_DEF_HPP
+
+#include <boost/geometry/extensions/index/translator/helpers.hpp>
+
+namespace boost { namespace geometry { namespace index { namespace translator {
+
+namespace dispatch {
+
+// Distinguish between def<Geometry>, def<Iterator> and def<SmartPtr>
+
+// Geometry
+template <typename Value, bool IsIterator, bool IsSmartPtr>
+struct def
+{
+ typedef typename detail::extract_bounding_geometry<Value>::type bounding_geometry_type;
+
+ bounding_geometry_type const& operator()(Value const& v) const
+ {
+ return detail::extract_bounding_geometry<Value>::get(v);
+ }
+};
+
+// Iterator
+template <typename Value, bool IsSmartPtr>
+struct def<Value, true, IsSmartPtr>
+{
+ typedef typename detail::extract_bounding_geometry<typename Value::value_type>::type bounding_geometry_type;
+
+ bounding_geometry_type const& operator()(Value const& v) const
+ {
+ return detail::extract_bounding_geometry<typename Value::value_type>::get(*v);
+ }
+};
+
+// SmartPtr
+template <typename Value>
+struct def<Value, false, true>
+{
+ typedef typename detail::extract_bounding_geometry<typename Value::element_type>::type bounding_geometry_type;
+
+ bounding_geometry_type const& operator()(Value const& v) const
+ {
+ return detail::extract_bounding_geometry<typename Value::element_type>::get(*v);
+ }
+};
+
+} // namespace dispatch
+
+template <typename Value>
+struct def
+ : public dispatch::def
+ <
+ Value,
+ detail::is_iterator<Value>::value,
+ detail::is_smart_ptr<Value>::value
+ >
+{
+};
+
+template <typename Value>
+struct def<Value*>
+{
+ typedef typename detail::extract_bounding_geometry<Value>::type bounding_geometry_type;
+
+ bounding_geometry_type const& operator()(const Value *v) const
+ {
+ return detail::extract_bounding_geometry<Value>::get(*v);
+ }
+};
+
+}}}} // namespace boost::geometry::index::translator
+
+#endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_TRANSLATOR_DEF_HPP

Added: sandbox-branches/geometry/index_080/boost/geometry/extensions/index/translator/helpers.hpp
==============================================================================
--- (empty file)
+++ sandbox-branches/geometry/index_080/boost/geometry/extensions/index/translator/helpers.hpp 2011-02-09 18:23:19 EST (Wed, 09 Feb 2011)
@@ -0,0 +1,164 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+//
+// Boost.SpatialIndex - translators helper functions
+//
+// Copyright 2011 Adam Wulkiewicz.
+// 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_EXTENSIONS_INDEX_TRANSLATOR_HELPERS_HPP
+#define BOOST_GEOMETRY_EXTENSIONS_INDEX_TRANSLATOR_HELPERS_HPP
+
+#include <utility>
+
+#include <boost/static_assert.hpp>
+
+#include <boost/mpl/has_xxx.hpp>
+#include <boost/mpl/and.hpp>
+
+namespace boost { namespace geometry { namespace index { namespace translator {
+
+namespace dispatch {
+
+// Distinguish between bounding geometries and other geometries
+
+template <typename Geometry, typename GeometryTag>
+struct bounding_geometry
+{
+ typedef void type;
+};
+
+template <typename Point>
+struct bounding_geometry<Point, geometry::point_tag>
+{
+ typedef Point type;
+};
+
+template <typename Box>
+struct bounding_geometry<Box, geometry::box_tag>
+{
+ typedef Box type;
+};
+
+// Extract object from std::pair by non-void tag
+
+template <typename Pair, typename FirstTag, typename SecondTag>
+struct choose_pair_element
+{
+ typedef typename Pair::first_type type;
+ static type const& get(Pair const& p) { return p.first; }
+};
+
+template <typename Pair, typename FirstTag>
+struct choose_pair_element<Pair, FirstTag, void>
+{
+ typedef typename Pair::first_type type;
+ static type const& get(Pair const& p) { return p.first; }
+};
+
+template <typename Pair, typename Second>
+struct choose_pair_element<Pair, void, Second>
+{
+ typedef typename Pair::second_type type;
+ static type const& get(Pair const& p) { return p.second; }
+};
+
+template <typename Pair>
+struct choose_pair_element<Pair, void, void>
+{
+ typedef void type;
+};
+
+} // namespace dispatch
+
+namespace detail {
+
+template <typename T>
+struct bounding_object_not_found_error
+{
+ static const bool value = false;
+};
+template <>
+struct bounding_object_not_found_error<void>
+{
+ static const bool value = true;
+};
+
+// Extract bounding geometry object
+
+template <typename Value>
+struct extract_bounding_geometry
+{
+ typedef typename dispatch::bounding_geometry<
+ Value,
+ typename geometry::traits::tag<Value>::type
+ >::type type;
+
+ BOOST_STATIC_ASSERT(!bounding_object_not_found_error<type>::value);
+
+ static type const& get(Value const& v) { return v; }
+};
+
+template <typename First, typename Second>
+struct extract_bounding_geometry< std::pair<First, Second> >
+{
+ typedef typename dispatch::choose_pair_element<
+ std::pair<First, Second>,
+ typename dispatch::bounding_geometry<
+ First,
+ typename geometry::traits::tag<First>::type
+ >::type,
+ typename dispatch::bounding_geometry<
+ Second,
+ typename geometry::traits::tag<Second>::type
+ >::type
+ > cp;
+
+ typedef typename cp::type type;
+
+ BOOST_STATIC_ASSERT(!bounding_object_not_found_error<type>::value);
+
+ static type const& get(std::pair<First, Second> const& v)
+ {
+ return cp::get(v);
+ }
+};
+
+// Recognize iterators and smart pointers
+
+BOOST_MPL_HAS_XXX_TRAIT_DEF(iterator_category)
+BOOST_MPL_HAS_XXX_TRAIT_DEF(value_type)
+BOOST_MPL_HAS_XXX_TRAIT_DEF(difference_type)
+BOOST_MPL_HAS_XXX_TRAIT_DEF(pointer)
+BOOST_MPL_HAS_XXX_TRAIT_DEF(reference)
+
+BOOST_MPL_HAS_XXX_TRAIT_DEF(element_type)
+
+// TODO
+// use has_operator_xxx in the future
+
+template <typename T>
+struct is_iterator
+{
+ static const bool value = boost::mpl::and_
+ <
+ has_iterator_category<T>,
+ has_value_type<T>,
+ has_difference_type<T>,
+ has_pointer<T>,
+ has_reference<T>
+ >::value;
+};
+
+template <typename T>
+struct is_smart_ptr
+{
+ static const bool value = has_element_type<T>::value;
+};
+
+} // namespace detail
+
+}}}} // namespace boost::geometry::index::translator
+
+#endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_TRANSLATOR_HELPERS_HPP

Added: sandbox-branches/geometry/index_080/boost/geometry/extensions/index/translator/index.hpp
==============================================================================
--- (empty file)
+++ sandbox-branches/geometry/index_080/boost/geometry/extensions/index/translator/index.hpp 2011-02-09 18:23:19 EST (Wed, 09 Feb 2011)
@@ -0,0 +1,38 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+//
+// Boost.SpatialIndex - container index value to bounding object translation
+//
+// Copyright 2011 Adam Wulkiewicz.
+// 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_EXTENSIONS_INDEX_TRANSLATOR_INDEX_HPP
+#define BOOST_GEOMETRY_EXTENSIONS_INDEX_TRANSLATOR_INDEX_HPP
+
+#include <boost/geometry/extensions/index/translator/helpers.hpp>
+
+namespace boost { namespace geometry { namespace index { namespace translator {
+
+template <typename Container>
+class index
+{
+public:
+ typedef typename detail::extract_bounding_geometry
+ <typename Container::value_type>::type bounding_geometry_type;
+
+ explicit index(Container const& c) : m_c(c) {}
+
+ bounding_geometry_type const& operator()(size_t i) const
+ {
+ return detail::extract_bounding_geometry
+ <typename Container::value_type>::get(m_c[i]);
+ }
+
+private:
+ Container const& m_c;
+};
+
+}}}} // namespace boost::geometry::index::translator
+
+#endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_TRANSLATOR_INDEX_HPP


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