voronoi.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // Boost.Polygon library voronoi.hpp header file
  2. // Copyright Andrii Sydorchuk 2010-2012.
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // See http://www.boost.org for updates, documentation, and revision history.
  7. #ifndef BOOST_POLYGON_VORONOI
  8. #define BOOST_POLYGON_VORONOI
  9. #include "isotropy.hpp"
  10. #include "point_concept.hpp"
  11. #include "segment_concept.hpp"
  12. #include "voronoi_builder.hpp"
  13. #include "voronoi_diagram.hpp"
  14. // Public methods to compute Voronoi diagram of a set of points and segments.
  15. // Coordinates of the points and of the endpoints of the segments should belong
  16. // to the 32-bit signed integer range [-2^31, 2^31-1]. To use wider input
  17. // coordinate range voronoi_builder configuration via coordinate type traits
  18. // is required.
  19. // Complexity - O(N*logN), memory usage - O(N), N - number of input objects.
  20. namespace boost {
  21. namespace polygon {
  22. template <typename Point, typename VB>
  23. typename enable_if<
  24. typename gtl_if<
  25. typename is_point_concept<
  26. typename geometry_concept<Point>::type
  27. >::type
  28. >::type,
  29. std::size_t
  30. >::type insert(const Point& point, VB* vb) {
  31. return vb->insert_point(x(point), y(point));
  32. }
  33. template <typename PointIterator, typename VB>
  34. typename enable_if<
  35. typename gtl_if<
  36. typename is_point_concept<
  37. typename geometry_concept<
  38. typename std::iterator_traits<PointIterator>::value_type
  39. >::type
  40. >::type
  41. >::type,
  42. void
  43. >::type insert(const PointIterator first, const PointIterator last, VB* vb) {
  44. for (PointIterator it = first; it != last; ++it) {
  45. insert(*it, vb);
  46. }
  47. }
  48. template <typename Segment, typename VB>
  49. typename enable_if<
  50. typename gtl_if<
  51. typename is_segment_concept<
  52. typename geometry_concept<Segment>::type
  53. >::type
  54. >::type,
  55. std::size_t
  56. >::type insert(const Segment& segment, VB* vb) {
  57. return vb->insert_segment(
  58. x(low(segment)), y(low(segment)),
  59. x(high(segment)), y(high(segment)));
  60. }
  61. template <typename SegmentIterator, typename VB>
  62. typename enable_if<
  63. typename gtl_if<
  64. typename is_segment_concept<
  65. typename geometry_concept<
  66. typename std::iterator_traits<SegmentIterator>::value_type
  67. >::type
  68. >::type
  69. >::type,
  70. void
  71. >::type insert(const SegmentIterator first,
  72. const SegmentIterator last,
  73. VB* vb) {
  74. for (SegmentIterator it = first; it != last; ++it) {
  75. insert(*it, vb);
  76. }
  77. }
  78. template <typename PointIterator, typename VD>
  79. typename enable_if<
  80. typename gtl_if<
  81. typename is_point_concept<
  82. typename geometry_concept<
  83. typename std::iterator_traits<PointIterator>::value_type
  84. >::type
  85. >::type
  86. >::type,
  87. void
  88. >::type construct_voronoi(const PointIterator first,
  89. const PointIterator last,
  90. VD* vd) {
  91. default_voronoi_builder builder;
  92. insert(first, last, &builder);
  93. builder.construct(vd);
  94. }
  95. template <typename SegmentIterator, typename VD>
  96. typename enable_if<
  97. typename gtl_if<
  98. typename is_segment_concept<
  99. typename geometry_concept<
  100. typename std::iterator_traits<SegmentIterator>::value_type
  101. >::type
  102. >::type
  103. >::type,
  104. void
  105. >::type construct_voronoi(const SegmentIterator first,
  106. const SegmentIterator last,
  107. VD* vd) {
  108. default_voronoi_builder builder;
  109. insert(first, last, &builder);
  110. builder.construct(vd);
  111. }
  112. template <typename PointIterator, typename SegmentIterator, typename VD>
  113. typename enable_if<
  114. typename gtl_and<
  115. typename gtl_if<
  116. typename is_point_concept<
  117. typename geometry_concept<
  118. typename std::iterator_traits<PointIterator>::value_type
  119. >::type
  120. >::type
  121. >::type,
  122. typename gtl_if<
  123. typename is_segment_concept<
  124. typename geometry_concept<
  125. typename std::iterator_traits<SegmentIterator>::value_type
  126. >::type
  127. >::type
  128. >::type
  129. >::type,
  130. void
  131. >::type construct_voronoi(const PointIterator p_first,
  132. const PointIterator p_last,
  133. const SegmentIterator s_first,
  134. const SegmentIterator s_last,
  135. VD* vd) {
  136. default_voronoi_builder builder;
  137. insert(p_first, p_last, &builder);
  138. insert(s_first, s_last, &builder);
  139. builder.construct(vd);
  140. }
  141. } // polygon
  142. } // boost
  143. #endif // BOOST_POLYGON_VORONOI