point_cloud_fusion v1.6.0
Loading...
Searching...
No Matches
point_cloud_fusion Namespace Reference

Namespaces

namespace  detail
 

Classes

class  DistributionFeatureCalibrator
 
struct  FeatureMapping
 
struct  is_vector
 
struct  is_vector< std::vector< T, A > >
 
struct  MotionTransform
 Endpoint transforms for fast scan motion interpolation. More...
 
struct  ObjectMotion
 
class  PointCloudFusion
 PointCloudFusion class. More...
 

Functions

bool readScalarField (const uint8_t *data, uint8_t datatype, bool bigendian, float &value)
 Read a PointField scalar and convert it to floating point.
 
bool writeScalarField (uint8_t *data, uint8_t datatype, bool bigendian, float value)
 Convert and write a floating-point value to a PointField scalar.
 
template<typename PointCloudPtr , typename Fields >
std::vector< PointCloudPtr > selectMotionCompatibleClouds (const std::vector< PointCloudPtr > &msgs, std::size_t point_step, const Fields &fields)
 Keep batch indices while excluding clouds with incompatible layouts.
 
void transformPointInterpolated (const MotionTransform &transform, uint32_t time_offset, float x, float y, float z, float &transformed_x, float &transformed_y, float &transformed_z)
 Transform a point using normalized quaternion interpolation.
 
void retainDeskewedPose (MotionTransform &transform)
 
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.
 

Variables

template<typename C >
constexpr bool is_vector_v = is_vector<C>::value
 

Function Documentation

◆ compensateObjectMotion()

bool point_cloud_fusion::compensateObjectMotion ( const ObjectMotion & motion,
float velocity,
uint32_t point_time,
float & x,
float & y,
float & z )
inline

Advance a measured acquisition ray using absolute radial velocity.

Add displacement along the acquisition ray before the rigid/deskew transform. Deskewed inputs subtract the acquisition origin in the header frame before computing the ray. Unknown, implausible, and zero measurements leave XYZ unchanged.

Definition at line 38 of file object_motion_compensation.hpp.

39 {
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}

◆ readScalarField()

bool point_cloud_fusion::readScalarField ( const uint8_t * data,
uint8_t datatype,
bool bigendian,
float & value )

Read a PointField scalar and convert it to floating point.

Parameters
dataAddress of the scalar value.
datatypesensor_msgs::msg::PointField datatype identifier.
bigendianWhether the source cloud uses big-endian byte order.
valueDestination for the converted value.
Returns
True when the datatype is supported.

Definition at line 82 of file feature_calibration.cpp.

82 {
83 using Field = sensor_msgs::msg::PointField;
84 switch (datatype) {
85 case Field::INT8:
86 value = loadScalar<int8_t>(data, bigendian);
87 break;
88 case Field::UINT8:
89 value = loadScalar<uint8_t>(data, bigendian);
90 break;
91 case Field::INT16:
92 value = loadScalar<int16_t>(data, bigendian);
93 break;
94 case Field::UINT16:
95 value = loadScalar<uint16_t>(data, bigendian);
96 break;
97 case Field::INT32:
98 value = static_cast<float>(loadScalar<int32_t>(data, bigendian));
99 break;
100 case Field::UINT32:
101 value = static_cast<float>(loadScalar<uint32_t>(data, bigendian));
102 break;
103 case Field::FLOAT32:
104 value = loadScalar<float>(data, bigendian);
105 break;
106 case Field::FLOAT64:
107 value = static_cast<float>(loadScalar<double>(data, bigendian));
108 break;
109 default:
110 return false;
111 }
112 return std::isfinite(value);
113}

◆ retainDeskewedPose()

void point_cloud_fusion::retainDeskewedPose ( MotionTransform & transform)
inline

Retain the header pose while preserving the acquisition origin trajectory.

Definition at line 86 of file motion_compensation.hpp.

86 {
87 MotionTransform inverse_rotation;
88 inverse_rotation.start_quaternion = {-transform.start_quaternion[0], -transform.start_quaternion[1],
89 -transform.start_quaternion[2], transform.start_quaternion[3]};
90 transformPointInterpolated(inverse_rotation, 0, transform.end_translation[0] - transform.start_translation[0],
91 transform.end_translation[1] - transform.start_translation[1],
92 transform.end_translation[2] - transform.start_translation[2], transform.end_ray_origin[0],
93 transform.end_ray_origin[1], transform.end_ray_origin[2]);
94 transform.ray_origin_max_time_offset = transform.max_time_offset;
95 transform.max_time_offset = 0;
96 transform.end_translation = transform.start_translation;
97 transform.end_quaternion = transform.start_quaternion;
98}
Endpoint transforms for fast scan motion interpolation.

