]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | <html> |
2 | ||
3 | <head> | |
4 | <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> | |
5 | <title>Connectivity Extraction Usage</title> | |
6 | </head> | |
7 | ||
8 | <body> | |
9 | ||
10 | <p><font face="Courier New">#include <boost/polygon/polygon.hpp><br> | |
11 | #include <cassert><br> | |
12 | namespace gtl = boost::polygon;<br> | |
13 | <br> | |
14 | //This function works with both the 90 and 45 versions<br> | |
15 | //of connectivity extraction algroithm<br> | |
16 | template <typename ce_type><br> | |
17 | void test_ce() {<br> | |
18 | //first we create an object to do the connectivity extraction<br> | |
19 | ce_type ce;<br> | |
20 | <br> | |
21 | //create some test data<br> | |
22 | std::vector<gtl::rectangle_data<int> > test_data;<br> | |
23 | test_data.push_back(gtl::rectangle_data<int>(10, 10, 90, 90));<br> | |
24 | test_data.push_back(gtl::rectangle_data<int>(0, 0, 20, 20));<br> | |
25 | test_data.push_back(gtl::rectangle_data<int>(80, 0, 100, 20));<br> | |
26 | test_data.push_back(gtl::rectangle_data<int>(0, 80, 20, 100));<br> | |
27 | test_data.push_back(gtl::rectangle_data<int>(80, 80, 100, 100));<br> | |
28 | //There is one big square and four little squares covering each<br> | |
29 | //of its corners.<br> | |
30 | <br> | |
31 | for(unsigned int i = 0; i < test_data.size(); ++i) {<br> | |
32 | //insert returns an id starting at zero and incrementing<br> | |
33 | //with each call<br> | |
34 | assert(ce.insert(test_data[i]) == i);<br> | |
35 | }<br> | |
36 | //notice that ids returned by ce.insert happen to match<br> | |
37 | //index into vector of inputs in this case<br> | |
38 | <br> | |
39 | //make sure the vector graph has elements for our nodes<br> | |
40 | std::vector<std::set<int> > graph(test_data.size());<br> | |
41 | <br> | |
42 | //populate the graph with edge data<br> | |
43 | ce.extract(graph);<br> | |
44 | <br> | |
45 | //make a map type graph to compare results<br> | |
46 | std::map<int, std::set<int> > map_graph;<br> | |
47 | ce.extract(map_graph);<br> | |
48 | <br> | |
49 | assert(map_graph.size() && map_graph.size() == graph.size());<br> | |
50 | for(unsigned int i = 0; i < graph.size(); ++i) {<br> | |
51 | assert(graph[i] == map_graph[i]);<br> | |
52 | if(i == 0)<br> | |
53 | assert(graph[i].size() == 4); //four little | |
54 | squares<br> | |
55 | else<br> | |
56 | assert(graph[i].size() == 1); //each little | |
57 | toches the big square<br> | |
58 | }<br> | |
59 | }<br> | |
60 | <br> | |
61 | int main() {<br> | |
62 | test_ce<gtl::connectivity_extraction_90<int> >();<br> | |
63 | test_ce<gtl::connectivity_extraction_45<int> >();<br> | |
64 | return 0;<br> | |
65 | }<br> | |
66 | <br> | |
67 | //Now you know how to use the connectivity extraction algorithm<br> | |
68 | //to extract the connectivity graph for overlapping geometry<br> | |
69 | </font></p> | |
70 | ||
71 | ||
72 | <table class="docinfo" rules="none" frame="void" id="table1"> | |
73 | <colgroup> | |
74 | <col class="docinfo-name"><col class="docinfo-content"> | |
75 | </colgroup> | |
76 | <tbody vAlign="top"> | |
77 | <tr> | |
78 | <th class="docinfo-name">Copyright:</th> | |
79 |