MRSL DecompUtil Library  0.1
An implementaion of convex decomposition over point cloud
ellipsoid_decomp.h
Go to the documentation of this file.
1 
5 #ifndef ELLIPSOID_DECOMP_H
6 #define ELLIPSOID_DECOMP_H
7 
8 #include <memory>
10 
16 template <int Dim>
18 public:
26  EllipsoidDecomp(const Vecf<Dim> &origin, const Vecf<Dim> &dim) {
27  global_bbox_min_ = origin;
28  global_bbox_max_ = origin + dim;
29  }
30 
32  void set_obs(const vec_Vecf<Dim> &obs) { obs_ = obs; }
33 
35  void set_local_bbox(const Vecf<Dim>& bbox) { local_bbox_ = bbox; }
36 
38  vec_Vecf<Dim> get_path() const { return path_; }
39 
41  vec_E<Polyhedron<Dim>> get_polyhedrons() const { return polyhedrons_; }
42 
44  vec_E<Ellipsoid<Dim>> get_ellipsoids() const { return ellipsoids_; }
45 
48  vec_E<LinearConstraint<Dim>> constraints;
49  constraints.resize(polyhedrons_.size());
50  for (unsigned int i = 0; i < polyhedrons_.size(); i++){
51  const Vecf<Dim> pt = (path_[i] + path_[i+1])/2;
52  constraints[i] = LinearConstraint<Dim>(pt, polyhedrons_[i].hyperplanes());
53  }
54  return constraints;
55  }
56 
62  void dilate(const vec_Vecf<Dim> &path, double offset_x = 0) {
63  const unsigned int N = path.size() - 1;
64  lines_.resize(N);
65  ellipsoids_.resize(N);
66  polyhedrons_.resize(N);
67 
68  for (unsigned int i = 0; i < N; i++) {
69  lines_[i] = std::make_shared<LineSegment<Dim>>(path[i], path[i+1]);
70  lines_[i]->set_local_bbox(local_bbox_);
71  lines_[i]->set_obs(obs_);
72  lines_[i]->dilate(offset_x);
73 
74  ellipsoids_[i] = lines_[i]->get_ellipsoid();
75  polyhedrons_[i] = lines_[i]->get_polyhedron();
76  }
77 
78 
79  path_ = path;
80 
81  if(global_bbox_min_.norm() != 0 || global_bbox_max_.norm() != 0) {
82  for(auto& it: polyhedrons_)
83  add_global_bbox(it);
84  }
85 
86  }
87 
88 protected:
89  template<int U = Dim>
90  typename std::enable_if<U == 2>::type
91  add_global_bbox(Polyhedron<Dim> &Vs) {
92  //**** add bound along X, Y axis
93 
94  //*** X
95  Vs.add(Hyperplane2D(Vec2f(global_bbox_max_(0), 0), Vec2f(1, 0)));
96  Vs.add(Hyperplane2D(Vec2f(global_bbox_min_(0), 0), Vec2f(-1, 0)));
97  //*** Y
98  Vs.add(Hyperplane2D(Vec2f(0, global_bbox_max_(1)), Vec2f(0, 1)));
99  Vs.add(Hyperplane2D(Vec2f(0, global_bbox_min_(1)), Vec2f(0, -1)));
100  }
101 
102  template<int U = Dim>
103  typename std::enable_if<U == 3>::type
104  add_global_bbox(Polyhedron<Dim> &Vs) {
105  //**** add bound along X, Y, Z axis
106  //*** Z
107  Vs.add(Hyperplane3D(Vec3f(0, 0, global_bbox_max_(2)), Vec3f(0, 0, 1)));
108  Vs.add(Hyperplane3D(Vec3f(0, 0, global_bbox_min_(2)), Vec3f(0, 0, -1)));
109 
110  //*** X
111  Vs.add(Hyperplane3D(Vec3f(global_bbox_max_(0), 0, 0), Vec3f(1, 0, 0)));
112  Vs.add(Hyperplane3D(Vec3f(global_bbox_min_(0), 0, 0), Vec3f(-1, 0, 0)));
113  //*** Y
114  Vs.add(Hyperplane3D(Vec3f(0, global_bbox_max_(1), 0), Vec3f(0, 1, 0)));
115  Vs.add(Hyperplane3D(Vec3f(0, global_bbox_max_(1), 0), Vec3f(0, -1, 0)));
116  }
117 
118  vec_Vecf<Dim> path_;
119  vec_Vecf<Dim> obs_;
120 
121  vec_E<Ellipsoid<Dim>> ellipsoids_;
122  vec_E<Polyhedron<Dim>> polyhedrons_;
123  std::vector<std::shared_ptr<LineSegment<Dim>>> lines_;
124 
125  Vecf<Dim> local_bbox_{Vecf<Dim>::Zero()};
126  Vecf<Dim> global_bbox_min_{Vecf<Dim>::Zero()}; // bounding box params
127  Vecf<Dim> global_bbox_max_{Vecf<Dim>::Zero()};
128 
129 };
130 
132 
134 #endif
vec_E< Vecf< N >> vec_Vecf
Vector of Eigen 1D float vector.
Definition: data_type.h:69
void set_local_bbox(const Vecf< Dim > &bbox)
Set dimension of bounding box.
Definition: ellipsoid_decomp.h:35
EllipsoidDecomp()
Simple constructor.
Definition: ellipsoid_decomp.h:20
EllipsoidDecomp Class.
Definition: ellipsoid_decomp.h:17
void dilate(const vec_Vecf< Dim > &path, double offset_x=0)
Decomposition thread.
Definition: ellipsoid_decomp.h:62
EllipsoidDecomp(const Vecf< Dim > &origin, const Vecf< Dim > &dim)
Basic constructor.
Definition: ellipsoid_decomp.h:26
[A, b] for
Definition: polyhedron.h:99
Polyhedron class.
Definition: polyhedron.h:41
LineSegment Class.
void add(const Hyperplane< Dim > &v)
Append Hyperplane.
Definition: polyhedron.h:49
vec_E< LinearConstraint< Dim > > get_constraints() const
Get the constraints of SFC as .
Definition: ellipsoid_decomp.h:47
vec_E< Ellipsoid< Dim > > get_ellipsoids() const
Get the ellipsoids.
Definition: ellipsoid_decomp.h:44
void set_obs(const vec_Vecf< Dim > &obs)
Set obstacle points.
Definition: ellipsoid_decomp.h:32
Vecf< 3 > Vec3f
Eigen 1D float vector of size 3.
Definition: data_type.h:79
vec_Vecf< Dim > get_path() const
Get the path that is used for dilation.
Definition: ellipsoid_decomp.h:38
std::vector< T, Eigen::aligned_allocator< T >> vec_E
Pre-allocated std::vector for Eigen using vec_E.
Definition: data_type.h:54
Vecf< 2 > Vec2f
Eigen 1D float vector of size 2.
Definition: data_type.h:75
vec_E< Polyhedron< Dim > > get_polyhedrons() const
Get the Safe Flight Corridor.
Definition: ellipsoid_decomp.h:41
Eigen::Matrix< decimal_t, N, 1 > Vecf
Eigen 1D float vector.
Definition: data_type.h:57
Hyperplane class.
Definition: polyhedron.h:13