MRSL DecompUtil Library  0.1
An implementaion of convex decomposition over point cloud
iterative_decomp.h
Go to the documentation of this file.
1 
5 #ifndef ITERATIVE_DECOMP_H
6 #define ITERATIVE_DECOMP_H
7 
9 
15 template <int Dim>
16 class IterativeDecomp : public EllipsoidDecomp<Dim>
17 {
18  public:
26  IterativeDecomp(const Vecf<Dim> &origin, const Vecf<Dim> &dim) :
27  EllipsoidDecomp<Dim>(origin, dim) {}
35  void dilate_iter(const vec_Vecf<Dim> &path_raw, int iter_num = 5,
36  decimal_t res = 0, decimal_t offset_x = 0) {
37  vec_Vecf<Dim> path = res > 0 ? downsample(path_raw, res) : path_raw;
38  this->dilate(path, offset_x);
39  vec_Vecf<Dim> new_path = simplify(path);
40  for (int i = 0; i < iter_num; i++) {
41  if (new_path.size() == path.size())
42  break;
43  else {
44  path = new_path;
45  this->dilate(path, offset_x);
46  new_path = simplify(path);
47  }
48  }
49  }
50 
51  protected:
54  // subdivide according to length
55  if (ps.size() < 2)
56  return ps;
57  vec_Vecf<Dim> path;
58  for (unsigned int i = 1; i < ps.size(); i++) {
59  decimal_t dist = (ps[i] - ps[i - 1]).norm();
60  int cnt = std::ceil(dist / d);
61  for (int j = 0; j < cnt; j++)
62  path.push_back(ps[i - 1] + j * (ps[i] - ps[i - 1]) / cnt);
63  }
64  path.push_back(ps.back());
65  return path;
66  }
67 
70  decimal_t dist = std::numeric_limits<decimal_t>::infinity();
71  for(const auto& it: vs.hyperplanes()){
72  decimal_t d = std::abs(it.n_.dot(pt - it.p_));
73  if(d < dist)
74  dist = d;
75  }
76  return dist;
77  }
78 
81  if(path.size() <= 2)
82  return path;
83 
84  Vecf<Dim> ref_pt = path.front();
85  vec_Vecf<Dim> new_path;
86  new_path.push_back(ref_pt);
87 
88  for(size_t i = 2; i < path.size(); i ++){
89  if(this->polyhedrons_[i-1].inside(ref_pt) &&
90  cal_closest_dist(ref_pt, this->polyhedrons_[i-1]) > 0.1) {
91  }
92  else{
93  ref_pt = path[i-1];
94  new_path.push_back(ref_pt);
95  }
96  }
97  new_path.push_back(path.back());
98  return new_path;
99  }
100 };
101 
103 
105 #endif
vec_E< Vecf< N >> vec_Vecf
Vector of Eigen 1D float vector.
Definition: data_type.h:69
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
decimal_t cal_closest_dist(const Vecf< Dim > &pt, const Polyhedron< Dim > &vs)
Get closest distance.
Definition: iterative_decomp.h:69
Polyhedron class.
Definition: polyhedron.h:41
EllipsoidDecomp Class.
vec_E< Hyperplane< Dim > > hyperplanes() const
Get the hyperplane array.
Definition: polyhedron.h:83
IterativeDecomp(const Vecf< Dim > &origin, const Vecf< Dim > &dim)
Basic constructor.
Definition: iterative_decomp.h:26
IterativeDecomp Class.
Definition: iterative_decomp.h:16
IterativeDecomp()
Simple constructor.
Definition: iterative_decomp.h:20
double decimal_t
Rename the float type used in lib.
Definition: data_type.h:50
vec_Vecf< Dim > downsample(const vec_Vecf< Dim > &ps, decimal_t d)
Uniformly sample path into many segments.
Definition: iterative_decomp.h:53
Eigen::Matrix< decimal_t, N, 1 > Vecf
Eigen 1D float vector.
Definition: data_type.h:57
vec_Vecf< Dim > simplify(const vec_Vecf< Dim > &path)
Remove redundant waypoints.
Definition: iterative_decomp.h:80
void dilate_iter(const vec_Vecf< Dim > &path_raw, int iter_num=5, decimal_t res=0, decimal_t offset_x=0)
Decomposition thread.
Definition: iterative_decomp.h:35