2012-05-05 03:40:55 +03:00
|
|
|
/*
|
|
|
|
* cgal_helper.h - Conversions between poly2d and CGAL
|
|
|
|
*
|
|
|
|
* Written 2012 by Werner Almesberger
|
|
|
|
* Copyright 2012 by Werner Almesberger
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CGAL_HELPER_H
|
|
|
|
#define CGAL_HELPER_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* References:
|
|
|
|
* http://www.cgal.org/Manual/latest/examples/Straight_skeleton_2/
|
|
|
|
* Create_saop_from_polygon_with_holes_2.cpp
|
|
|
|
* http://www.cgal.org/Manual/latest/examples/Straight_skeleton_2/print.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include "poly2d.h"
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
|
|
|
#include <CGAL/Polygon_with_holes_2.h>
|
|
|
|
|
|
|
|
|
|
|
|
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
|
|
|
|
|
|
|
|
typedef CGAL::Polygon_2<K> Polygon_2;
|
|
|
|
|
|
|
|
|
2012-05-08 04:12:21 +03:00
|
|
|
static inline Polygon_2 p2d_to_P2(const struct p2d *p, int ccw)
|
2012-05-05 03:40:55 +03:00
|
|
|
{
|
|
|
|
const struct v2d *v;
|
|
|
|
Polygon_2 np;
|
|
|
|
|
|
|
|
v = p->v;
|
|
|
|
do {
|
|
|
|
np.push_back(K::Point_2(v->x, v->y));
|
|
|
|
v = v->next;
|
|
|
|
}
|
|
|
|
while (v != p->v);
|
2012-05-08 04:12:21 +03:00
|
|
|
if (p2d_is_cw(p) == ccw)
|
|
|
|
np.reverse_orientation();
|
2012-05-05 03:40:55 +03:00
|
|
|
return np;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline struct p2d *P2_to_p2d(Polygon_2 p)
|
|
|
|
{
|
|
|
|
struct p2d *np;
|
|
|
|
|
|
|
|
np = p2d_new();
|
|
|
|
for (Polygon_2::Vertex_iterator vit = p.vertices_begin();
|
|
|
|
vit != p.vertices_end(); ++vit)
|
|
|
|
p2d_append(np, v2d_new(vit->x(), vit->y()));
|
|
|
|
p2d_close(np);
|
|
|
|
return np;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !CGAL_HELPER_H */
|