-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCGALTesting.cpp
193 lines (155 loc) · 7.18 KB
/
CGALTesting.cpp
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// CGAL Basic
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Point_set_3.h>
#include <CGAL/Point_set_3/IO.h>
// Drawing mesh
#include <CGAL/draw_surface_mesh.h>
#include <CGAL/draw_point_set_3.h>
// Preprocesssing
#include <CGAL/remove_outliers.h>
#include <CGAL/grid_simplify_point_set.h>
#include <CGAL/jet_smooth_point_set.h>
#include <CGAL/jet_estimate_normals.h>
#include <CGAL/mst_orient_normals.h>
// CGAL Reconstruction
#include <CGAL/poisson_surface_reconstruction.h>
#include <CGAL/Advancing_front_surface_reconstruction.h>
#include <CGAL/Scale_space_surface_reconstruction_3.h>
#include <CGAL/Scale_space_reconstruction_3/Jet_smoother.h>
#include <CGAL/Scale_space_reconstruction_3/Advancing_front_mesher.h>
// I/O
#include <fstream>
// Typedefs
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point;
typedef CGAL::Surface_mesh<Point> Mesh;
typedef Kernel::FT FT;
typedef Kernel::Point_3 Point_3;
typedef Kernel::Vector_3 Vector_3;
typedef Kernel::Sphere_3 Sphere_3;
typedef CGAL::Point_set_3<Point_3, Vector_3> Point_set;
int main(int argc, char* argv[])
{
// Opening PLY file ------------------------------------------------------------------------------------
const char* fname1 = "Level7DataCenterFinal.ply";
std::ifstream input;
input.open(fname1, std::ios_base::binary); // Opens the PLY file
std::cout << "File name used: " << fname1 << "\n";
if (input.fail()) {
std::cout << "Failed failbit when opening ifstream input file\n";
}
std::cout << "Reading PLY from ifstream . . .\n";
// Prepare objects for point and mesh manipulation
Point_set pointInformation;
Mesh initialSM; // Contains the information from the PLY file
if (!CGAL::IO::read_PLY(input, pointInformation))
{
std::cerr << "Invalid input file." << std::endl;
return EXIT_FAILURE;
}
else
{
std::cout << "Success\n";
//input >> pointInformation; // Put point information into the Point_set
std::cout << "Number of points: " << pointInformation.number_of_points() << "\n";
}
// Down sample the point cloud -----------------------------------------------------------------------------------------
bool skipDownSampling = false;
if (!skipDownSampling) {
// Compute average spacing using neighborhood of 6 points
std::cout << "Computing average spacing between neighbours...\n";
//double spacing = CGAL::compute_average_spacing<CGAL::Parallel_if_available_tag>(pointInformation, 6);
//std::cout << "Computing complete. Average spacing is : " << spacing << "\n";
std::cout << "Down sampling . . .\n";
// Simplify using a grid of size 2 * average spacing
typename Point_set::iterator gsim_it = CGAL::grid_simplify_point_set(pointInformation, 0.01);
pointInformation.remove(gsim_it, pointInformation.end());
std::cout << pointInformation.number_of_removed_points()
<< " point(s) removed after simplification." << std::endl;
pointInformation.collect_garbage();
std::cout << "Down sampling complete\n";
}
// Outlier removal -----------------------------------------------------------------------------------------
//CGAL::IO::read_PLY(input, pointInformation);
bool skipOutlierRemoval = false;
int numberOfNeighbours = 24;
double pointRemovalPercentage = 5.0;
if (!skipOutlierRemoval) {
std::cout << "Removing outliers . . .\n";
typename Point_set::iterator rout_it = CGAL::remove_outliers<CGAL::Parallel_if_available_tag>
(pointInformation,
numberOfNeighbours, // Number of neighbors considered for evaluation
pointInformation.parameters().threshold_percent(pointRemovalPercentage)); // Percentage of points to remove
pointInformation.remove(rout_it, pointInformation.end());
std::cout << pointInformation.number_of_removed_points()
<< " point(s) are outliers." << std::endl;
// Applying point set processing algorithm to a CGAL::Point_set_3
// object does not erase the points from memory but place them in
// the garbage of the object: memory can be freeed by the user.
pointInformation.collect_garbage();
std::cout << "Outliers removed \n";
}
// Surface Reconstruction -----------------------------------------------------------------------------------------
int POISSON = 0;
int ADVANCINGFRONT = 1;
int SCALESPACE = 3;
int chosenType = 1;
bool skipSurfaceReconstruction = true;
typedef std::array<std::size_t, 3> Facet; // Triple of indices
std::vector<Facet> facets;
if (!skipSurfaceReconstruction) {
// Poisson -----------------------------------------------------------------------------------------
if (chosenType == POISSON) {
std::cout << "Inside poisson\n";
std::cout << "Estimating normals...\n";
/*int noOfNeighbours = 24;
CGAL::Surface_mesh<Point_3> output_mesh;
CGAL::jet_estimate_normals<CGAL::Sequential_tag>
(pointInformation, noOfNeighbours); // Use 24 neighbors
// Orientation of normals, returns iterator to first unoriented point
typename Point_set::iterator unoriented_points_begin =
CGAL::mst_orient_normals(pointInformation, 24); // Use 24 neighbors
pointInformation.remove(unoriented_points_begin, pointInformation.end());
std::cout << "Normals complete\n";
std::cout << "Executing poisson...\n";
CGAL::poisson_surface_reconstruction_delaunay
(pointInformation.begin(), pointInformation.end(),
pointInformation.point_map(), pointInformation.normal_map(),
output_mesh, 0.01);
std::cout << "Poisson complete\n";*/
}
else if (chosenType == ADVANCINGFRONT) { // Advancing Front -----------------------------------------------------------------------------------------
std::cout << "Inside Advancing front\n";
std::cout << "Executing Advancing front...\n";
// The function is called using directly the points raw iterators
CGAL::advancing_front_surface_reconstruction(pointInformation.points().begin(),
pointInformation.points().end(),
std::back_inserter(facets));
std::cout << facets.size()
<< " facet(s) generated by reconstruction." << std::endl;
std::cout << "Advancing front complete\n";
}
else if (chosenType == SCALESPACE) { // Scale Space -------------------------------------------------
std::cout << "Inside Scale space\n";
std::cout << "Executing Scale space...\n";
CGAL::Scale_space_surface_reconstruction_3<Kernel> reconstruct
(pointInformation.points().begin(), pointInformation.points().end());
// Smooth using 4 iterations of Jet Smoothing
//reconstruct.increase_scale(4, CGAL::Scale_space_reconstruction_3::Jet_smoother<Kernel>());
// Mesh with the Advancing Front mesher with a maximum facet length of 0.5
reconstruct.reconstruct_surface(CGAL::Scale_space_reconstruction_3::Advancing_front_mesher<Kernel>(0.5));
std::cout << "Scale space complete\n";
}
}
// Draw the mesh ---------------------------------------------------------------------------------------------------
std::cout << "Drawing ...\n";
if (chosenType == POISSON) {
CGAL::draw(initialSM);
}
else
{
CGAL::draw(pointInformation);
}
return EXIT_SUCCESS;
}