gtl_connectivity_extraction_usage.htm 3.4 KB

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