PageRenderTime 24ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/Sweep_line_2/include/CGAL/Sweep_line_2_algorithms.h

https://gitlab.com/Namdhari/cgal-AnatoMeCo
C Header | 222 lines | 129 code | 32 blank | 61 comment | 0 complexity | ead1154a4ac088ab01951253b00ddde8 MD5 | raw file
  1. // Copyright (c) 2005,2006,2007,2009,2010,2011 Tel-Aviv University (Israel).
  2. // All rights reserved.
  3. //
  4. // This file is part of CGAL (www.cgal.org).
  5. // You can redistribute it and/or modify it under the terms of the GNU
  6. // General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. //
  9. // Licensees holding a valid commercial license may use this file in
  10. // accordance with the commercial license agreement provided with the software.
  11. //
  12. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  13. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  14. //
  15. // $URL$
  16. // $Id$
  17. //
  18. //
  19. // Author(s): Baruch Zukerman <baruchzu@post.tau.ac.il>
  20. // Efi Fogel <efif@post.tau.ac.il>
  21. // (based on old version by Tali Zvi)
  22. #ifndef CGAL_SWEEP_LINE_2_ALGORITHMS_H
  23. #define CGAL_SWEEP_LINE_2_ALGORITHMS_H
  24. /*!
  25. * \file Definition of the sweep-line related functions.
  26. */
  27. #include <CGAL/Sweep_line_2.h>
  28. #include <CGAL/Sweep_line_2/Sweep_line_2_visitors.h>
  29. #include <CGAL/Segment_2.h>
  30. #include <CGAL/Arr_segment_traits_2.h>
  31. #include <CGAL/Arr_polyline_traits_2.h>
  32. #include <CGAL/Arr_conic_traits_2.h>
  33. #include <CGAL/Arr_rational_function_traits_2.h>
  34. #include <CGAL/Arr_circle_segment_traits_2.h>
  35. #include <CGAL/Arr_linear_traits_2.h>
  36. #include <CGAL/Arr_rat_arc/Rational_arc_d_1.h>
  37. namespace CGAL {
  38. template <typename Curve>
  39. struct Default_arr_traits
  40. {};
  41. template <typename Kernel>
  42. struct Default_arr_traits<CGAL::Segment_2<Kernel> >
  43. {
  44. typedef CGAL::Arr_segment_traits_2<Kernel> Traits;
  45. };
  46. template <typename Kernel>
  47. struct Default_arr_traits<CGAL::Arr_segment_2<Kernel> >
  48. {
  49. typedef CGAL::Arr_segment_traits_2<Kernel> Traits;
  50. };
  51. template <typename SubcurveTraits>
  52. struct Default_arr_traits<CGAL::internal::Polycurve_2
  53. <SubcurveTraits, typename SubcurveTraits::Point_2> >
  54. {
  55. typedef CGAL::Arr_polyline_traits_2<SubcurveTraits> Traits;
  56. };
  57. template <typename Rat_kernel_, class Alg_kernel_, class Nt_traits_>
  58. struct Default_arr_traits<CGAL::_Conic_arc_2<Rat_kernel_, Alg_kernel_,
  59. Nt_traits_> >
  60. {
  61. typedef CGAL::Arr_conic_traits_2<Rat_kernel_, Alg_kernel_, Nt_traits_>
  62. Traits;
  63. };
  64. template <typename Algebraic_kernel_>
  65. struct Default_arr_traits<CGAL::Arr_rational_arc::Rational_arc_d_1<Algebraic_kernel_> >
  66. {
  67. typedef CGAL::Arr_rational_function_traits_2<Algebraic_kernel_> Traits;
  68. };
  69. template <typename Kernel_, bool Filter_>
  70. struct Default_arr_traits<CGAL::_Circle_segment_2<Kernel_, Filter_> >
  71. {
  72. typedef CGAL::Arr_circle_segment_traits_2<Kernel_, Filter_> Traits;
  73. };
  74. template <typename Kernel>
  75. struct Default_arr_traits<CGAL::Arr_linear_object_2<Kernel> >
  76. {
  77. typedef CGAL::Arr_linear_traits_2<Kernel> Traits;
  78. };
  79. /*!
  80. * Compute all intersection points induced by a range of input curves.
  81. * The intersections are calculated using the sweep-line algorithm.
  82. * \param begin An input iterator for the first curve in the range.
  83. * \param end A input past-the-end iterator for the range.
  84. * \param points Output: An output iterator for the intersection points
  85. * induced by the input curves.
  86. * \param report_endpoints If (true), the end points of the curves are also
  87. * reported as intersection points.
  88. * \pre The value-type of CurveInputIterator is Traits::Curve_2, and the
  89. * value-type of OutputIterator is Traits::Point_2.
  90. */
  91. template <class CurveInputIterator, class OutputIterator, class Traits>
  92. OutputIterator compute_intersection_points (CurveInputIterator curves_begin,
  93. CurveInputIterator curves_end,
  94. OutputIterator points,
  95. bool report_endpoints,
  96. Traits &tr)
  97. {
  98. // Define the sweep-line types:
  99. typedef Sweep_line_points_visitor<Traits,OutputIterator> Visitor;
  100. typedef Sweep_line_2< Traits,
  101. Sweep_line_points_visitor<Traits, OutputIterator> >
  102. Sweep_line;
  103. // Perform the sweep and obtain the intersection points.
  104. Visitor visitor (points, report_endpoints);
  105. Sweep_line sweep_line (&tr, &visitor);
  106. visitor.sweep(curves_begin, curves_end);
  107. return (visitor.output_iterator());
  108. }
  109. template <class CurveInputIterator, class OutputIterator>
  110. OutputIterator compute_intersection_points (CurveInputIterator curves_begin,
  111. CurveInputIterator curves_end,
  112. OutputIterator points,
  113. bool report_endpoints = false)
  114. {
  115. typedef typename std::iterator_traits<CurveInputIterator>::value_type Curve;
  116. typename Default_arr_traits<Curve>::Traits traits;
  117. return (compute_intersection_points(curves_begin, curves_end, points,
  118. report_endpoints, traits));
  119. }
  120. /*!
  121. * Compute all x-monotone subcurves that are disjoint in their interiors
  122. * induced by a range of input curves.
  123. * The subcurves are calculated using the sweep-line algorithm.
  124. * \param begin An input iterator for the first curve in the range.
  125. * \param end A input past-the-end iterator for the range.
  126. * \param points Output: An output iterator for the subcurve.
  127. * \param mult_overlaps If (true), the overlapping subcurve will be reported
  128. * multiple times.
  129. * \pre The value-type of CurveInputIterator is Traits::Curve_2, and the
  130. * value-type of OutputIterator is Traits::X_monotone_curve_2.
  131. */
  132. template <class CurveInputIterator, class OutputIterator, class Traits>
  133. OutputIterator compute_subcurves (CurveInputIterator curves_begin,
  134. CurveInputIterator curves_end,
  135. OutputIterator subcurves,
  136. bool mult_overlaps, Traits &tr)
  137. {
  138. // Define the sweep-line types:
  139. typedef Sweep_line_subcurves_visitor<Traits, OutputIterator> Visitor;
  140. typedef Sweep_line_2<Traits,
  141. Sweep_line_subcurves_visitor<Traits, OutputIterator> >
  142. Sweep_line;
  143. // Perform the sweep and obtain the subcurves.
  144. Visitor visitor (subcurves, mult_overlaps);
  145. Sweep_line sweep_line (&tr, &visitor);
  146. visitor.sweep(curves_begin, curves_end);
  147. return (visitor.output_iterator());
  148. }
  149. template <class CurveInputIterator, class OutputIterator>
  150. OutputIterator compute_subcurves (CurveInputIterator curves_begin,
  151. CurveInputIterator curves_end,
  152. OutputIterator subcurves,
  153. bool mult_overlaps = false)
  154. {
  155. typedef typename std::iterator_traits<CurveInputIterator>::value_type Curve;
  156. typename Default_arr_traits<Curve>::Traits m_traits;
  157. return compute_subcurves(curves_begin, curves_end, subcurves, mult_overlaps,
  158. m_traits);
  159. }
  160. /*!
  161. * Determine if there occurs an intersection between any pair of curves in
  162. * a given range.
  163. * \param begin An input iterator for the first curve in the range.
  164. * \param end A input past-the-end iterator for the range.
  165. * \return (true) if any pair of curves intersect; (false) otherwise.
  166. */
  167. template <class CurveInputIterator, class Traits>
  168. bool do_curves_intersect (CurveInputIterator curves_begin,
  169. CurveInputIterator curves_end, Traits &tr)
  170. {
  171. // Define the sweep-line types:
  172. typedef Sweep_line_do_curves_x_visitor<Traits> Visitor;
  173. typedef Sweep_line_2<Traits, Sweep_line_do_curves_x_visitor<Traits> >
  174. Sweep_line;
  175. // Perform the sweep and obtain the subcurves.
  176. Visitor visitor;
  177. Sweep_line sweep_line (&tr, &visitor);
  178. visitor.sweep(curves_begin, curves_end);
  179. return (visitor.found_intersection());
  180. }
  181. template <class CurveInputIterator>
  182. bool do_curves_intersect (CurveInputIterator curves_begin,
  183. CurveInputIterator curves_end)
  184. {
  185. typedef typename std::iterator_traits<CurveInputIterator>::value_type Curve;
  186. typename Default_arr_traits<Curve>::Traits m_traits;
  187. return do_curves_intersect (curves_begin, curves_end, m_traits);
  188. }
  189. } //namespace CGAL
  190. #endif