2 #include <CGAL/Simple_cartesian.h> 3 #include <CGAL/Partition_traits_2.h> 4 #include <CGAL/Partition_is_valid_traits_2.h> 5 #include <CGAL/polygon_function_objects.h> 6 #include <CGAL/partition_2.h> 11 using namespace se2ez;
16 using Kernel = CGAL::Simple_cartesian<double>;
19 CGAL::Partition_is_valid_traits_2<PartitionTraits, CGAL::Is_convex_2<PartitionTraits>>;
21 using Point = PartitionTraits::Point_2;
22 using Polygon = PartitionTraits::Polygon_2;
34 for (
const auto &point : geometry.
points)
40 for (
auto it = polygon.vertices_begin(); it != polygon.vertices_end(); ++it)
47 fillPoints(points, polygon);
49 return std::make_shared<Geometry>(
Geometry::CONVEX, points, Eigen::Vector3d{0, 0, 0});
54 bool collinear =
false;
55 for (
unsigned int i = 0; i < points.
size() - 2 && !collinear; ++i)
61 collinear |= CGAL::collinear(p, q, r);
71 toCGAL(poly, geometry);
72 return poly.is_convex();
78 toCGAL(poly, geometry);
79 return poly.is_simple();
85 toCGAL(poly, geometry);
87 if (poly.is_counterclockwise_oriented())
88 poly.reverse_orientation();
91 fillPoints(geometry.
points, poly);
97 toCGAL(poly, geometry);
99 if (poly.is_clockwise_oriented())
100 poly.reverse_orientation();
103 fillPoints(geometry.
points, poly);
109 toCGAL(poly, geometry);
121 toCGAL(poly, *geometry);
123 CGAL::approx_convex_partition_2(poly.vertices_begin(), poly.vertices_end(),
126 bool valid = CGAL::partition_is_valid_2(poly.vertices_begin(), poly.vertices_end(),
127 partitions.
begin(), partitions.
end(), vt);
133 for (
const auto &p : partitions)
149 toCGAL(poly, *geometry);
151 CGAL::optimal_convex_partition_2(poly.vertices_begin(), poly.vertices_end(),
154 bool valid = CGAL::partition_is_valid_2(poly.vertices_begin(), poly.vertices_end(),
155 partitions.
begin(), partitions.
end(), vt);
161 for (
const auto &p : partitions)
174 points[0] = geometry->points[0];
175 for (
unsigned int i = 1; i < geometry->points.size() - 1; ++i)
177 points[1] = geometry->points[i];
178 points[2] = geometry->points[i + 1];
180 if (collinear(points))
184 std::make_shared<Geometry>(
Geometry::CONVEX, points, geometry->offset, geometry->color));
void makeClockwise(Geometry &geometry)
If not clockwise, reorders polygon vertices to be in clockwise orientation.
double area(const Geometry &geometry)
Compute the area of a polygon.
const Type type
Type of geometry.
bool isSimple(const Geometry &geometry)
Checks if a polygon is simple, that is, it has no holes.
std::vector< GeometryPtr > shatter(const GeometryPtr &geometry)
"Shatters" a convex polygon into a fan of triangles using the first point as the root for all triangl...
CGAL::Partition_is_valid_traits_2< PartitionTraits, CGAL::Is_convex_2< PartitionTraits > > ValidityTraits
tf::EigenVector< Eigen::Vector2d > points
Point list for polygons.
A shared pointer wrapper for se2ez::Geometry.
std::vector< GeometryPtr > convexifyApproximate(const GeometryPtr &geometry)
Performs an approximate convex decomposition on the geometry.
PartitionTraits::Point_2 Point
A simple polygon (no holes).
void makeCounterClockwise(Geometry &geometry)
If not counterclockwise, reorders polygon vertices to be in counterclockwise orientation.
CGAL::Simple_cartesian< double > Kernel
std::vector< GeometryPtr > convexifyOptimal(const GeometryPtr &geometry)
Performs an optimal convex decomposition on the geometry.
T back_inserter(T... args)
bool isConvex(const Geometry &geometry)
Checks if a polygon is convex.
PartitionTraits::Polygon_2 Polygon
CGAL::Partition_traits_2< Kernel > PartitionTraits
T emplace_back(T... args)