From 08da170d1bc7689be191bebf8fd3face24e54a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Tue, 2 May 2017 12:35:45 +0200 Subject: [PATCH] Improved Alpha shapes 2 examples -- Added a weighted point data set -- Readability (indentation, typedefs, etc.) --- .../examples/Alpha_shapes_2/data/fin_weighted | 207 ++++++++++++++++++ .../Alpha_shapes_2/ex_alpha_shapes_2.cpp | 48 ++-- .../ex_weighted_alpha_shapes_2.cpp | 106 ++++----- 3 files changed, 271 insertions(+), 90 deletions(-) create mode 100644 Alpha_shapes_2/examples/Alpha_shapes_2/data/fin_weighted diff --git a/Alpha_shapes_2/examples/Alpha_shapes_2/data/fin_weighted b/Alpha_shapes_2/examples/Alpha_shapes_2/data/fin_weighted new file mode 100644 index 00000000000..030c5879020 --- /dev/null +++ b/Alpha_shapes_2/examples/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/examples/Alpha_shapes_2/ex_alpha_shapes_2.cpp b/Alpha_shapes_2/examples/Alpha_shapes_2/ex_alpha_shapes_2.cpp index e4bdffb8897..0fd24993b5d 100644 --- a/Alpha_shapes_2/examples/Alpha_shapes_2/ex_alpha_shapes_2.cpp +++ b/Alpha_shapes_2/examples/Alpha_shapes_2/ex_alpha_shapes_2.cpp @@ -8,40 +8,36 @@ #include #include +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; -typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef K::FT FT; +typedef K::Point_2 Point; +typedef K::Segment_2 Segment; -typedef K::FT FT; -typedef K::Point_2 Point; -typedef K::Segment_2 Segment; +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::Delaunay_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::Delaunay_triangulation_2 Triangulation_2; - -typedef CGAL::Alpha_shape_2 Alpha_shape_2; -typedef Alpha_shape_2::Alpha_shape_edges_iterator Alpha_shape_edges_iterator; +typedef Alpha_shape_2::Alpha_shape_edges_iterator Alpha_shape_edges_iterator; template -void -alpha_edges( const Alpha_shape_2& A, - OutputIterator out) +void alpha_edges( const Alpha_shape_2& A, OutputIterator out) { - for(Alpha_shape_edges_iterator it = A.alpha_shape_edges_begin(); - it != A.alpha_shape_edges_end(); - ++it){ + Alpha_shape_edges_iterator it = A.alpha_shape_edges_begin(), + end = A.alpha_shape_edges_end(); + for( ; it!=end; ++it) *out++ = A.segment(*it); - } } template -bool -file_input(OutputIterator out) +bool file_input(OutputIterator out) { std::ifstream is("./data/fin", std::ios::in); - if(is.fail()){ + if(is.fail()) + { std::cerr << "unable to open file for input" << std::endl; return false; } @@ -54,22 +50,20 @@ file_input(OutputIterator out) return true; } - // Reads a list of points and returns a list of segments // corresponding to the Alpha shape. int main() { std::list points; - if(! file_input(std::back_inserter(points))){ + if(! file_input(std::back_inserter(points))) return -1; - } Alpha_shape_2 A(points.begin(), points.end(), - FT(10000), - Alpha_shape_2::GENERAL); + FT(10000), + Alpha_shape_2::GENERAL); std::vector segments; - alpha_edges( A, std::back_inserter(segments)); + alpha_edges(A, std::back_inserter(segments)); std::cout << "Alpha Shape computed" << std::endl; std::cout << segments.size() << " alpha shape edges" << std::endl; diff --git a/Alpha_shapes_2/examples/Alpha_shapes_2/ex_weighted_alpha_shapes_2.cpp b/Alpha_shapes_2/examples/Alpha_shapes_2/ex_weighted_alpha_shapes_2.cpp index 21a047b2dd2..bb7112c924a 100644 --- a/Alpha_shapes_2/examples/Alpha_shapes_2/ex_weighted_alpha_shapes_2.cpp +++ b/Alpha_shapes_2/examples/Alpha_shapes_2/ex_weighted_alpha_shapes_2.cpp @@ -7,91 +7,71 @@ #include #include - typedef CGAL::Exact_predicates_inexact_constructions_kernel K; -typedef K::FT FT; -typedef K::Point_2 Point_base; -typedef K::Weighted_point_2 Point; -typedef K Gt; -typedef CGAL::Regular_triangulation_vertex_base_2 Rvb; -typedef CGAL::Alpha_shape_vertex_base_2 Vb; -typedef CGAL::Regular_triangulation_face_base_2 Rf; -typedef CGAL::Alpha_shape_face_base_2 Fb; +typedef K::FT FT; +typedef K::Weighted_point_2 Weighted_point; +typedef K::Segment_2 Segment; -typedef CGAL::Triangulation_data_structure_2 Tds; -typedef CGAL::Regular_triangulation_2 Triangulation_2; +typedef CGAL::Regular_triangulation_vertex_base_2 Rvb; +typedef CGAL::Alpha_shape_vertex_base_2 Vb; +typedef CGAL::Regular_triangulation_face_base_2 Rf; +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_2 Alpha_shape_2; +typedef Alpha_shape_2::Alpha_shape_edges_iterator Alpha_shape_edges_iterator; -typedef Alpha_shape_2::Alpha_shape_edges_iterator Alpha_shape_edges_iterator; - -template -void -alpha_edges(InputIterator begin, InputIterator end, - const FT &Alpha, - bool mode, - OutputIterator out) - // Generate Alpha Shape +template +void alpha_edges(const Alpha_shape_2& A, OutputIterator out) { - std::vector V_seg; - Alpha_shape_2 A(begin,end); - - if (mode) - { A.set_mode(Alpha_shape_2::GENERAL); } - else - { A.set_mode(Alpha_shape_2::REGULARIZED); }; - A.set_alpha(Alpha); - - for(Alpha_shape_edges_iterator it = A.alpha_shape_edges_begin(); - it != A.alpha_shape_edges_end(); - ++it){ + Alpha_shape_edges_iterator it = A.alpha_shape_edges_begin(), + end = A.alpha_shape_edges_end(); + for( ; it!=end; ++it) *out++ = A.segment(*it); - } } -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; - for( ; n>0 ; n--) - { - Point_base p(0., 0.); - is >> p; - if(is) { - L.push_back(Point (p, FT(n*n))); - } else { - return false; - } - } - std::cout << "Points inserted" << std::endl; + for( ; n>0; n--) + { + Weighted_point wp; + is >> wp; + L.push_back(wp); + } + return true; } - // Reads a list of points and returns a list of segments corresponding to // the weighted Alpha Shape. int main() { - std::list points; - file_input(points); - std::vector segments; - alpha_edges(points.begin(), points.end(), - FT(10000),Alpha_shape_2::GENERAL, - std::back_inserter(segments)); - std::cout << segments.size() << " alpha shape edges." << std::endl; + std::list wpoints; + if(!file_input(wpoints)) + return -1; + + Alpha_shape_2 A(wpoints.begin(), wpoints.end(), + FT(10000), + Alpha_shape_2::GENERAL); + + std::vector segments; + alpha_edges(A, std::back_inserter(segments)); + + std::cout << "Alpha Shape computed" << std::endl; + std::cout << segments.size() << " alpha shape edges" << std::endl; + std::cout << "Optimal alpha: " << *A.find_optimal_alpha(1)<