Skip to content

Commit 10f958c

Browse files
authored
Merge pull request #4863 from janetournois/Tet_remeshing-fix_peeling_slivers-jtournois
2 parents ac5b6ff + 92d3754 commit 10f958c

File tree

3 files changed

+58
-25
lines changed

3 files changed

+58
-25
lines changed

Tetrahedral_remeshing/include/CGAL/Tetrahedral_remeshing/internal/tetrahedral_adaptive_remeshing_impl.h

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ class Adaptive_remesher
286286
}
287287

288288
//peel off slivers
289-
std::size_t postprocess(const double sliver_angle = 0.1)
289+
std::size_t postprocess(const double sliver_angle = 2.)
290290
{
291291
if (m_protect_boundaries)
292292
return 0;
@@ -298,35 +298,33 @@ class Adaptive_remesher
298298

299299
std::size_t nb_slivers_peel = 0;
300300
std::vector<std::pair<Cell_handle, std::array<bool, 4> > > peelable_cells;
301+
#ifdef CGAL_TETRAHEDRAL_REMESHING_VERBOSE
302+
double mindh = 180.;
303+
#endif
301304
for (Cell_handle cit : tr().finite_cell_handles())
302305
{
303306
std::array<bool, 4> facets_on_surface;
304-
short count = 0;
305-
if(m_c3t3.is_in_complex(cit) && min_dihedral_angle(tr(), cit) < sliver_angle)
307+
if (m_c3t3.is_in_complex(cit))
306308
{
307-
for (int i = 0; i < 4; ++i)
308-
{
309-
if (!m_c3t3.is_in_complex(cit->neighbor(i)))
310-
{
311-
facets_on_surface[i] = true;
312-
++count;
313-
}
314-
else
315-
facets_on_surface[i] = false;
316-
}
317-
if(count > 1)
309+
const double dh = min_dihedral_angle(tr(), cit);
310+
if(dh < sliver_angle && is_peelable(m_c3t3, cit, facets_on_surface))
318311
peelable_cells.push_back(std::make_pair(cit, facets_on_surface));
312+
313+
#ifdef CGAL_TETRAHEDRAL_REMESHING_VERBOSE
314+
mindh = (std::min)(dh, mindh);
315+
#endif
319316
}
320317
}
321318

322319
#ifdef CGAL_TETRAHEDRAL_REMESHING_VERBOSE
320+
std::cout << "Min dihedral angle : " << mindh << std::endl;
323321
std::cout << "Peelable cells : " << peelable_cells.size() << std::endl;
324322
#endif
325323

326324
for (auto c_i : peelable_cells)
327325
{
328326
Cell_handle c = c_i.first;
329-
std::array<bool, 4> f_on_surface = c_i.second;
327+
const std::array<bool, 4>& f_on_surface = c_i.second;
330328

331329
boost::optional<Surface_patch_index> patch;
332330
for (int i = 0; i < 4; ++i)

Tetrahedral_remeshing/include/CGAL/Tetrahedral_remeshing/internal/tetrahedral_remeshing_helpers.h

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,41 @@ typename Tr::Geom_traits::FT min_dihedral_angle(const Tr& tr,
137137
c->vertex(3));
138138
}
139139

140+
template<typename C3t3>
141+
bool is_peelable(const C3t3& c3t3,
142+
const typename C3t3::Cell_handle ch,
143+
std::array<bool, 4>& facets_on_surface)
144+
{
145+
typedef typename C3t3::Triangulation::Geom_traits::FT FT;
146+
typedef typename C3t3::Facet Facet;
147+
148+
if(!c3t3.is_in_complex(ch))
149+
return false;
150+
151+
bool on_surface = false;
152+
for (int i = 0; i < 4; ++i)
153+
{
154+
facets_on_surface[i] = !c3t3.is_in_complex(ch->neighbor(i));
155+
on_surface = on_surface || facets_on_surface[i];
156+
}
157+
if(!on_surface)
158+
return false;
159+
160+
FT area_on_surface = 0.;
161+
FT area_inside = 0.;
162+
for (int i = 0; i < 4; ++i)
163+
{
164+
Facet f(ch, i);
165+
const FT facet_area = CGAL::approximate_sqrt(c3t3.triangulation().triangle(f).squared_area());
166+
if(facets_on_surface[i])
167+
area_on_surface += facet_area;
168+
else
169+
area_inside += facet_area;
170+
}
171+
172+
return (area_inside < 1.5 * area_on_surface);
173+
}
174+
140175
template<typename Tr>
141176
typename Tr::Geom_traits::Vector_3 facet_normal(const Tr& tr,
142177
const typename Tr::Facet& f)
@@ -1334,17 +1369,19 @@ void dump_cells_with_small_dihedral_angle(const Tr& tr,
13341369
cit != tr.finite_cells_end(); ++cit)
13351370
{
13361371
Cell_handle c = cit;
1337-
if ( c->subdomain_index() != Subdomain_index()
1338-
&& cell_select(c)
1339-
&& min_dihedral_angle(tr, c) < angle_bound)
1372+
if (c->subdomain_index() != Subdomain_index() && cell_select(c))
13401373
{
1341-
1342-
cells.push_back(c);
1343-
indices.push_back(c->subdomain_index());
1374+
double dh = min_dihedral_angle(tr, c);
1375+
if (dh < angle_bound)
1376+
{
1377+
cells.push_back(c);
1378+
indices.push_back(c->subdomain_index());
1379+
}
13441380
}
13451381
}
13461382
std::cout << "bad cells : " << cells.size() << std::endl;
13471383
dump_cells<Tr>(cells, indices, filename);
1384+
dump_cells_off(cells, tr, "bad_cells.off");
13481385
}
13491386

13501387
template<typename Tr>

Tetrahedral_remeshing/include/CGAL/tetrahedral_remeshing.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,10 @@ void tetrahedral_isotropic_remeshing(
259259
std::size_t nb_extra_iterations = 3;
260260
remesher.remesh(max_it, nb_extra_iterations);
261261

262-
#ifdef CGAL_TETRAHEDRAL_REMESHING_DEBUG
262+
#ifdef CGAL_TETRAHEDRAL_REMESHING_VERBOSE
263263
const double angle_bound = 5.0;
264264
Tetrahedral_remeshing::debug::dump_cells_with_small_dihedral_angle(tr,
265265
angle_bound, cell_select, "bad_cells.mesh");
266-
#endif
267-
#ifdef CGAL_TETRAHEDRAL_REMESHING_VERBOSE
268266
Tetrahedral_remeshing::internal::compute_statistics(tr,
269267
cell_select, "statistics_end.txt");
270268
#endif
@@ -455,7 +453,7 @@ void tetrahedral_isotropic_remeshing(
455453
std::size_t nb_extra_iterations = 3;
456454
remesher.remesh(max_it, nb_extra_iterations);
457455

458-
#ifdef CGAL_TETRAHEDRAL_REMESHING_DEBUG
456+
#ifdef CGAL_TETRAHEDRAL_REMESHING_VERBOSE
459457
const double angle_bound = 5.0;
460458
Tetrahedral_remeshing::debug::dump_cells_with_small_dihedral_angle(
461459
c3t3.triangulation(),

0 commit comments

Comments
 (0)