Room.cpp
Go to the documentation of this file.
1#include "Room.h"
2
3#include <tuple>
4
5#include <boost/geometry/algorithms/centroid.hpp>
6#include <boost/geometry/algorithms/detail/distance/interface.hpp>
7#include <boost/geometry/algorithms/detail/envelope/interface.hpp>
8#include <boost/geometry/algorithms/detail/within/interface.hpp>
9#include <boost/geometry/geometries/box.hpp>
10#include <boost/geometry/geometries/linestring.hpp>
11
14
16{
17
18 bool
19 Room::isInside(const Eigen::Vector3f& point, const bool restrictTo2dCheck) const
20 {
23
24 const bool isInsideXY = boost::geometry::within(pt, poly);
25
26 if (restrictTo2dCheck)
27 {
28 return isInsideXY;
29 }
30
31 const bool isInsideZ = point.z() >= zFloor and point.z() <= (zFloor + height);
32 return isInsideXY and isInsideZ;
33 }
34
35 Eigen::Vector2f
37 {
40
41 boost::geometry::centroid(poly, center);
42
44 }
45
46 std::tuple<Eigen::Vector2f, Eigen::Vector2f>
47 Room::aabb() const
48 {
50 boost::geometry::model::box<util::geometry::point_type> box;
51
52 boost::geometry::envelope(poly, box);
53
54 return {util::geometry::fromPoint(box.min_corner()),
55 util::geometry::fromPoint(box.max_corner())};
56 }
57
58 bool
59 Room::isInside(const Eigen::Vector2f& point, const float margin) const
60 {
63
64 if (not boost::geometry::within(pt, poly))
65 {
66 return false;
67 }
68 if (margin > 0.F)
69 {
70 const boost::geometry::model::linestring<util::geometry::point_type> boundary(
71 poly.outer().begin(), poly.outer().end());
72 if (boost::geometry::distance(pt, boundary) < margin)
73 {
74 return false;
75 }
76 }
77 return true;
78 }
79
80} // namespace armarx::navigation::algorithms
This file is part of ArmarX.
std::vector< Eigen::Vector2f > to2D(const std::vector< Eigen::Vector3f > &v)
Definition eigen.cpp:29
Eigen::Vector2f fromPoint(const point_type &pt)
Definition geometry.cpp:49
boost::geometry::model::d2::point_xy< float > point_type
Definition geometry.h:35
point_type toPoint(const Eigen::Vector2f &pt)
Definition geometry.cpp:43
polygon_type toPolygon(const std::vector< Eigen::Vector2f > &hull)
Definition geometry.cpp:31
boost::geometry::model::polygon< point_type > polygon_type
Definition geometry.h:36
bool isInside(const Eigen::Vector3f &point, bool restrictTo2dCheck=false) const
Definition Room.cpp:19
std::vector< Eigen::Vector2f > polygon
Definition Room.h:37
std::tuple< Eigen::Vector2f, Eigen::Vector2f > aabb() const
Definition Room.cpp:47
Eigen::Vector2f center() const
Definition Room.cpp:36