From d111e89aa9b9a4c32b21279a28ce04f21952bc1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Tue, 2 May 2017 12:36:50 +0200 Subject: [PATCH] Improved Alpha shapes 2 tests -- Added a weighted point data set -- Readability (indentation, typedefs, etc.) --- .../test/Alpha_shapes_2/data/fin_weighted | 207 ++++++++++++++++++ .../test/Alpha_shapes_2/test_alpha.cpp | 1 - .../test/Alpha_shapes_2/test_weight.cpp | 149 ++++++------- 3 files changed, 280 insertions(+), 77 deletions(-) create mode 100644 Alpha_shapes_2/test/Alpha_shapes_2/data/fin_weighted diff --git a/Alpha_shapes_2/test/Alpha_shapes_2/data/fin_weighted b/Alpha_shapes_2/test/Alpha_shapes_2/data/fin_weighted new file mode 100644 index 00000000000..030c5879020 --- /dev/null +++ b/Alpha_shapes_2/test/Alpha_shapes_2/data/fin_weighted @@ -0,0 +1,207 @@ +206 +39 498 19 +57 502 -90 +70 496 -75 +606 495 76 +25 492 -51 +54 492 25 +61 494 3 +78 494 29 +85 494 -47 +101 485 -38 +114 487 -39 +119 487 13 +126 490 -88 +140 488 67 +148 493 -19 +598 485 -88 +623 492 31 +34 481 -8 +163 480 94 +169 475 -13 +184 483 35 +194 478 -18 +337 482 45 +354 478 -29 +590 477 33 +621 480 -69 +25 471 -22 +196 467 67 +211 466 51 +224 474 -13 +234 466 -73 +244 468 -29 +246 474 -4 +259 465 -49 +267 466 -52 +277 474 44 +289 469 75 +298 466 50 +309 472 -26 +316 467 -71 +333 466 -87 +363 465 34 +367 465 42 +576 474 -76 +633 465 2 +17 458 -77 +383 455 -64 +394 456 -66 +578 456 13 +617 459 -69 +20 452 20 +366 451 -51 +413 454 12 +423 450 -34 +432 449 18 +441 447 -54 +567 452 -4 +612 449 95 +20 439 -86 +380 436 -52 +391 439 -18 +399 444 -59 +427 439 18 +562 440 77 +606 440 -9 +17 426 65 +433 431 21 +453 431 -33 +456 431 16 +537 433 95 +545 425 -5 +605 433 28 +17 417 30 +424 422 -63 +435 423 52 +459 421 -66 +532 421 -40 +607 415 87 +10 414 -32 +419 406 72 +438 412 -81 +460 413 87 +469 406 -78 +524 410 30 +609 412 -47 +13 396 39 +415 401 76 +444 403 48 +482 399 35 +519 395 90 +603 395 95 +13 385 -82 +417 390 -69 +439 386 14 +479 393 95 +512 385 21 +585 392 -20 +-5 379 17 +415 380 87 +439 384 95 +478 381 13 +487 379 -17 +499 380 23 +584 378 -55 +-2 367 19 +419 371 -23 +431 368 -22 +585 367 78 +10 356 -36 +576 361 44 +11 345 50 +582 353 -17 +9 342 31 +579 335 71 +16 331 -86 +567 333 84 +20 319 11 +574 320 89 +23 314 32 +568 306 -52 +22 299 80 +582 302 28 +25 290 -34 +571 293 -89 +31 280 -56 +560 284 -39 +34 268 32 +547 270 22 +42 259 77 +45 263 20 +553 263 18 +48 248 -9 +543 248 -97 +58 237 -57 +68 241 35 +77 241 21 +539 237 18 +85 225 -87 +525 229 0 +536 233 82 +103 221 56 +106 224 -49 +171 222 -35 +176 220 -11 +188 218 -77 +526 219 -22 +122 209 -27 +132 209 34 +144 212 -32 +150 205 -94 +164 209 81 +202 213 -52 +525 208 34 +214 204 -53 +452 197 -41 +525 197 77 +206 192 7 +430 189 90 +444 192 0 +455 193 -15 +469 190 10 +484 189 -81 +493 188 75 +535 193 12 +216 184 -39 +259 183 10 +363 175 -65 +370 178 78 +377 183 23 +387 181 34 +415 176 61 +504 177 -20 +511 177 84 +536 181 -74 +221 173 67 +230 169 -92 +243 166 3 +249 171 -59 +269 173 41 +343 172 70 +350 172 -54 +404 167 23 +410 170 -82 +420 171 79 +517 174 70 +545 172 -23 +274 158 56 +342 156 -22 +522 163 -33 +553 155 -43 +279 149 62 +332 148 77 +524 149 -25 +548 146 38 +275 140 -9 +320 138 34 +530 142 -50 +547 139 24 +286 127 13 +296 132 72 +319 130 -41 +525 126 -25 +538 131 -47 +301 124 -56 +305 117 0 +321 119 -80 diff --git a/Alpha_shapes_2/test/Alpha_shapes_2/test_alpha.cpp b/Alpha_shapes_2/test/Alpha_shapes_2/test_alpha.cpp index c30e9cf117f..251a01b4bf5 100644 --- a/Alpha_shapes_2/test/Alpha_shapes_2/test_alpha.cpp +++ b/Alpha_shapes_2/test/Alpha_shapes_2/test_alpha.cpp @@ -1,4 +1,3 @@ - #include #include #include diff --git a/Alpha_shapes_2/test/Alpha_shapes_2/test_weight.cpp b/Alpha_shapes_2/test/Alpha_shapes_2/test_weight.cpp index 317c15aae86..1ddbf60b5a4 100644 --- a/Alpha_shapes_2/test/Alpha_shapes_2/test_weight.cpp +++ b/Alpha_shapes_2/test/Alpha_shapes_2/test_weight.cpp @@ -1,7 +1,7 @@ /*********************************************************************** -Takes a list of points and returns a list of segments corresponding to -the weighted Alpha Shape. +Takes a list of weighted points and returns a list of segments +corresponding to the weighted Alpha Shape. ************************************************************************/ @@ -17,27 +17,26 @@ the weighted Alpha Shape. #include #include +typedef double coord_type; -typedef double coord_type; +typedef CGAL::Simple_cartesian SC; +typedef CGAL::Filtered_kernel K; +typedef K::Point_2 Point; +typedef K::Weighted_point_2 Weighted_point; +typedef K::Segment_2 Segment; +typedef K::Line_2 Line; +typedef K::Triangle_2 Triangle; -typedef CGAL::Simple_cartesian SC; -typedef CGAL::Filtered_kernel K; -typedef K::Point_2 Point_base; -typedef K::Weighted_point_2 Point; -typedef K::Segment_2 Segment; -typedef K::Line_2 Line; -typedef K::Triangle_2 Triangle; - -typedef K Gt; -typedef CGAL::Regular_triangulation_vertex_base_2 Rvb; -typedef CGAL::Regular_triangulation_face_base_2 Rf; +typedef K Gt; +typedef CGAL::Regular_triangulation_vertex_base_2 Rvb; +typedef CGAL::Regular_triangulation_face_base_2 Rf; //ExactComparisonTag is Tag_false -typedef CGAL::Alpha_shape_vertex_base_2 Vb; -typedef CGAL::Alpha_shape_face_base_2 Fb; -typedef CGAL::Triangulation_data_structure_2 Tds; -typedef CGAL::Regular_triangulation_2 Triangulation_2; -typedef CGAL::Alpha_shape_2 Alpha_shape_2; +typedef CGAL::Alpha_shape_vertex_base_2 Vb; +typedef CGAL::Alpha_shape_face_base_2 Fb; +typedef CGAL::Triangulation_data_structure_2 Tds; +typedef CGAL::Regular_triangulation_2 Triangulation_2; +typedef CGAL::Alpha_shape_2 Alpha_shape_2; //ExactComparisonTag is Tag_true typedef CGAL::Alpha_shape_vertex_base_2 Vb_TT; typedef CGAL::Alpha_shape_face_base_2 Fb_TT; -typedef CGAL::Triangulation_data_structure_2 Tds_TT; -typedef CGAL::Regular_triangulation_2 Triangulation_2_TT; -typedef CGAL::Alpha_shape_2 Alpha_shape_2_TT; + CGAL::Tag_true /* weighted */> Fb_TT; +typedef CGAL::Triangulation_data_structure_2 Tds_TT; +typedef CGAL::Regular_triangulation_2 Triangulation_2_TT; +typedef CGAL::Alpha_shape_2 Alpha_shape_2_TT; -typedef Alpha_shape_2::Face Face; -typedef Alpha_shape_2::Vertex Vertex; -typedef Alpha_shape_2::Edge Edge; -typedef Alpha_shape_2::Face_handle Face_handle; -typedef Alpha_shape_2::Vertex_handle Vertex_handle; +typedef Alpha_shape_2::Face Face; +typedef Alpha_shape_2::Vertex Vertex; +typedef Alpha_shape_2::Edge Edge; +typedef Alpha_shape_2::Face_handle Face_handle; +typedef Alpha_shape_2::Vertex_handle Vertex_handle; -typedef Alpha_shape_2::Face_circulator Face_circulator; +typedef Alpha_shape_2::Face_circulator Face_circulator; typedef Alpha_shape_2::Vertex_circulator Vertex_circulator; -typedef Alpha_shape_2::Locate_type Locate_type; +typedef Alpha_shape_2::Locate_type Locate_type; -typedef Alpha_shape_2::Face_iterator Face_iterator; -typedef Alpha_shape_2::Vertex_iterator Vertex_iterator; -typedef Alpha_shape_2::Edge_iterator Edge_iterator; -typedef Alpha_shape_2::Edge_circulator Edge_circulator; +typedef Alpha_shape_2::Face_iterator Face_iterator; +typedef Alpha_shape_2::Vertex_iterator Vertex_iterator; +typedef Alpha_shape_2::Edge_iterator Edge_iterator; +typedef Alpha_shape_2::Edge_circulator Edge_circulator; -typedef Alpha_shape_2::Alpha_iterator Alpha_iterator; -//--------------------------------------------------------------------- +typedef Alpha_shape_2::Alpha_iterator Alpha_iterator; template -void -alpha_edges(InputIterator begin, InputIterator end, - const typename Alpha_shape::FT& Alpha, - bool mode, - OutputIterator out) - // Generate Alpha Shape +void alpha_edges(InputIterator begin, InputIterator end, + const typename Alpha_shape::FT& Alpha, + bool mode, + OutputIterator out) { typedef typename Alpha_shape::Alpha_shape_edges_iterator Alpha_shape_edges_iterator; - std::vector V_seg; - Alpha_shape A(begin,end); - - if (mode) - { A.set_mode(Alpha_shape::GENERAL); } - else - { A.set_mode(Alpha_shape::REGULARIZED); }; + + // Generate Alpha Shape + Alpha_shape A(begin, end); + + if (mode) { + A.set_mode(Alpha_shape::GENERAL); + } else { + A.set_mode(Alpha_shape::REGULARIZED); + } + A.set_alpha(Alpha); - for(Alpha_shape_edges_iterator it = A.alpha_shape_edges_begin(); - it != A.alpha_shape_edges_end(); - ++it){ - *out++ = A.segment(*it); - } + Alpha_shape_edges_iterator eit = A.alpha_shape_edges_begin(), + eend = A.alpha_shape_edges_end(); + for( ; eit!=eend; ++eit) + *out++ = A.segment(*eit); } -//--------------------------------------------------------------------- -bool -file_input(std::list& L) +bool file_input(std::list& L) { - - std::ifstream is("./data/fin", std::ios::in); + std::ifstream is("./data/fin_weighted", std::ios::in); if(is.fail()) - { - std::cerr << "unable to open file for input" << std::endl; - return false; - } - - CGAL::set_ascii_mode(is); + { + std::cerr << "unable to open file for input" << std::endl; + return false; + } int n; is >> n; std::cout << "Reading " << n << " points" << std::endl; - Point_base p(1,2,3); + Weighted_point wp; for( ; n>0 ; n--) - { - is >> p; - L.push_back(Point (p,coord_type(n*n))); - } + { + is >> wp; + L.push_back(wp); + } + std::cout << "Points inserted" << std::endl; return true; } - -//------------------ main ------------------------------------------- +//------------------ main ------------------------------------------- int main() { - std::list points; - file_input(points); + std::list wpoints; + if(!file_input(wpoints)) + return -1; + + //ExactComparisonTag is Tag_false { std::vector segments; - alpha_edges(points.begin(), points.end(), + alpha_edges(wpoints.begin(), wpoints.end(), 10000.,Alpha_shape_2::GENERAL, std::back_inserter(segments)); std::cout << segments.size() << " alpha shape edges." << std::endl; } + //ExactComparisonTag is Tag_true { std::vector segments; - alpha_edges(points.begin(), points.end(), + alpha_edges(wpoints.begin(), wpoints.end(), 10000.,Alpha_shape_2_TT::GENERAL, std::back_inserter(segments)); std::cout << segments.size() << " alpha shape edges." << std::endl;