geometry.h
Go to the documentation of this file.
1 #pragma once
2 
3 // TODO To be moved to Simox after ROBDEKON demo
4 
5 #include <vector>
6 
7 #include <boost/geometry.hpp>
8 #include <boost/geometry/algorithms/area.hpp>
9 #include <boost/geometry/algorithms/assign.hpp>
10 #include <boost/geometry/algorithms/detail/within/interface.hpp>
11 #include <boost/geometry/core/cs.hpp>
12 #include <boost/geometry/geometries/point_xy.hpp>
13 #include <boost/geometry/geometries/polygon.hpp>
14 #include <boost/geometry/geometries/register/point.hpp>
15 
16 #include <VirtualRobot/MathTools.h>
17 
18 BOOST_GEOMETRY_REGISTER_POINT_2D(Eigen::Vector2f, float, cs::cartesian, x(), y())
19 
20 namespace armarx::geometry
21 {
22  namespace bg = boost::geometry;
23 
24  class ConvexHull
25  {
26  public:
27  using Point = bg::model::d2::point_xy<float>;
28 
29  ConvexHull(const VirtualRobot::MathTools::ConvexHull2D& hull) : ConvexHull(hull.vertices)
30  {
31  }
32 
33  ConvexHull(const std::vector<Eigen::Vector2f>& hull)
34  {
35  boost::geometry::assign_points(polygon, hull);
36  }
37 
38  bool
39  contains(const Eigen::Vector2f& point) const
40  {
41  return bg::within(Point(point.x(), point.y()), polygon);
42  }
43 
44  float
45  area() const
46  {
47  return static_cast<float>(bg::area(polygon));
48  }
49 
50  private:
51  bg::model::polygon<Point> polygon;
52  };
53 
54  // inline float area()
55  // {
56 
57  // return bg::area(polygon);
58  // }
59 
60 } // namespace armarx::geometry
armarx::armem::contains
bool contains(const MemoryID &general, const MemoryID &specific)
Indicates whether general is "less specific" than, or equal to, specific, i.e.
Definition: MemoryID.cpp:563
Point
Definition: PointCloud.h:21
visionx::Point
Eigen::Vector3f Point
Definition: ObjectShapeClassification.h:70
ConvexHull
Definition: convexHull.hpp:376
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27