Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77112 - in sandbox/gtl: boost/polygon libs/polygon/voronoi_example
From: sydorchuk.andriy_at_[hidden]
Date: 2012-02-24 18:22:17


Author: asydorchuk
Date: 2012-02-24 18:22:16 EST (Fri, 24 Feb 2012)
New Revision: 77112
URL: http://svn.boost.org/trac/boost/changeset/77112

Log:
Adding useful interface methods to voronoi_builder.hpp.
Updating voronoi_visualizer.
Text files modified:
   sandbox/gtl/boost/polygon/voronoi_builder.hpp | 66 +++++++++++++++++++++++++++------------
   sandbox/gtl/boost/polygon/voronoi_utils.hpp | 23 -------------
   sandbox/gtl/libs/polygon/voronoi_example/voronoi_visualizer.cpp | 56 +++++++++++++--------------------
   3 files changed, 70 insertions(+), 75 deletions(-)

Modified: sandbox/gtl/boost/polygon/voronoi_builder.hpp
==============================================================================
--- sandbox/gtl/boost/polygon/voronoi_builder.hpp (original)
+++ sandbox/gtl/boost/polygon/voronoi_builder.hpp 2012-02-24 18:22:16 EST (Fri, 24 Feb 2012)
@@ -65,37 +65,59 @@
               typename VP = detail::voronoi_predicates<CTT> >
     class voronoi_builder {
     public:
+ typedef typename CTT::int_type int_type;
+ typedef typename CTT::fpt_type fpt_type;
+
         voronoi_builder() {}
 
+ void insert_point(const int_type& x, const int_type& y) {
+ site_events_.push_back(site_event_type(x, y));
+ }
+
+ template <typename PointType>
+ void insert_point(const PointType& point) {
+ insert_point(point.x(), point.y());
+ }
+
         template <typename PointIterator>
         void insert_points(PointIterator first_point, PointIterator last_point) {
             // Create a site event from each input point.
             for (PointIterator it = first_point; it != last_point; ++it) {
- site_events_.push_back(site_event_type(it->x(), it->y()));
+ insert_point(*it);
             }
         }
 
- template <typename SegmentIterator>
- void insert_segments(SegmentIterator first_segment, SegmentIterator last_segment) {
+ void insert_segment(const int_type& x1, const int_type& y1,
+ const int_type& x2, const int_type& y2) {
             // Each segment creates three segment sites:
             // 1) the startpoint of the segment;
             // 2) the endpoint of the segment;
             // 3) the segment itself.
- point_comparison_predicate point_comparison;
+ point_type p1(x1, y1);
+ point_type p2(x2, y2);
+ site_events_.push_back(site_event_type(p1));
+ site_events_.push_back(site_event_type(p2));
+ if (point_comparison_(p1, p2)) {
+ site_events_.push_back(site_event_type(p1, p2));
+ } else {
+ site_events_.push_back(site_event_type(p2, p1));
+ }
+ }
+
+ template <typename PointType>
+ void insert_segment(const PointType& point1, const PointType& point2) {
+ insert_segment(point1.x(), point1.y(), point2.x(), point2.y());
+ }
+
+ template <typename SegmentType>
+ void insert_segment(const SegmentType& segment) {
+ insert_segment(segment.low(), segment.high());
+ }
+
+ template <typename SegmentIterator>
+ void insert_segments(SegmentIterator first_segment, SegmentIterator last_segment) {
             for (SegmentIterator it = first_segment; it != last_segment; ++it) {
- int_type x1 = it->low().x();
- int_type y1 = it->low().y();
- int_type x2 = it->high().x();
- int_type y2 = it->high().y();
- point_type p1(x1, y1);
- point_type p2(x2, y2);
- site_events_.push_back(site_event_type(p1));
- site_events_.push_back(site_event_type(p2));
- if (point_comparison(p1, p2)) {
- site_events_.push_back(site_event_type(p1, p2));
- } else {
- site_events_.push_back(site_event_type(p2, p1));
- }
+ insert_segment(*it);
             }
         }
 
@@ -147,12 +169,15 @@
 
         void clear() {
             site_events_.clear();
+ if (!beach_line_.empty())
+ beach_line_.clear();
+ if (!circle_events_.empty())
+ circle_events_.clear();
+ while (!end_points_.empty())
+ end_points_.pop();
         }
 
     private:
- typedef typename CTT::int_type int_type;
- typedef typename CTT::fpt_type fpt_type;
-
         typedef detail::point_2d<int_type> point_type;
         typedef detail::site_event<int_type> site_event_type;
         typedef typename std::vector<site_event_type>::const_iterator
@@ -517,6 +542,7 @@
         }
 
     private:
+ point_comparison_predicate point_comparison_;
         struct end_point_comparison {
             bool operator() (const end_point_type &end1, const end_point_type &end2) const {
                 return point_comparison(end2.first, end1.first);

Modified: sandbox/gtl/boost/polygon/voronoi_utils.hpp
==============================================================================
--- sandbox/gtl/boost/polygon/voronoi_utils.hpp (original)
+++ sandbox/gtl/boost/polygon/voronoi_utils.hpp 2012-02-24 18:22:16 EST (Fri, 24 Feb 2012)
@@ -14,7 +14,6 @@
 #include <stack>
 #include <vector>
 
-#include "polygon.hpp"
 #include "voronoi_diagram.hpp"
 
 namespace boost {
@@ -26,10 +25,8 @@
 template<>
 struct voronoi_utils_traits<double> {
     typedef double fpt_type;
- typedef point_data<fpt_type> point_type;
+ typedef detail::point_2d<fpt_type> point_type;
     typedef std::vector<point_type> point_set_type;
- typedef directed_line_segment_data<fpt_type> segment_type;
- typedef directed_line_segment_set_data<fpt_type> segment_set_type;
     typedef bounding_rectangle<fpt_type> brect_type;
     typedef struct {
         template <typename CT>
@@ -46,8 +43,6 @@
     typedef typename TRAITS::fpt_type fpt_type;
     typedef typename TRAITS::point_type point_type;
     typedef typename TRAITS::point_set_type point_set_type;
- typedef typename TRAITS::segment_type segment_type;
- typedef typename TRAITS::segment_set_type segment_set_type;
     typedef typename TRAITS::brect_type brect_type;
     typedef typename TRAITS::ctype_converter_type ctype_converter_type;
 
@@ -174,22 +169,6 @@
         return edge_points;
     }
 
- // Interpolate voronoi edge with a set of segments to satisfy maximal
- // error requirement.
- template <typename CT>
- static segment_set_type get_segment_interpolation(
- const voronoi_edge<CT> *edge,
- const bounding_rectangle<CT> &brect,
- fpt_type max_error) {
- point_set_type point_interpolation =
- get_point_interpolcation(edge, brect, max_error);
- segment_set_type ret_val;
- for (size_t i = 1; i < point_interpolation.size(); ++i)
- ret_val.insert(segment_type(point_interpolation[i-1],
- point_interpolation[i]));
- return ret_val;
- }
-
     // Find edge-rectangle intersection points.
     // Edge is represented by its origin, direction and type.
     static void find_intersections(

Modified: sandbox/gtl/libs/polygon/voronoi_example/voronoi_visualizer.cpp
==============================================================================
--- sandbox/gtl/libs/polygon/voronoi_example/voronoi_visualizer.cpp (original)
+++ sandbox/gtl/libs/polygon/voronoi_example/voronoi_visualizer.cpp 2012-02-24 18:22:16 EST (Fri, 24 Feb 2012)
@@ -33,8 +33,8 @@
   }
 
   void build(QString file_path) {
- ipoint_set_type point_sites;
- isegment_set_type segment_sites;
+ vb_.clear();
+ vd_.clear();
 
     // Open file.
     QFile data(file_path);
@@ -51,23 +51,21 @@
     in_stream >> num_point_sites;
     for (int i = 0; i < num_point_sites; ++i) {
       in_stream >> x1 >> y1;
- point_sites.push_back(ipoint_type(x1, y1));
+ vb_.insert_point(x1, y1);
     }
     in_stream >> num_edge_sites;
     for (int i = 0; i < num_edge_sites; ++i) {
       in_stream >> x1 >> y1 >> x2 >> y2;
- segment_sites.insert(isegment_type(ipoint_type(x1, y1),
- ipoint_type(x2, y2)));
+ vb_.insert_segment(x1, y1, x2, y2);
     }
     in_stream.flush();
 
     // Build voronoi diagram.
- vd_.clear();
- construct_voronoi(point_sites, segment_sites, &vd_);
+ vb_.construct(&vd_);
     brect_ = voronoi_utils<coordinate_type>::get_view_rectangle(
         vd_.bounding_rectangle(), 1.4);
- shift_ = point_data<double>((brect_.x_min() + brect_.x_max()) * 0.5,
- (brect_.y_min() + brect_.y_max()) * 0.5);
+ shift_ = point_type((brect_.x_min() + brect_.x_max()) * 0.5,
+ (brect_.y_min() + brect_.y_max()) * 0.5);
 
     exterior_edges_set_.clear();
     for (voronoi_edge_const_iterator_type it = vd_.edge_records().begin();
@@ -157,7 +155,7 @@
         if (internal_edges_only_ && exterior_edges_set_.count(&(*it))) {
           continue;
         }
- std::vector<opoint_type> temp_v =
+ std::vector<point_type> temp_v =
           voronoi_utils<coordinate_type>::get_point_interpolation(
               &(*it), brect_, 1E-3);
         for (int i = 0; i < static_cast<int>(temp_v.size()) - 1; ++i) {
@@ -179,7 +177,18 @@
   }
 
 private:
- void remove_exterior(const voronoi_diagram<double>::voronoi_edge_type* edge) {
+ typedef double coordinate_type;
+ typedef detail::point_2d<double> point_type;
+ typedef voronoi_diagram<double> VD;
+ typedef VD::voronoi_edge_type voronoi_edge_type;
+ typedef VD::voronoi_cells_type voronoi_cells_type;
+ typedef VD::voronoi_vertices_type voronoi_vertices_type;
+ typedef VD::voronoi_edges_type voronoi_edges_type;
+ typedef VD::voronoi_cell_const_iterator_type voronoi_cell_const_iterator_type;
+ typedef VD::voronoi_vertex_const_iterator_type voronoi_vertex_const_iterator_type;
+ typedef VD::voronoi_edge_const_iterator_type voronoi_edge_const_iterator_type;
+
+ void remove_exterior(const VD::voronoi_edge_type* edge) {
     if (exterior_edges_set_.count(edge)) {
       return;
     }
@@ -205,28 +214,9 @@
     glMatrixMode(GL_MODELVIEW);
   }
 
- typedef double coordinate_type;
- typedef point_data<int> ipoint_type;
- typedef point_data<double> opoint_type;
- typedef directed_line_segment_data<int> isegment_type;
- typedef std::vector<ipoint_type> ipoint_set_type;
- typedef directed_line_segment_set_data<int> isegment_set_type;
- typedef voronoi_diagram<coordinate_type>::voronoi_edge_type
- voronoi_edge_type;
- typedef voronoi_diagram<coordinate_type>::voronoi_cells_type
- voronoi_cells_type;
- typedef voronoi_diagram<coordinate_type>::voronoi_vertices_type
- voronoi_vertices_type;
- typedef voronoi_diagram<coordinate_type>::voronoi_edges_type
- voronoi_edges_type;
- typedef voronoi_diagram<coordinate_type>::voronoi_cell_const_iterator_type
- voronoi_cell_const_iterator_type;
- typedef voronoi_diagram<coordinate_type>::voronoi_vertex_const_iterator_type
- voronoi_vertex_const_iterator_type;
- typedef voronoi_diagram<coordinate_type>::voronoi_edge_const_iterator_type
- voronoi_edge_const_iterator_type;
- bounding_rectangle<coordinate_type> brect_;
- point_data<double> shift_;
+ bounding_rectangle<double> brect_;
+ point_type shift_;
+ default_voronoi_builder vb_;
   voronoi_diagram<coordinate_type> vd_;
   std::set<const voronoi_edge_type*> exterior_edges_set_;
   bool primary_edges_only_;


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