38 #include <pcl/pcl_config.h>
48 size_t numPoints = loader->numPoints();
49 m_useColors = loader->hasColors();
51 m_pointCloud = pcl::PointCloud<pcl::PointXYZRGB>::Ptr (
new pcl::PointCloud<pcl::PointXYZRGB>);
61 numColors = (*colors).numElements();
66 assert(numColors == numPoints);
71 std::cout <<
timestamp <<
"Creating PCL point cloud for filtering" << std::endl;
72 std::cout <<
timestamp <<
"Point cloud has " << numPoints <<
" points" << std::endl;
73 m_pointCloud->resize(numPoints);
75 for(
size_t i = 0; i < numPoints; i++)
84 uint8_t r = (*colors)[i][0];
85 uint8_t g = (*colors)[i][1];
86 uint8_t b = (*colors)[i][2];
91 m_pointCloud->points[i] = pcl::PointXYZRGB(r,g,b);
94 m_pointCloud->points[i].x = x;
95 m_pointCloud->points[i].y = y;
96 m_pointCloud->points[i].z = z;
99 m_pointCloud->width = numPoints;
100 m_pointCloud->height = 1;
105 m_kdTree = pcl::search::KdTree<pcl::PointXYZRGB>::Ptr(
new pcl::search::KdTree<pcl::PointXYZRGB> );
106 m_kdTree->setInputCloud (m_pointCloud);
109 void PCLFiltering::applyMLSProjection(
float searchRadius)
111 pcl::MovingLeastSquares<pcl::PointXYZRGB, pcl::PointNormal> mls;
112 pcl::PointCloud<pcl::PointNormal> mls_points;
115 mls.setInputCloud(m_pointCloud);
116 mls.setPolynomialFit(
true);
117 mls.setSearchMethod(m_kdTree);
118 mls.setSearchRadius(searchRadius);
120 std::cout <<
timestamp <<
"Applying MSL projection" << std::endl;
123 mls.process(mls_points);
125 std::cout <<
timestamp <<
"Filtered cloud has " << mls_points.size() <<
" points" << std::endl;
126 std::cout <<
timestamp <<
"Saving result" << std::endl;
129 m_pointCloud->resize(mls_points.size());
131 for(
size_t i = 0; i < mls_points.size(); i++)
133 m_pointCloud->points[i].x = mls_points.points[i].x;
134 m_pointCloud->points[i].y = mls_points.points[i].y;
135 m_pointCloud->points[i].z = mls_points.points[i].z;
138 m_pointCloud->height = 1;
139 m_pointCloud->width = mls_points.size();
143 void PCLFiltering::applyOutlierRemoval(
int meank,
float thresh)
145 pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered (
new pcl::PointCloud<pcl::PointXYZRGB>);
147 std::cout <<
timestamp <<
"Applying outlier removal" << std::endl;
150 pcl::StatisticalOutlierRemoval<pcl::PointXYZRGB> sor;
151 sor.setInputCloud (m_pointCloud);
152 sor.setMeanK (meank);
153 sor.setStddevMulThresh (thresh);
154 sor.filter (*cloud_filtered);
156 std::cout <<
timestamp <<
"Filtered cloud has " << cloud_filtered->size() <<
" points" << std::endl;
157 std::cout <<
timestamp <<
"Saving result" << std::endl;
159 m_pointCloud->width = cloud_filtered->width;
160 m_pointCloud->height = cloud_filtered->height;
161 m_pointCloud->points.swap (cloud_filtered->points);
168 floatArr points(
new float[3 * m_pointCloud->size()]);
176 for(
int i = 0; i < m_pointCloud->size(); i++)
179 points[pos ] = m_pointCloud->points[i].x;
180 points[pos + 1] = m_pointCloud->points[i].y;
181 points[pos + 2] = m_pointCloud->points[i].z;
185 colors[pos ] = m_pointCloud->points[i].r;
186 colors[pos + 1] = m_pointCloud->points[i].g;
187 colors[pos + 2] = m_pointCloud->points[i].b;
194 p->setPointArray(points, m_pointCloud->size());
198 p->setColorArray(
colors, m_pointCloud->size());
204 PCLFiltering::~PCLFiltering()