18 #ifndef PIC_UTIL_POLYLINE_HPP 19 #define PIC_UTIL_POLYLINE_HPP 23 #include "../base.hpp" 25 #include "../util/vec.hpp" 27 #ifndef PIC_DISABLE_EIGEN 28 #ifndef PIC_EIGEN_NOT_BUNDLED 29 #include "../externals/Eigen/Dense" 31 #include <Eigen/Dense> 40 template<
unsigned int N,
class T>
72 int n = int(
points.size());
74 if(n <= target_n_points) {
78 while(n > target_n_points) {
79 float area_min = FLT_MAX;
81 float a, b, c, area_tmp;
82 for(
int i = 0; i < (n - 2); i++) {
85 auto p1 =
points.at(i + 1);
86 auto p2 =
points.at(i + 2);
88 a = sqrtf(
float(p0.distanceSq(p1)));
89 b = sqrtf(
float(p1.distanceSq(p2)));
90 c = sqrtf(
float(p2.distanceSq(p0)));
92 float s = (a + b + c) / 2.0f ;
94 float area_sq = s * (s - a) * (s - b) * (s - c);
95 area_tmp = sqrtf(area_sq);
97 if(area_tmp < area_min) {
120 #ifndef PIC_DISABLE_EIGEN 128 for(
unsigned int i = 0; i < in.size(); i++) {
129 auto tmp =
Vec2i(in[i][0], in[i][1]);
137 #endif //PIC_UTIL_POLYLINE_HPP Polyline< 2, int > Polyline2i
Polyline2i.
Definition: polyline.hpp:118
void add(Vec< N, T > &point)
add
Definition: polyline.hpp:61
std::vector< Vec< N, T > > points
Definition: polyline.hpp:45
Polyline()
Definition: polyline.hpp:47
Vec< 2, int > Vec2i
Vec2i.
Definition: vec.hpp:829
#define PIC_INLINE
Definition: base.hpp:33
void simplify(int target_n_points)
simplify
Definition: polyline.hpp:70
PIC_INLINE void convertFromEigenToPolyLine(std::vector< Eigen::Vector2i > &in, Polyline2i &out)
convertFromEigenToPolyLine
Definition: polyline.hpp:126
Definition: bilateral_separation.hpp:25
Polyline(std::vector< Vec< N, T > > &points)
Definition: polyline.hpp:52
The Vec class.
Definition: vec.hpp:35
The Polyline class.
Definition: polyline.hpp:41