|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r77573 - sandbox/gtl/doc
From: sydorchuk.andriy_at_[hidden]
Date: 2012-03-26 18:09:53
Author: asydorchuk
Date: 2012-03-26 18:09:50 EDT (Mon, 26 Mar 2012)
New Revision: 77573
URL: http://svn.boost.org/trac/boost/changeset/77573
Log:
Updating links. Updating basic tutorial.
Added:
sandbox/gtl/doc/voronoi_basic_tutorial.htm (contents, props changed)
Text files modified:
sandbox/gtl/doc/index.htm | 11 ++++++-----
sandbox/gtl/doc/voronoi_builder.htm | 4 ++--
sandbox/gtl/doc/voronoi_diagram.htm | 3 ++-
sandbox/gtl/doc/voronoi_main.htm | 3 ++-
sandbox/gtl/doc/voronoi_predicates.htm | 3 ++-
sandbox/gtl/doc/voronoi_robust_fpt.htm | 3 ++-
sandbox/gtl/doc/voronoi_utils.htm | 3 ++-
7 files changed, 18 insertions(+), 12 deletions(-)
Modified: sandbox/gtl/doc/index.htm
==============================================================================
--- sandbox/gtl/doc/index.htm (original)
+++ sandbox/gtl/doc/index.htm 2012-03-26 18:09:50 EDT (Mon, 26 Mar 2012)
@@ -1,6 +1,5 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
-<!--
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><!--
Copyright 2009-2010 Intel Corporation
license banner
--><title>Boost Polygon Library: Main Page</title>
@@ -13,6 +12,8 @@
+
+
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1" /><!-- <link type="text/css" rel="stylesheet" href="adobe_source.css"> --></head><body><table style="margin: 0pt; padding: 0pt; width: 100%;" border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td style="background-color: rgb(238, 238, 238);" nowrap="1" valign="top">
<div style="padding: 5px;" align="center">
@@ -235,9 +236,9 @@
extraction application</li>
<li>Minkowski Sum Learn how to
apply Boost.Polygon capabilities to implement Minkowski sum of polygon sets</li>
- <li>Voronoi Basic Learn how
- to construct Voronoi diagrams without digging into library details.</li>
- <li>Voronoi Advanced
+ <li>Voronoi Basic Tutorial Learn how
+ to construct, traverse, visualize, associate data with Voronoi diagrams without digging into library details.</li>
+ <li>Voronoi Advanced Tutorial
Learn how to configure Voronoi builder and Voronoi diagram
datastructures to suit your requirements. </li>
</ul>
Added: sandbox/gtl/doc/voronoi_basic_tutorial.htm
==============================================================================
--- (empty file)
+++ sandbox/gtl/doc/voronoi_basic_tutorial.htm 2012-03-26 18:09:50 EDT (Mon, 26 Mar 2012)
@@ -0,0 +1,249 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html><head>
+
+
+
+<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>Polygon Usage</title></head><body>
+
+<h1>Voronoi Basic Tutorial<br>
+</h1>
+<p>In this tutorial we will cover basic usage of the Boost.Polygon
+Voronoi library. In most cases this should cover all you need from the
+library. Below we will discuss following topics:<br>
+</p>
+<ul>
+ <li>preparing input geometries;<br>
+ </li>
+ <li>construction of the Voronoi diagram;</li>
+ <li>traversing Voronoi graph;<br>
+ </li>
+ <li>associating user data with Voronoi primitives;</li>
+ <li>rendering Voronoi diagram.<br>
+ </li>
+</ul>
+And before you start don't forget to:<span style="font-family: Courier New,Courier,monospace;"><br>
+<br>
+#include "boost/polygon/voronoi.hpp"<br>
+using boost::polygon;<br>
+</span>
+<h1>Preparing Input Geometries<br>
+</h1>
+In the example that goes through this tutorial (LINK TO THE CODE!!!) we
+are going to construct Voronoi diagram of a few points and segments.
+Before executing the algorithm lets see how the user provided types for
+the input geometries might look like:<br>
+<br>
+<span style="font-family: Courier New,Courier,monospace;">class Point {</span><span style="font-family: Courier New,Courier,monospace;"></span><span style="font-family: Courier New,Courier,monospace;"><br>
+public:<br>
+ Point() {}<br>
+ Point(int x, int y) { this->x = x; this->y = y; }<br>
+<br>
+ // Those accessors are required!<br>
+ int x() const { return x; }<br>
+ int y() const { return y; }<br>
+<br>
+private:<br>
+ // Don't forget should be castable to the signed int32 type!<br>
+</span><span style="font-family: Courier New,Courier,monospace;"> int x;</span><br style="font-family: Courier New,Courier,monospace;">
+
+<span style="font-family: Courier New,Courier,monospace;"> int y;</span><br style="font-family: Courier New,Courier,monospace;">
+<span style="font-family: Courier New,Courier,monospace;">};<br>
+<br>
+class Segment {<br>
+public:<br>
+ Segment() {}<br>
+ Segment(int x1, int y1, int x2, int y2) : p0(x1, y1), p1(x2, y2) {}<br>
+<br>
+ // Those accessors are required!<br>
+ Point low() const { return p0; }<br>
+ Point high() const { return p1; }<br>
+</span><span style="font-family: Courier New,Courier,monospace;"><br>
+private:<br>
+ Point p0;<br>
+ Point p1;</span><br>
+<span style="font-family: Courier New,Courier,monospace;">};<br>
+<br>
+</span>Once declared we can create sample input:<br>
+<br>
+<span style="font-family: Courier New,Courier,monospace;">std::vector<Point> points;</span><span style="font-family: Courier New,Courier,monospace;"><br>
+points.push_back(Point());<br>
+points.push_back(Point());</span><br>
+<span style="font-family: Courier New,Courier,monospace;">std::vector<Segment> segments;<br>
+segments.push_back(Segment());<br>
+segments.push_back(Segment());<br>
+</span>
+<h1>Construction of the Voronoi Diagram<br>
+</h1>
+
+
+Now let's construct Voronoi diagram of the input set of points and segments:<br>
+<br>
+<span style="font-family: Courier New,Courier,monospace;">voronoi_diagram<double> vd;<br>
+construct_voronoi(points, segments, vd);<br>
+<br>
+</span>So brief, isn't that awesome!<br>
+<h1>Traversing Voronoi Graph</h1>
+At the next step we are going to traverse Voronoi graph and count the
+number of primary edges. In case you forgot we consider edge to be a
+primary one if it doesn't go between the segment and its endpoint.<br>
+There are three ways to do that and we are going to cover all of them
+(each Voronoi edge has an opposite twin edge, that's why we devide
+resulting number by two):<br>
+<ul>
+ <li>simply iterating over Voronoi edges:<br>
+ <span style="font-family: Courier New,Courier,monospace;"><br>
+int get_num_primary_edges1(const voronoi_diagram<double> &vd) {<br>
+ int result = 0;<br>
+ for (voronoi_diagram<double>::const_edge_iterator it = vd.edges().begin();<br>
+ it != vd.edges().end(); ++it) {<br>
+ if (it->is_primary())<br>
+ ++result;<br>
+ }<br>
+ return result / 2;<br>
+}</span><br>
+ <span style="font-family: Courier New,Courier,monospace;"> </span><br>
+ </li>
+ <li>iterating over Voronoi cell and then traversing edges around that cell:<br>
+ <br>
+ <span style="font-family: Courier New,Courier,monospace;">int get_num_primary_edges2(const voronoi_diagram<double> &vd) {<br>
+ int result = 0;<br>
+ for (voronoi_diagram<double>::const_cell_iterator it = vd.cells().begin();<br>
+ it != vd.cells().end(); ++it) {<br>
+ const voronoi_diagram<double>::cell_type &cell = *it;<br>
+ const voronoi_diagram<double>::edge_type *edge = cell.incident_edge();<br>
+ // This is the best way to iterate edges around Voronoi cell.<br>
+ do {<br>
+ ++result;<br>
+ edge = edge->next();<br>
+ } while (edge != cell.incident_edge());<br>
+ }<br>
+ return result / 2;<br>
+}</span><br>
+ <br>
+ </li>
+ <li>iterating over Voronoi vertices and then traversing edges around that vertex:<br>
+ <br>
+ <span style="font-family: Courier New,Courier,monospace;">int get_num_primary_edges3(const voronoi_diagram<double> &vd) {<br>
+ int result = 0;<br>
+ for (voronoi_diagram<double>::const_vertex_iterator it = vd.vertices().begin();<br>
+ it != vd.vertices().end(); ++it) {<br>
+ const voronoi_diagram<double>::vertex_type &vertex = *it;<br>
+ const voronoi_diagram<double>::edge_type *edge = vertex.incident_edge();<br>
+ // This is the best way to iterate edges around Voronoi vertex.<br>
+ do {<br>
+ ++result;<br>
+ edge = edge->rot_next();<br>
+ } while (edge != vertex.incident_edge());<br>
+ }<br>
+ return result / 2;<br>
+}</span><br>
+ </li>
+</ul>
+This should give a very nice idea on how to traverse Voronoi diagram.<br>
+<h1>Associating user data with Voronoi primitives</h1>
+A few simple cases of associating user data with Voronoi primitives are following:<br>
+<ul>
+ <li>associating number of incident edges with each cell, vertex;</li>
+ <li>associating color with each edge;</li>
+ <li>using DFS or BFS on the Voronoi graph requires to mark visited edges/vertices/cells.</li>
+</ul>
+We will consider first example and will try to associate number of incident edges with each cell.<br>
+Note: Each Voronoi primitive contains mutable pointer to void* type, that enables to associate any type of data with it.<br>
+<br>
+<span style="font-family: Courier New,Courier,monospace;">vector<int> counts;<br>
+counts.reserve(vd.num_cells()); // This is required as reallocation of underlying vector will invalidate all the pointers.<br>
+for (voronoi_diagram<double>::const_cell_iterator it = vd.cells().begin();<br>
+ it != vd.vertices().end(); ++it) {<br>
+ </span><span style="font-family: Courier New,Courier,monospace;">const voronoi_diagram<double>::cell_type &cell = *it;<br>
+ const voronoi_diagram<double>::edge_type *edge = cell.incident_edge();<br>
+ int count = 0;<br>
+ do {<br>
+ ++count;<br>
+ edge = edge->next();<br>
+ } while (edge != cell.incident_edge());<br>
+ counts.push_back(count);<br>
+ cell.data(&counts.back());<br>
+</span><span style="font-family: Courier New,Courier,monospace;">}<br>
+</span><br>
+Note: In the example above we could not simply use count variable
+without a vector, because pointer to it will become invalid as soon as
+we leave the scope of enclosing for-loop.<br>
+<h1>Rendering Voronoi diagram</h1>
+There are two main issues that don't allow to strictly render output
+Voronoi diagram using modern rendering tools like OpenGL or DirectX.
+Those are:<br>
+<ul>
+ <li>Some of the Voronoi edges are infinite, so should be clipped;</li>
+ <li>Some of the Voronoi edge are parabolic arcs, so should be discretized.</li>
+</ul>
+All this functionality is already implemented in the Voronoi utils.
+Before clipping edges we should define clipping rectangle. It is
+usually handy to choose it so that it wraps all the input geometries
+plus some offset.<br>
+<br>
+<span style="font-family: Courier New,Courier,monospace;">bounding_rectangle<double> bbox;</span><br style="font-family: Courier New,Courier,monospace;">
+<span style="font-family: Courier New,Courier,monospace;">for (std::vector<Point>::iterator it = points.begin(); it != points.end(); ++it)<br>
+ bbox.update(it->x(), it->y());<br>
+for (std::vector<Segment>::iterator it = segments.begin(); it != segments.end(); ++it) {<br>
+ bbox.update(it->low().x(), it->low().y());<br>
+ bbox.update(it->high().x(), it->high().y());<br>
+}<br>
+return voronoi_utils<double>::scale(bbox, 1.1); // Add 10% offset to the bounding rectangle.<br>
+</span><br>
+Lets consider that we have 3rd party library function that draws segments using following prototype:<span style="font-family: Courier New,Courier,monospace;"><br>
+<br>
+void draw_segment(double x1, double y1, double x2, double y2);<br>
+<br>
+</span>Then function that renders our diagram edges will have following implementation:<br>
+<br>
+<span style="font-family: Courier New,Courier,monospace;">void render_diagram(const voronoi_diagram<double> &vd,<br>
+
+const voronoi_utils<double>::brect_type &bbox) {<br>
+ </span><span style="font-family: Courier New,Courier,monospace;">for (voronoi_diagram<double>::const_edge_iterator it = vd.edges().begin();<br>
+ it != vd.edges().end(); ++it) {<br>
+</span><span style="font-family: Courier New,Courier,monospace;"> it->data(&(*it)); // We use data pointer to mark visited edges (by pointing to itself);</span><br>
+<span style="font-family: Courier New,Courier,monospace;"> if (it->twin()) continue; // We don't want to draw the same edge twice;<br>
+ voronoi_utils<double>::point_set_type polyline;<br>
+ if (it->is_linear)<br>
+ voronoi_utils<double>::clip(*it, bbox, polyline);<br>
+ else<br>
+ // Parabolic edges are always finite.<br>
+ voronoi_utils<double>::discretize(*it, 1E-3, polyline);<br>
+ // Note: discretized edges may also lie outside of the bbox.<br>
+ // So user might do additional clipping before rendering each such edge. <br>
+ for (int i = 1; i < polyline.size(); ++i)<br>
+ draw_segment(polyline[i-1].x(), polyline[i-1].y(), polyline[i].x(), polyline[i].y());<br>
+
+ }</span><br>
+<span style="font-family: Courier New,Courier,monospace;">}<br>
+<br>
+</span>I hope the reader managed to get to this point and found the
+Basic tutorial to be useful (in the end it's not so basic). It's worth
+to notice that construction of the Voronoi diagram takes only two lines
+of code, everything else is about initializing input data structures,
+traversing Voronoi graph, associating data with diagram primitives and
+using Voronoi utililities. In
+default mode Voronoi diagram operates with signed int (32 bit) input
+coordinate type and double (64 bit) output coordinate type. In case you
+are intersted in expanding those try Voronoi Advanced Tutorial.<br>
+<span style="font-family: Courier New,Courier,monospace;"></span><br>
+<table class="docinfo" id="table1" frame="void" rules="none">
+ <colgroup>
+ <col class="docinfo-name"><col class="docinfo-content">
+ </colgroup>
+ <tbody valign="top">
+ <tr>
+ <th class="docinfo-name">Copyright:</th>
+ <td>Copyright © Intel Corporation 2008-2010.</td>
+ </tr>
+ <tr class="field">
+ <th class="docinfo-name">License:</th>
+ <td class="field-body">Distributed under the Boost Software License,
+ Version 1.0. (See accompanying file <tt class="literal">
+ <span class="pre">LICENSE_1_0.txt</span></tt> or copy at
+ <a class="reference" target="_top" href="http://www.boost.org/LICENSE_1_0.txt">
+ http://www.boost.org/LICENSE_1_0.txt>)</td>
+ </tr>
+</tbody></table>
+
+</body></html>
\ No newline at end of file
Modified: sandbox/gtl/doc/voronoi_builder.htm
==============================================================================
--- sandbox/gtl/doc/voronoi_builder.htm (original)
+++ sandbox/gtl/doc/voronoi_builder.htm 2012-03-26 18:09:50 EDT (Mon, 26 Mar 2012)
@@ -7,6 +7,7 @@
+
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>Contents</title></head><body>
@@ -69,8 +70,7 @@
<li>Performance Analysis</li>
<li>Layout Versus Schematic Tutorial</li>
<li>Minkowski Sum Tutorial</li>
- <li><a href="voronoi_diagram_basic_tutorial.htm">Voronoi Diagram
- Basic Tutorial</a></li>
+ <li>Voronoi Basic Tutorial</li>
<li><a href="voronoi_diagram_advanced_tutorial.htm">Voronoi
Diagram Advanced Tutorial</a></li>
</ul>
Modified: sandbox/gtl/doc/voronoi_diagram.htm
==============================================================================
--- sandbox/gtl/doc/voronoi_diagram.htm (original)
+++ sandbox/gtl/doc/voronoi_diagram.htm 2012-03-26 18:09:50 EDT (Mon, 26 Mar 2012)
@@ -22,6 +22,7 @@
+
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>Contents</title><meta http-equiv="content-type" content="text/html; charset=utf-8"><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body>
@@ -91,7 +92,7 @@
<li>Performance Analysis</li>
<li>Layout Versus Schematic Tutorial</li>
<li>Minkowski Sum Tutorial</li>
- <li>Voronoi Basic Tutorial</li>
+ <li>Voronoi Basic Tutorial</li>
<li>Voronoi Advanced Tutorial</li>
</ul>
</div>
Modified: sandbox/gtl/doc/voronoi_main.htm
==============================================================================
--- sandbox/gtl/doc/voronoi_main.htm (original)
+++ sandbox/gtl/doc/voronoi_main.htm 2012-03-26 18:09:50 EDT (Mon, 26 Mar 2012)
@@ -25,6 +25,7 @@
+
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>Contents</title><meta http-equiv="content-type" content="text/html; charset=utf-8"><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body>
@@ -95,7 +96,7 @@
<li>Performance Analysis</li>
<li>Layout Versus Schematic Tutorial</li>
<li>Minkowski Sum Tutorial</li>
- <li>Voronoi Basic Tutorial</li>
+ <li>Voronoi Basic Tutorial</li>
<li>Voronoi Advanced Tutorial</li>
</ul>
</div>
Modified: sandbox/gtl/doc/voronoi_predicates.htm
==============================================================================
--- sandbox/gtl/doc/voronoi_predicates.htm (original)
+++ sandbox/gtl/doc/voronoi_predicates.htm 2012-03-26 18:09:50 EDT (Mon, 26 Mar 2012)
@@ -11,6 +11,7 @@
+
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>Contents</title></head><body>
@@ -79,7 +80,7 @@
<li>Performance Analysis</li>
<li>Layout Versus Schematic Tutorial</li>
<li>Minkowski Sum Tutorial</li>
- <li>Voronoi Basic Tutorial</li>
+ <li>Voronoi Basic Tutorial</li>
<li>Voronoi Advanced Tutorial</li>
</ul>
</div>
Modified: sandbox/gtl/doc/voronoi_robust_fpt.htm
==============================================================================
--- sandbox/gtl/doc/voronoi_robust_fpt.htm (original)
+++ sandbox/gtl/doc/voronoi_robust_fpt.htm 2012-03-26 18:09:50 EDT (Mon, 26 Mar 2012)
@@ -11,6 +11,7 @@
+
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>Contents</title></head><body>
@@ -80,7 +81,7 @@
<li>Performance Analysis</li>
<li>Layout Versus Schematic Tutorial</li>
<li>Minkowski Sum Tutorial</li>
- <li>Voronoi Basic Tutorial</li>
+ <li>Voronoi Basic Tutorial</li>
<li>Voronoi Advanced Tutorial</li>
</ul>
</div>
Modified: sandbox/gtl/doc/voronoi_utils.htm
==============================================================================
--- sandbox/gtl/doc/voronoi_utils.htm (original)
+++ sandbox/gtl/doc/voronoi_utils.htm 2012-03-26 18:09:50 EDT (Mon, 26 Mar 2012)
@@ -18,6 +18,7 @@
+
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>Contents</title><meta http-equiv="content-type" content="text/html; charset=utf-8"><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body>
@@ -87,7 +88,7 @@
<li>Performance Analysis</li>
<li>Layout Versus Schematic Tutorial</li>
<li>Minkowski Sum Tutorial</li>
- <li>Voronoi Basic Tutorial</li>
+ <li>Voronoi Basic Tutorial</li>
<li>Voronoi Advanced Tutorial</li>
</ul>
</div>
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