38 #ifndef PCL_POINT_CLOUD_COLOR_HANDLERS_IMPL_HPP_ 39 #define PCL_POINT_CLOUD_COLOR_HANDLERS_IMPL_HPP_ 41 #include <pcl/pcl_macros.h> 44 template <
typename Po
intT>
bool 47 if (!capable_ || !cloud_)
52 scalars->SetNumberOfComponents (3);
54 vtkIdType nr_points = cloud_->points.size ();
55 reinterpret_cast<vtkUnsignedCharArray*
>(&(*scalars))->SetNumberOfTuples (nr_points);
58 unsigned char* colors =
new unsigned char[nr_points * 3];
61 for (vtkIdType cp = 0; cp < nr_points; ++cp)
63 colors[cp * 3 + 0] =
static_cast<unsigned char> (r_);
64 colors[cp * 3 + 1] =
static_cast<unsigned char> (g_);
65 colors[cp * 3 + 2] =
static_cast<unsigned char> (b_);
67 reinterpret_cast<vtkUnsignedCharArray*
>(&(*scalars))->SetArray (colors, 3 * nr_points, 0);
72 template <
typename Po
intT>
bool 75 if (!capable_ || !cloud_)
80 scalars->SetNumberOfComponents (3);
82 vtkIdType nr_points = cloud_->points.size ();
83 reinterpret_cast<vtkUnsignedCharArray*
>(&(*scalars))->SetNumberOfTuples (nr_points);
86 unsigned char* colors =
new unsigned char[nr_points * 3];
90 int r_ =
static_cast<int> (pcl_lrint (r * 255.0)),
91 g_ = static_cast<int> (pcl_lrint (g * 255.0)),
92 b_ = static_cast<int> (pcl_lrint (b * 255.0));
95 for (vtkIdType cp = 0; cp < nr_points; ++cp)
97 colors[cp * 3 + 0] =
static_cast<unsigned char> (r_);
98 colors[cp * 3 + 1] =
static_cast<unsigned char> (g_);
99 colors[cp * 3 + 2] =
static_cast<unsigned char> (b_);
101 reinterpret_cast<vtkUnsignedCharArray*
>(&(*scalars))->SetArray (colors, 3 * nr_points, 0);
106 template <
typename Po
intT>
void 113 if (field_idx_ != -1)
121 if (field_idx_ != -1)
129 template <
typename Po
intT>
bool 132 if (!capable_ || !cloud_)
137 scalars->SetNumberOfComponents (3);
139 vtkIdType nr_points = cloud_->points.size ();
140 reinterpret_cast<vtkUnsignedCharArray*
>(&(*scalars))->SetNumberOfTuples (nr_points);
141 unsigned char* colors =
reinterpret_cast<vtkUnsignedCharArray*
>(&(*scalars))->GetPointer (0);
146 for (
size_t d = 0; d < fields_.size (); ++d)
147 if (fields_[d].name ==
"x")
148 x_idx =
static_cast<int> (d);
153 for (vtkIdType cp = 0; cp < nr_points; ++cp)
156 if (!pcl_isfinite (cloud_->points[cp].x) ||
157 !pcl_isfinite (cloud_->points[cp].y) ||
158 !pcl_isfinite (cloud_->points[cp].z))
161 colors[j ] = cloud_->points[cp].r;
162 colors[j + 1] = cloud_->points[cp].g;
163 colors[j + 2] = cloud_->points[cp].b;
170 for (vtkIdType cp = 0; cp < nr_points; ++cp)
172 int idx =
static_cast<int> (cp) * 3;
173 colors[idx ] = cloud_->points[cp].r;
174 colors[idx + 1] = cloud_->points[cp].g;
175 colors[idx + 2] = cloud_->points[cp].b;
182 template <
typename Po
intT>
213 template <
typename Po
intT>
bool 221 scalars->SetNumberOfComponents (3);
223 vtkIdType nr_points =
cloud_->points.size ();
224 reinterpret_cast<vtkUnsignedCharArray*
>(&(*scalars))->SetNumberOfTuples (nr_points);
225 unsigned char* colors =
reinterpret_cast<vtkUnsignedCharArray*
>(&(*scalars))->GetPointer (0);
231 for (
size_t d = 0; d <
fields_.size (); ++d)
233 x_idx =
static_cast<int> (d);
238 for (vtkIdType cp = 0; cp < nr_points; ++cp)
241 if (!pcl_isfinite (
cloud_->points[cp].x) ||
242 !pcl_isfinite (
cloud_->points[cp].y) ||
243 !pcl_isfinite (
cloud_->points[cp].z))
248 float h =
cloud_->points[cp].h;
249 float v =
cloud_->points[cp].v;
250 float s =
cloud_->points[cp].s;
254 h = h < 0.0f ? h - (((int)h)/360 - 1)*360 : h - (((
int)h)/360)*360;
257 if (s > 1.0f) s = 1.0f;
258 if (s < 0.0f) s = 0.0f;
259 if (v > 1.0f) v = 1.0f;
260 if (v < 0.0f) v = 0.0f;
264 colors[idx] = colors[idx+1] = colors[idx+2] = v*255;
272 float p = v * (1 - s);
273 float q = v * (1 - s * f);
274 float t = v * (1 - s * (1 - f));
279 colors[idx] = v*255; colors[idx+1] = t*255; colors[idx+2] = p*255;
break;
281 colors[idx] = q*255; colors[idx+1] = v*255; colors[idx+2] = p*255;
break;
283 colors[idx] = p*255; colors[idx+1] = v*255; colors[idx+2] = t*255;
break;
285 colors[idx] = p*255; colors[idx+1] = q*255; colors[idx+2] = v*255;
break;
287 colors[idx] = t*255; colors[idx+1] = p*255; colors[idx+2] = v*255;
break;
289 colors[idx] = v*255; colors[idx+1] = p*255; colors[idx+2] = q*255;
break;
298 for (vtkIdType cp = 0; cp < nr_points; ++cp)
300 float h =
cloud_->points[cp].h;
301 float v =
cloud_->points[cp].v;
302 float s =
cloud_->points[cp].s;
306 h = h < 0.0f ? h - (((int)h)/360 - 1)*360 : h - (((
int)h)/360)*360;
309 if (s > 1.0f) s = 1.0f;
310 if (s < 0.0f) s = 0.0f;
311 if (v > 1.0f) v = 1.0f;
312 if (v < 0.0f) v = 0.0f;
316 colors[idx] = colors[idx+1] = colors[idx+2] = v*255;
324 float p = v * (1 - s);
325 float q = v * (1 - s * f);
326 float t = v * (1 - s * (1 - f));
331 colors[idx] = v*255; colors[idx+1] = t*255; colors[idx+2] = p*255;
break;
333 colors[idx] = q*255; colors[idx+1] = v*255; colors[idx+2] = p*255;
break;
335 colors[idx] = p*255; colors[idx+1] = v*255; colors[idx+2] = t*255;
break;
337 colors[idx] = p*255; colors[idx+1] = q*255; colors[idx+2] = v*255;
break;
339 colors[idx] = t*255; colors[idx+1] = p*255; colors[idx+2] = v*255;
break;
341 colors[idx] = v*255; colors[idx+1] = p*255; colors[idx+2] = q*255;
break;
351 template <
typename Po
intT>
void 364 template <
typename Po
intT>
bool 372 scalars->SetNumberOfComponents (1);
374 vtkIdType nr_points =
cloud_->points.size ();
375 reinterpret_cast<vtkFloatArray*
>(&(*scalars))->SetNumberOfTuples (nr_points);
379 float* colors =
new float[nr_points];
385 for (
size_t d = 0; d <
fields_.size (); ++d)
387 x_idx =
static_cast<int> (d);
392 for (vtkIdType cp = 0; cp < nr_points; ++cp)
395 if (!pcl_isfinite (
cloud_->points[cp].x) || !pcl_isfinite (
cloud_->points[cp].y) || !pcl_isfinite (
cloud_->points[cp].z))
398 const uint8_t* pt_data =
reinterpret_cast<const uint8_t*
> (&
cloud_->points[cp]);
401 colors[j] = field_data;
408 for (vtkIdType cp = 0; cp < nr_points; ++cp)
410 const uint8_t* pt_data =
reinterpret_cast<const uint8_t*
> (&
cloud_->points[cp]);
413 if (!pcl_isfinite (field_data))
416 colors[j] = field_data;
420 reinterpret_cast<vtkFloatArray*
>(&(*scalars))->SetArray (colors, j, 0);
425 template <
typename Po
intT>
void 439 template <
typename Po
intT>
bool 447 scalars->SetNumberOfComponents (4);
449 vtkIdType nr_points =
cloud_->points.size ();
450 reinterpret_cast<vtkUnsignedCharArray*
>(&(*scalars))->SetNumberOfTuples (nr_points);
451 unsigned char* colors =
reinterpret_cast<vtkUnsignedCharArray*
>(&(*scalars))->GetPointer (0);
456 for (
size_t d = 0; d <
fields_.size (); ++d)
458 x_idx =
static_cast<int> (d);
463 for (vtkIdType cp = 0; cp < nr_points; ++cp)
466 if (!pcl_isfinite (
cloud_->points[cp].x) ||
467 !pcl_isfinite (
cloud_->points[cp].y) ||
468 !pcl_isfinite (
cloud_->points[cp].z))
471 colors[j ] =
cloud_->points[cp].r;
472 colors[j + 1] =
cloud_->points[cp].g;
473 colors[j + 2] =
cloud_->points[cp].b;
474 colors[j + 3] =
cloud_->points[cp].a;
481 for (vtkIdType cp = 0; cp < nr_points; ++cp)
483 int idx =
static_cast<int> (cp) * 4;
484 colors[idx ] =
cloud_->points[cp].r;
485 colors[idx + 1] =
cloud_->points[cp].g;
486 colors[idx + 2] =
cloud_->points[cp].b;
487 colors[idx + 3] =
cloud_->points[cp].a;
493 #endif // PCL_POINT_CLOUD_COLOR_HANDLERS_IMPL_HPP_ int getFieldIndex(const pcl::PCLPointCloud2 &cloud, const std::string &field_name)
Get the index of a specified field (i.e., dimension/channel)
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Set the input cloud to be used.
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.
PointCloudColorHandlerHSVField(const PointCloudConstPtr &cloud)
Constructor.
virtual bool getColor(vtkSmartPointer< vtkDataArray > &scalars) const
Obtain the actual color for the input dataset as vtk scalars.
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.
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.
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.
PointCloudConstPtr cloud_
A pointer to the input dataset.
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.
bool capable_
True if this handler is capable of handling the input data, false otherwise.
virtual bool getColor(vtkSmartPointer< vtkDataArray > &scalars) const
Obtain the actual color for the input dataset as vtk scalars.