Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75771 - in sandbox-branches/geometry/index: boost/geometry/extensions/index/rtree boost/geometry/extensions/index/rtree/node boost/geometry/extensions/index/rtree/visitors boost/geometry/extensions/index/translator tests
From: adam.wulkiewicz_at_[hidden]
Date: 2011-12-02 09:16:46


Author: awulkiew
Date: 2011-12-02 09:16:43 EST (Fri, 02 Dec 2011)
New Revision: 75771
URL: http://svn.boost.org/trac/boost/changeset/75771

Log:
Reference to temporary - error fixed.
Added:
   sandbox-branches/geometry/index/tests/t1.cpp (contents, props changed)
   sandbox-branches/geometry/index/tests/t2.cpp (contents, props changed)
Removed:
   sandbox-branches/geometry/index/boost/geometry/extensions/index/translator/getter.hpp
Text files modified:
   sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_default.hpp | 4 ++--
   sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/rtree.hpp | 2 +-
   sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/visitors/nearest.hpp | 25 +++++++++++++++++++------
   sandbox-branches/geometry/index/boost/geometry/extensions/index/translator/def.hpp | 16 ++++++++--------
   sandbox-branches/geometry/index/boost/geometry/extensions/index/translator/index.hpp | 4 ++--
   sandbox-branches/geometry/index/boost/geometry/extensions/index/translator/translator.hpp | 15 ++++++++++++++-
   sandbox-branches/geometry/index/tests/additional_glut_vis.cpp | 33 +++++++++++++++++++++++----------
   sandbox-branches/geometry/index/tests/rtree_function.hpp | 2 +-
   sandbox-branches/geometry/index/tests/translators.hpp | 5 -----
   9 files changed, 70 insertions(+), 36 deletions(-)

Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_default.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_default.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/node/node_default.hpp 2011-12-02 09:16:43 EST (Fri, 02 Dec 2011)
@@ -147,7 +147,7 @@
 template <typename Value, typename Translator>
 struct element_indexable_type
 {
- typedef typename Translator::indexable_type type;
+ typedef typename translator::indexable_type<Translator>::type type;
 };
 
 template <typename Value, typename Parameters, typename Box, typename Allocators, typename Tag, typename Translator>
@@ -162,7 +162,7 @@
 // element's indexable getter
 
 template <typename Value, typename Translator>
