Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77688 - sandbox/gtl/libs/polygon/voronoi_example
From: sydorchuk.andriy_at_[hidden]
Date: 2012-04-01 14:15:13


Author: asydorchuk
Date: 2012-04-01 14:15:13 EDT (Sun, 01 Apr 2012)
New Revision: 77688
URL: http://svn.boost.org/trac/boost/changeset/77688

Log:
Finalizing advanced tutorial source code.

Text files modified:
   sandbox/gtl/libs/polygon/voronoi_example/Jamfile.v2 | 10 ++++++++++
   sandbox/gtl/libs/polygon/voronoi_example/voronoi_advanced_tutorial.cpp | 34 ++++++++++++++++++++++++++++++++--
   2 files changed, 42 insertions(+), 2 deletions(-)

Modified: sandbox/gtl/libs/polygon/voronoi_example/Jamfile.v2
==============================================================================
--- sandbox/gtl/libs/polygon/voronoi_example/Jamfile.v2 (original)
+++ sandbox/gtl/libs/polygon/voronoi_example/Jamfile.v2 2012-04-01 14:15:13 EDT (Sun, 01 Apr 2012)
@@ -7,6 +7,15 @@
 import testing ;
 
 lib opengl : : <name>opengl32 ;
+
+project voronoi_example
+ :
+ requirements
+ <include>.
+ <toolset>msvc:<asynch-exceptions>on
+ <library>$(BOOST_ROOT)/libs/timer/build//boost_timer
+ ;
+
 exe voronoi_visualizer
     :
       voronoi_visualizer.cpp
@@ -25,3 +34,4 @@
     :
         [ run voronoi_advanced_tutorial.cpp ]
     ;
+

Modified: sandbox/gtl/libs/polygon/voronoi_example/voronoi_advanced_tutorial.cpp
==============================================================================
--- sandbox/gtl/libs/polygon/voronoi_example/voronoi_advanced_tutorial.cpp (original)
+++ sandbox/gtl/libs/polygon/voronoi_example/voronoi_advanced_tutorial.cpp 2012-04-01 14:15:13 EDT (Sun, 01 Apr 2012)
@@ -8,12 +8,20 @@
 // See http://www.boost.org for updates, documentation, and revision history.
 
 #include <cmath>
+#include <cstdio>
+#include <ctime>
+#include <string>
 
 // This will work properly only with GCC compiler.
 #include <ieee754.h>
 typedef long double fpt80;
 
-#include "boost/polygon/voronoi.hpp"
+// Random generators and distributions.
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/uniform_int_distribution.hpp>
+#include <boost/timer/timer.hpp>
+
+#include <boost/polygon/voronoi.hpp>
 using namespace boost::polygon;
 
 struct my_ulp_comparison {
@@ -110,10 +118,32 @@
   typedef my_fpt_converter to_efpt_converter_type;
 };
 
+const unsigned int GENERATED_POINTS = 100;
+const boost::int64_t MAX = 0x1000000000000LL;
+
 #include <iostream>
 int main () {
- voronoi_diagram<fpt80, my_voronoi_diagram_traits> vd;
+ boost::mt19937_64 gen(std::time(0));
+ boost::random::uniform_int_distribution<boost::int64_t> distr(-MAX, MAX-1);
   voronoi_builder<boost::int64_t, my_voronoi_ctype_traits> vb;
+ voronoi_diagram<fpt80, my_voronoi_diagram_traits> vd;
+ for (size_t i = 0; i < GENERATED_POINTS; ++i) {
+ boost::int64_t x = distr(gen);
+ boost::int64_t y = distr(gen);
+ vb.insert_point(x, y);
+ }
+
+ printf("Constructing Voronoi diagram of %d points...\n", GENERATED_POINTS);
+ boost::timer::cpu_timer t;
+ t.start();
   vb.construct(&vd);
+ boost::timer::cpu_times times = t.elapsed();
+ std::string ftime = boost::timer::format(times, 5, "%w");
+
+ printf("Consturction done in: %s seconds.\n", ftime.c_str());
+ printf("Resulting Voronoi graph has following stats:\n");
+ printf("Number of Voronoi cells: %d.\n", vd.num_cells());
+ printf("Number of Voronoi vertices: %d.\n", vd.num_vertices());
+ printf("Number of Voronoi edges: %d.\n", vd.num_edges());
   return 0;
 }


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