Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85563 - in trunk/libs/geometry: doc/html/img/index/rtree doc/index/rtree index/example
From: adam.wulkiewicz_at_[hidden]
Date: 2013-09-04 07:57:34


Author: awulkiew
Date: 2013-09-04 07:57:34 EDT (Wed, 04 Sep 2013)
New Revision: 85563
URL: http://svn.boost.org/trac/boost/changeset/85563

Log:
[geometry][index] example: added segment and linestring intersects queries to glut_vis, doc: added pictures of those queries results.

Added:
   trunk/libs/geometry/doc/html/img/index/rtree/intersects_linestring.png (contents, props changed)
   trunk/libs/geometry/doc/html/img/index/rtree/intersects_segment.png (contents, props changed)
Text files modified:
   trunk/libs/geometry/doc/index/rtree/query.qbk | 7 +-
   trunk/libs/geometry/index/example/glut_vis.cpp | 111 ++++++++++++++++++++++++++++++++++++++-
   2 files changed, 111 insertions(+), 7 deletions(-)

Added: trunk/libs/geometry/doc/html/img/index/rtree/intersects_linestring.png
==============================================================================
Binary file. No diff available.

Added: trunk/libs/geometry/doc/html/img/index/rtree/intersects_segment.png
==============================================================================
Binary file. No diff available.

Modified: trunk/libs/geometry/doc/index/rtree/query.qbk
==============================================================================
--- trunk/libs/geometry/doc/index/rtree/query.qbk Wed Sep 4 07:17:34 2013 (r85562)
+++ trunk/libs/geometry/doc/index/rtree/query.qbk 2013-09-04 07:57:34 EDT (Wed, 04 Sep 2013) (r85563)
@@ -57,8 +57,8 @@
 ]
 
 [table
-[[intersects(Ring)] [intersects(Polygon)] [intersects(MultiPolygon)]]
-[[[$img/index/rtree/intersects_ring.png]] [[$img/index/rtree/intersects_poly.png]] [[$img/index/rtree/intersects_mpoly.png]]]
+[[intersects(Ring)] [intersects(Polygon)] [intersects(MultiPolygon)] [intersects(Segment)] [intersects(Linestring)]]
+[[[$img/index/rtree/intersects_ring.png]] [[$img/index/rtree/intersects_poly.png]] [[$img/index/rtree/intersects_mpoly.png]] [[$img/index/rtree/intersects_segment.png]] [[$img/index/rtree/intersects_linestring.png]]]
 ]
 
 To use a spatial predicate one may use one of the functions defined in `boost::geometry::index` namespace.
@@ -80,8 +80,7 @@
 [h5 Nearest neighbours queries]
 
 Nearest neighbours queries returns `__value__`s which are closest to some point in space.
-Additionally it is possible to define how the distance to the `Value` should be calculated.
-The example of knn query is presented below. 5 `__value__`s nearest to some point are orange.
+The example of knn query is presented below. 5 `__value__`s nearest to the point are orange.
 
 [$img/index/rtree/knn.png]
 

Modified: trunk/libs/geometry/index/example/glut_vis.cpp
==============================================================================
--- trunk/libs/geometry/index/example/glut_vis.cpp Wed Sep 4 07:17:34 2013 (r85562)
+++ trunk/libs/geometry/index/example/glut_vis.cpp 2013-09-04 07:57:34 EDT (Wed, 04 Sep 2013) (r85563)
@@ -14,6 +14,7 @@
 #include <boost/geometry/index/rtree.hpp>
 
 #include <boost/geometry/geometries/linestring.hpp>
+#include <boost/geometry/geometries/segment.hpp>
 #include <boost/geometry/geometries/ring.hpp>
 #include <boost/geometry/geometries/polygon.hpp>
 #include <boost/geometry/multi/geometries/multi_polygon.hpp>
@@ -31,6 +32,7 @@
 typedef bg::model::box<P> B;
 //bgi::rtree<B> t(2, 1);
 typedef bg::model::linestring<P> LS;
+typedef bg::model::segment<P> S;
 typedef bg::model::ring<P> R;
 typedef bg::model::polygon<P> Poly;
 typedef bg::model::multi_polygon<Poly> MPoly;
@@ -50,10 +52,12 @@
 R search_ring;
 Poly search_poly;
 MPoly search_multi_poly;
+S search_segment;
+LS search_linestring;
 LS search_path;
 
 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_all, qm_ri, qm_pi, qm_mpi, qm_path
+ qm_knn, qm_c, qm_d, qm_i, qm_o, qm_w, qm_nc, qm_nd, qm_ni, qm_no, qm_nw, qm_all, qm_ri, qm_pi, qm_mpi, qm_si, qm_lsi, qm_path
 } query_mode = qm_knn;
 
 bool search_valid = false;
@@ -335,6 +339,81 @@
         std::cout << "boxes not found\n";
 }
 
