File: snap_rounding.cpp

package info (click to toggle)
cgal 4.13-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 101,504 kB
  • sloc: cpp: 703,154; ansic: 163,044; sh: 674; fortran: 616; python: 411; makefile: 115
file content (41 lines) | stat: -rw-r--r-- 1,667 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <CGAL/Cartesian.h>
#include <CGAL/Quotient.h>
#include <CGAL/MP_Float.h>
#include <CGAL/Snap_rounding_traits_2.h>
#include <CGAL/Snap_rounding_2.h>

typedef CGAL::Quotient<CGAL::MP_Float>           Number_type;
typedef CGAL::Cartesian<Number_type>             Kernel;
typedef CGAL::Snap_rounding_traits_2<Kernel>     Traits;
typedef Kernel::Segment_2                        Segment_2;
typedef Kernel::Point_2                          Point_2;
typedef std::list<Segment_2>                     Segment_list_2;
typedef std::list<Point_2>                       Polyline_2;
typedef std::list<Polyline_2>                    Polyline_list_2;

int main()
{
  Segment_list_2 seg_list;
  Polyline_list_2 output_list;

  seg_list.push_back(Segment_2(Point_2(0, 0), Point_2(10, 10)));
  seg_list.push_back(Segment_2(Point_2(0, 10), Point_2(10, 0)));
  seg_list.push_back(Segment_2(Point_2(3, 0), Point_2(3, 10)));
  seg_list.push_back(Segment_2(Point_2(7, 0), Point_2(7, 10)));

  // Generate an iterated snap-rounding representation, where the centers of
  // the hot pixels bear their original coordinates, using 5 kd trees:
  CGAL::snap_rounding_2<Traits,Segment_list_2::const_iterator,Polyline_list_2>
    (seg_list.begin(), seg_list.end(), output_list, 1.0, true, false, 5);

  int counter = 0;
  Polyline_list_2::const_iterator iter1;
  for (iter1 = output_list.begin(); iter1 != output_list.end(); ++iter1) {
    std::cout << "Polyline number " << ++counter << ":\n";
    Polyline_2::const_iterator iter2;
    for (iter2 = iter1->begin(); iter2 != iter1->end(); ++iter2)
      std::cout << "    (" << iter2->x() << ":" << iter2->y() << ")\n";
  }

  return(0);
}