Skip to content

Commit 7b31f1c

Browse files
roncapatahcorde
andauthored
Initialize lookup table only once at compile time (#1330)
Signed-off-by: Patrick Roncagliolo <[email protected]> Co-authored-by: Alejandro Hernández Cordero <[email protected]>
1 parent 9bbca6e commit 7b31f1c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

rviz_default_plugins/src/rviz_default_plugins/displays/pointcloud/transformers/rgb8_pc_transformer.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030

3131
#include <algorithm>
32+
#include <array>
3233

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

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

7778
// Create a look-up table for colors
78-
float rgb_lut[256];
79-
for (int i = 0; i < 256; ++i) {
80-
rgb_lut[i] = static_cast<float>(i) / 255.0f;
81-
}
79+
constexpr static std::array<float, 256> rgb_lut = [](){
80+
std::array<float, 256> result{};
81+
for (int i = 0; i < 256; ++i) {
82+
result[i] = static_cast<float>(i) / 255.0f;
83+
}
84+
return result;
85+
}();
86+
8287
if (rgb != -1) { // rgb
8388
for (V_PointCloudPoint::iterator iter = points_out.begin(); iter != points_out.end();
8489
++iter, rgb_ptr += point_step)

0 commit comments

Comments
 (0)