+template <typename Predicate>
+void query_segment()
+{
+ float x = ( rand() % 1000 ) / 10.0f;
+ float y = ( rand() % 1000 ) / 10.0f;
+ float w = 10.0f - ( rand() % 1000 ) / 50.0f;
+ float h = 10.0f - ( rand() % 1000 ) / 50.0f;
+ w += 0 <= w ? 10 : -10;
+ h += 0 <= h ? 10 : -10;
+
+ boost::geometry::set<0, 0>(search_segment, x - w);
+ boost::geometry::set<0, 1>(search_segment, y - h);
+ boost::geometry::set<1, 0>(search_segment, x + w);
+ boost::geometry::set<1, 1>(search_segment, y + h);
+
+ nearest_boxes.clear();
+ found_count = t.query(Predicate(search_segment), std::back_inserter(nearest_boxes) );
+
+ if ( found_count > 0 )
+ {
+ std::cout << "search segment: ";
+ bgi::detail::utilities::print_indexable(std::cout, P(x-w, y-h));
+ bgi::detail::utilities::print_indexable(std::cout, P(x+w, y+h));
+
+ std::cout << "\nfound: ";
+ for ( size_t i = 0 ; i < nearest_boxes.size() ; ++i )
+ {
+ bgi::detail::utilities::print_indexable(std::cout, nearest_boxes[i]);
+ std::cout << '\n';
+ }
+ }
+ else
+ std::cout << "boxes not found\n";
+}
+
+template <typename Predicate>
+void query_linestring()
+{
+ 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_linestring.clear();
+ float a = 0;
+ float d = 0;
+ for ( size_t i = 0 ; i < 300 ; ++i, a += 0.05, d += 0.005 )
+ {
+ float xx = x + w * d * ::cos(a);
+ float yy = y + h * d * ::sin(a);
+ search_linestring.push_back(P(xx, yy));
+ }
+
+ nearest_boxes.clear();
+ found_count = t.query(Predicate(search_linestring), std::back_inserter(nearest_boxes) );
+
+ if ( found_count > 0 )
+ {
+ std::cout << "search linestring: ";
+ BOOST_FOREACH(P const& p, search_linestring)
+ {
+ bgi::detail::utilities::print_indexable(std::cout, p);
+ std::cout << ' ';
+ }
+ std::cout << "\nfound: ";
+ for ( size_t i = 0 ; i < nearest_boxes.size() ; ++i )
+ {
+ bgi::detail::utilities::print_indexable(std::cout, nearest_boxes[i]);
+ std::cout << '\n';
+ }
+ }
+ else
+ std::cout << "boxes not found\n";
+}
+
 void search()
 {
     namespace d = bgi::detail;
@@ -369,6 +448,10 @@
         query_poly< d::spatial_predicate<Poly, d::intersects_tag, false> >();
     else if ( query_mode == qm_mpi )
         query_multi_poly< d::spatial_predicate<MPoly, d::intersects_tag, false> >();
+ else if ( query_mode == qm_si )
+ query_segment< d::spatial_predicate<S, d::intersects_tag, false> >();
+ else if ( query_mode == qm_lsi )
+ query_linestring< d::spatial_predicate<LS, d::intersects_tag, false> >();
     else if ( query_mode == qm_path )
         query_path();
 
@@ -403,7 +486,7 @@
     glEnd();
 }
 
-void draw_path(LS const& ls)
+void draw_linestring(LS const& ls)
 {
     glBegin(GL_LINE_STRIP);
 
@@ -418,6 +501,20 @@
     glEnd();
 }
 
+void draw_segment(S const& s)
+{
+ float x1 = boost::geometry::get<0, 0>(s);
+ float y1 = boost::geometry::get<0, 1>(s);
+ float x2 = boost::geometry::get<1, 0>(s);
+ float y2 = boost::geometry::get<1, 1>(s);
+ float z = bgi::detail::rtree::utilities::view<RTree>(t).depth();
+
+ glBegin(GL_LINES);
+ glVertex3f(x1, y1, z);
+ glVertex3f(x2, y2, z);
+ glEnd();
+}
+
 template <typename Box>
 void draw_box(Box const& box)
 {
@@ -487,8 +584,12 @@
             draw_polygon(search_poly);
         else if ( query_mode == qm_mpi )
             draw_multi_polygon(search_multi_poly);
+ else if ( query_mode == qm_si )
+ draw_segment(search_segment);
+ else if ( query_mode == qm_lsi )
+ draw_linestring(search_linestring);
         else if ( query_mode == qm_path )
- draw_path(search_path);
+ draw_linestring(search_path);
         else
             draw_box(search_box);
 
@@ -686,6 +787,10 @@
                 query_mode = qm_pi;
             else if ( current_line == "mpi" )
                 query_mode = qm_mpi;
+ else if ( current_line == "si" )
+ query_mode = qm_si;
+ else if ( current_line == "lsi" )
+ query_mode = qm_lsi;
             else if ( current_line == "path" )
                 query_mode = qm_path;
             


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