Root/
| 1 | /* |
| 2 | * cgal_helper.h - Conversions between poly2d and CGAL |
| 3 | * |
| 4 | * Written 2012, 2015 by Werner Almesberger |
| 5 | * Copyright 2012, 2015 by Werner Almesberger |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2.1 of the License, or (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #ifndef CGAL_HELPER_H |
| 14 | #define CGAL_HELPER_H |
| 15 | |
| 16 | /* |
| 17 | * References: |
| 18 | * http://www.cgal.org/Manual/latest/examples/Straight_skeleton_2/ |
| 19 | * Create_saop_from_polygon_with_holes_2.cpp |
| 20 | * http://www.cgal.org/Manual/latest/examples/Straight_skeleton_2/print.h |
| 21 | */ |
| 22 | |
| 23 | extern "C" { |
| 24 | #include <stdbool.h> |
| 25 | |
| 26 | #include "poly2d.h" |
| 27 | } |
| 28 | |
| 29 | #include <vector> |
| 30 | |
| 31 | #include <CGAL/Exact_predicates_inexact_constructions_kernel.h> |
| 32 | #include <CGAL/Polygon_with_holes_2.h> |
| 33 | |
| 34 | |
| 35 | typedef CGAL::Exact_predicates_inexact_constructions_kernel K; |
| 36 | |
| 37 | typedef CGAL::Polygon_2<K> Polygon_2; |
| 38 | |
| 39 | |
| 40 | static inline Polygon_2 p2d_to_P2(const struct p2d *p, bool ccw) |
| 41 | { |
| 42 | const struct v2d *v; |
| 43 | Polygon_2 np; |
| 44 | |
| 45 | v = p->v; |
| 46 | do { |
| 47 | np.push_back(K::Point_2(v->x, v->y)); |
| 48 | v = v->next; |
| 49 | } |
| 50 | while (v != p->v); |
| 51 | if (p2d_is_cw(p) == ccw) |
| 52 | np.reverse_orientation(); |
| 53 | return np; |
| 54 | } |
| 55 | |
| 56 | |
| 57 | static inline struct p2d *P2_to_p2d(Polygon_2 p) |
| 58 | { |
| 59 | struct p2d *np; |
| 60 | |
| 61 | np = p2d_new(); |
| 62 | for (Polygon_2::Vertex_iterator vit = p.vertices_begin(); |
| 63 | vit != p.vertices_end(); ++vit) |
| 64 | p2d_append(np, v2d_new(vit->x(), vit->y())); |
| 65 | p2d_close(np); |
| 66 | return np; |
| 67 | } |
| 68 | |
| 69 | #endif /* !CGAL_HELPER_H */ |
| 70 |
Branches:
master