-inline typename Translator::indexable_type const&
+inline typename Translator::result_type
 element_indexable(Value const& el, Translator const& tr)
 {
         return tr(el);

Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/rtree.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/rtree.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/rtree.hpp 2011-12-02 09:16:43 EST (Fri, 02 Dec 2011)
@@ -73,7 +73,7 @@
 public:
     typedef Value value_type;
     typedef Translator translator_type;
- typedef typename translator_type::indexable_type indexable_type;
+ typedef typename translator::indexable_type<Translator>::type indexable_type;
     typedef typename index::default_box_type<indexable_type>::type box_type;
 
     typedef typename detail::rtree::options_type<Parameters>::type options_type;

Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/visitors/nearest.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/visitors/nearest.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/rtree/visitors/nearest.hpp 2011-12-02 09:16:43 EST (Fri, 02 Dec 2011)
@@ -13,6 +13,7 @@
 #include <boost/geometry/extensions/index/rtree/distance_predicates.hpp>
 
 #include <boost/geometry/extensions/index/rtree/node/node.hpp>
+#include <boost/geometry/extensions/index/translator/translator.hpp>
 
 namespace boost { namespace geometry { namespace index {
 
@@ -26,8 +27,10 @@
 struct nearest_one
 {
 public:
- typedef typename Translator::indexable_type indexable_type;
- typedef typename geometry::default_distance_result<Point, indexable_type>::type distance_type;
+ typedef typename geometry::default_distance_result<
+ Point,
+ typename translator::indexable_type<Translator>::type
+ >::type distance_type;
 
     inline nearest_one()
         : m_comp_dist(std::numeric_limits<distance_type>::max())
@@ -67,8 +70,10 @@
 struct nearest_k
 {
 public:
- typedef typename Translator::indexable_type indexable_type;
- typedef typename geometry::default_distance_result<Point, indexable_type>::type distance_type;
+ typedef typename geometry::default_distance_result<
+ Point,
+ typename translator::indexable_type<Translator>::type
+ >::type distance_type;
 
     inline explicit nearest_k(size_t k)
         : m_count(k)
@@ -159,9 +164,17 @@
     typedef typename node_distances_calc::result_type node_distances_type;
     typedef index::detail::distances_predicates_check<DistancesPredicates, Box, rtree::node_tag> node_distances_predicates_check;
 
- typedef index::detail::distances_calc<DistancesPredicates, typename Translator::indexable_type, rtree::value_tag> value_distances_calc;
+ typedef index::detail::distances_calc<
+ DistancesPredicates,
+ typename translator::indexable_type<Translator>::type,
+ rtree::value_tag
+ > value_distances_calc;
     typedef typename value_distances_calc::result_type value_distances_type;
- typedef index::detail::distances_predicates_check<DistancesPredicates, typename Translator::indexable_type, rtree::value_tag> value_distances_predicates_check;
+ typedef index::detail::distances_predicates_check<
+ DistancesPredicates,
+ typename translator::indexable_type<Translator>::type,
+ rtree::value_tag
+ > value_distances_predicates_check;
 
     inline nearest(Translator const& t, DistancesPredicates const& dist_pred, Predicates const& pred, Result & r)
         : m_tr(t), m_dist_pred(dist_pred), m_pred(pred)

Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/translator/def.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/translator/def.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/translator/def.hpp 2011-12-02 09:16:43 EST (Fri, 02 Dec 2011)
@@ -22,9 +22,9 @@
 template <typename Value, bool IsIterator, bool IsSmartPtr>
 struct def
 {
- typedef typename detail::extract_indexable<Value>::type indexable_type;
+ typedef typename detail::extract_indexable<Value>::type const& result_type;
 
- indexable_type const& operator()(Value const& v) const
+ result_type operator()(Value const& v) const
     {
         return detail::extract_indexable<Value>::get(v);
     }
@@ -39,9 +39,9 @@
 template <typename Value, bool IsSmartPtr>
 struct def<Value, true, IsSmartPtr>
 {
- typedef typename detail::extract_indexable<typename Value::value_type>::type indexable_type;
+ typedef typename detail::extract_indexable<typename Value::value_type>::type const& result_type;
 
- indexable_type const& operator()(Value const& v) const
+ result_type operator()(Value const& v) const
     {
         return detail::extract_indexable<typename Value::value_type>::get(*v);
     }
@@ -56,9 +56,9 @@
 template <typename Value>
 struct def<Value, false, true>
 {
- typedef typename detail::extract_indexable<typename Value::element_type>::type indexable_type;
+ typedef typename detail::extract_indexable<typename Value::element_type>::type const& result_type;
 
- indexable_type const& operator()(Value const& v) const
+ result_type operator()(Value const& v) const
     {
         return detail::extract_indexable<typename Value::element_type>::get(*v);
     }
@@ -85,9 +85,9 @@
 template <typename Value>
 struct def<Value*>
 {
- typedef typename detail::extract_indexable<Value>::type indexable_type;
+ typedef typename detail::extract_indexable<Value>::type const& result_type;
 
- indexable_type const& operator()(const Value *v) const
+ result_type operator()(const Value *v) const
     {
         return detail::extract_indexable<Value>::get(*v);
     }

Deleted: sandbox-branches/geometry/index/boost/geometry/extensions/index/translator/getter.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/translator/getter.hpp 2011-12-02 09:16:43 EST (Fri, 02 Dec 2011)
+++ (empty file)
@@ -1,36 +0,0 @@
-// Boost.Geometry (aka GGL, Generic Geometry Library)
-//
-// Boost.SpatialIndex - value to bounding object translation as a getter (object's member function)
-//
-// 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_GETTER_HPP
-#define BOOST_GEOMETRY_EXTENSIONS_INDEX_TRANSLATOR_GETTER_HPP
-
-namespace boost { namespace geometry { namespace index { namespace translator {
-
-template <typename Value, typename Indexable, Indexable const& (Value::*Getter)() const>
-struct getter
-{
- typedef Indexable indexable_type;
-
- indexable_type const& operator()(Value const& v) const
- {
- return (v.*Getter)();
- }
-
- bool equals(Value const& v1, Value const& v2) const
- {
- //return geometry::equals(operator()(v1), operator()(v2));
- return v1 == v2;
- }
-};
-
-// TODO: awulkiew - implement specialization for Value* ?
-
-}}}} // namespace boost::geometry::index::translator
-
-#endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_TRANSLATOR_GETTER_HPP

Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/translator/index.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/translator/index.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/translator/index.hpp 2011-12-02 09:16:43 EST (Fri, 02 Dec 2011)
@@ -19,11 +19,11 @@
 {
 public:
     typedef typename detail::extract_indexable
- <typename Container::value_type>::type indexable_type;
+ <typename Container::value_type>::type const& result_type;
 
     explicit index(Container const& c) : m_c(c) {}
 
- indexable_type const& operator()(size_t i) const
+ result_type operator()(size_t i) const
     {
         return detail::extract_indexable
             <typename Container::value_type>::get(m_c[i]);

Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/translator/translator.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/translator/translator.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/translator/translator.hpp 2011-12-02 09:16:43 EST (Fri, 02 Dec 2011)
@@ -12,6 +12,19 @@
 
 #include <boost/geometry/extensions/index/translator/def.hpp>
 #include <boost/geometry/extensions/index/translator/index.hpp>
-#include <boost/geometry/extensions/index/translator/getter.hpp>
+
+namespace boost { namespace geometry { namespace index { namespace translator {
+
+template <typename Translator>
+struct indexable_type
+{
+ typedef typename boost::remove_const<
+ typename boost::remove_reference<
+ typename Translator::result_type
+ >::type
+ >::type type;
+};
+
+}}}} // namespace boost::geometry::index::translator
 
 #endif // BOOST_GEOMETRY_EXTENSIONS_INDEX_TRANSLATOR_TRANSLATOR_HPP

Modified: sandbox-branches/geometry/index/tests/additional_glut_vis.cpp
==============================================================================
--- sandbox-branches/geometry/index/tests/additional_glut_vis.cpp (original)
+++ sandbox-branches/geometry/index/tests/additional_glut_vis.cpp 2011-12-02 09:16:43 EST (Fri, 02 Dec 2011)
@@ -38,7 +38,7 @@
 B search_box;
 
 enum query_mode_type {
- qm_knn, qm_c, qm_d, qm_i, qm_o, qm_w, qm_nc, qm_nd, qm_ni, qm_no, qm_nw
+ qm_knn, qm_c, qm_d, qm_i, qm_o, qm_w, qm_nc, qm_nd, qm_ni, qm_no, qm_nw, qm_all
 } query_mode = qm_knn;
 
 bool search_valid = false;
@@ -78,14 +78,23 @@
 template <typename Predicate>
 void query()
 {
- float x = ( rand() % 1000 ) / 10.0f;
- float y = ( rand() % 1000 ) / 10.0f;
- float w = 10 + ( rand() % 1000 ) / 100.0f;
- float h = 10 + ( rand() % 1000 ) / 100.0f;
-
- search_box = B(P(x - w, y - h), P(x + w, y + h));
- nearest_boxes.clear();
- found_count = t.query(Predicate(search_box), std::back_inserter(nearest_boxes) );
+ if ( query_mode != qm_all )
+ {
+ float x = ( rand() % 1000 ) / 10.0f;
+ float y = ( rand() % 1000 ) / 10.0f;
+ float w = 10 + ( rand() % 1000 ) / 100.0f;
+ float h = 10 + ( rand() % 1000 ) / 100.0f;
+
+ search_box = B(P(x - w, y - h), P(x + w, y + h));
+ nearest_boxes.clear();
+ found_count = t.query(Predicate(search_box), std::back_inserter(nearest_boxes) );
+ }
+ else
+ {
+ search_box = t.box();
+ nearest_boxes.clear();
+ found_count = t.query(Predicate(search_box), std::back_inserter(nearest_boxes) );
+ }
 
     if ( found_count > 0 )
     {
@@ -99,7 +108,7 @@
         }
     }
     else
- std::cout << "nearest not found\n";
+ std::cout << "boxes not found\n";
 }
 
 void search()
@@ -126,6 +135,8 @@
         query< bgi::detail::not_overlaps<B> >();
     else if ( query_mode == qm_nw )
         query< bgi::detail::not_within<B> >();
+ else if ( query_mode == qm_all )
+ query< bgi::detail::intersects<B> >();
 
     search_valid = true;
 }
@@ -305,6 +316,8 @@
                 query_mode = qm_no;
             else if ( current_line == "nw" )
                 query_mode = qm_nw;
+ else if ( current_line == "all" )
+ query_mode = qm_all;
             
             search();
             glutPostRedisplay();

Modified: sandbox-branches/geometry/index/tests/rtree_function.hpp
==============================================================================
--- sandbox-branches/geometry/index/tests/rtree_function.hpp (original)
+++ sandbox-branches/geometry/index/tests/rtree_function.hpp 2011-12-02 09:16:43 EST (Fri, 02 Dec 2011)
@@ -159,7 +159,7 @@
     namespace bg = boost::geometry;
     namespace bgi = boost::geometry::index;
 
- typedef typename Translator::indexable_type indexable_type;
+ typedef typename bgi::translator::indexable_type<Translator>::type indexable_type;
     typedef bg::default_distance_result<Point, indexable_type>::type distance_type;
 
     if ( c1.size() != c2.size() )

Added: sandbox-branches/geometry/index/tests/t1.cpp
==============================================================================
--- (empty file)
+++ sandbox-branches/geometry/index/tests/t1.cpp 2011-12-02 09:16:43 EST (Fri, 02 Dec 2011)
@@ -0,0 +1,45 @@
+#include <iostream>
+#include <fstream>
+
+#include <boost/geometry/extensions/index/rtree/rtree.hpp>
+
+namespace bg = boost::geometry;
+namespace bgi = bg::index;
+
+typedef bg::model::point<double, 2, bg::cs::cartesian> P;
+typedef bg::model::box<P> B;
+typedef bgi::rtree<
+ B,
+ bgi::linear<4, 2>
+> RTB;
+typedef bgi::rtree<
+ P,
+ bgi::linear<4, 2>
+> RTP;
+
+int main()
+{
+ RTB rtb;
+ rtb.insert(B(P(0,0),P(1,1)));
+ rtb.insert(B(P(1,0),P(2,1)));
+ rtb.insert(B(P(2,0),P(3,1)));
+ rtb.insert(B(P(2,2),P(3,3)));
+ rtb.insert(B(P(4,4),P(5,5)));
+
+ std::vector<B> res;
+ B bb = rtb.box();
+ rtb.query(bb, std::back_inserter(res));
+
+ RTP rtp;
+ rtp.insert(P(0,0));
+ rtp.insert(P(1,0));
+ rtp.insert(P(2,0));
+ rtp.insert(P(2,2));
+ rtp.insert(P(4,4));
+
+ std::vector<P> resp;
+ B bp = rtp.box();
+ rtp.query(bp, std::back_inserter(resp));
+
+ int a = 10;
+}

Added: sandbox-branches/geometry/index/tests/t2.cpp
==============================================================================
--- (empty file)
+++ sandbox-branches/geometry/index/tests/t2.cpp 2011-12-02 09:16:43 EST (Fri, 02 Dec 2011)
@@ -0,0 +1,66 @@
+
+#include <iostream>
+#include <deque>
+
+#include <boost/geometry/extensions/index/rtree/rtree.hpp>
+#include <boost/geometry/extensions/index/inserter.hpp>
+
+#include <boost/geometry/geometries/point.hpp>
+
+
+typedef boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian>
+ BGCartesianPoint;
+typedef boost::geometry::model::box<BGCartesianPoint>
+ BGCartesianBox;
+typedef boost::geometry::model::segment<BGCartesianPoint>
+ BGCartesianSegment;
+namespace bgi = boost::geometry::index;
+
+
+struct myTranslator
+{
+ typedef BGCartesianBox result_type;
+
+ result_type operator()(BGCartesianPoint const& seg) const
+ {
+ result_type envelope;
+ boost::geometry::envelope(seg, envelope);
+ return envelope;
+ }
+
+ bool equals(BGCartesianPoint const& go1, BGCartesianPoint const& go2) const
+ {
+ return (go1.get<0>() == go2.get<0>()) &&
+ (go1.get<1>() == go2.get<1>());
+ }
+};
+
+typedef bgi::rtree
+ <BGCartesianPoint,
+ bgi::rstar<32, 8>,
+ myTranslator>
+ BGRTree;
+
+int main()
+{
+ BGRTree rTree;
+ for (int i = 0; i < 50; ++i)
+ {
+ BGCartesianPoint p(i, i);
+ rTree.insert(p);
+
+ BGCartesianBox envelope(BGCartesianPoint(i-0.5, i-0.5),
+ BGCartesianPoint(i+0.5, i+0.5));
+
+ std::deque<BGCartesianPoint> dq;
+
+ if (rTree.query(envelope, std::back_inserter(dq)))
+ std::cout << "Retrieved inserted object nr. " << i << "\n";
+ else
+ std::cout << "Could not retrieve inserted object nr. " << i << "\n";
+ }
+
+ std::cout << "Total objects: " << rTree.size();
+ std::cin.get();
+ return 0;
+}
\ No newline at end of file

Modified: sandbox-branches/geometry/index/tests/translators.hpp
==============================================================================
--- sandbox-branches/geometry/index/tests/translators.hpp (original)
+++ sandbox-branches/geometry/index/tests/translators.hpp 2011-12-02 09:16:43 EST (Fri, 02 Dec 2011)
@@ -95,11 +95,6 @@
 
     BOOST_CHECK( bg::equals(tmp_b, ppb(tmp_ppb)) );
     BOOST_CHECK( bg::equals(tmp_b, pbp(tmp_pbp)) );
-
- tests_translators_val<P> val_p(tmp_p);
- bgit::getter<tests_translators_val<P>, P, &tests_translators_val<P>::get_box> tr_get_p;
-
- BOOST_CHECK( bg::equals(tmp_p, tr_get_p(val_p)) );
 }
 
 #endif // TESTS_TRANSLATORS_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