123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
- <title>Connectivity Extraction Usage</title>
- </head>
- <body>
- <p><font face="Courier New">#include <boost/polygon/polygon.hpp><br>
- #include <cassert><br>
- namespace gtl = boost::polygon;<br>
- <br>
- //This function works with both the 90 and 45 versions<br>
- //of connectivity extraction algroithm<br>
- template <typename ce_type><br>
- void test_ce() {<br>
- //first we create an object to do the connectivity extraction<br>
- ce_type ce;<br>
- <br>
- //create some test data<br>
- std::vector<gtl::rectangle_data<int> > test_data;<br>
- test_data.push_back(gtl::rectangle_data<int>(10, 10, 90, 90));<br>
- test_data.push_back(gtl::rectangle_data<int>(0, 0, 20, 20));<br>
- test_data.push_back(gtl::rectangle_data<int>(80, 0, 100, 20));<br>
- test_data.push_back(gtl::rectangle_data<int>(0, 80, 20, 100));<br>
- test_data.push_back(gtl::rectangle_data<int>(80, 80, 100, 100));<br>
- //There is one big square and four little squares covering each<br>
- //of its corners.<br>
- <br>
- for(unsigned int i = 0; i < test_data.size(); ++i) {<br>
- //insert returns an id starting at zero and incrementing<br>
- //with each call<br>
- assert(ce.insert(test_data[i]) == i);<br>
- }<br>
- //notice that ids returned by ce.insert happen to match<br>
- //index into vector of inputs in this case<br>
- <br>
- //make sure the vector graph has elements for our nodes<br>
- std::vector<std::set<int> > graph(test_data.size());<br>
- <br>
- //populate the graph with edge data<br>
- ce.extract(graph);<br>
- <br>
- //make a map type graph to compare results<br>
- std::map<int, std::set<int> > map_graph;<br>
- ce.extract(map_graph);<br>
- <br>
- assert(map_graph.size() && map_graph.size() == graph.size());<br>
- for(unsigned int i = 0; i < graph.size(); ++i) {<br>
- assert(graph[i] == map_graph[i]);<br>
- if(i == 0)<br>
- assert(graph[i].size() == 4); //four little
- squares<br>
- else<br>
- assert(graph[i].size() == 1); //each little
- toches the big square<br>
- }<br>
- }<br>
- <br>
- int main() {<br>
- test_ce<gtl::connectivity_extraction_90<int> >();<br>
- test_ce<gtl::connectivity_extraction_45<int> >();<br>
- return 0;<br>
- }<br>
- <br>
- //Now you know how to use the connectivity extraction algorithm<br>
- //to extract the connectivity graph for overlapping 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 © 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>
|