38 #ifndef PCL_POINT_CLOUD_IMAGE_EXTRACTORS_IMPL_HPP_
39 #define PCL_POINT_CLOUD_IMAGE_EXTRACTORS_IMPL_HPP_
45 #include <pcl/common/io.h>
48 template <
typename Po
intT>
bool
54 std::vector<pcl::PCLPointField> fields;
58 if (field_x_idx == -1 || field_y_idx == -1 || field_z_idx == -1)
60 const size_t offset_x = fields[field_x_idx].offset;
61 const size_t offset_y = fields[field_y_idx].offset;
62 const size_t offset_z = fields[field_z_idx].offset;
67 img.
step = img.
width *
sizeof (
unsigned char) * 3;
70 for (
size_t i = 0; i < cloud.
points.size (); ++i)
75 pcl::getFieldValue<PointT, float> (cloud.
points[i], offset_x, x);
76 pcl::getFieldValue<PointT, float> (cloud.
points[i], offset_y, y);
77 pcl::getFieldValue<PointT, float> (cloud.
points[i], offset_z, z);
78 img.
data[i * 3 + 0] =
static_cast<unsigned char>((x + 1.0) * 127);
79 img.
data[i * 3 + 1] =
static_cast<unsigned char>((y + 1.0) * 127);
80 img.
data[i * 3 + 2] =
static_cast<unsigned char>((z + 1.0) * 127);
87 template <
typename Po
intT>
bool
93 std::vector<pcl::PCLPointField> fields;
101 const size_t offset = fields[field_idx].offset;
106 img.
step = img.
width *
sizeof (
unsigned char) * 3;
109 for (
size_t i = 0; i < cloud.
points.size (); ++i)
112 pcl::getFieldValue<PointT, uint32_t> (cloud.
points[i], offset, val);
113 img.
data[i * 3 + 0] = (val >> 16) & 0x0000ff;
114 img.
data[i * 3 + 1] = (val >> 8) & 0x0000ff;
115 img.
data[i * 3 + 2] = (val) & 0x0000ff;
122 template <
typename Po
intT>
bool
128 std::vector<pcl::PCLPointField> fields;
132 const size_t offset = fields[field_idx].offset;
141 img.
step = img.
width *
sizeof (
unsigned short);
143 unsigned short* data =
reinterpret_cast<unsigned short*
>(&img.
data[0]);
144 for (
size_t i = 0; i < cloud.
points.size (); ++i)
147 pcl::getFieldValue<PointT, uint32_t> (cloud.
points[i], offset, val);
148 data[i] =
static_cast<unsigned short>(val);
152 case COLORS_RGB_RANDOM:
157 img.
step = img.
width *
sizeof (
unsigned char) * 3;
160 std::srand(std::time(0));
161 std::map<uint32_t, size_t> colormap;
163 for (
size_t i = 0; i < cloud.
points.size (); ++i)
166 pcl::getFieldValue<PointT, uint32_t> (cloud.
points[i], offset, val);
167 if (colormap.count (val) == 0)
169 colormap[val] = i * 3;
170 img.
data[i * 3 + 0] =
static_cast<uint8_t
> ((std::rand () % 256));
171 img.
data[i * 3 + 1] =
static_cast<uint8_t
> ((std::rand () % 256));
172 img.
data[i * 3 + 2] =
static_cast<uint8_t
> ((std::rand () % 256));
176 memcpy (&img.
data[i * 3], &img.
data[colormap[val]], 3);
187 template <
typename Po
intT>
bool
193 std::vector<pcl::PCLPointField> fields;
197 const size_t offset = fields[field_idx].offset;
202 img.
step = img.
width *
sizeof (
unsigned short);
204 unsigned short* data =
reinterpret_cast<unsigned short*
>(&img.
data[0]);
206 float scaling_factor = scaling_factor_;
207 float data_min = 0.0f;
208 if (scaling_method_ == SCALING_FULL_RANGE)
210 float min = std::numeric_limits<float>::infinity();
211 float max = -std::numeric_limits<float>::infinity();
212 for (
size_t i = 0; i < cloud.
points.size (); ++i)
215 pcl::getFieldValue<PointT, float> (cloud.
points[i], offset, val);
221 scaling_factor = min == max ? 0 : std::numeric_limits<unsigned short>::max() / (max - min);
225 for (
size_t i = 0; i < cloud.
points.size (); ++i)
228 pcl::getFieldValue<PointT, float> (cloud.
points[i], offset, val);
229 if (scaling_method_ == SCALING_NO)
233 else if (scaling_method_ == SCALING_FULL_RANGE)
235 data[i] = (val - data_min) * scaling_factor;
237 else if (scaling_method_ == SCALING_FIXED_FACTOR)
239 data[i] = val * scaling_factor;
246 #endif // PCL_POINT_CLOUD_IMAGE_EXTRACTORS_IMPL_HPP_
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
std::vector< pcl::uint8_t > data
virtual bool extract(const PointCloud &cloud, pcl::PCLImage &img) const
Obtain the label image from the given cloud.
uint32_t width
The point cloud width (if organized as an image-structure).
uint32_t height
The point cloud height (if organized as an image-structure).
virtual bool extract(const PointCloud &cloud, pcl::PCLImage &image) const
Obtain the image from the given cloud.
bool isOrganized() const
Return whether a dataset is organized (e.g., arranged in a structured grid).
virtual bool extract(const PointCloud &cloud, pcl::PCLImage &img) const
Obtain the color image from the given cloud.
virtual bool extract(const PointCloud &cloud, pcl::PCLImage &img) const
Obtain the color image from the given cloud.
int getFieldIndex(const pcl::PCLPointCloud2 &cloud, const std::string &field_name)
Get the index of a specified field (i.e., dimension/channel)
PointCloud represents the base class in PCL for storing collections of 3D points. ...