forked from AngusKung/Efficient_Surface_Detection
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewerESD.cpp
More file actions
140 lines (124 loc) · 4.19 KB
/
Copy pathviewerESD.cpp
File metadata and controls
140 lines (124 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
- Efforts of Yen-Cheng Kung
- Please cite the paper "Efficient Surface Detection for Augmented Reality on 3D Point Clouds" if you use this code.
- Paper can be found at : http://dl.acm.org/citation.cfm?id=2949058
*/
#include <cstdlib>
#include <climits>
#include <cmath>
#include <vector>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <boost/format.hpp>
// PCL input/output
#include <pcl/console/parse.h>
#include <pcl/common/transforms.h>
#include <pcl/io/png_io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/io/file_io.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/visualization/point_cloud_color_handlers.h>
#include <pcl/registration/ndt.h>
#include <pcl/features/normal_3d.h>
//PCL other
#include <pcl/filters/passthrough.h>
#include <pcl/segmentation/supervoxel_clustering.h>
// The segmentation class this example is for
#include <pcl/segmentation/lccp_segmentation.h>
// VTK
#include <vtkImageReader2Factory.h>
#include <vtkImageReader2.h>
#include <vtkImageData.h>
#include <vtkImageFlip.h>
#include <vtkPolyLine.h>
//planar segmentation
#include <pcl/ModelCoefficients.h>
#include <pcl/point_types.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/sample_consensus/model_types.h>
#include <pcl/segmentation/sac_segmentation.h>
using namespace std;
bool loadPointCloudFile(const string& fileName, pcl::PCLPointCloud2& pointCloud);
int main(int argc, char ** argv){
if (argc == 1) {
PCL_INFO("Usage: ./viewerESD [input_point_cloud]\n");
PCL_INFO(" Ex: ./viewerESD result/30_xyzrgbl.ply\n");
PCL_INFO("Notice:\n");
PCL_INFO(" [input_point_cloud] supports only the output of MPSS (format: pcl::PointXYZRGBL)\n");
return false;
}
pcl::PointCloud<pcl::PointXYZRGBL>::Ptr input_cloud_ptr (new pcl::PointCloud<pcl::PointXYZRGBL>);
string pcd_filename = argv[1];
PCL_INFO ("Loading pointcloud\n");
//----- check if the provided pcd file contains normals -----
pcl::PCLPointCloud2 input_pointcloud; //inpu_pointcloud2 ,new version of pcl
if (loadPointCloudFile(pcd_filename, input_pointcloud))
{
PCL_ERROR ("ERROR: Could not read input point cloud %s.\n", pcd_filename.c_str ());
return (3);
}
pcl::fromPCLPointCloud2 (input_pointcloud, *input_cloud_ptr);
PCL_INFO ("Done making cloud\n");
//----- viewer for curvature -----
/*pcl::PointCloud<pcl::PointXYZRGB>::Ptr show_result_ptr (new pcl::PointCloud<pcl::PointXYZRGB>);
for(size_t i = 0; i <input_cloud_ptr->points.size();i++){
pcl::PointXYZRGB showP;
pcl::PointXYZRGBL resultP = input_cloud_ptr->points.at(i);
showP.x = resultP.x;
showP.y = resultP.y;
showP.z = resultP.z;
int color = 255 - 2*resultP.label;
if(color < 60)
color = 60;
showP.r = color;
showP.g = color;
showP.b = color;
show_result_ptr->push_back(showP);
}*/
pcl::PointCloud<pcl::PointXYZL>::Ptr show_result_ptr (new pcl::PointCloud<pcl::PointXYZL>);
for(size_t i = 0; i <input_cloud_ptr->points.size();i++){
pcl::PointXYZL showP;
pcl::PointXYZRGBL resultP = input_cloud_ptr->points.at(i);
showP.x = resultP.x;
showP.y = resultP.y;
showP.z = resultP.z;
showP.label = resultP.label;
show_result_ptr->push_back(showP);
}
pcl::visualization::PCLVisualizer::Ptr viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));
viewer->setBackgroundColor (0, 0, 0);
viewer->addPointCloud (show_result_ptr, "maincloud");
//----- Visualization Loop -----
PCL_INFO ("Loading viewer\n");
while (!viewer->wasStopped ()){
viewer->spinOnce (100);
}
}
bool
loadPointCloudFile(const string& fileName, pcl::PCLPointCloud2& pointCloud)
{
if (fileName.find(".pcd") != string::npos) {
printf("Load PCD file...");
if (pcl::io::loadPCDFile(fileName.c_str(), pointCloud)) {
printf("Fail!\n");
return true;
}
printf("Success!\n");
}
else if (fileName.find(".ply") != string::npos) {
printf("Load PLY file...");
if (pcl::io::loadPLYFile(fileName.c_str(), pointCloud)) {
printf("Fail!\n");
return true;
}
printf("Success!\n");
}
else {
printf("Not supported input format!\n");
return true;
}
return false;
}