34#include "MechEyeApi.h"
35#include <pcl/point_types.h>
36#include <pcl/io/ply_io.h>
37#include <pcl/visualization/pcl_visualizer.h>
38#include <vtkOutputWindow.h>
41inline void toPCL(pcl::PointCloud<pcl::PointXYZ>& pointCloud,
45 uint32_t size = pointXYZMap.
height() * pointXYZMap.
width();
46 pointCloud.resize(size);
48 for (
size_t i = 0; i < size; i++) {
49 pointCloud[i].x = 0.001 * pointXYZMap[i].x;
50 pointCloud[i].y = 0.001 * pointXYZMap[i].y;
51 pointCloud[i].z = 0.001 * pointXYZMap[i].z;
57inline void toPCL(pcl::PointCloud<pcl::PointXYZRGB>& colorPointCloud,
61 uint32_t size = pointXYZBGRMap.
height() * pointXYZBGRMap.
width();
62 colorPointCloud.resize(size);
64 for (
size_t i = 0; i < size; i++) {
65 colorPointCloud[i].x = 0.001 * pointXYZBGRMap[i].x;
66 colorPointCloud[i].y = 0.001 * pointXYZBGRMap[i].y;
67 colorPointCloud[i].z = 0.001 * pointXYZBGRMap[i].z;
69 colorPointCloud[i].r = pointXYZBGRMap[i].r;
70 colorPointCloud[i].g = pointXYZBGRMap[i].g;
71 colorPointCloud[i].b = pointXYZBGRMap[i].b;
77inline void viewPCL(
const pcl::PointCloud<pcl::PointXYZ>& pointCloud)
79 vtkOutputWindow::SetGlobalWarningDisplay(0);
80 if (pointCloud.empty())
83 pcl::visualization::PCLVisualizer cloudViewer(
"Cloud Viewer");
84 cloudViewer.setShowFPS(
false);
85 cloudViewer.setBackgroundColor(0, 0, 0);
86 cloudViewer.addPointCloud(pointCloud.makeShared());
87 cloudViewer.addCoordinateSystem(0.01);
88 cloudViewer.addText(
"Cloud Size: " + std::to_string(pointCloud.size()), 0, 25, 20, 1, 1, 1,
90 cloudViewer.addText(
"Press r/R to reset camera view point to center.", 0, 0, 16, 1, 1, 1,
92 cloudViewer.initCameraParameters();
93 while (!cloudViewer.wasStopped()) {
94 cloudViewer.spinOnce(20);
95 std::this_thread::sleep_for(std::chrono::milliseconds(100));
99inline void viewPCL(
const pcl::PointCloud<pcl::PointXYZRGB>& colorPointCloud)
101 vtkOutputWindow::SetGlobalWarningDisplay(0);
102 if (colorPointCloud.empty())
105 pcl::visualization::PCLVisualizer cloudViewer(
"Cloud Viewer");
106 cloudViewer.setShowFPS(
false);
107 cloudViewer.setBackgroundColor(0, 0, 0);
108 cloudViewer.addPointCloud(colorPointCloud.makeShared());
109 cloudViewer.addCoordinateSystem(0.01);
110 cloudViewer.addText(
"Cloud Size: " + std::to_string(colorPointCloud.size()), 0, 25, 20, 1, 1, 1,
112 cloudViewer.addText(
"Press r/R to reset camera view point to center.", 0, 0, 16, 1, 1, 1,
114 cloudViewer.initCameraParameters();
115 while (!cloudViewer.wasStopped()) {
116 cloudViewer.spinOnce(20);
117 std::this_thread::sleep_for(std::chrono::milliseconds(100));
123 pcl::PointCloud<pcl::PointXYZ> pointCloud(pointXYZMap.
width(), pointXYZMap.
height());
124 toPCL(pointCloud, pointXYZMap);
125 pcl::PLYWriter writer;
126 writer.write(path, pointCloud,
true);
127 std::cout <<
"PointCloudXYZ has : " << pointCloud.width * pointCloud.height <<
" data points."
129 std::cout <<
"PointCloudXYZ saved to: " << path << std::endl;
135 pcl::PointCloud<pcl::PointXYZRGB> pointCloud(pointXYZBGRMap.
width(), pointXYZBGRMap.
height());
136 toPCL(pointCloud, pointXYZBGRMap);
137 pcl::PLYWriter writer;
138 writer.write(path, pointCloud,
true);
139 std::cout <<
"PointCloudXYZRGB has : " << pointCloud.width * pointCloud.height
140 <<
" data points." << std::endl;
141 std::cout <<
"PointCloudXYZRGB saved to: " << path << std::endl;
Definition of data structure in device capturing image.