Skip to content

Commit 46240a0

Browse files
amaldevpAmal Dev Parakkat
authored and
Amal Dev Parakkat
committed
add free functions for both versions
1 parent 6619636 commit 46240a0

File tree

2 files changed

+44
-27
lines changed

2 files changed

+44
-27
lines changed

Ball_merge_surface_reconstruction/examples/Ball_merge_surface_reconstruction/ball_merge_reconstruction.cpp

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,29 @@ typedef K::Point_3 Point;
1515

1616
int main(int argc, char **argv)
1717
{
18-
double tlen;
1918
const char *inFilename = argv[1];//Filename
2019
std::ifstream inStream(inFilename);//Read the file
2120
std::vector<std::array<unsigned char, 3>> meshVertexColors;//Variable to hold if the input has textures
2221
Point p;
2322
double par = atof(argv[2]);//Parameter to check IR
2423
int option = atoi(argv[3]);//Option to select global and local variants - 1 for global and 0 for local
25-
if (argc >= 5)//If local, there is an option to give extra optional parameter to filter long triangles
26-
tlen = atof(argv[4]);
27-
else
28-
tlen = 200.0;//If not provided, default 200 will be taken
24+
2925

3026
std::vector<Point> points;
3127
CGAL::IO::read_points(argv[1], std::back_inserter(points));
3228

33-
CGAL::Ball_merge_surface_reconstruction<K, CGAL::Parallel_tag> bmsr;
34-
bmsr.option=option;
35-
bmsr(points, par, tlen);
36-
37-
// AF: In case of duplicated points the colors of vertices will be wrong
38-
39-
std::vector<std::vector<int>> meshFaceIndices;
40-
bmsr.set_triangle_indices_hull1(meshFaceIndices);
41-
std::string st = "BMOut1.ply";
42-
43-
CGAL::IO::write_polygon_soup(st, points, meshFaceIndices);
44-
meshFaceIndices.clear();
45-
46-
if (option == 1){//Sometimes, in the gloabl case, the largest group would be a mould created by the convex hull, just to avoid it, we will write the second largest group as well
47-
bmsr.set_triangle_indices_hull2(meshFaceIndices);
48-
st="BMOut2.ply";
49-
CGAL::IO::write_polygon_soup(st, points, meshFaceIndices);
29+
if (option == 0)
30+
{
31+
double tlen = (argc >= 5) ? atof(argv[4]) : 200.;
32+
std::vector<std::array<int,3>> meshFaceIndices;
33+
CGAL::ball_merge_surface_reconstruction_local<CGAL::Parallel_if_available_tag>(points, meshFaceIndices, par, tlen);
34+
CGAL::IO::write_polygon_soup("BMOut1.ply", points, meshFaceIndices);
35+
}
36+
else{
37+
std::vector<std::array<int,3>> meshFaceIndices1, meshFaceIndices2;
38+
CGAL::ball_merge_surface_reconstruction_global<CGAL::Parallel_if_available_tag>(points, meshFaceIndices1, meshFaceIndices2, par);
39+
CGAL::IO::write_polygon_soup("BMOut1.ply", points, meshFaceIndices1);
40+
CGAL::IO::write_polygon_soup("BMOut2.ply", points, meshFaceIndices2);
5041
}
5142

5243
return 0;

Ball_merge_surface_reconstruction/include/CGAL/Ball_merge_surface_reconstruction.h

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class Ball_merge_surface_reconstruction {
168168
// }
169169
// }
170170

171-
void set_triangle_indices_hull1(std::vector<std::vector<int>>& meshFaceIndices) const
171+
void set_triangle_indices_hull1(std::vector<std::array<int,3>>& meshFaceIndices) const
172172
{
173173
std::vector<bool> visited(dt3.number_of_cells(),false);
174174
for (Cell_handle cell : dt3.finite_cell_handles()){
@@ -177,7 +177,7 @@ void set_triangle_indices_hull1(std::vector<std::vector<int>>& meshFaceIndices)
177177
//If global, write the cell details of the largest group to the PLY file
178178
if (cell_groups[cell->info()] == maingroup && (cell_groups[cell->neighbor(i)->info()] != maingroup || dt3.is_infinite(cell->neighbor(i)))){
179179
//Write the triangles between cells if they have have different labels and one of them is labeled as the same as the largest group
180-
std::vector<int> indices(3);
180+
std::array<int, 3> indices;
181181
for (int j = 0; j < 3; ++j){
182182
indices[j] = cell->vertex((i + 1 + j) % 4)->info();
183183
}
@@ -193,7 +193,7 @@ void set_triangle_indices_hull1(std::vector<std::vector<int>>& meshFaceIndices)
193193
if (dt3.is_infinite(cell->neighbor(i))||!_function(cell, cell->neighbor(i)) == 1){
194194
//If the cells cannot be merged, then write the triangle between these two cells to the PLY file
195195
visited[cell->info()]=true;
196-
std::vector<int> indices(3);
196+
std::array<int,3> indices;
197197
for (int j = 0; j < 3; ++j){
198198
indices[j] = cell->vertex((i + 1 + j) % 4)->info();
199199
}
@@ -205,15 +205,15 @@ void set_triangle_indices_hull1(std::vector<std::vector<int>>& meshFaceIndices)
205205
}
206206
}
207207

208-
void set_triangle_indices_hull2(std::vector<std::vector<int>>& meshFaceIndices) const
208+
void set_triangle_indices_hull2(std::vector<std::array<int,3>>& meshFaceIndices) const
209209
{
210210
for (Cell_handle cell : dt3.finite_cell_handles())
211211
{
212212
for (int i = 0; i < 4; ++i)
213213
if (cell_groups[cell->info()] == secondgroup && (dt3.is_infinite(cell->neighbor(i)) || cell_groups[cell->neighbor(i)->info()] != secondgroup))
214214
{
215215
//Write the triangles between cells if they have have different labels and one of them is labeled as the same as the second largest group
216-
std::vector<int> indices(3);
216+
std::array<int,3> indices;
217217
for (int j = 0; j < 3; j++)
218218
indices[j] = cell->vertex((i + 1 + j) % 4)->info();
219219
if (i%2==1)
@@ -224,6 +224,32 @@ void set_triangle_indices_hull1(std::vector<std::vector<int>>& meshFaceIndices)
224224
}
225225
};
226226

227+
/// \ingroup PkgBallMergeRef
228+
template <class Concurrency_tag, class Traits>
229+
void ball_merge_surface_reconstruction_local(const std::vector<CGAL::Point_3<Traits>>& points,
230+
std::vector<std::array<int, 3> >& out_triangles,
231+
double parameter, double tlen=200.)
232+
{
233+
CGAL::Ball_merge_surface_reconstruction<Traits, Concurrency_tag> bmsr;
234+
bmsr.option=0;
235+
bmsr(points, parameter, tlen);
236+
bmsr.set_triangle_indices_hull1(out_triangles);
237+
}
238+
239+
/// \ingroup PkgBallMergeRef
240+
template <class Concurrency_tag, class Traits>
241+
void ball_merge_surface_reconstruction_global(const std::vector<CGAL::Point_3<Traits>>& points,
242+
std::vector<std::array<int, 3> >& out_triangles1,
243+
std::vector<std::array<int, 3> >& out_triangles2,
244+
double parameter)
245+
{
246+
CGAL::Ball_merge_surface_reconstruction<Traits, Concurrency_tag> bmsr;
247+
bmsr.option=1;
248+
bmsr(points, parameter, 0);
249+
bmsr.set_triangle_indices_hull1(out_triangles1);
250+
bmsr.set_triangle_indices_hull2(out_triangles2);
251+
}
252+
227253

228254
} // namespace CGAL
229255

0 commit comments

Comments
 (0)