45#include <pcl/common/io.h>
46#include <pcl/common/colors.h>
47#include <pcl/common/point_tests.h>
50template <
typename Po
intT>
bool
60 std::size_t size = img.
encoding ==
"mono16" ? 2 : 3;
61 for (std::size_t i = 0; i < cloud.
size (); ++i)
63 std::memset (&img.
data[i * size], 0, size);
70template <
typename Po
intT>
bool
73 std::vector<pcl::PCLPointField>
fields;
77 if (field_x_idx == -1 || field_y_idx == -1 || field_z_idx == -1)
79 const std::size_t offset_x =
fields[field_x_idx].offset;
80 const std::size_t offset_y =
fields[field_y_idx].offset;
81 const std::size_t offset_z =
fields[field_z_idx].offset;
84 img.
width = cloud.width;
86 img.
step = img.
width *
sizeof (
unsigned char) * 3;
89 for (std::size_t i = 0; i < cloud.size (); ++i)
97 img.
data[i * 3 + 0] =
static_cast<unsigned char>((x + 1.0) * 127);
98 img.
data[i * 3 + 1] =
static_cast<unsigned char>((y + 1.0) * 127);
99 img.
data[i * 3 + 2] =
static_cast<unsigned char>((z + 1.0) * 127);
106template <
typename Po
intT>
bool
109 std::vector<pcl::PCLPointField>
fields;
117 const std::size_t offset =
fields[field_idx].offset;
120 img.
width = cloud.width;
121 img.
height = cloud.height;
122 img.
step = img.
width *
sizeof (
unsigned char) * 3;
125 for (std::size_t i = 0; i < cloud.size (); ++i)
129 img.
data[i * 3 + 0] = (val >> 16) & 0x0000ff;
130 img.
data[i * 3 + 1] = (val >> 8) & 0x0000ff;
131 img.
data[i * 3 + 2] = (val) & 0x0000ff;
138template <
typename Po
intT>
bool
141 std::vector<pcl::PCLPointField>
fields;
145 const std::size_t offset =
fields[field_idx].offset;
152 img.
width = cloud.width;
153 img.
height = cloud.height;
154 img.
step = img.
width *
sizeof (
unsigned short);
156 unsigned short* data =
reinterpret_cast<unsigned short*
>(&img.
data[0]);
157 for (std::size_t i = 0; i < cloud.size (); ++i)
161 data[i] =
static_cast<unsigned short>(val);
168 img.
width = cloud.width;
169 img.
height = cloud.height;
170 img.
step = img.
width *
sizeof (
unsigned char) * 3;
173 std::srand(std::time(
nullptr));
174 std::map<std::uint32_t, std::size_t> colormap;
176 for (std::size_t i = 0; i < cloud.size (); ++i)
180 if (colormap.count (val) == 0)
182 colormap[val] = i * 3;
183 img.
data[i * 3 + 0] =
static_cast<std::uint8_t
> ((std::rand () % 256));
184 img.
data[i * 3 + 1] =
static_cast<std::uint8_t
> ((std::rand () % 256));
185 img.
data[i * 3 + 2] =
static_cast<std::uint8_t
> ((std::rand () % 256));
189 memcpy (&img.
data[i * 3], &img.
data[colormap[val]], 3);
197 img.
width = cloud.width;
198 img.
height = cloud.height;
199 img.
step = img.
width *
sizeof (
unsigned char) * 3;
202 std::srand(std::time(
nullptr));
203 std::set<std::uint32_t> labels;
204 std::map<std::uint32_t, std::size_t> colormap;
207 for (
const auto& point: cloud)
220 std::size_t color = 0;
221 for (
const std::uint32_t &label : labels)
228 for (std::size_t i = 0; i < cloud.size (); ++i)
243template <
typename Po
intT>
bool
246 std::vector<pcl::PCLPointField>
fields;
250 const std::size_t offset =
fields[field_idx].offset;
253 img.
width = cloud.width;
254 img.
height = cloud.height;
255 img.
step = img.
width *
sizeof (
unsigned short);
257 unsigned short* data =
reinterpret_cast<unsigned short*
>(&img.
data[0]);
260 float data_min = 0.0f;
263 float min = std::numeric_limits<float>::infinity();
264 float max = -std::numeric_limits<float>::infinity();
265 for (
const auto& point: cloud)
274 scaling_factor = min == max ? 0 : std::numeric_limits<unsigned short>::max() / (max - min);
278 for (std::size_t i = 0; i < cloud.size (); ++i)
288 data[i] = (val - data_min) * scaling_factor;
292 data[i] = val * scaling_factor;
static std::size_t size()
static const unsigned char * data()
std::uint32_t width
The point cloud width (if organized as an image-structure).
bool isOrganized() const
Return whether a dataset is organized (e.g., arranged in a structured grid).
std::uint32_t height
The point cloud height (if organized as an image-structure).
int getFieldIndex(const pcl::PointCloud< PointT > &, const std::string &field_name, std::vector< pcl::PCLPointField > &fields)
bool isFinite(const PointT &pt)
Tests if the 3D components of a point are all finite param[in] pt point to be tested return true if f...
void getFieldValue(const PointT &pt, std::size_t field_offset, ValT &value)
Get the value at a specified field in a point.
std::vector< std::uint8_t > data