$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r69197 - in sandbox-branches/geometry/index_080_nhch: boost/geometry/extensions/index/rtree tests
From: adam.wulkiewicz_at_[hidden]
Date: 2011-02-22 20:31:47
Author: awulkiew
Date: 2011-02-22 20:31:45 EST (Tue, 22 Feb 2011)
New Revision: 69197
URL: http://svn.boost.org/trac/boost/changeset/69197
Log:
tests added
Added:
   sandbox-branches/geometry/index_080_nhch/tests/additional_glut_vis.cpp   (contents, props changed)
   sandbox-branches/geometry/index_080_nhch/tests/additional_sizes_and_times.cpp   (contents, props changed)
Text files modified: 
   sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree.hpp               |    15 ++++++++++                              
   sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_internal_node.hpp |    51 +++++++++++++++++++++++++++++++++++++   
   sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_leaf.hpp          |    38 +++++++++++++++++++++++++++             
   sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_node.hpp          |    15 ++++++++++                              
   sandbox-branches/geometry/index_080_nhch/tests/main.cpp                                                |     9 ++---                                   
   sandbox-branches/geometry/index_080_nhch/tests/rtree_native.hpp                                        |    55 ----------------------------------------
   6 files changed, 121 insertions(+), 62 deletions(-)
Modified: sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree.hpp
==============================================================================
--- sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree.hpp	(original)
+++ sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree.hpp	2011-02-22 20:31:45 EST (Tue, 22 Feb 2011)
@@ -325,7 +325,7 @@
      * \brief Print Rtree (mainly for debug)
      */
     // awulkiew - print() method changed to operator<<
-    friend std::ostream & operator<<(std::ostream &os, rtree &r)
+    friend std::ostream & operator<<(std::ostream &os, rtree const& r)
     {
         os << "===================================" << std::endl;
         os << " Min/Max: " << r.m_min_elems_per_node << " / " << r.m_max_elems_per_node << std::endl;
@@ -336,6 +336,19 @@
         return os;
     }
 
+#ifdef BOOST_GEOMETRY_INDEX_RTREE_ENABLE_GL_DRAW
+
+    void gl_draw() const
+    {
+        glClear(GL_COLOR_BUFFER_BIT);
+
+        m_root->gl_draw(m_translator);
+
+        glFlush();
+    }
+
+#endif // BOOST_GEOMETRY_INDEX_RTREE_ENABLE_GL_DRAW
+
 private:
 
     /// number of elements
Modified: sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_internal_node.hpp
==============================================================================
--- sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_internal_node.hpp	(original)
+++ sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_internal_node.hpp	2011-02-22 20:31:45 EST (Tue, 22 Feb 2011)
@@ -214,6 +214,57 @@
         }
     }
 
