38 #ifndef PCL_POINT_CLOUD_COLOR_HANDLERS_IMPL_HPP_ 39 #define PCL_POINT_CLOUD_COLOR_HANDLERS_IMPL_HPP_ 44 #include <pcl/pcl_macros.h> 45 #include <pcl/common/colors.h> 48 template <
typename Po
intT>
bool 51 if (!capable_ || !cloud_)
56 scalars->SetNumberOfComponents (3);
58 vtkIdType nr_points = cloud_->points.size ();
59 reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetNumberOfTuples (nr_points);
62 unsigned char* colors =
new unsigned char[nr_points * 3];
65 for (vtkIdType cp = 0; cp < nr_points; ++cp)
67 colors[cp * 3 + 0] = static_cast<unsigned char> (r_);
68 colors[cp * 3 + 1] = static_cast<unsigned char> (g_);
69 colors[cp * 3 + 2] = static_cast<unsigned char> (b_);
71 reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetArray (colors, 3 * nr_points, 0, vtkUnsignedCharArray::VTK_DATA_ARRAY_DELETE);
76 template <
typename Po
intT>
bool 79 if (!capable_ || !cloud_)
84 scalars->SetNumberOfComponents (3);
86 vtkIdType nr_points = cloud_->points.size ();
87 reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetNumberOfTuples (nr_points);
90 unsigned char* colors =
new unsigned char[nr_points * 3];
94 int r_ = static_cast<int> (pcl_lrint (r * 255.0)),
95 g_ = static_cast<int> (pcl_lrint (g * 255.0)),
96 b_ = static_cast<int> (pcl_lrint (b * 255.0));
99 for (vtkIdType cp = 0; cp < nr_points; ++cp)
101 colors[cp * 3 + 0] = static_cast<unsigned char> (r_);
102 colors[cp * 3 + 1] = static_cast<unsigned char> (g_);
103 colors[cp * 3 + 2] = static_cast<unsigned char> (b_);
105 reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetArray (colors, 3 * nr_points, 0, vtkUnsignedCharArray::VTK_DATA_ARRAY_DELETE);
110 template <
typename Po
intT>
void 117 if (field_idx_ != -1)
125 if (field_idx_ != -1)
133 template <
typename Po
intT>
bool 136 if (!capable_ || !cloud_)
140 std::vector<pcl::PCLPointField> fields;
143 if (rgba_index == -1)
146 int rgba_offset = fields[rgba_index].offset;
150 scalars->SetNumberOfComponents (3);
152 vtkIdType nr_points = cloud_->points.size ();
153 reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetNumberOfTuples (nr_points);
154 unsigned char* colors = reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->GetPointer (0);
159 for (
size_t d = 0; d < fields_.size (); ++d)
160 if (fields_[d].name ==
"x")
161 x_idx = static_cast<int> (d);
167 for (vtkIdType cp = 0; cp < nr_points; ++cp)
170 if (!pcl_isfinite (cloud_->points[cp].x) ||
171 !pcl_isfinite (cloud_->points[cp].y) ||
172 !pcl_isfinite (cloud_->points[cp].z))
175 memcpy (&rgb, (reinterpret_cast<const char *> (&cloud_->points[cp])) + rgba_offset, sizeof (
pcl::RGB));
177 colors[j + 1] = rgb.g;
178 colors[j + 2] = rgb.b;
185 for (vtkIdType cp = 0; cp < nr_points; ++cp)
187 int idx = static_cast<int> (cp) * 3;
188 memcpy (&rgb, (reinterpret_cast<const char *> (&cloud_->points[cp])) + rgba_offset, sizeof (
pcl::RGB));
189 colors[idx ] = rgb.r;
190 colors[idx + 1] = rgb.g;
191 colors[idx + 2] = rgb.b;
198 template <
typename Po
intT>
229 template <
typename Po
intT>
bool 232 if (!capable_ || !cloud_)
237 scalars->SetNumberOfComponents (3);
239 vtkIdType nr_points = cloud_->points.size ();
240 reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetNumberOfTuples (nr_points);
241 unsigned char* colors = reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->GetPointer (0);
247 for (
size_t d = 0; d < fields_.size (); ++d)
248 if (fields_[d].name ==
"x")
249 x_idx = static_cast<int> (d);
254 for (vtkIdType cp = 0; cp < nr_points; ++cp)
257 if (!pcl_isfinite (cloud_->points[cp].x) ||
258 !pcl_isfinite (cloud_->points[cp].y) ||
259 !pcl_isfinite (cloud_->points[cp].z))
264 float h = cloud_->points[cp].h;
265 float v = cloud_->points[cp].v;
266 float s = cloud_->points[cp].s;
270 h = h < 0.0f ? h - (((int)h)/360 - 1)*360 : h - (((
int)h)/360)*360;
273 if (s > 1.0f) s = 1.0f;
274 if (s < 0.0f) s = 0.0f;
275 if (v > 1.0f) v = 1.0f;
276 if (v < 0.0f) v = 0.0f;
280 colors[idx] = colors[idx+1] = colors[idx+2] = v*255;
288 float p = v * (1 - s);
289 float q = v * (1 - s * f);
290 float t = v * (1 - s * (1 - f));
295 colors[idx] = v*255; colors[idx+1] = t*255; colors[idx+2] = p*255;
break;
297 colors[idx] = q*255; colors[idx+1] = v*255; colors[idx+2] = p*255;
break;
299 colors[idx] = p*255; colors[idx+1] = v*255; colors[idx+2] = t*255;
break;
301 colors[idx] = p*255; colors[idx+1] = q*255; colors[idx+2] = v*255;
break;
303 colors[idx] = t*255; colors[idx+1] = p*255; colors[idx+2] = v*255;
break;
305 colors[idx] = v*255; colors[idx+1] = p*255; colors[idx+2] = q*255;
break;
314 for (vtkIdType cp = 0; cp < nr_points; ++cp)
316 float h = cloud_->points[cp].h;
317 float v = cloud_->points[cp].v;
318 float s = cloud_->points[cp].s;
322 h = h < 0.0f ? h - (((int)h)/360 - 1)*360 : h - (((
int)h)/360)*360;
325 if (s > 1.0f) s = 1.0f;
326 if (s < 0.0f) s = 0.0f;
327 if (v > 1.0f) v = 1.0f;
328 if (v < 0.0f) v = 0.0f;
332 colors[idx] = colors[idx+1] = colors[idx+2] = v*255;
340 float p = v * (1 - s);
341 float q = v * (1 - s * f);
342 float t = v * (1 - s * (1 - f));
347 colors[idx] = v*255; colors[idx+1] = t*255; colors[idx+2] = p*255;
break;
349 colors[idx] = q*255; colors[idx+1] = v*255; colors[idx+2] = p*255;
break;
351 colors[idx] = p*255; colors[idx+1] = v*255; colors[idx+2] = t*255;
break;
353 colors[idx] = p*255; colors[idx+1] = q*255; colors[idx+2] = v*255;
break;
355 colors[idx] = t*255; colors[idx+1] = p*255; colors[idx+2] = v*255;
break;
357 colors[idx] = v*255; colors[idx+1] = p*255; colors[idx+2] = q*255;
break;
367 template <
typename Po
intT>
void 373 if (field_idx_ != -1)
380 template <
typename Po
intT>
bool 383 if (!capable_ || !cloud_)
388 scalars->SetNumberOfComponents (1);
390 vtkIdType nr_points = cloud_->points.size ();
391 reinterpret_cast<vtkFloatArray*>(&(*scalars))->SetNumberOfTuples (nr_points);
395 float* colors =
new float[nr_points];
401 for (
size_t d = 0; d < fields_.size (); ++d)
402 if (fields_[d].name ==
"x")
403 x_idx = static_cast<int> (d);
408 for (vtkIdType cp = 0; cp < nr_points; ++cp)
411 if (!pcl_isfinite (cloud_->points[cp].x) || !pcl_isfinite (cloud_->points[cp].y) || !pcl_isfinite (cloud_->points[cp].z))
414 const uint8_t* pt_data = reinterpret_cast<const uint8_t*> (&cloud_->points[cp]);
415 memcpy (&field_data, pt_data + fields_[field_idx_].offset,
pcl::getFieldSize (fields_[field_idx_].datatype));
417 colors[j] = field_data;
424 for (vtkIdType cp = 0; cp < nr_points; ++cp)
426 const uint8_t* pt_data = reinterpret_cast<const uint8_t*> (&cloud_->points[cp]);
427 memcpy (&field_data, pt_data + fields_[field_idx_].offset,
pcl::getFieldSize (fields_[field_idx_].datatype));
429 if (!pcl_isfinite (field_data))
432 colors[j] = field_data;
436 reinterpret_cast<vtkFloatArray*>(&(*scalars))->SetArray (colors, j, 0, vtkFloatArray::VTK_DATA_ARRAY_DELETE);
441 template <
typename Po
intT>
void 448 if (field_idx_ != -1)
455 template <
typename Po
intT>
bool 458 if (!capable_ || !cloud_)
463 scalars->SetNumberOfComponents (4);
465 vtkIdType nr_points = cloud_->points.size ();
466 reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->SetNumberOfTuples (nr_points);
467 unsigned char* colors = reinterpret_cast<vtkUnsignedCharArray*>(&(*scalars))->GetPointer (0);
472 for (
size_t d = 0; d < fields_.size (); ++d)
473 if (fields_[d].name ==
"x")
474 x_idx = static_cast<int> (d);
479 for (vtkIdType cp = 0; cp < nr_points; ++cp)
482 if (!pcl_isfinite (cloud_->points[cp].x) ||
483 !pcl_isfinite (cloud_->points[cp].y) ||
484 !pcl_isfinite (cloud_->points[cp].z))
487 colors[j ] = cloud_->points[cp].r;
488 colors[j + 1] = cloud_->points[cp].g;
489 colors[j + 2] = cloud_->points[cp].b;
490 colors[j + 3] = cloud_->points[cp].a;
497 for (vtkIdType cp = 0; cp < nr_points; ++cp)
499 int idx = static_cast<int> (cp) * 4;
500 colors[idx ] = cloud_->points[cp].r;
501 colors[idx + 1] = cloud_->points[cp].g;
502 colors[idx + 2] = cloud_->points[cp].b;
503 colors[idx + 3] = cloud_->points[cp].a;
510 template <
typename Po
intT>
void 515 if (field_idx_ != -1)
523 template <
typename Po
intT>
bool 526 if (!capable_ || !cloud_)
531 scalars->SetNumberOfComponents (3);
533 vtkIdType nr_points = cloud_->points.size ();
534 reinterpret_cast<vtkUnsignedCharArray*> (&(*scalars))->SetNumberOfTuples (nr_points);
535 unsigned char* colors = reinterpret_cast<vtkUnsignedCharArray*> (&(*scalars))->GetPointer (0);
538 std::map<uint32_t, pcl::RGB> colormap;
539 if (!static_mapping_)
541 std::set<uint32_t> labels;
543 for (vtkIdType i = 0; i < nr_points; ++i)
544 labels.insert (cloud_->points[i].label);
548 for (std::set<uint32_t>::iterator iter = labels.begin (); iter != labels.end (); ++iter, ++color)
553 for (vtkIdType cp = 0; cp < nr_points; ++cp)
558 colors[j ] = color.r;
559 colors[j + 1] = color.g;
560 colors[j + 2] = color.b;
568 #endif // PCL_POINT_CLOUD_COLOR_HANDLERS_IMPL_HPP_ virtual void setInputCloud(const PointCloudConstPtr &cloud)
Set the input cloud to be used.
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...
int getFieldIndex(const pcl::PCLPointCloud2 &cloud, const std::string &field_name)
Get the index of a specified field (i.e., dimension/channel)
virtual bool getColor(vtkSmartPointer< vtkDataArray > &scalars) const
Obtain the actual color for the input dataset as vtk scalars.
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Set the input cloud to be used.
virtual bool getColor(vtkSmartPointer< vtkDataArray > &scalars) const
Obtain the actual color for the input dataset as vtk scalars.
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Set the input cloud to be used.
PointCloudColorHandlerHSVField(const PointCloudConstPtr &cloud)
Constructor.
static size_t size()
Get the number of colors in the lookup table.
Base Handler class for PointCloud colors.
PointCloud::ConstPtr PointCloudConstPtr
PCL_EXPORTS void getRandomColors(double &r, double &g, double &b, double min=0.2, double max=2.8)
Get (good) random values for R/G/B.
int s_field_idx_
The field index for "S".
std::vector< pcl::PCLPointField > fields_
The list of fields available for this PointCloud.
A structure representing RGB color information.
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Set the input cloud to be used.
virtual bool getColor(vtkSmartPointer< vtkDataArray > &scalars) const
Obtain the actual color for the input dataset as vtk scalars.
int getFieldSize(const int datatype)
Obtains the size of a specific field data type in bytes.
static RGB at(unsigned int color_id)
Get a color from the lookup table with a given id.
virtual bool getColor(vtkSmartPointer< vtkDataArray > &scalars) const
Obtain the actual color for the input dataset as vtk scalars.
int v_field_idx_
The field index for "V".
virtual bool getColor(vtkSmartPointer< vtkDataArray > &scalars) const
Obtain the actual color for the input dataset as vtk scalars.
int field_idx_
The index of the field holding the data that represents the color.
A point structure representing Euclidean xyz coordinates, and the RGB color.
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Set the input cloud to be used.
virtual bool getColor(vtkSmartPointer< vtkDataArray > &scalars) const
Obtain the actual color for the input dataset as vtk scalars.
virtual bool getColor(vtkSmartPointer< vtkDataArray > &scalars) const
Obtain the actual color for the input dataset as vtk scalars.
bool capable_
True if this handler is capable of handling the input data, false otherwise.