27 #include <pcl/io/pcd_io.h>
28 #include <pcl/common/colors.h>
33 template <> visionx::PointContentType getPointContentType<pcl::PointXYZ>()
35 return visionx::ePoints;
37 template <> visionx::PointContentType getPointContentType<pcl::PointXYZL>()
39 return visionx::eLabeledPoints;
41 template <> visionx::PointContentType getPointContentType<pcl::PointXYZI>()
43 return visionx::eIntensity;
46 PointContentType getPointContentType<pcl::PointNormal>()
48 return visionx::eOrientedPoints;
50 template <> visionx::PointContentType getPointContentType<pcl::PointXYZRGBA>()
52 return visionx::eColoredPoints;
54 template <> visionx::PointContentType getPointContentType<pcl::PointXYZRGBL>()
56 return visionx::eColoredLabeledPoints;
58 template <> visionx::PointContentType getPointContentType<pcl::PointXYZRGBNormal>()
60 return visionx::eColoredOrientedPoints;
68 case visionx::ePoints:
69 return sizeof(visionx::Point3D);
71 case visionx::eColoredPoints:
72 return sizeof(visionx::ColoredPoint3D);
74 case visionx::eOrientedPoints:
75 return sizeof(visionx::OrientedPoint3D);
77 case visionx::eColoredOrientedPoints:
78 return sizeof(visionx::ColoredOrientedPoint3D);
80 case visionx::eLabeledPoints:
81 return sizeof(visionx::LabeledPoint3D);
83 case visionx::eColoredLabeledPoints:
84 return sizeof(visionx::ColoredLabeledPoint3D);
86 case visionx::eIntensity:
87 return sizeof(visionx::IntensityPoint3D);
99 case visionx::eColoredPoints:
100 case visionx::eColoredOrientedPoints:
101 case visionx::eColoredLabeledPoints:
112 case visionx::eLabeledPoints:
113 case visionx::eColoredLabeledPoints:
123 const unsigned int Area = sourcePtr->width * sourcePtr->height;
124 visionx::ColoredPoint3D* pBuffer =
new visionx::ColoredPoint3D[
Area];
126 size_t size = sourcePtr->points.size();
127 auto& points = sourcePtr->points;
128 for (
size_t i = 0; i < size; i++)
131 auto& pB = pBuffer[i];
141 memcpy(
target[0], pBuffer,
Area *
sizeof(visionx::ColoredPoint3D));
146 void convertToPCL(
void**
source, visionx::MetaPointCloudFormatPtr pointCloudFormat, pcl::PointCloud<pcl::PointXYZRGBA>::Ptr targetPtr)
148 if (pointCloudFormat->type == visionx::ePoints)
150 targetPtr->width =
static_cast<uint32_t
>(pointCloudFormat->width);
151 targetPtr->height =
static_cast<uint32_t
>(pointCloudFormat->height);
152 targetPtr->points.resize(pointCloudFormat->size /
getBytesPerPoint(pointCloudFormat->type));
153 visionx::Point3D* pBuffer =
reinterpret_cast<visionx::Point3D*
>(*source);
154 size_t size = targetPtr->points.size();
155 auto& points = targetPtr->points;
156 for (
size_t i = 0; i < size; i++)
159 auto& pB = pBuffer[i];
165 else if (pointCloudFormat->type == visionx::eColoredPoints)
167 targetPtr->width =
static_cast<uint32_t
>(pointCloudFormat->width);
168 targetPtr->height =
static_cast<uint32_t
>(pointCloudFormat->height);
169 targetPtr->points.resize(pointCloudFormat->size /
getBytesPerPoint(pointCloudFormat->type));
170 visionx::ColoredPoint3D* pBuffer =
reinterpret_cast<visionx::ColoredPoint3D*
>(*source);
171 size_t size = targetPtr->points.size();
172 auto& points = targetPtr->points;
173 for (
size_t i = 0; i < size; i++)
176 auto& pB = pBuffer[i];
187 else if (pointCloudFormat->type == visionx::eColoredLabeledPoints)
190 pcl::PointCloud<pcl::PointXYZRGBL>::Ptr temp(
new pcl::PointCloud<pcl::PointXYZRGBL>());
192 pcl::copyPointCloud(*temp, *targetPtr);
198 const unsigned int Area = sourcePtr->width * sourcePtr->height;
199 visionx::LabeledPoint3D* pBuffer =
new visionx::LabeledPoint3D[
Area];
201 for (
size_t i = 0; i < sourcePtr->points.size(); i++)
203 pBuffer[i].point.x = sourcePtr->points[i].x;
204 pBuffer[i].point.y = sourcePtr->points[i].y;
205 pBuffer[i].point.z = sourcePtr->points[i].z;
206 pBuffer[i].label =
static_cast<int>(sourcePtr->points[i].label);
209 memcpy(
target[0], pBuffer,
Area *
sizeof(visionx::LabeledPoint3D));
214 void convertToPCL(
void**
source, visionx::MetaPointCloudFormatPtr pointCloudFormat, pcl::PointCloud<pcl::PointXYZL>::Ptr targetPtr)
216 targetPtr->width =
static_cast<uint32_t
>(pointCloudFormat->width);
217 targetPtr->height =
static_cast<uint32_t
>(pointCloudFormat->height);
218 targetPtr->points.resize(pointCloudFormat->size /
getBytesPerPoint(pointCloudFormat->type));
219 visionx::LabeledPoint3D* pBuffer =
reinterpret_cast<visionx::LabeledPoint3D*
>(*source);
221 for (
size_t i = 0; i < targetPtr->points.size(); i++)
223 targetPtr->points[i].x = pBuffer[i].point.x;
224 targetPtr->points[i].y = pBuffer[i].point.y;
225 targetPtr->points[i].z = pBuffer[i].point.z;
226 targetPtr->points[i].label =
static_cast<uint32_t
>(pBuffer[i].label);
234 const unsigned int Area = sourcePtr->width * sourcePtr->height;
235 visionx::IntensityPoint3D* pBuffer =
new visionx::IntensityPoint3D[
Area];
237 for (
size_t i = 0; i < sourcePtr->points.size(); i++)
239 pBuffer[i].point.x = sourcePtr->points[i].x;
240 pBuffer[i].point.y = sourcePtr->points[i].y;
241 pBuffer[i].point.z = sourcePtr->points[i].z;
242 pBuffer[i].intensity = sourcePtr->points[i].intensity;
245 memcpy(
target[0], pBuffer,
Area *
sizeof(visionx::IntensityPoint3D));
250 void convertToPCL(
void**
source, visionx::MetaPointCloudFormatPtr pointCloudFormat, pcl::PointCloud<pcl::PointXYZI>::Ptr targetPtr)
252 targetPtr->width =
static_cast<uint32_t
>(pointCloudFormat->width);
253 targetPtr->height =
static_cast<uint32_t
>(pointCloudFormat->height);
254 targetPtr->points.resize(pointCloudFormat->size /
getBytesPerPoint(pointCloudFormat->type));
255 visionx::IntensityPoint3D* pBuffer =
reinterpret_cast<visionx::IntensityPoint3D*
>(*source);
257 for (
size_t i = 0; i < targetPtr->points.size(); i++)
259 targetPtr->points[i].x = pBuffer[i].point.x;
260 targetPtr->points[i].y = pBuffer[i].point.y;
261 targetPtr->points[i].z = pBuffer[i].point.z;
262 targetPtr->points[i].intensity = pBuffer[i].intensity;
270 const unsigned int Area = sourcePtr->width * sourcePtr->height;
271 visionx::Point3D* pBuffer =
new visionx::Point3D[
Area];
273 for (
size_t i = 0; i < sourcePtr->points.size(); i++)
275 pBuffer[i].x = sourcePtr->points[i].x;
276 pBuffer[i].y = sourcePtr->points[i].y;
277 pBuffer[i].z = sourcePtr->points[i].z;
280 memcpy(
target[0], pBuffer,
Area *
sizeof(visionx::Point3D));
285 void convertToPCL(
void**
source, visionx::MetaPointCloudFormatPtr pointCloudFormat, pcl::PointCloud<pcl::PointXYZ>::Ptr targetPtr)
287 targetPtr->width =
static_cast<uint32_t
>(pointCloudFormat->width);
288 targetPtr->height =
static_cast<uint32_t
>(pointCloudFormat->height);
289 targetPtr->points.resize(pointCloudFormat->size /
getBytesPerPoint(pointCloudFormat->type));
290 visionx::Point3D* pBuffer =
reinterpret_cast<visionx::Point3D*
>(*source);
292 for (
size_t i = 0; i < targetPtr->points.size(); i++)
294 targetPtr->points[i].x = pBuffer[i].x;
295 targetPtr->points[i].y = pBuffer[i].y;
296 targetPtr->points[i].z = pBuffer[i].z;
300 void convertToPCL(
const ColoredPointCloud&
source, pcl::PointCloud<pcl::PointXYZRGBA>::Ptr targetPtr)
302 targetPtr->points.resize(targetPtr->size());
304 for (
size_t i = 0; i < targetPtr->points.size(); i++)
306 targetPtr->points[i].x =
source.at(i).point.x;
307 targetPtr->points[i].y =
source.at(i).point.y;
308 targetPtr->points[i].z =
source.at(i).point.z;
309 targetPtr->points[i].r =
source.at(i).color.r;
310 targetPtr->points[i].g =
source.at(i).color.g;
311 targetPtr->points[i].b =
source.at(i).color.b;
312 targetPtr->points[i].a =
source.at(i).color.a;
318 target.resize(sourcePtr->size());
320 for (
size_t i = 0; i <
target.size(); i++)
322 target.at(i).point.x = sourcePtr->points[i].x;
323 target.at(i).point.y = sourcePtr->points[i].y;
324 target.at(i).point.z = sourcePtr->points[i].z;
325 target.at(i).color.r = sourcePtr->points[i].r;
326 target.at(i).color.g = sourcePtr->points[i].g;
327 target.at(i).color.b = sourcePtr->points[i].b;
328 target.at(i).color.a = sourcePtr->points[i].a;
335 const unsigned int Area = sourcePtr->width * sourcePtr->height;
336 visionx::ColoredLabeledPoint3D* pBuffer =
new visionx::ColoredLabeledPoint3D[
Area];
338 for (
size_t i = 0; i < sourcePtr->points.size(); i++)
340 pBuffer[i].point.x = sourcePtr->points[i].x;
341 pBuffer[i].point.y = sourcePtr->points[i].y;
342 pBuffer[i].point.z = sourcePtr->points[i].z;
343 pBuffer[i].color.r = sourcePtr->points[i].r;
344 pBuffer[i].color.g = sourcePtr->points[i].g;
345 pBuffer[i].color.b = sourcePtr->points[i].b;
346 pBuffer[i].color.a = sourcePtr->points[i].a;
347 pBuffer[i].label =
static_cast<int>(sourcePtr->points[i].label);
350 memcpy(
target[0], pBuffer,
Area *
sizeof(visionx::ColoredLabeledPoint3D));
355 ColoredLabeledPointCloud&
target)
359 for (std::size_t i = 0; i <
source.size(); ++i)
361 const pcl::PointXYZRGBL& p =
source.points[i];
362 target[i].point = visionx::Point3D { p.x, p.y, p.z };
363 target[i].color = visionx::RGBA { p.r, p.g, p.b, p.a };
364 target[i].label =
static_cast<int>(p.label);
369 pcl::PointCloud<pcl::PointXYZRGBL>&
target)
373 for (std::size_t i = 0; i <
source.size(); ++i)
375 const visionx::ColoredLabeledPoint3D& p =
source[i];
384 target[i].label =
static_cast<uint32_t
>(p.label);
389 void convertToPCL(
void**
source, visionx::MetaPointCloudFormatPtr pointCloudFormat, pcl::PointCloud<pcl::PointXYZRGBL>::Ptr targetPtr)
392 if (pointCloudFormat->type == visionx::eColoredLabeledPoints)
394 targetPtr->width =
static_cast<uint32_t
>(pointCloudFormat->width);
395 targetPtr->height =
static_cast<uint32_t
>(pointCloudFormat->height);
396 targetPtr->points.resize(pointCloudFormat->size /
getBytesPerPoint(pointCloudFormat->type));
398 visionx::ColoredLabeledPoint3D* pBuffer =
reinterpret_cast<visionx::ColoredLabeledPoint3D*
>(*source);
400 for (
size_t i = 0; i < targetPtr->points.size(); i++)
402 targetPtr->points[i].x = pBuffer[i].point.x;
403 targetPtr->points[i].y = pBuffer[i].point.y;
404 targetPtr->points[i].z = pBuffer[i].point.z;
405 targetPtr->points[i].r = pBuffer[i].color.r;
406 targetPtr->points[i].g = pBuffer[i].color.g;
407 targetPtr->points[i].b = pBuffer[i].color.b;
408 targetPtr->points[i].a = pBuffer[i].color.a;
409 targetPtr->points[i].label =
static_cast<uint32_t
>(pBuffer[i].label);
412 else if (pointCloudFormat->type == visionx::eColoredPoints)
415 pcl::PointCloud<pcl::PointXYZRGBA>::Ptr temp(
new pcl::PointCloud<pcl::PointXYZRGBA>());
417 pcl::copyPointCloud(*temp, *targetPtr);
420 else if (pointCloudFormat->type == visionx::eLabeledPoints)
423 pcl::PointCloud<pcl::PointXYZL>::Ptr temp(
new pcl::PointCloud<pcl::PointXYZL>());
425 pcl::copyPointCloud(*temp, *targetPtr);
431 const unsigned int area = sourcePtr->width * sourcePtr->height;
432 std::vector<visionx::ColoredOrientedPoint3D> buffer(area);
434 for (
size_t i = 0; i < sourcePtr->points.size(); i++)
436 buffer[i].point.x = sourcePtr->points[i].x;
437 buffer[i].point.y = sourcePtr->points[i].y;
438 buffer[i].point.z = sourcePtr->points[i].z;
439 buffer[i].color.r = sourcePtr->points[i].r;
440 buffer[i].color.g = sourcePtr->points[i].g;
441 buffer[i].color.b = sourcePtr->points[i].b;
442 buffer[i].normal.nx = sourcePtr->points[i].normal_x;
443 buffer[i].normal.ny = sourcePtr->points[i].normal_y;
444 buffer[i].normal.nz = sourcePtr->points[i].normal_z;
447 copy(buffer.begin(), buffer.end(),
static_cast<visionx::ColoredOrientedPoint3D*
>(
target[0]));
450 void convertToPCL(
void**
source, visionx::MetaPointCloudFormatPtr pointCloudFormat, pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr targetPtr)
452 targetPtr->width =
static_cast<uint32_t
>(pointCloudFormat->width);
453 targetPtr->height =
static_cast<uint32_t
>(pointCloudFormat->height);
454 targetPtr->points.resize(pointCloudFormat->size /
getBytesPerPoint(pointCloudFormat->type));
455 visionx::ColoredOrientedPoint3D* pBuffer =
static_cast<visionx::ColoredOrientedPoint3D*
>(*source);
457 for (
size_t i = 0; i < targetPtr->points.size(); i++)
459 targetPtr->points[i].x = pBuffer[i].point.x;
460 targetPtr->points[i].y = pBuffer[i].point.y;
461 targetPtr->points[i].z = pBuffer[i].point.z;
462 targetPtr->points[i].r = pBuffer[i].color.r;
463 targetPtr->points[i].g = pBuffer[i].color.g;
464 targetPtr->points[i].b = pBuffer[i].color.b;
465 targetPtr->points[i].normal_x = pBuffer[i].normal.nx;
466 targetPtr->points[i].normal_y = pBuffer[i].normal.ny;
467 targetPtr->points[i].normal_z = pBuffer[i].normal.nz;
475 visionx::ColoredPoint3D* pBuffer =
reinterpret_cast<ColoredPoint3D*
>(
target);
477 size_t size = sourcePtr->points.size();
478 auto& points = sourcePtr->points;
479 for (
size_t i = 0; i < size; i++)
482 auto& pB = pBuffer[i];
496 void convertToPCL(
void**
source, visionx::MetaPointCloudFormatPtr pointCloudFormat, pcl::PointCloud<pcl::PointXYZRGB>::Ptr targetPtr)
498 if (pointCloudFormat->type == visionx::eColoredPoints)
502 targetPtr->width = pointCloudFormat->width;
503 targetPtr->height = pointCloudFormat->height;
504 targetPtr->points.resize(pointCloudFormat->size /
getBytesPerPoint(pointCloudFormat->type));
505 visionx::ColoredPoint3D* pBuffer =
reinterpret_cast<visionx::ColoredPoint3D*
>(*source);
506 size_t size = targetPtr->points.size();
507 auto& points = targetPtr->points;
508 for (
size_t i = 0; i < size; i++)
511 auto& pB = pBuffer[i];
521 else if (pointCloudFormat->type == visionx::eColoredLabeledPoints)
524 pcl::PointCloud<pcl::PointXYZRGBL>::Ptr temp(
new pcl::PointCloud<pcl::PointXYZRGBL>());
526 pcl::copyPointCloud(*temp, *targetPtr);
532 target.pointSize = pointSize;
534 std::size_t numPoints = sourcePtr->width * sourcePtr->height;
535 target.points.reserve(numPoints);
537 armarx::DebugDrawer24BitColoredPointCloudElement e;
538 for (
const auto& p : sourcePtr->points)
555 float value = (
static_cast<int>(e.z) / 10) % 256;
557 e.color.r =
static_cast<Ice::Byte
>((
value > 128) ? (
value - 128) * 2 : 0);
558 e.color.g =
static_cast<Ice::Byte
>((
value < 128) ? 2 *
value : 255 - ((
value - 128) * 2));
559 e.color.b =
static_cast<Ice::Byte
>((
value < 128) ? 255 - (2 *
value) : 0);
562 target.points.push_back(e);
569 target.pointSize = pointSize;
571 std::size_t numPoints = sourcePtr->width * sourcePtr->height;
572 target.points.reserve(numPoints);
573 std::map<uint32_t, pcl::RGB> colorMap;
575 armarx::DebugDrawer24BitColoredPointCloudElement e;
576 for (
const auto& p : sourcePtr->points)
586 if (!colorMap.count(p.label))
588 colorMap[p.label] = pcl::GlasbeyLUT::at(p.label % pcl::GlasbeyLUT::size());
590 const auto c = colorMap[p.label];
599 float value = (
static_cast<int>(e.z) / 10) % 256;
601 e.color.r =
static_cast<Ice::Byte
>((
value > 128) ? (
value - 128) * 2 : 0);
602 e.color.g =
static_cast<Ice::Byte
>((
value < 128) ? 2 *
value : 255 - ((
value - 128) * 2));
603 e.color.b =
static_cast<Ice::Byte
>((
value < 128) ? 255 - (2 *
value) : 0);
606 target.points.push_back(e);
612 const pcl::PointCloud<pcl::PointXYZ>::Ptr& sourcePtr,
613 armarx::DebugDrawer24BitColoredPointCloud&
target,
618 target.pointSize = pointSize;
620 std::size_t numPoints = sourcePtr->width * sourcePtr->height;
621 target.points.reserve(numPoints);
623 armarx::DebugDrawer24BitColoredPointCloudElement e;
624 for (
const auto& p : sourcePtr->points)
633 float value = (
static_cast<int>(e.z) / 10) % 256;
635 e.color.r =
static_cast<Ice::Byte
>((
value > 128) ? (
value - 128) * 2 : 0);
636 e.color.g =
static_cast<Ice::Byte
>((
value < 128) ? 2 *
value : 255 - ((
value - 128) * 2));
637 e.color.b =
static_cast<Ice::Byte
>((
value < 128) ? 255 - (2 *
value) : 0);
639 target.points.push_back(e);
646 target.pointSize = pointSize;
648 std::size_t numPoints = sourcePtr->width * sourcePtr->height;
649 target.points.reserve(numPoints);
650 std::map<uint32_t, pcl::RGB> colorMap;
652 armarx::DebugDrawer24BitColoredPointCloudElement e;
653 for (
const auto& p : sourcePtr->points)
669 if (!colorMap.count(p.label))
671 colorMap[p.label] = pcl::GlasbeyLUT::at(p.label % pcl::GlasbeyLUT::size());
673 const auto c = colorMap[p.label];
682 float value = (
static_cast<int>(e.z) / 10) % 256;
684 e.color.r =
static_cast<Ice::Byte
>((
value > 128) ? (
value - 128) * 2 : 0);
685 e.color.g =
static_cast<Ice::Byte
>((
value < 128) ? 2 *
value : 255 - ((
value - 128) * 2));
686 e.color.b =
static_cast<Ice::Byte
>((
value < 128) ? 255 - (2 *
value) : 0);
689 target.points.push_back(e);
752 static std::vector<std::string> makePointContentTypeNames()
754 std::vector<std::string>
names(7);
755 names.at(ePoints) =
"ePoints";
756 names.at(eColoredPoints) =
"eColoredPoints";
757 names.at(eOrientedPoints) =
"eOrientedPoints";
758 names.at(eColoredOrientedPoints) =
"eColoredOrientedPoints";
759 names.at(eLabeledPoints) =
"eLabeledPoints";
760 names.at(eColoredLabeledPoints) =
"eColoredLabeledPoints";
761 names.at(eIntensity) =
"eIntensity";
765 std::string
toString(PointContentType pointContent)
767 static const std::vector<std::string>
names = makePointContentTypeNames();
768 return names.at(pointContent);