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
216 if (!capable_ || !cloud_)
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)
232 if (fields_[d].name ==
"x")
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))
251 if (cloud_->points[cp].s == 0)
253 colors[idx] = colors[idx+1] = colors[idx+2] = cloud_->points[cp].v;
256 float a = cloud_->points[cp].h / 60;
259 float p = cloud_->points[cp].v * (1 - cloud_->points[cp].s);
260 float q = cloud_->points[cp].v * (1 - cloud_->points[cp].s * f);
261 float t = cloud_->points[cp].v * (1 - cloud_->points[cp].s * (1 - f));
266 colors[idx] = cloud_->points[cp].v; colors[idx+1] = t; colors[idx+2] = p;
break;
268 colors[idx] = q; colors[idx+1] = cloud_->points[cp].v; colors[idx+2] = p;
break;
270 colors[idx] = p; colors[idx+1] = cloud_->points[cp].v; colors[idx+2] = t;
break;
272 colors[idx] = p; colors[idx+1] = q; colors[idx+2] = cloud_->points[cp].v;
break;
274 colors[idx] = t; colors[idx+1] = p; colors[idx+2] = cloud_->points[cp].v;
break;
276 colors[idx] = cloud_->points[cp].v; colors[idx+1] = p; colors[idx+2] = q;
break;
284 for (vtkIdType cp = 0; cp < nr_points; ++cp)
289 if (cloud_->points[cp].s == 0)
291 colors[idx] = colors[idx+1] = colors[idx+2] = cloud_->points[cp].v;
294 float a = cloud_->points[cp].h / 60;
297 float p = cloud_->points[cp].v * (1 - cloud_->points[cp].s);
298 float q = cloud_->points[cp].v * (1 - cloud_->points[cp].s * f);
299 float t = cloud_->points[cp].v * (1 - cloud_->points[cp].s * (1 - f));
304 colors[idx] = cloud_->points[cp].v; colors[idx+1] = t; colors[idx+2] = p;
break;
306 colors[idx] = q; colors[idx+1] = cloud_->points[cp].v; colors[idx+2] = p;
break;
308 colors[idx] = p; colors[idx+1] = cloud_->points[cp].v; colors[idx+2] = t;
break;
310 colors[idx] = p; colors[idx+1] = q; colors[idx+2] = cloud_->points[cp].v;
break;
312 colors[idx] = t; colors[idx+1] = p; colors[idx+2] = cloud_->points[cp].v;
break;
314 colors[idx] = cloud_->points[cp].v; colors[idx+1] = p; colors[idx+2] = q;
break;
322 template <
typename Po
intT>
void
328 if (field_idx_ != -1)
335 template <
typename Po
intT>
bool
338 if (!capable_ || !cloud_)
343 scalars->SetNumberOfComponents (1);
345 vtkIdType nr_points = cloud_->points.size ();
346 reinterpret_cast<vtkFloatArray*
>(&(*scalars))->SetNumberOfTuples (nr_points);
350 float* colors =
new float[nr_points];
356 for (
size_t d = 0; d < fields_.size (); ++d)
357 if (fields_[d].name ==
"x")
358 x_idx =
static_cast<int> (d);
363 for (vtkIdType cp = 0; cp < nr_points; ++cp)
366 if (!pcl_isfinite (cloud_->points[cp].x) || !pcl_isfinite (cloud_->points[cp].y) || !pcl_isfinite (cloud_->points[cp].z))
369 const uint8_t* pt_data =
reinterpret_cast<const uint8_t*
> (&cloud_->points[cp]);
370 memcpy (&field_data, pt_data + fields_[field_idx_].offset,
pcl::getFieldSize (fields_[field_idx_].datatype));
372 colors[j] = field_data;
379 for (vtkIdType cp = 0; cp < nr_points; ++cp)
381 const uint8_t* pt_data =
reinterpret_cast<const uint8_t*
> (&cloud_->points[cp]);
382 memcpy (&field_data, pt_data + fields_[field_idx_].offset,
pcl::getFieldSize (fields_[field_idx_].datatype));
384 if (!pcl_isfinite (field_data))
387 colors[j] = field_data;
391 reinterpret_cast<vtkFloatArray*
>(&(*scalars))->SetArray (colors, j, 0);
395 #endif // PCL_POINT_CLOUD_COLOR_HANDLERS_IMPL_HPP_