46e399eb59
[SVN r62301]
128 lines
5.0 KiB
HTML
128 lines
5.0 KiB
HTML
<html>
|
||
|
||
<head>
|
||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||
<title>Property Merge Usage</title>
|
||
</head>
|
||
|
||
<body>
|
||
|
||
<p><font face="Courier New">/*<br>
|
||
Copyright 2008 Intel Corporation<br>
|
||
<br>
|
||
Use, modification and distribution are subject to the Boost Software License,<br>
|
||
Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at<br>
|
||
http://www.boost.org/LICENSE_1_0.txt).<br>
|
||
*/<br>
|
||
#include <boost/polygon/polygon.hpp><br>
|
||
#include <cassert><br>
|
||
namespace gtl = boost::polygon;<br>
|
||
using namespace boost::polygon::operators;<br>
|
||
<br>//just a little meta-programming to get things off on the right foot<br>
|
||
template <typename T><br>
|
||
struct lookup_polygon_set_type { typedef gtl::polygon_set_data<int> type; };<br>
|
||
template <typename T, typename T2><br>
|
||
struct lookup_polygon_set_type<gtl::property_merge_90<T, T2> > { <br>
|
||
typedef gtl::polygon_90_set_data<int> type; };<br>
|
||
<br>
|
||
//This function works with both the 90 and general versions<br>
|
||
//of property merge/map overlay algorithm<br>
|
||
template <typename pm_type><br>
|
||
void test_pm() {<br>
|
||
std::vector<gtl::rectangle_data<int> > test_data;<br>
|
||
test_data.push_back(gtl::rectangle_data<int>(11, 10, 31, 30));<br>
|
||
test_data.push_back(gtl::rectangle_data<int>(1, 0, 21, 20));<br>
|
||
test_data.push_back(gtl::rectangle_data<int>(6, 15, 16, 25));<br>
|
||
<br>
|
||
pm_type pm;<br>
|
||
<br>
|
||
//insert our test geometry into the property merge algorithm<br>
|
||
for(unsigned int i = 0; i < test_data.size(); ++i) {<br>
|
||
pm.insert(test_data[i], i); //notice I use the index as the
|
||
property value<br>
|
||
}<br>
|
||
<br>
|
||
typedef typename lookup_polygon_set_type<pm_type>::type polygon_set_type;<br>
|
||
typedef std::map<std::set<int>, polygon_set_type>
|
||
property_merge_result_type;<br>
|
||
<br>
|
||
std::set<int> key;<br>
|
||
<br>
|
||
//There are 8 different combinations of our input geometries<br>
|
||
//null combination is not interesting, so really 7<br>
|
||
<br>
|
||
property_merge_result_type result;<br>
|
||
pm.merge(result);<br>
|
||
<br>
|
||
//lets enumerate boolean combinations of inputs (hold onto your hats)<br>
|
||
for(unsigned int i = 0; i < 8; ++i) {<br>
|
||
bool bits[3] = {i & 1, i & 2, i & 4}; //break out bit array<br>
|
||
polygon_set_type test_set;<br>
|
||
std::set<int> key;<br>
|
||
for(unsigned int j = 0; j < 3; ++j) {<br>
|
||
if(bits[j]) {<br>
|
||
key.insert(key.end(), j);<br>
|
||
test_set += test_data[j];<br>
|
||
}<br>
|
||
}<br>
|
||
for(unsigned int j = 0; j < 3; ++j) {<br>
|
||
if(bits[j]) {<br>
|
||
test_set *= test_data[j];<br>
|
||
}<br>
|
||
}<br>
|
||
for(unsigned int j = 0; j < 3; ++j) {<br>
|
||
if(!bits[j])<br>
|
||
test_set -= test_data[j];<br>
|
||
}<br>
|
||
if(test_set.empty()) {<br>
|
||
//only the null combination should not exist<br>
|
||
assert(i == 0);<br>
|
||
//a combination that does not exist should not<br>
|
||
//be present in result<br>
|
||
assert(result.find(key) == result.end());<br>
|
||
} else {<br>
|
||
assert(gtl::equivalence(result[key], test_set));<br>
|
||
}<br>
|
||
}<br>
|
||
<br>
|
||
//Notice that we have to do O(2^n) booleans to compose the same<br>
|
||
//result that is produced in one pass of property merge<br>
|
||
//given n input layers (8 = 2^3 in this example)<br>
|
||
}<br>
|
||
<br>
|
||
int main() {<br>
|
||
|
||
test_pm<gtl::property_merge_90<int, int> >();<br>
|
||
|
||
test_pm<gtl::property_merge<int, int> >();<br>
|
||
|
||
return 0;<br>
|
||
}<br>
|
||
//Now you know how to use the manhattan and arbitrary angle property<br>
|
||
//merge algorithms to perform map overlay on n layers of input geometry<br>
|
||
</font></p>
|
||
|
||
|
||
<table class="docinfo" rules="none" frame="void" id="table1">
|
||
<colgroup>
|
||
<col class="docinfo-name"><col class="docinfo-content">
|
||
</colgroup>
|
||
<tbody vAlign="top">
|
||
<tr>
|
||
<th class="docinfo-name">Copyright:</th>
|
||
<td>Copyright <20> 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</a>)</td>
|
||
</tr>
|
||
</table>
|
||
|
||
</body>
|
||
|
||
</html>
|