33 #include <pcl/search/impl/search.hpp>
34 #include <pcl/features/normal_3d.h>
35 #include <pcl/kdtree/kdtree_flann.h>
36 #include <pcl/features/shot_omp.h>
38 #include <pcl/pcl_config.h>
41 int main(
int argc,
char *argv[])
46 std::cout <<
"Usage: " << argv[0] <<
" input_mesh_filename" << std::endl;
47 std::cout <<
"Example: " << argv[0] <<
" bun0.pcd" << std::endl;
50 std::string input_file = argv[1];
59 std::cout <<
"load point cloud" << std::endl;
67 PointCloudT >::pmap_type;
69 std::cout <<
"create vertex-normal map" << std::endl;
76 std::cout <<
"compute shot color estimation" << std::endl;
87 std::vector< int > indices;
88 indices.resize(pc.points.size());
89 for(
size_t i = 0; i < indices.size(); ++i)
90 indices[i] =
static_cast< int >(i);
91 pcl::search::KdTree< PointType >::Ptr tree;
92 tree.reset(
new pcl::search::KdTree< PointType >(
false));
93 tree->setInputCloud(pc.makeShared());
97 pcl::NormalEstimation< PointType, NormalType > n;
98 n.setInputCloud(pc.makeShared());
99 #if PCL_VERSION_COMPARE(<, 1, 11, 0)
100 boost::shared_ptr< std::vector< int > > indicesptr(
new std::vector< int >(indices));
102 std::shared_ptr< std::vector< int > > indicesptr(
new std::vector< int >(indices));
104 n.setIndices(indicesptr);
105 n.setSearchMethod(tree);
106 n.setRadiusSearch(20 * mr);
110 pcl::search::KdTree< PointType >::Ptr rgbaTree;
111 rgbaTree.reset(
new pcl::search::KdTree< PointType >(
false));
114 pcl::SHOTColorEstimationOMP< PointType, NormalType, pcl::SHOT1344 > shot1344(
116 shot1344.setInputNormals(pc.makeShared());
117 shot1344.setRadiusSearch(20 * mr);
118 pcl::PointCloud< pcl::SHOT1344 >::Ptr shots1344(
new pcl::PointCloud< pcl::SHOT1344 >());
119 shot1344.setInputCloud(pc.makeShared());
120 shot1344.setIndices(indicesptr);
121 shot1344.setSearchMethod(rgbaTree);
122 shot1344.compute(*shots1344);
174 #include <pcl/point_cloud.h>
175 #include <pcl/features/normal_3d_omp.h>
176 #include <pcl/io/pcd_io.h>
177 #include <pcl/features/shot.h>
178 #include <pcl/features/shot_omp.h>
179 #include "pcl/features/shot_lrf.h"
180 #include <pcl/features/3dsc.h>
181 #include <pcl/features/usc.h>
186 #undef NDEBUG // enable assert in release mode
191 template<
typename CloudType >
193 print_cloud(
const CloudType &cloud)
195 std::cout <<
"*** PointCloud = \n" << cloud << std::endl;
197 std::cout <<
"*** points = " << std::endl;
198 for(
int i = 0; i < cloud.points.size(); i++)
200 std::cout <<
"cloud.points[" << i <<
"] = " << cloud.points[i]
206 #define EXPECT_NEAR(v1, v2, epsilon) assert(fabs((v1)-(v2)) <= (epsilon))
214 std::string input_filename(
"bun0.pcd");
217 pcl::PointCloud<pcl::PointXYZ> cloud;
220 if(pcl::io::loadPCDFile(input_filename, cloud) < 0)
222 std::cout <<
"Failed to load file '" << input_filename <<
"'." << std::endl;
223 std::cout <<
"This file is provided in PCL sources." << std::endl;
232 std::vector< int > indices;
233 typedef pcl::search::KdTree<pcl::PointXYZ>::Ptr KdTreePtr;
235 indices.resize(cloud.points.size());
236 for(
size_t i = 0; i < indices.size(); ++i)
237 indices[i] =
static_cast< int >(i);
238 tree.reset(
new pcl::search::KdTree< pcl::PointXYZ >(
false));
239 tree->setInputCloud(cloud.makeShared());
243 pcl::NormalEstimation< pcl::PointXYZ, pcl::Normal > n;
244 pcl::PointCloud< pcl::Normal >::Ptr normals(
new pcl::PointCloud< pcl::Normal >());
245 n.setInputCloud(cloud.makeShared());
246 boost::shared_ptr< std::vector< int > > indicesptr(
new std::vector< int >(indices));
247 n.setIndices(indicesptr);
248 n.setSearchMethod(tree);
249 n.setRadiusSearch(20 * mr);
251 std::cout <<
"normals->points.size() = " << normals->points.size() << std::endl;
254 pcl::PointCloud< pcl::PointXYZRGBA > cloudWithColors;
255 for(
int i = 0; i < static_cast< int >(cloud.points.size()); ++i)
258 p.x = cloud.points[i].x;
259 p.y = cloud.points[i].y;
260 p.z = cloud.points[i].z;
264 p.g = ((255 - i) % 255);
265 p.b = ((i * 37) % 255);
266 cloudWithColors.push_back(p);
270 pcl::search::KdTree< pcl::PointXYZRGBA >::Ptr rgbaTree;
271 rgbaTree.reset(
new pcl::search::KdTree< pcl::PointXYZRGBA >(
false));
274 pcl::SHOTColorEstimationOMP< pcl::PointXYZRGBA, pcl::Normal, pcl::SHOT1344 > shot1344(
true,
276 shot1344.setInputNormals(normals);
277 shot1344.setRadiusSearch(20 * mr);
278 pcl::PointCloud< pcl::SHOT1344 >::Ptr shots1344(
new pcl::PointCloud< pcl::SHOT1344 >());
279 shot1344.setInputCloud(cloudWithColors.makeShared());
280 shot1344.setIndices(indicesptr);
281 shot1344.setSearchMethod(rgbaTree);
284 shot1344.compute(*shots1344);
287 EXPECT_NEAR(shots1344->points[103].descriptor[10], 0.0020453099, 1e-5);
288 EXPECT_NEAR(shots1344->points[103].descriptor[11], 0.0021887729, 1e-5);
289 EXPECT_NEAR(shots1344->points[103].descriptor[21], 0.057930067, 1e-5);
290 EXPECT_NEAR(shots1344->points[103].descriptor[42], 0.011778189, 1e-5);
291 EXPECT_NEAR(shots1344->points[103].descriptor[53], 0.0065085669, 1e-5);
292 EXPECT_NEAR(shots1344->points[103].descriptor[54], 0.012025614, 1e-5);
293 EXPECT_NEAR(shots1344->points[103].descriptor[55], 0.0044803056, 1e-5);
294 EXPECT_NEAR(shots1344->points[103].descriptor[64], 0.0644530654, 1e-5);
295 EXPECT_NEAR(shots1344->points[103].descriptor[65], 0.0465045683, 1e-5);
296 EXPECT_NEAR(shots1344->points[103].descriptor[86], 0.011518310, 1e-5);
298 EXPECT_NEAR(shots1344->points[103].descriptor[357], 0.0020453099, 1e-5);
299 EXPECT_NEAR(shots1344->points[103].descriptor[360], 0.0027993850, 1e-5);
300 EXPECT_NEAR(shots1344->points[103].descriptor[386], 0.0451327376, 1e-5);
301 EXPECT_NEAR(shots1344->points[103].descriptor[387], 0.0544394031, 1e-5);
302 EXPECT_NEAR(shots1344->points[103].descriptor[389], 0.0047547864, 1e-5);
303 EXPECT_NEAR(shots1344->points[103].descriptor[453], 0.0051176427, 1e-5);
304 EXPECT_NEAR(shots1344->points[103].descriptor[481], 0.0053625242, 1e-5);
305 EXPECT_NEAR(shots1344->points[103].descriptor[482], 0.012025614, 1e-5);
306 EXPECT_NEAR(shots1344->points[103].descriptor[511], 0.0057367259, 1e-5);
307 EXPECT_NEAR(shots1344->points[103].descriptor[512], 0.048375979, 1e-5);
309 std::cout <<
"All checks passed." << std::endl;