+#ifdef BOOST_GEOMETRY_INDEX_RTREE_ENABLE_GL_DRAW
+
+    /**
+     * \brief Draw Rtree subtree using OpenGL (mainly for debug)
+     */
+    virtual void gl_draw(Translator const& tr) const
+    {
+        // TODO: awulkiew - implement 3d version
+        if ( traits::dimension<traits::point_type<Box>::type>::value == 2 )
+        {
+            for (typename node_map::const_iterator it = m_nodes.begin();
+                it != m_nodes.end(); ++it)
+            {
+                size_t lvl = this->get_level();
+                if ( lvl == 0 )
+                    glColor3f(1.0f, 0.0f, 0.0f);
+                else if ( lvl == 1 )
+                    glColor3f(0.0f, 1.0f, 0.0f);
+                else if ( lvl == 2 )
+                    glColor3f(0.0f, 0.0f, 1.0f);
+                else if ( lvl == 3 )
+                    glColor3f(1.0f, 1.0f, 0.0f);
+                else if ( lvl == 4 )
+                    glColor3f(1.0f, 0.0f, 1.0f);
+                else if ( lvl == 5 )
+                    glColor3f(0.0f, 1.0f, 1.0f);
+                else
+                    glColor3f(0.5f, 0.5f, 0.5f);
+
+                glBegin(GL_LINE_LOOP);
+                glVertex2f(
+                    geometry::get<min_corner, 0>(it->first),
+                    geometry::get<min_corner, 1>(it->first));
+                glVertex2f(
+                    geometry::get<max_corner, 0>(it->first),
+                    geometry::get<min_corner, 1>(it->first));
+                glVertex2f(
+                    geometry::get<max_corner, 0>(it->first),
+                    geometry::get<max_corner, 1>(it->first));
+                glVertex2f(
+                    geometry::get<min_corner, 0>(it->first),
+                    geometry::get<max_corner, 1>(it->first));
+                glEnd();
+
+                it->second->gl_draw(tr);
+            }
+        }
+    }
+
+#endif // BOOST_GEOMETRY_INDEX_RTREE_ENABLE_GL_DRAW
+
     // awulkiew - internal node only virtual methods
 
     /**
Modified: sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_leaf.hpp
==============================================================================
--- sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_leaf.hpp	(original)
+++ sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_leaf.hpp	2011-02-22 20:31:45 EST (Tue, 22 Feb 2011)
@@ -218,6 +218,44 @@
         os << "\t" << " --< Leaf --------" << std::endl;
     }
 
+#ifdef BOOST_GEOMETRY_INDEX_RTREE_ENABLE_GL_DRAW
+
+    /**
+     * \brief Draw leaf using OpenGL (mainly for debug)
+     */
+    virtual void gl_draw(Translator const& tr) const
+    {
+        // TODO: awulkiew - implement 3d version
+        if ( traits::dimension<traits::point_type<Box>::type>::value == 2 )
+        {
+            for (typename leaf_map::const_iterator it = m_nodes.begin();
+                it != m_nodes.end(); ++it)
+            {
+                glColor3f(1.0f, 1.0f, 1.0f);
+
+                Box box;
+                detail::convert_to_box(tr(*it), box);
+
+                glBegin(GL_LINE_LOOP);
+                glVertex2f(
+                    geometry::get<min_corner, 0>(box),
+                    geometry::get<min_corner, 1>(box));
+                glVertex2f(
+                    geometry::get<max_corner, 0>(box),
+                    geometry::get<min_corner, 1>(box));
+                glVertex2f(
+                    geometry::get<max_corner, 0>(box),
+                    geometry::get<max_corner, 1>(box));
+                glVertex2f(
+                    geometry::get<min_corner, 0>(box),
+                    geometry::get<max_corner, 1>(box));
+                glEnd();
+            }
+        }
+    }
+
+#endif // BOOST_GEOMETRY_INDEX_RTREE_ENABLE_GL_DRAW
+
     // awulkiew - leaf only virtual methods
 
     /**
Modified: sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_node.hpp
==============================================================================
--- sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_node.hpp	(original)
+++ sandbox-branches/geometry/index_080_nhch/boost/geometry/extensions/index/rtree/rtree_node.hpp	2011-02-22 20:31:45 EST (Tue, 22 Feb 2011)
@@ -139,12 +139,25 @@
      * \brief Print Rtree subtree (mainly for debug)
      */
     // awulkiew - ostream parameter added
-    virtual void print(std::ostream &, Translator const& tr) const
+    virtual void print(std::ostream &, Translator const&) const
     {
         // TODO: mloskot - define & use GGL exception
         throw std::logic_error("shouldn't be here");
     }
 
