45 #include <pcl/common/io.h>
46 #include <pcl/common/colors.h>
47 #include <pcl/common/point_tests.h>
50 template <
typename Po
intT>
bool
56 bool result = this->extractImpl (cloud, img);
58 if (paint_nans_with_black_ && result)
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);
71 template <
typename Po
intT>
bool
74 std::vector<pcl::PCLPointField> fields;
75 int field_x_idx = pcl::getFieldIndex<PointT> (
"normal_x", fields);
76 int field_y_idx = pcl::getFieldIndex<PointT> (
"normal_y", fields);
77 int field_z_idx = pcl::getFieldIndex<PointT> (
"normal_z", 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;
87 img.
step = img.
width *
sizeof (
unsigned char) * 3;
90 for (std::size_t i = 0; i < cloud.
size (); ++i)
95 pcl::getFieldValue<PointT, float> (cloud[i], offset_x, x);
96 pcl::getFieldValue<PointT, float> (cloud[i], offset_y, y);
97 pcl::getFieldValue<PointT, float> (cloud[i], offset_z, z);
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);
107 template <
typename Po
intT>
bool
110 std::vector<pcl::PCLPointField> fields;
111 int field_idx = pcl::getFieldIndex<PointT> (
"rgb", fields);
114 field_idx = pcl::getFieldIndex<PointT> (
"rgba", fields);
118 const std::size_t offset = fields[field_idx].offset;
123 img.
step = img.
width *
sizeof (
unsigned char) * 3;
126 for (std::size_t i = 0; i < cloud.
size (); ++i)
129 pcl::getFieldValue<PointT, std::uint32_t> (cloud[i], offset, val);
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;
139 template <
typename Po
intT>
bool
142 std::vector<pcl::PCLPointField> fields;
143 int field_idx = pcl::getFieldIndex<PointT> (
"label", fields);
146 const std::size_t offset = fields[field_idx].offset;
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)
161 pcl::getFieldValue<PointT, std::uint32_t> (cloud[i], offset, val);
162 data[i] =
static_cast<unsigned short>(val);
166 case COLORS_RGB_RANDOM:
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)
180 pcl::getFieldValue<PointT, std::uint32_t> (cloud[i], offset, val);
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);
195 case COLORS_RGB_GLASBEY:
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)
214 pcl::getFieldValue<PointT, std::uint32_t> (point, offset, val);
221 std::size_t color = 0;
222 for (
const std::uint32_t &label : labels)
224 colormap[label] = color % GlasbeyLUT::size ();
229 for (std::size_t i = 0; i < cloud.size (); ++i)
232 pcl::getFieldValue<PointT, std::uint32_t> (cloud[i], offset, val);
233 memcpy (&img.
data[i * 3], GlasbeyLUT::data () + colormap[val] * 3, 3);
244 template <
typename Po
intT>
bool
247 std::vector<pcl::PCLPointField> fields;
248 int field_idx = pcl::getFieldIndex<PointT> (field_name_, fields);
251 const std::size_t offset = fields[field_idx].offset;
256 img.
step = img.
width *
sizeof (
unsigned short);
258 auto* data =
reinterpret_cast<unsigned short*
>(img.
data.data());
260 float scaling_factor = scaling_factor_;
261 float data_min = 0.0f;
262 if (scaling_method_ == SCALING_FULL_RANGE)
264 float min = std::numeric_limits<float>::infinity();
265 float max = -std::numeric_limits<float>::infinity();
266 for (
const auto& point: cloud)
269 pcl::getFieldValue<PointT, float> (point, offset, val);
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)
282 pcl::getFieldValue<PointT, float> (cloud[i], offset, val);
283 if (scaling_method_ == SCALING_NO)
287 else if (scaling_method_ == SCALING_FULL_RANGE)
289 data[i] = (val - data_min) * scaling_factor;
291 else if (scaling_method_ == SCALING_FIXED_FACTOR)
293 data[i] = val * scaling_factor;
PointCloud represents the base class in PCL for storing collections of 3D points.
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).
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...
std::vector< std::uint8_t > data