Improved Alpha shapes 2 tests

-- Added a weighted point data set
-- Readability (indentation, typedefs, etc.)
This commit is contained in:
Mael Rouxel-Labbé 2017-05-02 12:36:50 +02:00
parent 08da170d1b
commit c7d5ddbeb0
3 changed files with 280 additions and 77 deletions

View File

@ -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

View File

@ -1,4 +1,3 @@
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Filtered_kernel.h>
#include <CGAL/algorithm.h>

View File

@ -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 <CGAL/Regular_triangulation_2.h>
#include <CGAL/Alpha_shape_2.h>
typedef double coord_type;
typedef double coord_type;
typedef CGAL::Simple_cartesian<coord_type> SC;
typedef CGAL::Filtered_kernel<SC> 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<coord_type> SC;
typedef CGAL::Filtered_kernel<SC> 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<Gt> Rvb;
typedef CGAL::Regular_triangulation_face_base_2<Gt> Rf;
typedef K Gt;
typedef CGAL::Regular_triangulation_vertex_base_2<Gt> Rvb;
typedef CGAL::Regular_triangulation_face_base_2<Gt> Rf;
//ExactComparisonTag is Tag_false
typedef CGAL::Alpha_shape_vertex_base_2<Gt,Rvb> Vb;
typedef CGAL::Alpha_shape_face_base_2<Gt, Rf> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb,Fb> Tds;
typedef CGAL::Regular_triangulation_2<Gt,Tds> Triangulation_2;
typedef CGAL::Alpha_shape_2<Triangulation_2> Alpha_shape_2;
typedef CGAL::Alpha_shape_vertex_base_2<Gt,Rvb> Vb;
typedef CGAL::Alpha_shape_face_base_2<Gt, Rf> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb,Fb> Tds;
typedef CGAL::Regular_triangulation_2<Gt,Tds> Triangulation_2;
typedef CGAL::Alpha_shape_2<Triangulation_2> Alpha_shape_2;
//ExactComparisonTag is Tag_true
typedef CGAL::Alpha_shape_vertex_base_2<Gt,Rvb,
@ -45,101 +44,99 @@ typedef CGAL::Alpha_shape_vertex_base_2<Gt,Rvb,
CGAL::Tag_true /* weighted */> Vb_TT;
typedef CGAL::Alpha_shape_face_base_2<Gt, Rf,
CGAL::Tag_true /* exact */,
CGAL::Tag_true /* weighted */> Fb_TT;
typedef CGAL::Triangulation_data_structure_2<Vb_TT,Fb_TT> Tds_TT;
typedef CGAL::Regular_triangulation_2<Gt,Tds_TT> Triangulation_2_TT;
typedef CGAL::Alpha_shape_2<Triangulation_2_TT,CGAL::Tag_true> Alpha_shape_2_TT;
CGAL::Tag_true /* weighted */> Fb_TT;
typedef CGAL::Triangulation_data_structure_2<Vb_TT,Fb_TT> Tds_TT;
typedef CGAL::Regular_triangulation_2<Gt,Tds_TT> Triangulation_2_TT;
typedef CGAL::Alpha_shape_2<Triangulation_2_TT,CGAL::Tag_true> 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 <class Alpha_shape,class InputIterator, class OutputIterator>
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<Segment> 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<Point>& L)
bool file_input(std::list<Weighted_point>& 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<Point> points;
file_input(points);
std::list<Weighted_point> wpoints;
if(!file_input(wpoints))
return -1;
//ExactComparisonTag is Tag_false
{
std::vector<Segment> segments;
alpha_edges<Alpha_shape_2>(points.begin(), points.end(),
alpha_edges<Alpha_shape_2>(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<Segment> segments;
alpha_edges<Alpha_shape_2_TT>(points.begin(), points.end(),
alpha_edges<Alpha_shape_2_TT>(wpoints.begin(), wpoints.end(),
10000.,Alpha_shape_2_TT::GENERAL,
std::back_inserter(segments));
std::cout << segments.size() << " alpha shape edges." << std::endl;