Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81921 - in sandbox-branches/geometry/index: doc/html doc/html/geometry_index/r_tree doc/images doc/rtree tests
From: adam.wulkiewicz_at_[hidden]
Date: 2012-12-13 17:37:07


Author: awulkiew
Date: 2012-12-13 17:37:06 EST (Thu, 13 Dec 2012)
New Revision: 81921
URL: http://svn.boost.org/trac/boost/changeset/81921

Log:
Added MultiPolygon spatial query picture to docs.
Added MultiPolygon query to GLUT Vis.
Added:
   sandbox-branches/geometry/index/doc/images/intersects_mpoly.png (contents, props changed)
Text files modified:
   sandbox-branches/geometry/index/doc/html/geometry_index/r_tree/spatial_queries.html | 11 +++
   sandbox-branches/geometry/index/doc/html/index.html | 2
   sandbox-branches/geometry/index/doc/rtree/spatial_query.qbk | 4
   sandbox-branches/geometry/index/tests/additional_glut_vis.cpp | 117 ++++++++++++++++++++++++++++++++++-----
   4 files changed, 115 insertions(+), 19 deletions(-)

Modified: sandbox-branches/geometry/index/doc/html/geometry_index/r_tree/spatial_queries.html
==============================================================================
--- sandbox-branches/geometry/index/doc/html/geometry_index/r_tree/spatial_queries.html (original)
+++ sandbox-branches/geometry/index/doc/html/geometry_index/r_tree/spatial_queries.html 2012-12-13 17:37:06 EST (Thu, 13 Dec 2012)
@@ -114,6 +114,7 @@
 <colgroup>
 <col>
 <col>
+<col>
 </colgroup>
 <thead><tr>
 <th>
@@ -126,6 +127,11 @@
                   intersects(Polygon)
                 </p>
               </th>
+<th>
+ <p>
+ intersects(MultiPolygon)
+ </p>
+ </th>
 </tr></thead>
 <tbody><tr>
 <td>
@@ -138,6 +144,11 @@
                   <span class="inlinemediaobject"><img src="../../../images/intersects_poly.png" alt="intersects_poly"></span>
                 </p>
               </td>
+<td>
+ <p>
+ <span class="inlinemediaobject"><img src="../../../images/intersects_mpoly.png" alt="intersects_mpoly"></span>
+ </p>
+ </td>
 </tr></tbody>
 </table></div>
 <div class="section">

Modified: sandbox-branches/geometry/index/doc/html/index.html
==============================================================================
--- sandbox-branches/geometry/index/doc/html/index.html (original)
+++ sandbox-branches/geometry/index/doc/html/index.html 2012-12-13 17:37:06 EST (Thu, 13 Dec 2012)
@@ -56,7 +56,7 @@
 </div>
 </div>
 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
-<td align="left"><p><small>Last revised: December 13, 2012 at 18:36:05 GMT</small></p></td>
+<td align="left"><p><small>Last revised: December 13, 2012 at 22:34:06 GMT</small></p></td>
 <td align="right"><div class="copyright-footer"></div></td>
 </tr></table>
 <hr>

Added: sandbox-branches/geometry/index/doc/images/intersects_mpoly.png
==============================================================================
Binary file. No diff available.

Modified: sandbox-branches/geometry/index/doc/rtree/spatial_query.qbk
==============================================================================
--- sandbox-branches/geometry/index/doc/rtree/spatial_query.qbk (original)
+++ sandbox-branches/geometry/index/doc/rtree/spatial_query.qbk 2012-12-13 17:37:06 EST (Thu, 13 Dec 2012)
@@ -21,8 +21,8 @@
 ]
 
 [table
-[[intersects(Ring)] [intersects(Polygon)]]
-[[[$../images/intersects_ring.png]] [[$../images/intersects_poly.png]]]
+[[intersects(Ring)] [intersects(Polygon)] [intersects(MultiPolygon)]]
+[[[$../images/intersects_ring.png]] [[$../images/intersects_poly.png]] [[$../images/intersects_mpoly.png]]]
 ]
 
 [section Basic queries]

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 2012-12-13 17:37:06 EST (Thu, 13 Dec 2012)
@@ -17,6 +17,7 @@
 
 #include <boost/geometry/geometries/ring.hpp>
 #include <boost/geometry/geometries/polygon.hpp>