+#ifdef BOOST_GEOMETRY_INDEX_RTREE_ENABLE_GL_DRAW
+
+    /**
+     * \brief Draw Rtree subtree using OpenGL (mainly for debug)
+     */
+    virtual void gl_draw(Translator const&) const
+    {
+        // TODO: mloskot - define & use GGL exception
+        throw std::logic_error("shouldn't be here");
+    }
+
+#endif // BOOST_GEOMETRY_INDEX_RTREE_ENABLE_GL_DRAW
+
     // awulkiew - leaf only virtual methods
 
     /**
Added: sandbox-branches/geometry/index_080_nhch/tests/additional_glut_vis.cpp
==============================================================================
--- (empty file)
+++ sandbox-branches/geometry/index_080_nhch/tests/additional_glut_vis.cpp	2011-02-22 20:31:45 EST (Tue, 22 Feb 2011)
@@ -0,0 +1,77 @@
+#include <boost/geometry/geometry.hpp>
+
+#include <gl/glut.h>
+#define BOOST_GEOMETRY_INDEX_RTREE_ENABLE_GL_DRAW
+
+#include <boost/geometry/extensions/index/rtree/rtree.hpp>
+#include <boost/geometry/extensions/index/translator/index.hpp>
+
+#include <iostream>
+
+void render_scene(void)
+{
+    typedef boost::geometry::model::point<float, 2, boost::geometry::cs::cartesian> P;
+    typedef boost::geometry::model::box<P> B;
+
+    boost::geometry::index::rtree<B> t(5, 0);
+
+    for ( size_t i = 0 ; i < 50 ; ++i )
+    {
+        float x = ( rand() % 10000 ) / 1000.0f;
+        float y = ( rand() % 10000 ) / 1000.0f;
+        float w = ( rand() % 10000 ) / 100000.0f;
+        float h = ( rand() % 10000 ) / 100000.0f;
+
+        t.insert(B(P(x - w, y - h),P(x + w, y + h)));
+    }
+
+    t.gl_draw();
+}
+
+void resize(int w, int h)
+{
+    if ( h == 0 )
+        h = 1;
+
+    float ratio = float(w) / h;
+
+    glMatrixMode(GL_PROJECTION);
+    glLoadIdentity();
+
+    glViewport(0, 0, w, h);
+
+    gluPerspective(45, ratio, 1, 1000);
+    glMatrixMode(GL_MODELVIEW);
+    glLoadIdentity();
+    gluLookAt(
+        5.0f, 5.0f, 15.0f, 
+        5.0f, 5.0f, -1.0f,
+        0.0f, 1.0f, 0.0f);
+}
+
+void mouse(int button, int state, int x, int y)
+{
+    if ( state == GLUT_DOWN )
+    {
+        glutPostRedisplay();
+    }
+}
+
+int main(int argc, char **argv)
+{
+    glutInit(&argc, argv);
+    glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
+    glutInitWindowPosition(100,100);
+    glutInitWindowSize(320,320);
+    glutCreateWindow("Mouse click to generate new tree");
+
+    glutDisplayFunc(render_scene);
+    glutReshapeFunc(resize);
+    glutMouseFunc(mouse);
+
+    std::cout << "Mouse click to generate new tree";
+
+    glutMainLoop();
+
+    return 0;
+}
Added: sandbox-branches/geometry/index_080_nhch/tests/additional_sizes_and_times.cpp
==============================================================================
--- (empty file)
+++ sandbox-branches/geometry/index_080_nhch/tests/additional_sizes_and_times.cpp	2011-02-22 20:31:45 EST (Tue, 22 Feb 2011)
@@ -0,0 +1,66 @@
+#include <boost/geometry/geometry.hpp>
+
+#include <boost/geometry/extensions/index/rtree/rtree.hpp>
+
+#include <iostream>
+
+#include <boost/timer.hpp>
+#include <boost/foreach.hpp>
+
+int main()
+{
+    {
+        typedef boost::geometry::model::point<float, 2, boost::geometry::cs::cartesian> P;
+        typedef boost::geometry::model::box<P> B;
+
+        boost::geometry::index::rtree<B>::rtree_leaf l;
+        boost::geometry::index::rtree<B>::rtree_internal_node n;
+
+        std::cout << "shared ptr size: " << sizeof(boost::shared_ptr<int>) << '\n';
+        std::cout << "vector size: " << sizeof(std::vector<int>) << '\n';
+        std::cout << "internal node size: " << sizeof(n) << '\n';
+        std::cout << "leaf size: " << sizeof(l) << '\n';        
+    }
+
+    {
+        typedef boost::geometry::model::point<float, 2, boost::geometry::cs::cartesian> P;
+        typedef boost::geometry::model::box<P> B;
+
+        // randomize boxes
+        const size_t n = 10000;
+        std::vector<B> v(n);
+        for ( size_t i = 0 ; i < n ; ++i )
+        {
+            float x = ( rand() % 10000 ) / 1000.0f;
+            float y = ( rand() % 10000 ) / 1000.0f;
+            float w = ( rand() % 10000 ) / 100000.0f;
+            float h = ( rand() % 10000 ) / 100000.0f;
+            v[i] = B(P(x - w, y - h),P(x + w, y + h));
+        }
+
+        boost::geometry::index::rtree<B> t(5, 1);
+
+        std::cout << "inserting time test...\n";
+
+        boost::timer tim;
+
+        BOOST_FOREACH(B &b, v)
+        {
+            t.insert(b);
+        }
+
+        std::cout << "time: " << tim.elapsed() << "s\n";
+        std::cout << "removing time test...\n";
+
+        tim.restart();
+
+        BOOST_FOREACH(B &b, v)
+        {
+            t.remove(b);
+        }
+
+        std::cout << "time: " << tim.elapsed() << "s\n";
+    }
+
+    return 0;
+}
Modified: sandbox-branches/geometry/index_080_nhch/tests/main.cpp
==============================================================================
--- sandbox-branches/geometry/index_080_nhch/tests/main.cpp	(original)
+++ sandbox-branches/geometry/index_080_nhch/tests/main.cpp	2011-02-22 20:31:45 EST (Tue, 22 Feb 2011)
@@ -1,13 +1,12 @@
-
 #include <tests/translators.hpp>
 #include <tests/rtree_native.hpp>
 #include <tests/rtree_filters.hpp>
 
 int main()
 {
-	tests_translators_hpp();
-	tests_rtree_native_hpp();
-	tests_rtree_filters_hpp();
+    tests_translators_hpp();
+    tests_rtree_native_hpp();
+    tests_rtree_filters_hpp();
 
-	return 0;
+    return 0;
 }
Modified: sandbox-branches/geometry/index_080_nhch/tests/rtree_native.hpp
==============================================================================
--- sandbox-branches/geometry/index_080_nhch/tests/rtree_native.hpp	(original)
+++ sandbox-branches/geometry/index_080_nhch/tests/rtree_native.hpp	2011-02-22 20:31:45 EST (Tue, 22 Feb 2011)
@@ -13,8 +13,6 @@
 
 #include <map>
 
-#include <boost/timer.hpp>
-
 void tests_rtree_native_hpp()
 {
         std::cout << "tests\rtree_native.hpp\n";
@@ -193,59 +191,6 @@
         std::cerr << t;
     }
 
-    {
-        typedef boost::geometry::model::point<float, 2, boost::geometry::cs::cartesian> P;
-        typedef boost::geometry::model::box<P> B;
-
-        boost::geometry::index::rtree<B>::rtree_leaf l;
-        boost::geometry::index::rtree<B>::rtree_internal_node n;
-
-        std::cout << "shared ptr size: " << sizeof(boost::shared_ptr<int>) << '\n';
-        std::cout << "vector size: " << sizeof(std::vector<int>) << '\n';
-        std::cout << "internal node size: " << sizeof(n) << '\n';
-        std::cout << "leaf size: " << sizeof(l) << '\n';        
-    }
-
-    {
-        typedef boost::geometry::model::point<float, 2, boost::geometry::cs::cartesian> P;
-        typedef boost::geometry::model::box<P> B;
-
-        // randomize boxes
-        const size_t n = 10000;
-        std::vector<B> v(n);
-        for ( size_t i = 0 ; i < n ; ++i )
-        {
-            float x = ( rand() % 100000 ) / 1000.0f;
-            float y = ( rand() % 100000 ) / 1000.0f;
-            float w = ::fabs(( rand() % 100000 ) / 100000.0f);
-            float h = ::fabs((rand() % 100000 ) / 100000.0f);
-            v[i] = B(P(x - w, y - h),P(x + w, y + h));
-        }
-
-        boost::geometry::index::rtree<B> t(5, 1);
-
-        std::cout << "inserting time test...\n";
-
-        boost::timer tim;
-
-        BOOST_FOREACH(B &b, v)
-        {
-            t.insert(b);
-        }
-
-        std::cout << "time: " << tim.elapsed() << "s\n";
-        std::cout << "removing time test...\n";
-
-        tim.restart();
-
-        BOOST_FOREACH(B &b, v)
-        {
-            t.remove(b);
-        }
-
-        std::cout << "time: " << tim.elapsed() << "s\n";
-    }
-
     // ERROR!
     // remove_in expects previously inserted box - it should remove all objects inside some bigger box
 }