Coverage Control Library
Loading...
Searching...
No Matches
utilities.h
Go to the documentation of this file.
1/*
2 * This file is part of the CoverageControl library
3 *
4 * Author: Saurav Agarwal
5 * Contact: sauravag@seas.upenn.edu, agr.saurav1@gmail.com
6 * Repository: https://github.com/KumarRobotics/CoverageControl
7 *
8 * Copyright (c) 2024, Saurav Agarwal
9 *
10 * The CoverageControl library is free software: you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or (at your
13 * option) any later version.
14 *
15 * The CoverageControl library is distributed in the hope that it will be
16 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
18 * Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along with
21 * CoverageControl library. If not, see <https://www.gnu.org/licenses/>.
22 */
23
29#ifndef CPPSRC_CORE_INCLUDE_COVERAGECONTROL_CGAL_UTILITIES_H_
30#define CPPSRC_CORE_INCLUDE_COVERAGECONTROL_CGAL_UTILITIES_H_
31
32#include <CGAL/Boolean_set_operations_2.h>
33#include <CGAL/Polygon_2_algorithms.h>
34#include <omp.h>
35
36#include <list>
37#include <vector>
38
41
42namespace CoverageControl {
43
44inline Point2 CGALtoCC(CGAL_Point2 const pt) {
45 return Point2(CGAL::to_double(pt.x()), CGAL::to_double(pt.y()));
46}
48 std::vector<Ray_2> rays_;
49 std::vector<Line_2> lines_;
50 std::vector<Segment_2> segments_;
52 void operator<<(const Ray_2 &ray) { rays_.push_back(ray); }
53 void operator<<(const Line_2 &line) { lines_.push_back(line); }
54 void operator<<(const Segment_2 &seg) { segments_.push_back(seg); }
55};
56
57template <class Arrangement>
59 typename Arrangement::Ccb_halfedge_const_circulator circ,
60 Polygon_2 &polygon) {
61 polygon.clear();
62 typename Arrangement::Ccb_halfedge_const_circulator curr = circ;
63 typename Arrangement::Halfedge_const_handle he;
64 auto pt = curr->source()->point();
65 do {
66 he = curr;
67 pt = he->target()->point();
68 polygon.push_back(pt);
69 ++curr;
70 } while (curr != circ);
71}
72
73template <class Arrangement>
74inline void CGAL_GeneratePolygons(const Arrangement &arr,
75 std::list<Polygon_2> &polygon_list) {
76 /* CGAL_precondition (arr.is_valid()); */
77 typename Arrangement::Face_const_iterator fit;
78 for (fit = arr.faces_begin(); fit != arr.faces_end(); ++fit) {
79 if (fit->is_unbounded()) {
80 continue;
81 } else {
82 Polygon_2 polygon;
83 CGAL_CCBTraversal<Arrangement>(fit->outer_ccb(), polygon);
84 if (not polygon.is_counterclockwise_oriented()) {
85 polygon.reverse_orientation();
86 }
87 polygon_list.push_back(polygon);
88 }
89 }
90}
91
92inline bool IsPointInPoly(CGAL_Point2 const &pt, Polygon_2 const &poly) {
93 if (CGAL::bounded_side_2(poly.begin(), poly.end(), pt, K()) ==
94 CGAL::ON_UNBOUNDED_SIDE) {
95 return false;
96 }
97 return true;
98}
99
100inline void PrunePolygons(std::list<Polygon_2> &polygon_list,
101 int const &map_size) {
102 Polygon_2 bbox_poly;
103 bbox_poly.push_back(CGAL_Point2(0, 0));
104 bbox_poly.push_back(CGAL_Point2(map_size, 0));
105 bbox_poly.push_back(CGAL_Point2(map_size, map_size));
106 bbox_poly.push_back(CGAL_Point2(0, map_size));
107 for (auto it = polygon_list.begin(); it != polygon_list.end();) {
108 if (not CGAL::do_intersect(bbox_poly, *it)) {
109 it = polygon_list.erase(it);
110 } else {
111 ++it;
112 }
113 }
114}
115
116} /* namespace CoverageControl */
117#endif // CPPSRC_CORE_INCLUDE_COVERAGECONTROL_CGAL_UTILITIES_H_
Contains the configuration for the CGAL library.
K::Ray_2 Ray_2
Definition config.h:53
CGAL::Exact_predicates_exact_constructions_kernel K
Definition config.h:49
CGAL::Polygon_2< K > Polygon_2
Definition config.h:57
K::Segment_2 Segment_2
Definition config.h:52
K::Line_2 Line_2
Definition config.h:54
K::Point_2 CGAL_Point2
Definition config.h:50
Eigen::Vector2d Point2
Definition typedefs.h:44
Namespace for the CoverageControl library.
void PrunePolygons(std::list< Polygon_2 > &polygon_list, int const &map_size)
Definition utilities.h:100
void CGAL_CCBTraversal(typename Arrangement::Ccb_halfedge_const_circulator circ, Polygon_2 &polygon)
Definition utilities.h:58
Point2 CGALtoCC(CGAL_Point2 const pt)
Definition utilities.h:44
void CGAL_GeneratePolygons(const Arrangement &arr, std::list< Polygon_2 > &polygon_list)
Definition utilities.h:74
bool IsPointInPoly(CGAL_Point2 const &pt, Polygon_2 const &poly)
Definition utilities.h:92
void operator<<(const Ray_2 &ray)
Definition utilities.h:52
void operator<<(const Line_2 &line)
Definition utilities.h:53
std::vector< Line_2 > lines_
Definition utilities.h:49
void operator<<(const Segment_2 &seg)
Definition utilities.h:54
std::vector< Segment_2 > segments_
Definition utilities.h:50
Contains typedefs for the library.