111void GenCorners(T h, T w, T l, T *x_cor, T *y_cor, T *z_cor) {
112 T half_w =
static_cast<T
>(w * 0.5f);
113 T half_l =
static_cast<T
>(l * 0.5f);
114 y_cor[0] = y_cor[1] = y_cor[2] = y_cor[3] = (T)0;
115 y_cor[4] = y_cor[5] = y_cor[6] = y_cor[7] = -h;
116 x_cor[0] = x_cor[4] = half_l;
117 z_cor[0] = z_cor[4] = half_w;
118 x_cor[1] = x_cor[5] = half_l;
119 z_cor[1] = z_cor[5] = -half_w;
120 x_cor[2] = x_cor[6] = -half_l;
121 z_cor[2] = z_cor[6] = -half_w;
122 x_cor[3] = x_cor[7] = -half_l;
123 z_cor[3] = z_cor[7] = half_w;
127bool Occlude(
const T *bbox1,
const T &h1,
const T *bbox2,
const T &h2) {
128 T overlap_x = std::min(bbox1[2], bbox2[2]) - std::max(bbox1[0], bbox2[0]);
129 T overlap_y = std::min(bbox1[3], bbox2[3]) - std::max(bbox1[1], bbox2[1]);
130 if (overlap_y <= (T)0 || overlap_x <= (T)0) {
133 const T HEIGHT_BIG_MOT =
static_cast<T
>(3.0f);
134 const T OCC_RATIO = (T)0.1f;
135 T bh1 = bbox1[3] - bbox1[1];
136 T bh2 = bbox2[3] - bbox2[1];
137 T inter_area = overlap_x * overlap_y;
138 T area = bh2 * (bbox2[2] - bbox2[0]);
140 T thres_occ_ratio = h2 < HEIGHT_BIG_MOT ? 2 * OCC_RATIO : OCC_RATIO;
141 bool occ = occ_ratio > thres_occ_ratio &&
178 const T *bbox,
const T *rot,
const T *hwl,
179 const T *location,
const bool &check_truncation,
180 T *bbox_res =
nullptr, T *bbox_near =
nullptr) {
184 T x_corners[8] = {0};
185 T y_corners[8] = {0};
186 T z_corners[8] = {0};
187 GenCorners(h, w, l, x_corners, y_corners, z_corners);
189 T x_min = std::numeric_limits<float>::max();
190 T x_max = -std::numeric_limits<float>::max();
191 T y_min = std::numeric_limits<float>::max();
192 T y_max = -std::numeric_limits<float>::max();
196 for (
int i = 0; i < 8; ++i) {
197 x_box[0] = x_corners[i];
198 x_box[1] = y_corners[i];
199 x_box[2] = z_corners[i];
204 if (bbox_near !=
nullptr) {
206 pts_proj[i2] = x_proj[0];
207 pts_proj[i2 + 1] = x_proj[1];
209 x_min = std::min(x_min, x_proj[0]);
210 x_max = std::max(x_max, x_proj[0]);
211 y_min = std::min(y_min, x_proj[1]);
212 y_max = std::max(y_max, x_proj[1]);
213 if (check_truncation) {
214 x_min = std::min(std::max(x_min, (T)0), (T)(width - 1));
215 x_max = std::min(std::max(x_max, (T)0), (T)(width - 1));
216 y_min = std::min(std::max(y_min, (T)0), (T)(height - 1));
217 y_max = std::min(std::max(y_max, (T)0), (T)(height - 1));
220 if (bbox_res !=
nullptr) {
226 if (bbox_near !=
nullptr) {
227 T bbox_front[4] = {0};
228 T bbox_rear[4] = {0};
229 std::swap(pts_proj[4], pts_proj[8]);
230 std::swap(pts_proj[5], pts_proj[9]);
231 std::swap(pts_proj[6], pts_proj[10]);
232 std::swap(pts_proj[7], pts_proj[11]);
235 if (bbox_rear[3] - bbox_rear[1] > bbox_front[3] - bbox_front[1]) {
236 memcpy(bbox_near, bbox_rear,
sizeof(T) * 4);
238 memcpy(bbox_near, bbox_front,
sizeof(T) * 4);
253 const std::pair<T, T> &range, T *z_offset) {
254 ACHECK(range.first < range.second);
255 if (x_start > x_end) {
256 std::swap(x_start, x_end);
257 std::swap(z_start, z_end);
260 T x_check_l = std::max(x_start, range.first);
261 T x_check_r = std::min(x_end, range.second);
262 T overlap_x = x_check_r - x_check_l;
263 if (overlap_x < 1e-6) {
268 T z_check_l = z_start + (x_check_l - x_start) * dz_divide_dx;
269 T z_check_r = z_start + (x_check_r - x_start) * dz_divide_dx;
270 T z_nearest = std::min(z_check_l, z_check_r);
271 if (z_nearest < *z_offset) {
272 *z_offset = z_nearest;
278 const T *plane,
const T *pts_c,
279 const T *k_mat,
int width,
int height,
280 T ratio_x_over_z, T *dx_dz,
281 bool check_lowerbound =
true) {
282 const T Z_RESOLUTION =
static_cast<T
>(1e-1);
283 const T Z_UNSTABLE_RATIO =
static_cast<T
>(0.3f);
285 dx_dz[0] = dx_dz[1] = (T)0;
291 T pt_of_line_seg_l[3] = {0};
292 T pt_of_line_seg_r[3] = {0};
294 ls.
pt_start, k_mat, plane, pt_of_line_seg_l);
296 ls.
pt_end, k_mat, plane, pt_of_line_seg_r);
297 if (!is_front_l || !is_front_r) {
300 ADEBUG <<
"l&r on-ground points: " << pt_of_line_seg_l[0] <<
", "
301 << pt_of_line_seg_l[1] <<
", " << pt_of_line_seg_l[2] <<
" | "
302 << pt_of_line_seg_r[0] <<
", " << pt_of_line_seg_r[1] <<
", "
303 << pt_of_line_seg_r[2];
308 T pos[3] = {pt_of_line_seg_l[0], pt_of_line_seg_l[1], pt_of_line_seg_l[2]};
309 T v[3] = {pt_of_line_seg_r[0] - pt_of_line_seg_l[0],
310 pt_of_line_seg_r[1] - pt_of_line_seg_l[1],
311 pt_of_line_seg_r[2] - pt_of_line_seg_l[2]};
312 T ry =
static_cast<T
>(-atan2(v[2], v[0]));
321 T pt2[3] = {ratio_x_over_z, (T)0, (T)1};
322 T pt1_local[3] = {0};
323 T pt2_local[3] = {0};
326 std::pair<T, T> range;
330 T pts_local[12] = {0};
338 T x[2] = {pt1_local[0], pt1_local[2]};
339 T xp[2] = {pt2_local[0], pt2_local[2]};
342 T zs[4] = {pts_local[2], pts_local[5], pts_local[8], pts_local[11]};
343 T z_offset =
static_cast<T
>(0);
344 bool all_positive = zs[0] > 0.0f && zs[1] > 0.f && zs[2] > 0.f && zs[3] > 0.f;
346 z_offset = std::min(zs[0], std::min(zs[1], std::min(zs[2], zs[3])));
348 z_offset = std::max(zs[0], std::max(zs[1], std::max(zs[2], zs[3])));
349 T xs[4] = {pts_local[0], pts_local[3], pts_local[6], pts_local[9]};
359 if (z_offset < Z_RESOLUTION && z_offset > -Z_RESOLUTION) {
364 if (z_offset >
static_cast<T
>(0.0f) && check_lowerbound) {
369 center_c[0] = (pts_c[0] + pts_c[3] + pts_c[6] + pts_c[9]) / 4;
370 center_c[2] = (pts_c[2] + pts_c[5] + pts_c[8] + pts_c[11]) / 4;
371 T z_avg = center_c[2];
373 T dz_local = -z_offset;
377 T center_local[3] = {0};
379 center_local[0] += dx_local;
381 center_local[2] += dz_local;
382 T center_local_to_c[3] = {0};
385 dx_dz[0] = center_local_to_c[0] - center_c[0];
386 dx_dz[1] = center_local_to_c[2] - center_c[2];
388 T dz_max = z_avg * Z_UNSTABLE_RATIO;
389 if (z_offset >
static_cast<T
>(0.0f) && std::abs(dx_dz[1]) > dz_max) {
390 dx_dz[0] = dx_dz[1] = 0;