+#include <boost/geometry/multi/geometries/multi_polygon.hpp>
 
 #include <boost/geometry/extensions/index/rtree/visitors/gl_draw.hpp>
 #include <boost/geometry/extensions/index/rtree/visitors/print.hpp>
@@ -31,6 +32,7 @@
 //bgi::rtree<B> t(2, 1);
 typedef bg::model::ring<P> R;
 typedef bg::model::polygon<P> Poly;
+typedef bg::model::multi_polygon<Poly> MPoly;
 
 bgi::rtree<
     B,
@@ -47,9 +49,10 @@
 B search_box;
 R search_ring;
 Poly search_poly;
+MPoly search_multi_poly;
 
 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_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
 } query_mode = qm_knn;
 
 bool search_valid = false;
@@ -227,6 +230,78 @@
         std::cout << "boxes not found\n";
 }
 
+template <typename Predicate>
+void query_multi_poly()
+{
+ 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_multi_poly.clear();
+
+ search_multi_poly.push_back(Poly());
+ search_multi_poly[0].outer().push_back(P(x - w, y - h));
+ search_multi_poly[0].outer().push_back(P(x - w/2, y - h));
+ search_multi_poly[0].outer().push_back(P(x, y - 3*h/2));
+ search_multi_poly[0].outer().push_back(P(x + w/2, y - h));
+ search_multi_poly[0].outer().push_back(P(x + w, y - h));
+ search_multi_poly[0].outer().push_back(P(x + w, y - h/2));
+ search_multi_poly[0].outer().push_back(P(x + 3*w/2, y));
+ search_multi_poly[0].outer().push_back(P(x + w, y + h/2));
+ search_multi_poly[0].outer().push_back(P(x + w, y + h));
+ search_multi_poly[0].outer().push_back(P(x + w/2, y + h));
+ search_multi_poly[0].outer().push_back(P(x, y + 3*h/2));
+ search_multi_poly[0].outer().push_back(P(x - w/2, y + h));
+ search_multi_poly[0].outer().push_back(P(x - w, y + h));
+ search_multi_poly[0].outer().push_back(P(x - w, y + h/2));
+ search_multi_poly[0].outer().push_back(P(x - 3*w/2, y));
+ search_multi_poly[0].outer().push_back(P(x - w, y - h/2));
+ search_multi_poly[0].outer().push_back(P(x - w, y - h));
+
+ search_multi_poly[0].inners().push_back(Poly::ring_type());
+ search_multi_poly[0].inners()[0].push_back(P(x - w/2, y - h/2));
+ search_multi_poly[0].inners()[0].push_back(P(x + w/2, y - h/2));
+ search_multi_poly[0].inners()[0].push_back(P(x + w/2, y + h/2));
+ search_multi_poly[0].inners()[0].push_back(P(x - w/2, y + h/2));
+ search_multi_poly[0].inners()[0].push_back(P(x - w/2, y - h/2));
+
+ search_multi_poly.push_back(Poly());
+ search_multi_poly[1].outer().push_back(P(x - 2*w, y - 2*h));
+ search_multi_poly[1].outer().push_back(P(x - 6*w/5, y - 2*h));
+ search_multi_poly[1].outer().push_back(P(x - 6*w/5, y - 6*h/5));
+ search_multi_poly[1].outer().push_back(P(x - 2*w, y - 6*h/5));
+ search_multi_poly[1].outer().push_back(P(x - 2*w, y - 2*h));
+
+ search_multi_poly.push_back(Poly());
+ search_multi_poly[2].outer().push_back(P(x + 6*w/5, y + 6*h/5));
+ search_multi_poly[2].outer().push_back(P(x + 2*w, y + 6*h/5));
+ search_multi_poly[2].outer().push_back(P(x + 2*w, y + 2*h));
+ search_multi_poly[2].outer().push_back(P(x + 6*w/5, y + 2*h));
+ search_multi_poly[2].outer().push_back(P(x + 6*w/5, y + 6*h/5));
+
+ nearest_boxes.clear();
+ found_count = t.spatial_query(Predicate(search_multi_poly), std::back_inserter(nearest_boxes) );
+
+ if ( found_count > 0 )
+ {
+ std::cout << "search multi_poly[0] outer: ";
+ BOOST_FOREACH(P const& p, search_multi_poly[0].outer())
+ {
+ bgi::detail::rtree::visitors::detail::print_indexable(std::cout, p);
+ std::cout << ' ';
+ }
+ std::cout << "\nfound: ";
+ for ( size_t i = 0 ; i < nearest_boxes.size() ; ++i )
+ {
+ bgi::detail::rtree::visitors::detail::print_indexable(std::cout, nearest_boxes[i]);
+ std::cout << '\n';
+ }
+ }
+ else
+ std::cout << "boxes not found\n";
+}
+
 void search()
 {
     if ( query_mode == qm_knn )
@@ -257,6 +332,8 @@
         query_ring< bgi::detail::intersects<R> >();
     else if ( query_mode == qm_pi )
         query_poly< bgi::detail::intersects<Poly> >();
+ else if ( query_mode == qm_mpi )
+ query_multi_poly< bgi::detail::intersects<MPoly> >();
 
     search_valid = true;
 }
