4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=windows-1252">
5 <title>Property Merge Usage
</title>
10 <p><font face=
"Courier New">/*
<br>
11 Copyright
2008 Intel Corporation
<br>
13 Use, modification and distribution are subject to the Boost Software License,
<br>
14 Version
1.0. (See accompanying file LICENSE_1_0.txt or copy at
<br>
15 http://www.boost.org/LICENSE_1_0.txt).
<br>
17 #include
<boost/polygon/polygon.hpp
><br>
18 #include
<cassert
><br>
19 namespace gtl = boost::polygon;
<br>
20 using namespace boost::polygon::operators;
<br>
21 <br>//just a little meta-programming to get things off on the right foot
<br>
22 template
<typename T
><br>
23 struct lookup_polygon_set_type { typedef gtl::polygon_set_data
<int
> type; };
<br>
24 template
<typename T, typename T2
><br>
25 struct lookup_polygon_set_type
<gtl::property_merge_90
<T, T2
> > {
<br>
26 typedef gtl::polygon_90_set_data
<int
> type; };
<br>
28 //This function works with both the
90 and general versions
<br>
29 //of property merge/map overlay algorithm
<br>
30 template
<typename pm_type
><br>
32 std::vector
<gtl::rectangle_data
<int
> > test_data;
<br>
33 test_data.push_back(gtl::rectangle_data
<int
>(
11,
10,
31,
30));
<br>
34 test_data.push_back(gtl::rectangle_data
<int
>(
1,
0,
21,
20));
<br>
35 test_data.push_back(gtl::rectangle_data
<int
>(
6,
15,
16,
25));
<br>
37 pm_type pm;
<br>
39 //insert our test geometry into the property merge algorithm
<br>
40 for(unsigned int i =
0; i
< test_data.size(); ++i) {
<br>
41 pm.insert(test_data[i], i); //notice I use the index as the
45 typedef typename lookup_polygon_set_type
<pm_type
>::type polygon_set_type;
<br>
46 typedef std::map
<std::set
<int
>, polygon_set_type
>
47 property_merge_result_type;
<br>
49 std::set
<int
> key;
<br>
51 //There are
8 different combinations of our input geometries
<br>
52 //null combination is not interesting, so really
7<br>
54 property_merge_result_type result;
<br>
55 pm.merge(result);
<br>
57 //lets enumerate boolean combinations of inputs (hold onto your hats)
<br>
58 for(unsigned int i =
0; i
< 8; ++i) {
<br>
59 bool bits[
3] = {i
& 1, i
& 2, i
& 4}; //break out bit array
<br>
60 polygon_set_type test_set;
<br>
61 std::set
<int
> key;
<br>
62 for(unsigned int j =
0; j
< 3; ++j) {
<br>
63 if(bits[j]) {
<br>
64 key.insert(key.end(), j);
<br>
65 test_set += test_data[j];
<br>
66 }
<br>
67 }
<br>
68 for(unsigned int j =
0; j
< 3; ++j) {
<br>
69 if(bits[j]) {
<br>
70 test_set *= test_data[j];
<br>
71 }
<br>
72 }
<br>
73 for(unsigned int j =
0; j
< 3; ++j) {
<br>
74 if(!bits[j])
<br>
75 test_set -= test_data[j];
<br>
76 }
<br>
77 if(test_set.empty()) {
<br>
78 //only the null combination should not exist
<br>
79 assert(i ==
0);
<br>
80 //a combination that does not exist should not
<br>
81 //be present in result
<br>
82 assert(result.find(key) == result.end());
<br>
83 } else {
<br>
84 assert(gtl::equivalence(result[key], test_set));
<br>
85 }
<br>
88 //Notice that we have to do O(
2^n) booleans to compose the same
<br>
89 //result that is produced in one pass of property merge
<br>
90 //given n input layers (
8 =
2^
3 in this example)
<br>
95 test_pm
<gtl::property_merge_90
<int, int
> >();
<br>
97 test_pm
<gtl::property_merge
<int, int
> >();
<br>
101 //Now you know how to use the manhattan and arbitrary angle property
<br>
102 //merge algorithms to perform map overlay on n layers of input geometry
<br>
106 <table class=
"docinfo" rules=
"none" frame=
"void" id=
"table1">
108 <col class=
"docinfo-name"><col class=
"docinfo-content">
112 <th class=
"docinfo-name">Copyright:
</th>
113 <td>Copyright © Intel Corporation
2008-
2010.
</td>
116 <th class=
"docinfo-name">License:
</th>
117 <td class=
"field-body">Distributed under the Boost Software License,
118 Version
1.0. (See accompanying file
<tt class=
"literal">
119 <span class=
"pre">LICENSE_1_0.txt
</span></tt> or copy at
120 <a class=
"reference" target=
"_top" href=
"http://www.boost.org/LICENSE_1_0.txt">
121 http://www.boost.org/LICENSE_1_0.txt
</a>)
</td>