◆ selectMotionCompatibleClouds()

template<typename PointCloudPtr , typename Fields >
std::vector< PointCloudPtr > point_cloud_fusion::selectMotionCompatibleClouds ( const std::vector< PointCloudPtr > & msgs,
std::size_t point_step,
const Fields & fields )

Keep batch indices while excluding clouds with incompatible layouts.

Definition at line 35 of file motion_compensation.hpp.

37 {
38 std::vector<PointCloudPtr> motion_msgs = msgs;
39 for (auto& motion_msg : motion_msgs) {
40 if (motion_msg && (motion_msg->point_step != point_step || motion_msg->fields != fields)) {
41 motion_msg.reset();
42 }
43 }
44 return motion_msgs;
45}
std::vector< int > fields
std::size_t point_step

◆ transformPointInterpolated()

void point_cloud_fusion::transformPointInterpolated ( const MotionTransform & transform,
uint32_t time_offset,
float x,
float y,
float z,
float & transformed_x,
float & transformed_y,
float & transformed_z )
inline

Transform a point using normalized quaternion interpolation.

Definition at line 50 of file motion_compensation.hpp.

57 {
58 const float alpha = transform.max_time_offset > 0
59 ? std::min(1.0F, static_cast<float>(time_offset) / static_cast<float>(transform.max_time_offset))
60 : 0.0F;
61 const float inverse_alpha = 1.0F - alpha;
62
63 float qx = inverse_alpha * transform.start_quaternion[0] + alpha * transform.end_quaternion[0];
64 float qy = inverse_alpha * transform.start_quaternion[1] + alpha * transform.end_quaternion[1];
65 float qz = inverse_alpha * transform.start_quaternion[2] + alpha * transform.end_quaternion[2];
66 float qw = inverse_alpha * transform.start_quaternion[3] + alpha * transform.end_quaternion[3];
67 const float inverse_norm = 1.0F / std::sqrt(qx * qx + qy * qy + qz * qz + qw * qw);
68 qx *= inverse_norm;
69 qy *= inverse_norm;
70 qz *= inverse_norm;
71 qw *= inverse_norm;
72
73 // Rotate with q * p * conjugate(q), avoiding temporary tf2 objects.
74 const float tx = 2.0F * (qy * z - qz * y);
75 const float ty = 2.0F * (qz * x - qx * z);
76 const float tz = 2.0F * (qx * y - qy * x);
77 transformed_x =
78 x + qw * tx + (qy * tz - qz * ty) + inverse_alpha * transform.start_translation[0] + alpha * transform.end_translation[0];
79 transformed_y =
80 y + qw * ty + (qz * tx - qx * tz) + inverse_alpha * transform.start_translation[1] + alpha * transform.end_translation[1];
81 transformed_z =
82 z + qw * tz + (qx * ty - qy * tx) + inverse_alpha * transform.start_translation[2] + alpha * transform.end_translation[2];
83}

◆ writeScalarField()

bool point_cloud_fusion::writeScalarField ( uint8_t * data,
uint8_t datatype,
bool bigendian,
float value )

Convert and write a floating-point value to a PointField scalar.

Parameters
dataAddress of the destination scalar.
datatypesensor_msgs::msg::PointField datatype identifier.
bigendianWhether the destination cloud uses big-endian byte order.
valueValue to convert and write.
Returns
True when the datatype is supported.

Definition at line 115 of file feature_calibration.cpp.

115 {
116 using Field = sensor_msgs::msg::PointField;
117 switch (datatype) {
118 case Field::INT8:
119 storeScalar(data, bigendian, saturate<int8_t>(value));
120 break;
121 case Field::UINT8:
122 storeScalar(data, bigendian, saturate<uint8_t>(value));
123 break;
124 case Field::INT16:
125 storeScalar(data, bigendian, saturate<int16_t>(value));
126 break;
127 case Field::UINT16:
128 storeScalar(data, bigendian, saturate<uint16_t>(value));
129 break;
130 case Field::INT32:
131 storeScalar(data, bigendian, saturate<int32_t>(value));
132 break;
133 case Field::UINT32:
134 storeScalar(data, bigendian, saturate<uint32_t>(value));
135 break;
136 case Field::FLOAT32:
137 storeScalar(data, bigendian, value);
138 break;
139 case Field::FLOAT64:
140 storeScalar(data, bigendian, static_cast<double>(value));
141 break;
142 default:
143 return false;
144 }
145 return true;
146}

Variable Documentation

◆ is_vector_v

template<typename C >
bool point_cloud_fusion::is_vector_v = is_vector<C>::value
inlineconstexpr

Definition at line 46 of file point_cloud_fusion.hpp.