42 template <
typename Po
intT>
void
49 scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
50 scalars->SetNumberOfComponents (3);
52 vtkIdType nr_points = cloud_->points.size ();
53 reinterpret_cast<vtkUnsignedCharArray*
>(&(*scalars))->SetNumberOfTuples (nr_points);
56 unsigned char* colors =
new unsigned char[nr_points * 3];
59 for (vtkIdType cp = 0; cp < nr_points; ++cp)
61 colors[cp * 3 + 0] =
static_cast<unsigned char> (r_);
62 colors[cp * 3 + 1] =
static_cast<unsigned char> (g_);
63 colors[cp * 3 + 2] =
static_cast<unsigned char> (b_);
65 reinterpret_cast<vtkUnsignedCharArray*
>(&(*scalars))->SetArray (colors, 3 * nr_points, 0);
69 template <
typename Po
intT>
void
76 scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
77 scalars->SetNumberOfComponents (3);
79 vtkIdType nr_points = cloud_->points.size ();
80 reinterpret_cast<vtkUnsignedCharArray*
>(&(*scalars))->SetNumberOfTuples (nr_points);
83 unsigned char* colors =
new unsigned char[nr_points * 3];
87 int r_ =
static_cast<int> (
pcl_lrint (r * 255.0)),
88 g_ = static_cast<int> (
pcl_lrint (g * 255.0)),
89 b_ = static_cast<int> (
pcl_lrint (b * 255.0));
92 for (vtkIdType cp = 0; cp < nr_points; ++cp)
94 colors[cp * 3 + 0] =
static_cast<unsigned char> (r_);
95 colors[cp * 3 + 1] =
static_cast<unsigned char> (g_);
96 colors[cp * 3 + 2] =
static_cast<unsigned char> (b_);
98 reinterpret_cast<vtkUnsignedCharArray*
>(&(*scalars))->SetArray (colors, 3 * nr_points, 0);
102 template <
typename Po
intT>
108 if (field_idx_ != -1)
116 if (field_idx_ != -1)
124 template <
typename Po
intT>
void
131 scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
132 scalars->SetNumberOfComponents (3);
134 vtkIdType nr_points = cloud_->points.size ();
135 reinterpret_cast<vtkUnsignedCharArray*
>(&(*scalars))->SetNumberOfTuples (nr_points);
136 unsigned char* colors =
reinterpret_cast<vtkUnsignedCharArray*
>(&(*scalars))->GetPointer (0);
141 for (
size_t d = 0; d < fields_.size (); ++d)
142 if (fields_[d].name ==
"x")
143 x_idx =
static_cast<int> (d);
148 for (vtkIdType cp = 0; cp < nr_points; ++cp)
157 colors[idx ] = cloud_->points[cp].r;
158 colors[idx + 1] = cloud_->points[cp].g;
159 colors[idx + 2] = cloud_->points[cp].b;
166 for (vtkIdType cp = 0; cp < nr_points; ++cp)
168 int idx =
static_cast<int> (cp) * 3;
169 colors[idx ] = cloud_->points[cp].r;
170 colors[idx + 1] = cloud_->points[cp].g;
171 colors[idx + 2] = cloud_->points[cp].b;
177 template <
typename Po
intT>
183 if (field_idx_ == -1)
191 if (s_field_idx_ == -1)
199 if (v_field_idx_ == -1)
208 template <
typename Po
intT>
void
215 scalars = vtkSmartPointer<vtkUnsignedCharArray>::New ();
216 scalars->SetNumberOfComponents (3);
218 vtkIdType nr_points = cloud_->points.size ();
219 reinterpret_cast<vtkUnsignedCharArray*
>(&(*scalars))->SetNumberOfTuples (nr_points);
220 unsigned char* colors =
reinterpret_cast<vtkUnsignedCharArray*
>(&(*scalars))->GetPointer (0);
226 for (
size_t d = 0; d < fields_.size (); ++d)
227 if (fields_[d].name ==
"x")
228 x_idx =
static_cast<int> (d);
233 for (vtkIdType cp = 0; cp < nr_points; ++cp)
246 if (cloud_->points[cp].s == 0)
248 colors[idx] = colors[idx+1] = colors[idx+2] = cloud_->points[cp].v;
251 float a = cloud_->points[cp].h / 60;
254 float p = cloud_->points[cp].v * (1 - cloud_->points[cp].s);
255 float q = cloud_->points[cp].v * (1 - cloud_->points[cp].s * f);
256 float t = cloud_->points[cp].v * (1 - cloud_->points[cp].s * (1 - f));
261 colors[idx] = cloud_->points[cp].v; colors[idx+1] = t; colors[idx+2] = p;
break;
263 colors[idx] = q; colors[idx+1] = cloud_->points[cp].v; colors[idx+2] = p;
break;
265 colors[idx] = p; colors[idx+1] = cloud_->points[cp].v; colors[idx+2] = t;
break;
267 colors[idx] = p; colors[idx+1] = q; colors[idx+2] = cloud_->points[cp].v;
break;
269 colors[idx] = t; colors[idx+1] = p; colors[idx+2] = cloud_->points[cp].v;
break;
271 colors[idx] = cloud_->points[cp].v; colors[idx+1] = p; colors[idx+2] = q;
break;
279 for (vtkIdType cp = 0; cp < nr_points; ++cp)
284 if (cloud_->points[cp].s == 0)
286 colors[idx] = colors[idx+1] = colors[idx+2] = cloud_->points[cp].v;
289 float a = cloud_->points[cp].h / 60;
292 float p = cloud_->points[cp].v * (1 - cloud_->points[cp].s);
293 float q = cloud_->points[cp].v * (1 - cloud_->points[cp].s * f);
294 float t = cloud_->points[cp].v * (1 - cloud_->points[cp].s * (1 - f));
299 colors[idx] = cloud_->points[cp].v; colors[idx+1] = t; colors[idx+2] = p;
break;
301 colors[idx] = q; colors[idx+1] = cloud_->points[cp].v; colors[idx+2] = p;
break;
303 colors[idx] = p; colors[idx+1] = cloud_->points[cp].v; colors[idx+2] = t;
break;
305 colors[idx] = p; colors[idx+1] = q; colors[idx+2] = cloud_->points[cp].v;
break;
307 colors[idx] = t; colors[idx+1] = p; colors[idx+2] = cloud_->points[cp].v;
break;
309 colors[idx] = cloud_->points[cp].v; colors[idx+1] = p; colors[idx+2] = q;
break;
316 template <
typename Po
intT>
320 field_name_ (field_name)
323 if (field_idx_ != -1)
330 template <
typename Po
intT>
void
337 scalars = vtkSmartPointer<vtkFloatArray>::New ();
338 scalars->SetNumberOfComponents (1);
340 vtkIdType nr_points = cloud_->points.size ();
341 reinterpret_cast<vtkFloatArray*
>(&(*scalars))->SetNumberOfTuples (nr_points);
345 float* colors =
new float[nr_points];
351 for (
size_t d = 0; d < fields_.size (); ++d)
352 if (fields_[d].name ==
"x")
353 x_idx =
static_cast<int> (d);
358 for (vtkIdType cp = 0; cp < nr_points; ++cp)
364 const uint8_t* pt_data =
reinterpret_cast<const uint8_t*
> (&cloud_->points[cp]);
365 memcpy (&field_data, pt_data + fields_[field_idx_].offset,
pcl::getFieldSize (fields_[field_idx_].datatype));
367 colors[j] = field_data;
374 for (vtkIdType cp = 0; cp < nr_points; ++cp)
376 const uint8_t* pt_data =
reinterpret_cast<const uint8_t*
> (&cloud_->points[cp]);
377 memcpy (&field_data, pt_data + fields_[field_idx_].offset,
pcl::getFieldSize (fields_[field_idx_].datatype));
382 colors[j] = field_data;
386 reinterpret_cast<vtkFloatArray*
>(&(*scalars))->SetArray (colors, j, 0);
390 template <
typename Po
intT>
395 if (field_x_idx_ == -1)
398 if (field_y_idx_ == -1)
401 if (field_z_idx_ == -1)
407 template <
typename Po
intT>
void
414 points = vtkSmartPointer<vtkPoints>::New ();
415 points->SetDataTypeToFloat ();
417 vtkSmartPointer<vtkFloatArray> data = vtkSmartPointer<vtkFloatArray>::New ();
418 data->SetNumberOfComponents (3);
419 vtkIdType nr_points = cloud_->points.size ();
423 float* pts =
static_cast<float*
> (malloc (nr_points * 3 *
sizeof (
float)));
426 if (cloud_->is_dense)
428 for (vtkIdType i = 0; i < nr_points; ++i)
430 pts[i * 3 + 0] = cloud_->points[i].x;
431 pts[i * 3 + 1] = cloud_->points[i].y;
432 pts[i * 3 + 2] = cloud_->points[i].z;
434 data->SetArray (&pts[0], nr_points * 3, 0);
435 points->SetData (data);
440 for (vtkIdType i = 0; i < nr_points; ++i)
446 pts[j * 3 + 0] = cloud_->points[i].x;
447 pts[j * 3 + 1] = cloud_->points[i].y;
448 pts[j * 3 + 2] = cloud_->points[i].z;
452 data->SetArray (&pts[0], j * 3, 0);
453 points->SetData (data);
458 template <
typename Po
intT>
463 if (field_x_idx_ == -1)
466 if (field_y_idx_ == -1)
469 if (field_z_idx_ == -1)
475 template <
typename Po
intT>
void
482 points = vtkSmartPointer<vtkPoints>::New ();
483 points->SetDataTypeToFloat ();
484 points->SetNumberOfPoints (cloud_->points.size ());
488 for (vtkIdType i = 0; i < static_cast<vtkIdType> (cloud_->points.size ()); ++i)
490 p[0] = cloud_->points[i].normal[0];
491 p[1] = cloud_->points[i].normal[1];
492 p[2] = cloud_->points[i].normal[2];
494 points->SetPoint (i, p);
499 template <
typename Po
intT>
504 if (field_x_idx_ == -1)
507 if (field_y_idx_ == -1)
510 if (field_z_idx_ == -1)
512 field_name_ = x_field_name + y_field_name + z_field_name;
517 template <
typename Po
intT>
void
524 points = vtkSmartPointer<vtkPoints>::New ();
525 points->SetDataTypeToFloat ();
526 points->SetNumberOfPoints (cloud_->points.size ());
531 for (vtkIdType i = 0; i < static_cast<vtkIdType> (cloud_->points.size ()); ++i)
534 const uint8_t* pt_data =
reinterpret_cast<const uint8_t*
> (&cloud_->points[i]);
535 memcpy (&data, pt_data + fields_[field_x_idx_].offset,
sizeof (
float));
538 memcpy (&data, pt_data + fields_[field_y_idx_].offset,
sizeof (
float));
541 memcpy (&data, pt_data + fields_[field_z_idx_].offset,
sizeof (
float));
544 points->SetPoint (i, p);