Skip to content

Commit

Permalink
Initialize lookup table only once at compile time (#1330)
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Roncagliolo <[email protected]>
Co-authored-by: Alejandro Hernández Cordero <[email protected]>
  • Loading branch information
roncapat and ahcorde authored Jan 24, 2025
1 parent 9bbca6e commit 7b31f1c
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@


#include <algorithm>
#include <array>

#include "rviz_default_plugins/displays/pointcloud/point_cloud_helpers.hpp"

Expand Down Expand Up @@ -75,10 +76,14 @@ bool RGB8PCTransformer::transform(
const uint32_t point_step = cloud->point_step;

// Create a look-up table for colors
float rgb_lut[256];
for (int i = 0; i < 256; ++i) {
rgb_lut[i] = static_cast<float>(i) / 255.0f;
}
constexpr static std::array<float, 256> rgb_lut = [](){
std::array<float, 256> result{};
for (int i = 0; i < 256; ++i) {
result[i] = static_cast<float>(i) / 255.0f;
}
return result;
}();

if (rgb != -1) { // rgb
for (V_PointCloudPoint::iterator iter = points_out.begin(); iter != points_out.end();
++iter, rgb_ptr += point_step)
Expand Down

0 comments on commit 7b31f1c

Please sign in to comment.