mirror of
https://github.com/boostorg/geometry.git
synced 2026-02-13 12:32:09 +00:00
158 lines
7.7 KiB
HTML
158 lines
7.7 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|
<title>Boost.Geometry (aka GGL, Generic Geometry Library)</title>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css">
|
|
<link href="tabs.css" rel="stylesheet" type="text/css">
|
|
</head>
|
|
|
|
<table cellpadding="2" width="100%">
|
|
<tbody>
|
|
<tr>
|
|
<td valign="top">
|
|
<img alt="Boost.Geometry" src="images/ggl-logo-big.png" height="80" width="200">
|
|
|
|
</td>
|
|
<td valign="top" align="right">
|
|
<a href="http://www.boost.org">
|
|
<img alt="Boost C++ Libraries" src="images/accepted_by_boost.png" height="80" width="230" border="0">
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<!-- Generated by Doxygen 1.5.9 -->
|
|
<div class="navigation" id="top">
|
|
<div class="tabs">
|
|
<ul>
|
|
<li><a href="index.html"><span>Main Page</span></a></li>
|
|
<li><a href="pages.html"><span>Related Pages</span></a></li>
|
|
<li><a href="modules.html"><span>Modules</span></a></li>
|
|
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
|
|
<li><a href="annotated.html"><span>Classes</span></a></li>
|
|
<li><a href="files.html"><span>Files</span></a></li>
|
|
<li><a href="examples.html"><span>Examples</span></a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div class="contents">
|
|
<h1>x01_qt_example.cpp</h1>This sample demonstrates that by usage of concepts, external geometries can be handled by GGL, just calling by a one-line registration macro. In this case for the Qt Widget Library.<p>
|
|
The example, code shown below, results in this window-output: <div align="center">
|
|
<img src="x01_qt_example_output.png" alt="x01_qt_example_output.png">
|
|
</div>
|
|
<p>
|
|
<div class="fragment"><pre class="fragment"><span class="comment">// Boost.Geometry (aka GGL, Generic Geometry Library)</span>
|
|
<span class="comment">//</span>
|
|
<span class="comment">// Copyright Barend Gehrels 2007-2009, Geodan, Amsterdam, the Netherlands</span>
|
|
<span class="comment">// Use, modification and distribution is subject to the Boost Software License,</span>
|
|
<span class="comment">// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at</span>
|
|
<span class="comment">// http://www.boost.org/LICENSE_1_0.txt)</span>
|
|
|
|
<span class="comment">// Qt Example</span>
|
|
|
|
<span class="comment">// Qt is a well-known and often used platform independent widget library</span>
|
|
|
|
<span class="comment">// To build and run this example:</span>
|
|
<span class="comment">// 1) download (from http://qt.nokia.com), configure and make QT</span>
|
|
<span class="comment">// 2) if necessary, adapt Qt clause in include path</span>
|
|
|
|
<span class="preprocessor">#include <sstream></span>
|
|
|
|
<span class="preprocessor">#include <QtGui></span>
|
|
|
|
<span class="preprocessor">#include <boost/geometry/geometry.hpp></span>
|
|
<span class="preprocessor">#include <<a class="code" href="register_2point_8hpp.html">boost/geometry/geometries/register/point.hpp</a>></span>
|
|
<span class="preprocessor">#include <<a class="code" href="ring_8hpp.html">boost/geometry/geometries/register/ring.hpp</a>></span>
|
|
|
|
|
|
<span class="comment">// Adapt a QPointF such that it can be handled by GGL</span>
|
|
<a name="a0"></a><a class="code" href="register_2point_8hpp.html#f174f265da534d30be10c2f5a4a2c75e">BOOST_GEOMETRY_REGISTER_POINT_2D_GET_SET</a>(QPointF, <span class="keywordtype">double</span>, cs::cartesian, x, y, setX, setY)
|
|
|
|
<span class="comment">// Adapt a QPolygonF as well.</span>
|
|
<span class="comment">// A QPolygonF has no holes (interiors) so it is similar to a GGL ring</span>
|
|
<a name="a1"></a><a class="code" href="ring_8hpp.html#742491bcf6ece3b0c9d21d5f6a991ac1">BOOST_GEOMETRY_REGISTER_RING</a>(QPolygonF)
|
|
|
|
|
|
<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])
|
|
{
|
|
<span class="comment">// This usage QApplication and QLabel is adapted from</span>
|
|
<span class="comment">// http://en.wikipedia.org/wiki/Qt_(toolkit)#Qt_hello_world</span>
|
|
QApplication app(argc, argv);
|
|
|
|
<span class="comment">// Declare a polygon. This is just Qt. The Qt Polygon can be used</span>
|
|
<span class="comment">// in GGL as well, just by its oneline registration above.</span>
|
|
QPolygonF polygon;
|
|
|
|
<span class="comment">// Qt methods can be used, in this case to add points</span>
|
|
polygon
|
|
<< QPointF(10, 20) << QPointF(20, 30)
|
|
<< QPointF(30, 20) << QPointF(20, 10)
|
|
<< QPointF(10, 20);
|
|
|
|
<span class="comment">// GGL methods can be used, e.g. to calculate area</span>
|
|
std::ostringstream out;
|
|
out << <span class="stringliteral">"GGL area: "</span> << <a name="a2"></a><a class="code" href="group__area.html#gd0e9e99685a9d45895162bd1fd96a136" title="Calculate area of a geometry.">boost::geometry::area</a>(polygon) << std::endl;
|
|
|
|
<span class="comment">// Some functionality is defined in both Qt and GGL</span>
|
|
QPointF p(20,20);
|
|
out << <span class="stringliteral">"Qt contains: "</span>
|
|
<< (polygon.containsPoint(p, Qt::WindingFill) ? <span class="stringliteral">"yes"</span> : <span class="stringliteral">"no"</span>)
|
|
<< std::endl
|
|
<< <span class="stringliteral">"GGL within: "</span>
|
|
<< (<a name="a3"></a><a class="code" href="group__within.html#ge8d7fe4e3391e7e0cadf14cc23b7cec1" title="Within, examine if a geometry is within another geometry.">boost::geometry::within</a>(p, polygon) ? <span class="stringliteral">"yes"</span> : <span class="stringliteral">"no"</span>)
|
|
<< std::endl;
|
|
<span class="comment">// Detail: if point is ON boundary, Qt says yes, GGL says no.</span>
|
|
|
|
|
|
<span class="comment">// Qt defines an iterator</span>
|
|
<span class="comment">// (which is actually required for GGL, it's part of the ring-concept)</span>
|
|
<span class="comment">// such that GGL can use the points of this polygon</span>
|
|
QPolygonF::const_iterator it;
|
|
<span class="keywordflow">for</span> (it = polygon.begin(); it != polygon.end(); ++it)
|
|
{
|
|
<span class="comment">// Stream Delimiter-Separated, just to show something GGL can do</span>
|
|
out << <a name="a4"></a><a class="code" href="group__utility.html#g62cc5db4d3bb1147591298b3500f8f1a" title="Main DSV-streaming function.">boost::geometry::dsv</a>(*it) << std::endl;
|
|
}
|
|
|
|
<span class="comment">// Stream the polygon as well</span>
|
|
out << <a class="code" href="group__utility.html#g62cc5db4d3bb1147591298b3500f8f1a" title="Main DSV-streaming function.">boost::geometry::dsv</a>(polygon) << std::endl;
|
|
|
|
<span class="comment">// Just show what we did in a label</span>
|
|
QLabel label(out.str().c_str());
|
|
label.show();
|
|
<span class="keywordflow">return</span> app.exec();
|
|
|
|
<span class="comment">// What else could be useful, functionality that GGL has and Qt not (yet)?</span>
|
|
<span class="comment">// - simplify a polygon (to get less points and preserve shape)</span>
|
|
<span class="comment">// - clip a polygon with a box</span>
|
|
<span class="comment">// - calculate the centroid</span>
|
|
<span class="comment">// - calculate the perimeter</span>
|
|
<span class="comment">// - calculate the convex hull</span>
|
|
<span class="comment">// - transform it using matrix transformations</span>
|
|
}
|
|
|
|
</pre></div> </div>
|
|
<hr size="1">
|
|
<table width="100%">
|
|
<tbody>
|
|
<tr>
|
|
<td align="left"><small>
|
|
<p>December 1, 2009</p>
|
|
</small></td>
|
|
<td align="right">
|
|
<small>Copyright © 1995-2009 Barend Gehrels, Geodan, Amsterdam<br>
|
|
Copyright © 2008-2009 Bruno Lalande, Paris<br>
|
|
Copyright © 2009 Mateusz Loskot, Cadcorp, London<br>
|
|
</small>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<address style="text-align: right;"><small>
|
|
Documentation is generated by <a href="http://www.doxygen.org/index.html">Doxygen</a>
|
|
</small></address>
|
|
</body>
|
|
</html>
|