Skip to content

Commit

Permalink
Revert "Suggestion to be discussed"
Browse files Browse the repository at this point in the history
This reverts commit 77091b1.
  • Loading branch information
tizianoGuadagnino committed Nov 7, 2024
1 parent 0adb69b commit a2d4e31
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions ros/src/kinematic_icp_ros/utils/RosUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
// SOFTWARE.
#include "kinematic_icp_ros/utils/RosUtils.hpp"

#include <limits>
#include <cmath>
#include <cstdint>

namespace kinematic_icp_ros::utils {

Expand Down Expand Up @@ -56,19 +57,23 @@ std::vector<double> NormalizeTimestamps(const std::vector<double> &timestamps) {

auto ExtractTimestampsFromMsg(const PointCloud2::ConstSharedPtr msg,
const PointField &timestamp_field) {
auto number_of_digits_decimal_part = [](const auto &stamp) {
const uint64_t number_of_seconds = static_cast<uint64_t>(std::round(stamp));
return number_of_seconds > 0 ? std::floor(std::log10(number_of_seconds) + 1) : 1;
};
auto extract_timestamps =
[&msg]<typename T>(sensor_msgs::PointCloud2ConstIterator<T> &&it) -> std::vector<double> {
[&]<typename T>(sensor_msgs::PointCloud2ConstIterator<T> &&it) -> std::vector<double> {
const size_t n_points = msg->height * msg->width;
std::vector<double> timestamps;
timestamps.reserve(n_points);
for (size_t i = 0; i < n_points; ++i, ++it) {
double stamp = static_cast<double>(*it);
// If the stamp is larger than the max of int32, we assume the stamp is in
// nanoseconds instead of seconds and perform conversion
if (*it > std::numeric_limits<int32_t>::max()) {
stamp *= 1e-9;
double stampd = static_cast<double>(*it);
// If the number of digits is greater than 10,
// the stamp is in nanoseconds instead of seconds, perform conversion
if (number_of_digits_decimal_part(*it) > 10) {
stampd *= 1e-9;
}
timestamps.emplace_back(stamp);
timestamps.emplace_back(stampd);
}
return timestamps;
};
Expand Down

0 comments on commit a2d4e31

Please sign in to comment.