PageRenderTime 70ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/Periodic_2_triangulation_2/test/Periodic_2_triangulation_2/test_p2t2_triangulation_prog1.cpp

https://gitlab.com/Namdhari/cgal-AnatoMeCo
C++ | 225 lines | 193 code | 15 blank | 17 comment | 57 complexity | c050749d5b027fbb5d03cf1ca75b584c MD5 | raw file
  1. // Author(s) : Nico Kruithof <Nico@nghk.nl>
  2. #include <fstream>
  3. #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
  4. #include <CGAL/Periodic_2_triangulation_traits_2.h>
  5. #include <CGAL/Periodic_2_triangulation_2.h>
  6. struct K : CGAL::Exact_predicates_inexact_constructions_kernel {};
  7. typedef CGAL::Periodic_2_triangulation_traits_2<K> Gt;
  8. typedef CGAL::Periodic_2_triangulation_2<Gt> Triangulation;
  9. typedef Triangulation::Vertex_circulator Vertex_circulator;
  10. typedef Triangulation::Point Point;
  11. typedef Gt::Vector_2 Vector;
  12. typedef Triangulation::Segment Segment;
  13. typedef Triangulation::Triangle Triangle;
  14. typedef Triangulation::Periodic_point_iterator Periodic_point_iterator;
  15. typedef Triangulation::Periodic_segment_iterator Periodic_segment_iterator;
  16. typedef Triangulation::Periodic_triangle_iterator Periodic_triangle_iterator;
  17. void test_point_location_in_a_triangulation_with_a_single_point(Triangulation &t)
  18. {
  19. CGAL_assertion(t.number_of_vertices() == 1);
  20. Point &p = t.vertices_begin()->point();
  21. Triangulation::Locate_type lt;
  22. int li;
  23. for (int offset_x = 0; offset_x < t.number_of_sheets()[0]; ++offset_x)
  24. {
  25. for (int offset_y = 0; offset_y < t.number_of_sheets()[1]; ++offset_y)
  26. {
  27. Triangulation::Offset offset(offset_x, offset_y);
  28. {
  29. // Test the triangle iterator
  30. Triangulation::Periodic_triangle_iterator triang_it;
  31. const Triangulation::Periodic_triangle_iterator triang_it_beyond = t.periodic_triangles_end();
  32. {
  33. // Locate the point at the only vertex
  34. int on_boundary = 0;
  35. int on_inside = 0;
  36. triang_it = t.periodic_triangles_begin();
  37. while(triang_it != triang_it_beyond)
  38. {
  39. CGAL::Bounded_side side = t.side_of_face(p, offset, triang_it.get_face(), lt, li);
  40. if (side != CGAL::ON_UNBOUNDED_SIDE)
  41. {
  42. CGAL_assertion(lt == Triangulation::VERTEX);
  43. }
  44. on_boundary += (side == CGAL::ON_BOUNDARY ? 1 : 0);
  45. on_inside += (side == CGAL::ON_BOUNDED_SIDE ? 1 : 0);
  46. Triangle triangle = t.triangle(*triang_it);
  47. triangle.vertex(0); // Avoid warning
  48. ++triang_it;
  49. }
  50. CGAL_assertion(on_boundary == 6);
  51. CGAL_assertion(on_inside == 0);
  52. }
  53. {
  54. // Locate point on an edge
  55. int on_boundary = 0;
  56. int on_inside = 0;
  57. triang_it = t.periodic_triangles_begin();
  58. while(triang_it != triang_it_beyond)
  59. {
  60. CGAL::Bounded_side side = t.side_of_face(p + Vector(0.0, 0.1), offset, triang_it.get_face(), lt, li);
  61. if (side != CGAL::ON_UNBOUNDED_SIDE)
  62. {
  63. CGAL_assertion(lt == Triangulation::EDGE);
  64. }
  65. on_boundary += (side == CGAL::ON_BOUNDARY ? 1 : 0);
  66. on_inside += (side == CGAL::ON_BOUNDED_SIDE ? 1 : 0);
  67. Triangle triangle = t.triangle(*triang_it);
  68. triangle.vertex(0); // Avoid warning
  69. ++triang_it;
  70. }
  71. CGAL_assertion(on_boundary == 2);
  72. CGAL_assertion(on_inside == 0);
  73. }
  74. {
  75. // Locate point inside a face
  76. int on_boundary = 0;
  77. int on_inside = 0;
  78. triang_it = t.periodic_triangles_begin();
  79. while(triang_it != triang_it_beyond)
  80. {
  81. CGAL::Bounded_side side = t.side_of_face(p + Vector(0.1, 0.2), offset, triang_it.get_face(), lt, li);
  82. if (side != CGAL::ON_UNBOUNDED_SIDE)
  83. {
  84. CGAL_assertion(lt == Triangulation::FACE);
  85. }
  86. on_boundary += (side == CGAL::ON_BOUNDARY ? 1 : 0);
  87. on_inside += (side == CGAL::ON_BOUNDED_SIDE ? 1 : 0);
  88. Triangle triangle = t.triangle(*triang_it);
  89. triangle.vertex(0); // Avoid warning
  90. ++triang_it;
  91. }
  92. CGAL_assertion(on_boundary == 0);
  93. CGAL_assertion(on_inside == 1);
  94. }
  95. }
  96. {
  97. // Test the face iterator
  98. Triangulation::Face_iterator face_it;
  99. const Triangulation::Face_iterator face_it_beyond = t.faces_end();
  100. {
  101. // Locate the point at the only vertex
  102. int on_boundary = 0;
  103. int on_inside = 0;
  104. face_it = t.faces_begin();
  105. while(face_it != face_it_beyond)
  106. {
  107. CGAL::Bounded_side side = t.side_of_face(p, offset, face_it, lt, li);
  108. if (side != CGAL::ON_UNBOUNDED_SIDE)
  109. {
  110. CGAL_assertion(lt == Triangulation::VERTEX);
  111. }
  112. on_boundary += (side == CGAL::ON_BOUNDARY ? 1 : 0);
  113. on_inside += (side == CGAL::ON_BOUNDED_SIDE ? 1 : 0);
  114. ++face_it;
  115. }
  116. CGAL_assertion(on_boundary == 6);
  117. CGAL_assertion(on_inside == 0);
  118. }
  119. {
  120. // Locate point on an edge
  121. int on_boundary = 0;
  122. int on_inside = 0;
  123. face_it = t.faces_begin();
  124. while(face_it != face_it_beyond)
  125. {
  126. CGAL::Bounded_side side = t.side_of_face(p + Vector(0.1, 0.0), offset, face_it, lt, li);
  127. if (side != CGAL::ON_UNBOUNDED_SIDE)
  128. {
  129. CGAL_assertion(lt == Triangulation::EDGE);
  130. }
  131. on_boundary += (side == CGAL::ON_BOUNDARY ? 1 : 0);
  132. on_inside += (side == CGAL::ON_BOUNDED_SIDE ? 1 : 0);
  133. ++face_it;
  134. }
  135. CGAL_assertion(on_boundary == 2);
  136. CGAL_assertion(on_inside == 0);
  137. }
  138. {
  139. // Locate point inside a face
  140. int on_boundary = 0;
  141. int on_inside = 0;
  142. face_it = t.faces_begin();
  143. while(face_it != face_it_beyond)
  144. {
  145. CGAL::Bounded_side side = t.side_of_face(p + Vector(0.1, 0.2), offset, face_it, lt, li);
  146. if (side != CGAL::ON_UNBOUNDED_SIDE)
  147. {
  148. CGAL_assertion(lt == Triangulation::FACE);
  149. }
  150. on_boundary += (side == CGAL::ON_BOUNDARY ? 1 : 0);
  151. on_inside += (side == CGAL::ON_BOUNDED_SIDE ? 1 : 0);
  152. ++face_it;
  153. }
  154. CGAL_assertion(on_boundary == 0);
  155. CGAL_assertion(on_inside == 1);
  156. }
  157. }
  158. }
  159. }
  160. }
  161. int main()
  162. {
  163. Triangulation t;
  164. // Insert the first point
  165. Point first_point(0.5, 0.5);
  166. t.insert(first_point);
  167. CGAL_assertion(t.is_valid(true));
  168. {
  169. // Testing the point iterator
  170. Periodic_point_iterator it = t.periodic_points_begin();
  171. Periodic_point_iterator beyond = t.periodic_points_end();
  172. CGAL_assertion(std::distance(it, beyond) == 9);
  173. while(it != beyond)
  174. {
  175. Point p = t.point(*it);
  176. p.x(); // Avoid warning
  177. ++it;
  178. }
  179. }
  180. {
  181. // Testing the segment iterator
  182. Periodic_segment_iterator it = t.periodic_segments_begin();
  183. Periodic_segment_iterator beyond = t.periodic_segments_end();
  184. CGAL_assertion(std::distance(it, beyond) == 27);
  185. while(it != beyond)
  186. {
  187. Segment s = t.segment(*it);
  188. s.point(0); // Avoid warning
  189. ++it;
  190. }
  191. }
  192. {
  193. // Testing the triangle iterator
  194. Periodic_triangle_iterator it = t.periodic_triangles_begin();
  195. Periodic_triangle_iterator beyond = t.periodic_triangles_end();
  196. CGAL_assertion(std::distance(it, beyond) == 18);
  197. while(it != beyond)
  198. {
  199. Triangle triangle = t.triangle(*it);
  200. triangle.vertex(0); // Avoid warning
  201. ++it;
  202. }
  203. }
  204. test_point_location_in_a_triangulation_with_a_single_point(t);
  205. // std::ifstream in("data/triangulation_prog1.cin");
  206. // std::istream_iterator<Point> begin(in);
  207. // std::istream_iterator<Point> end;
  208. // t.insert(begin, end);
  209. return 0;
  210. }