@@ -289,12 +366,13 @@
     glEnd();
 }
 
-void draw_query_box_area()
+template <typename Box>
+void draw_box(Box const& box)
 {
- float x1 = boost::geometry::get<bg::min_corner, 0>(search_box);
- float y1 = boost::geometry::get<bg::min_corner, 1>(search_box);
- float x2 = boost::geometry::get<bg::max_corner, 0>(search_box);
- float y2 = boost::geometry::get<bg::max_corner, 1>(search_box);
+ float x1 = boost::geometry::get<bg::min_corner, 0>(box);
+ float y1 = boost::geometry::get<bg::min_corner, 1>(box);
+ float x2 = boost::geometry::get<bg::max_corner, 0>(box);
+ float y2 = boost::geometry::get<bg::max_corner, 1>(box);
     float z = t.depth();
 
     // search box
@@ -307,7 +385,7 @@
 }
 
 template <typename Range>
-void draw_ring_area(Range const& range)
+void draw_ring(Range const& range)
 {
     float z = t.depth();
 
@@ -324,16 +402,19 @@
     glEnd();
 }
 
-void draw_query_ring_area()
+template <typename Polygon>
+void draw_polygon(Polygon const& polygon)
 {
- draw_ring_area(search_ring);
+ draw_ring(polygon.outer());
+ BOOST_FOREACH(Poly::ring_type const& r, polygon.inners())
+ draw_ring(r);
 }
 
-void draw_query_poly_area()
+template <typename MultiPolygon>
+void draw_multi_polygon(MultiPolygon const& multi_polygon)
 {
- draw_ring_area(search_poly.outer());
- BOOST_FOREACH(Poly::ring_type const& r, search_poly.inners())
- draw_ring_area(r);
+ BOOST_FOREACH(Poly const& p, multi_polygon)
+ draw_polygon(p);
 }
 
 void render_scene(void)
@@ -349,11 +430,13 @@
         if ( query_mode == qm_knn )
             draw_knn_area();
         else if ( query_mode == qm_ri )
- draw_query_ring_area();
+ draw_ring(search_ring);
         else if ( query_mode == qm_pi )
- draw_query_poly_area();
+ draw_polygon(search_poly);
+ else if ( query_mode == qm_mpi )
+ draw_multi_polygon(search_multi_poly);
         else
- draw_query_box_area();
+ draw_box(search_box);
 
         for ( size_t i = 0 ; i < nearest_boxes.size() ; ++i )
             boost::geometry::index::detail::rtree::visitors::detail::gl_draw_indexable(nearest_boxes[i], t.depth());
@@ -513,6 +596,8 @@
                 query_mode = qm_ri;
             else if ( current_line == "pi" )
                 query_mode = qm_pi;
+ else if ( current_line == "mpi" )
+ query_mode = qm_mpi;
             
             search();
             glutPostRedisplay();


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