31 #include <unordered_map> 38 const float linear_resolution,
39 const float angular_resolution,
43 const int angle = std::lround(M_PI * 2 / angular_resolution);
47 for (
int syaw = 0; syaw < angle; syaw++)
49 const float yaw = syaw * angular_resolution;
51 for (d[0] = -range; d[0] <= range; d[0]++)
53 for (d[1] = -range; d[1] <= range; d[1]++)
55 if (d[0] == 0 && d[1] == 0)
57 if (d.
sqlen() > range * range)
59 for (d[2] = 0; d[2] < angle; d[2]++)
62 const float yaw_e = d[2] * angular_resolution;
63 const float diff_val[3] =
65 d[0] * linear_resolution,
66 d[1] * linear_resolution,
67 d[2] * angular_resolution
73 motion.
rotate(-syaw * angular_resolution);
74 const float cos_v = cosf(motion[2]);
75 const float sin_v = sinf(motion[2]);
77 const float inter = 1.0 / d.
len();
79 if (fabs(sin_v) < 0.1)
81 for (
float i = 0; i < 1.0; i += inter)
83 const float x = diff_val[0] * i;
84 const float y = diff_val[1] * i;
87 x / linear_resolution, y / linear_resolution, yaw / angular_resolution);
89 if (registered.find(pos) == registered.end())
92 registered[pos] =
true;
101 const float r1 = motion[1] + motion[0] * cos_v / sin_v;
102 const float r2 = std::copysign(
103 sqrtf(powf(motion[0], 2.0) + powf(motion[0] * cos_v / sin_v, 2.0)),
106 float dyaw = yaw_e - yaw;
109 else if (dyaw > M_PI)
112 const float cx = d[0] * linear_resolution + r2 * cosf(yaw_e + M_PI / 2);
113 const float cy = d[1] * linear_resolution + r2 * sinf(yaw_e + M_PI / 2);
114 const float cx_s = r1 * cosf(yaw + M_PI / 2);
115 const float cy_s = r1 * sinf(yaw + M_PI / 2);
119 for (
float i = 0; i < 1.0; i += inter)
121 const float r = r1 * (1.0 - i) + r2 * i;
122 const float cx2 = cx_s * (1.0 - i) + cx * i;
123 const float cy2 = cy_s * (1.0 - i) + cy * i;
124 const float cyaw = yaw + i * dyaw;
126 const float posf_raw[3] =
128 (cx2 - r * cosf(cyaw + M_PI / 2)) / linear_resolution,
129 (cy2 - r * sinf(cyaw + M_PI / 2)) / linear_resolution,
130 cyaw / angular_resolution
135 if (registered.find(pos) == registered.end())
138 registered[pos] =
true;
140 distf += (posf - posf_prev).len();
150 for (
auto& cache :
cache_[syaw])
154 size_t a_baddr, a_addr;
155 size_t b_baddr, b_addr;
156 gm_addr(a, a_baddr, a_addr);
157 gm_addr(b, b_baddr, b_addr);
158 if (a_baddr == b_baddr)
160 return (a_addr < b_addr);
162 return (a_baddr < b_baddr);
164 std::sort(cache.second.motion_.begin(), cache.second.motion_.end(), comp);
void cycleUnsigned(const int res, const ArgList &...rest)
void rotate(const float ang)
TFSIMD_FORCE_INLINE const tfScalar & y() const
std::vector< Cache > cache_
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
TFSIMD_FORCE_INLINE const tfScalar & x() const
std::vector< CyclicVecInt< 3, 2 > > motion_
void reset(const float linear_resolution, const float angular_resolution, const int range, const std::function< void(CyclicVecInt< 3, 2 >, size_t &, size_t &)> gm_addr)