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::fill_n(&img.
data[i * size], size, 0);
71template <
typename Po
intT>
bool
74 std::vector<pcl::PCLPointField>
fields;
78 if (field_x_idx == -1 || field_y_idx == -1 || field_z_idx == -1)
80 const std::size_t offset_x =
fields[field_x_idx].offset;
81 const std::size_t offset_y =
fields[field_y_idx].offset;
82 const std::size_t offset_z =
fields[field_z_idx].offset;
85 img.
width = cloud.width;
87 img.
step = img.
width *
sizeof (
unsigned char) * 3;
90 for (std::size_t i = 0; i < cloud.size (); ++i)
98 img.
data[i * 3 + 0] =
static_cast<unsigned char>((x + 1.0) * 127);
99 img.
data[i * 3 + 1] =
static_cast<unsigned char>((y + 1.0) * 127);
100 img.
data[i * 3 + 2] =
static_cast<unsigned char>((z + 1.0) * 127);
107template <
typename Po
intT>
bool
110 std::vector<pcl::PCLPointField>
fields;
118 const std::size_t offset =
fields[field_idx].offset;
121 img.
width = cloud.width;
122 img.
height = cloud.height;
123 img.
step = img.
width *
sizeof (
unsigned char) * 3;
126 for (std::size_t i = 0; i < cloud.size (); ++i)
130 img.
data[i * 3 + 0] = (val >> 16) & 0x0000ff;
131 img.
data[i * 3 + 1] = (val >> 8) & 0x0000ff;
132 img.
data[i * 3 + 2] = (val) & 0x0000ff;
139template <
typename Po
intT>
bool
142 std::vector<pcl::PCLPointField>
fields;
146 const std::size_t offset =
fields[field_idx].offset;
153 img.
width = cloud.width;
154 img.
height = cloud.height;
155 img.
step = img.
width *
sizeof (
unsigned short);
157 auto* data =
reinterpret_cast<unsigned short*
>(img.
data.data());
158 for (std::size_t i = 0; i < cloud.size (); ++i)
162 data[i] =
static_cast<unsigned short>(val);
169 img.
width = cloud.width;
170 img.
height = cloud.height;
171 img.
step = img.
width *
sizeof (
unsigned char) * 3;
174 std::srand(std::time(
nullptr));
175 std::map<std::uint32_t, std::size_t> colormap;
177 for (std::size_t i = 0; i < cloud.size (); ++i)
181 if (colormap.count (val) == 0)
183 colormap[val] = i * 3;
184 img.
data[i * 3 + 0] =
static_cast<std::uint8_t
> ((std::rand () % 256));
185 img.
data[i * 3 + 1] =
static_cast<std::uint8_t
> ((std::rand () % 256));
186 img.
data[i * 3 + 2] =
static_cast<std::uint8_t
> ((std::rand () % 256));
190 memcpy (&img.
data[i * 3], &img.
data[colormap[val]], 3);
198 img.
width = cloud.width;
199 img.
height = cloud.height;
200 img.
step = img.
width *
sizeof (
unsigned char) * 3;
203 std::srand(std::time(
nullptr));
204 std::set<std::uint32_t> labels;
205 std::map<std::uint32_t, std::size_t> colormap;
208 for (
const auto& point: cloud)
221 std::size_t color = 0;
222 for (
const std::uint32_t &label : labels)
229 for (std::size_t i = 0; i < cloud.size (); ++i)
244template <
typename Po
intT>
bool
247 std::vector<pcl::PCLPointField>
fields;
251 const std::size_t offset =
fields[field_idx].offset;
254 img.
width = cloud.width;
255 img.
height = cloud.height;
256 img.
step = img.
width *
sizeof (
unsigned short);
258 auto* data =
reinterpret_cast<unsigned short*
>(img.
data.data());
261 float data_min = 0.0f;
264 float min = std::numeric_limits<float>::infinity();
265 float max = -std::numeric_limits<float>::infinity();
266 for (
const auto& point: cloud)
275 scaling_factor = min == max ? 0 : std::numeric_limits<unsigned short>::max() / (max - min);
279 for (std::size_t i = 0; i < cloud.size (); ++i)
289 data[i] = (val - data_min) * scaling_factor;
293 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