32 #include <unordered_map> 43 const float linear_resolution,
44 const float angular_resolution,
48 const int angle = std::lround(M_PI * 2 / angular_resolution);
53 for (
int syaw = 0; syaw < angle; syaw++)
55 const float yaw = syaw * angular_resolution;
57 for (d[0] = -range; d[0] <= range; d[0]++)
59 for (d[1] = -range; d[1] <= range; d[1]++)
61 if (d[0] == 0 && d[1] == 0)
63 if (d.
sqlen() > range * range)
65 for (d[2] = 0; d[2] < angle; d[2]++)
68 const float yaw_e = d[2] * angular_resolution;
69 const float diff_val[3] =
71 d[0] * linear_resolution,
72 d[1] * linear_resolution,
73 d[2] * angular_resolution
79 motion.
rotate(-syaw * angular_resolution);
80 const float cos_v = cosf(motion[2]);
81 const float sin_v = sinf(motion[2]);
83 const float inter = 1.0 / d.
len();
85 if (std::abs(sin_v) < 0.1)
87 for (
float i = 0; i < 1.0; i += inter)
89 const float x = diff_val[0] * i;
90 const float y = diff_val[1] * i;
93 x / linear_resolution, y / linear_resolution, yaw / angular_resolution);
95 if (registered.find(pos) == registered.end())
98 for (
int i = 0; i < 3; ++i)
99 max_range[i] = std::max(max_range[i], std::abs(pos[i]));
100 registered[pos] =
true;
109 const float r1 = motion[1] + motion[0] * cos_v / sin_v;
110 const float r2 = std::copysign(
111 std::sqrt(std::pow(motion[0], 2) + std::pow(motion[0] * cos_v / sin_v, 2)),
114 float dyaw = yaw_e - yaw;
117 else if (dyaw > M_PI)
120 const float cx = d[0] * linear_resolution + r2 * cosf(yaw_e + M_PI / 2);
121 const float cy = d[1] * linear_resolution + r2 * sinf(yaw_e + M_PI / 2);
122 const float cx_s = r1 * cosf(yaw + M_PI / 2);
123 const float cy_s = r1 * sinf(yaw + M_PI / 2);
127 for (
float i = 0; i < 1.0; i += inter)
129 const float r = r1 * (1.0 - i) + r2 * i;
130 const float cx2 = cx_s * (1.0 - i) + cx * i;
131 const float cy2 = cy_s * (1.0 - i) + cy * i;
132 const float cyaw = yaw + i * dyaw;
134 const float posf_raw[3] =
136 (cx2 - r * cosf(cyaw + M_PI / 2)) / linear_resolution,
137 (cy2 - r * sinf(cyaw + M_PI / 2)) / linear_resolution,
138 cyaw / angular_resolution
143 if (registered.find(pos) == registered.end())
146 registered[pos] =
true;
148 distf += (posf - posf_prev).len();
158 for (
auto& cache :
cache_[syaw])
162 size_t a_baddr, a_addr;
163 size_t b_baddr, b_addr;
164 gm_addr(a, a_baddr, a_addr);
165 gm_addr(b, b_baddr, b_addr);
166 if (a_baddr == b_baddr)
168 return (a_addr < b_addr);
170 return (a_baddr < b_baddr);
172 std::sort(cache.second.motion_.begin(), cache.second.motion_.end(), comp);
void cycleUnsigned(const int res, const ArgList &...rest)
TFSIMD_FORCE_INLINE const tfScalar & y() const
std::vector< CyclicVecInt< 3, 2 > > motion_
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
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)
void rotate(const float ang)
TFSIMD_FORCE_INLINE const tfScalar & x() const
CyclicVecInt< 3, 2 > max_range_
std::vector< Cache > cache_