point_cloud_fusion v1.6.0
Loading...
Searching...
No Matches
object_motion_compensation.hpp
Go to the documentation of this file.
1// Copyright Institute for Automotive Engineering (ika), RWTH Aachen University
2// SPDX-License-Identifier: Apache-2.0
3
4#pragma once
5
6#include <array>
7#include <cmath>
8#include <cstdint>
9
10namespace point_cloud_fusion {
11
17 uint32_t invalid_flags_mask{0};
19 float time_scale_sec{1.0e-9F};
20 float doppler_sign{1.0F};
22 float max_speed_mps{100.0F};
23 std::array<float, 3> end_ray_origin{0.0F, 0.0F, 0.0F};
25};
26
34// clang-format off
35#ifdef __CUDACC__
36__host__ __device__
37#endif
38inline bool compensateObjectMotion(const ObjectMotion& motion, float velocity, uint32_t point_time,
39 float& x, float& y, float& z) {
40 // clang-format on
41 const float dt = motion.reference_offset_sec - static_cast<float>(point_time) * motion.time_scale_sec;
42 if (!std::isfinite(velocity) || std::abs(velocity) > motion.max_speed_mps || !std::isfinite(dt) ||
43 std::abs(dt) > motion.max_time_offset_sec || velocity == 0.0F || dt == 0.0F) {
44 return false;
45 }
46 float origin_alpha = 0.0F;
47 if (motion.ray_origin_max_time_offset > 0) {
48 origin_alpha = point_time >= motion.ray_origin_max_time_offset
49 ? 1.0F
50 : static_cast<float>(point_time) / static_cast<float>(motion.ray_origin_max_time_offset);
51 }
52 const float ray_x = x - origin_alpha * motion.end_ray_origin[0];
53 const float ray_y = y - origin_alpha * motion.end_ray_origin[1];
54 const float ray_z = z - origin_alpha * motion.end_ray_origin[2];
55 const float range_squared = ray_x * ray_x + ray_y * ray_y + ray_z * ray_z;
56 if (!std::isfinite(range_squared) || range_squared <= 0.0F) return false;
57#ifdef __CUDA_ARCH__
58 const float inverse_range = rsqrtf(range_squared);
59#else
60 const float inverse_range = 1.0F / std::sqrt(range_squared);
61#endif
62 const float displacement_scale = motion.doppler_sign * velocity * dt * inverse_range;
63 if (!std::isfinite(displacement_scale)) return false;
64 x += ray_x * displacement_scale;
65 y += ray_y * displacement_scale;
66 z += ray_z * displacement_scale;
67 return true;
68}
69
70} // namespace point_cloud_fusion
bool compensateObjectMotion(const ObjectMotion &motion, float velocity, uint32_t point_time, float &x, float &y, float &z)
Advance a measured acquisition ray using absolute radial velocity.