10 #include <boost/foreach.hpp> 11 #include <boost/geometry.hpp> 12 #include <boost/geometry/geometries/multi_polygon.hpp> 13 #include <boost/geometry/geometries/point_xy.hpp> 14 #include <boost/geometry/geometries/polygon.hpp> 16 #include <boost/geometry/algorithms/convex_hull.hpp> 20 namespace solverBoost {
52 this->m_boost_polygon = other.m_boost_polygon;
53 #if ENABLE_POLYGON_VALIDITY_CHECKS 54 boost::geometry::validity_failure_type failure;
55 bool valid = boost::geometry::is_valid(m_boost_polygon, failure);
57 std::cout <<
"COLLISION_BOOST_POLYGON: the boost polygon is invalid" 65 for (
auto vert = vertices.rbegin(); vert < vertices.rend(); vert++) {
66 boost::geometry::append(m_boost_polygon,
70 boost::geometry::append(m_boost_polygon,
bg_point_type(vert[0], vert[1]));
74 boost::geometry::interior_rings(m_boost_polygon).resize(num_holes);
77 for (
const auto &vert : hole_contour) {
78 boost::geometry::append(m_boost_polygon,
81 auto vert = hole_contour.front();
82 boost::geometry::append(m_boost_polygon,
88 #if ENABLE_POLYGON_VALIDITY_CHECKS 89 boost::geometry::validity_failure_type failure;
90 bool valid = boost::geometry::is_valid(m_boost_polygon, failure);
92 std::cout <<
"COLLISION_BOOST_POLYGON: the boost polygon is invalid" 101 for (
int i = 0; i < 4; i++) {
102 double x = obj->
segments()[i].point1().x;
103 double y = obj->
segments()[i].point1().y;
104 boost::geometry::append(m_boost_polygon,
bg_point_type(x, y));
106 double x = obj->
segments()[0].point1().x;
107 double y = obj->
segments()[0].point1().y;
108 boost::geometry::append(m_boost_polygon,
bg_point_type(x, y));
109 #if ENABLE_POLYGON_VALIDITY_CHECKS 110 boost::geometry::validity_failure_type failure;
111 bool valid = boost::geometry::is_valid(m_boost_polygon, failure);
113 std::cout <<
"COLLISION_BOOST_POLYGON: the boost polygon is invalid" 123 for (
int i = 0; i < 4; i++) {
124 double x = obj->
segments()[i].point1().x;
125 double y = obj->
segments()[i].point1().y;
126 boost::geometry::append(m_boost_polygon,
bg_point_type(x, y));
128 double x = obj->
segments()[0].point1().x;
129 double y = obj->
segments()[0].point1().y;
130 boost::geometry::append(m_boost_polygon,
bg_point_type(x, y));
132 #if ENABLE_POLYGON_VALIDITY_CHECKS 133 bool valid = boost::geometry::is_valid(m_boost_polygon);
141 #if ENABLE_POLYGON_VALIDITY_CHECKS 142 boost::geometry::validity_failure_type failure;
143 bool valid = boost::geometry::is_valid(polygon, failure);
146 <<
"COLLISION_BOOST_POLYGON: the constructed boost polygon is invalid" 151 m_boost_polygon = polygon;
156 int extend(std::vector<BoostPolygon> &output,
double radius)
const;
158 int buffer(std::vector<BoostPolygon> &output,
double radius)
const;
163 triangulation::TriangulationQuality qual =
164 triangulation::TriangulationQuality())
const;
166 int getTrapezoids(std::vector<BoostPolygon> &output,
int axis = 0)
const;
173 return boost::geometry::within(m_boost_polygon, other.m_boost_polygon);
178 bg_polygon_type *
getInternal(
void)
const {
return &m_boost_polygon; }
181 mutable bg_polygon_type m_boost_polygon;
BoostPolygon(void)
Constructs a BoostPolygon from Polygon.
std::vector< Eigen::Vector2d > getVertices() const
collision::PolygonConstPtr toPolygon(triangulation::TriangulationQuality qual=triangulation::TriangulationQuality()) const
Converts the BoostPolygon into a collision Polygon.
BoostPolygonConstPtr convexHull(void) const
Computes a convex hull of the given BoostPolygon.
std::shared_ptr< BoostPolygon > BoostPolygonPtr
BoostPolygon(const collision::RectangleAABB *obj)
Constructs a BoostPolygon from RectangleAABB.
int extend(std::vector< BoostPolygon > &output, double radius) const
int getTrapezoids(std::vector< BoostPolygon > &output, int axis=0) const
boost::geometry::model::d2::point_xy< double > bg_point_type
boost::geometry::model::polygon< bg_point_type > bg_polygon_type
std::shared_ptr< const BoostPolygon > BoostPolygonConstPtr
std::shared_ptr< const Polygon > PolygonConstPtr
std::vector< std::vector< Eigen::Vector2d > > getHoleVertices() const
bool within(const BoostPolygon &other) const
Returns true if the BoostPolygon is completely contained within another BoostPolygon object...
BoostPolygon(const collision::RectangleOBB *obj)
Constructs a BoostPolygon from RectangleOBB.
int buffer(std::vector< BoostPolygon > &output, double radius) const
Buffers (enlargens) the polygon with a given radius.
bg_polygon_type * getInternal(void) const
Returns the contained boost.Geometry polygon object.
BoostPolygon(const collision::Polygon *obj)
BoostPolygon(const bg_polygon_type polygon)
Constructs a BoostPolygon from Boost.Geometry polygon.
std::vector< LineSegment > segments(void) const
BoostPolygon(const BoostPolygon &other)
std::vector< LineSegment > segments(void) const
virtual ~BoostPolygon(void)
Polygon contains Triangles and Vertices.
BoostPolygon allows to use boost.Geometry functions for Polygon objects.