Skip to content

Commit

Permalink
Merge pull request #2137 from sloriot/PMP-bug_fixes
Browse files Browse the repository at this point in the history
Polygon Mesh Processing bug fixes
  • Loading branch information
lrineau authored May 26, 2017
2 parents 4fdabc3 + 5578075 commit ab87eaf
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 46 deletions.
28 changes: 27 additions & 1 deletion BGL/include/CGAL/boost/graph/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,32 @@ make_tetrahedron(const P& p0, const P& p1, const P& p2, const P& p3, Graph& g)
return opposite(h2,g);
}

/// \cond SKIP_IN_DOC
template <class Traits, class TriangleMesh, class VertexPointMap>
bool is_degenerate_triangle_face(
typename boost::graph_traits<TriangleMesh>::halfedge_descriptor hd,
TriangleMesh& tmesh,
const VertexPointMap& vpmap,
const Traits& traits)
{
CGAL_assertion(!is_border(hd, tmesh));

const typename Traits::Point_3& p1 = get(vpmap, target( hd, tmesh) );
const typename Traits::Point_3& p2 = get(vpmap, target(next(hd, tmesh), tmesh) );
const typename Traits::Point_3& p3 = get(vpmap, source( hd, tmesh) );
return traits.collinear_3_object()(p1, p2, p3);
}

template <class Traits, class TriangleMesh, class VertexPointMap>
bool is_degenerate_triangle_face(
typename boost::graph_traits<TriangleMesh>::face_descriptor fd,
TriangleMesh& tmesh,
const VertexPointMap& vpmap,
const Traits& traits)
{
return is_degenerate_triangle_face(halfedge(fd,tmesh), tmesh, vpmap, traits);
}
/// \endcond

namespace internal {

Expand Down Expand Up @@ -725,7 +751,7 @@ clear_impl(FaceGraph& g)
}
}

}
} //end of internal namespace

/**
* \ingroup PkgBGLHelperFct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ namespace Polygon_mesh_processing {
}

//face index map given as a named parameter, or as an internal property map
FIMap fim = choose_param(get_param(np, CGAL::face_index),
get_const_property_map(CGAL::face_index, pmesh));
FIMap fim = boost::choose_param(get_param(np, CGAL::face_index),
get_const_property_map(CGAL::face_index, pmesh));

return internal::border_halfedges_impl(faces, fim, out, pmesh, np);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@ namespace internal {

BOOST_FOREACH(face_descriptor f, face_range)
{
input_triangles_.push_back(triangle(f));
Triangle_3 t = triangle(f);
if (t.is_degenerate()) continue;
input_triangles_.push_back(t);
input_patch_ids_.push_back(get_patch_id(f));
}
CGAL_assertion(input_triangles_.size() == input_patch_ids_.size());
Expand Down Expand Up @@ -1510,15 +1512,15 @@ namespace internal {
{
if (is_border(h, mesh_))
continue;
if (PMP::is_degenerated(h, mesh_, vpmap_, GeomTraits()))
if (is_degenerate_triangle_face(h, mesh_, vpmap_, GeomTraits()))
degenerate_faces.insert(h);
}
while(!degenerate_faces.empty())
{
halfedge_descriptor h = *(degenerate_faces.begin());
degenerate_faces.erase(degenerate_faces.begin());

if (!PMP::is_degenerated(h, mesh_, vpmap_, GeomTraits()))
if (!is_degenerate_triangle_face(h, mesh_, vpmap_, GeomTraits()))
//this can happen when flipping h has consequences further in the mesh
continue;

Expand Down Expand Up @@ -1570,10 +1572,10 @@ namespace internal {
}

if (!is_border(hf, mesh_)
&& PMP::is_degenerated(hf, mesh_, vpmap_, GeomTraits()))
&& is_degenerate_triangle_face(hf, mesh_, vpmap_, GeomTraits()))
degenerate_faces.insert(hf);
if (!is_border(hfo, mesh_)
&& PMP::is_degenerated(hfo, mesh_, vpmap_, GeomTraits()))
&& is_degenerate_triangle_face(hfo, mesh_, vpmap_, GeomTraits()))
degenerate_faces.insert(hfo);

break;
Expand All @@ -1592,7 +1594,7 @@ namespace internal {
{
if (is_border(h, mesh_))
continue;
if (PMP::is_degenerated(h, mesh_, vpmap_, GeomTraits()))
if (is_degenerate_triangle_face(h, mesh_, vpmap_, GeomTraits()))
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ namespace Polygon_mesh_processing {
*
* @param pmesh a polygon mesh with triangulated surface patches to be remeshed
* @param faces the range of triangular faces defining one or several surface patches to be remeshed
* @param target_edge_length the edge length that is targetted in the remeshed patch
* @param target_edge_length the edge length that is targetted in the remeshed patch.
* If `0` is passed then only the edge-flip, tangential relaxation, and projection steps will be done.
* @param np optional sequence of \ref namedparameters among the ones listed below
*
* @pre if constraints protection is activated, the constrained edges should
Expand Down Expand Up @@ -230,9 +231,11 @@ void isotropic_remeshing(const FaceRange& faces
#ifdef CGAL_PMP_REMESHING_VERBOSE
std::cout << " * Iteration " << (i + 1) << " *" << std::endl;
#endif

remesher.split_long_edges(high);
remesher.collapse_short_edges(low, high);
if (target_edge_length>0)
{
remesher.split_long_edges(high);
remesher.collapse_short_edges(low, high);
}
remesher.equalize_valences();
remesher.tangential_relaxation(smoothing_1d, nb_laplacian);
remesher.project_to_surface();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,30 +126,7 @@ struct Less_along_ray{
}
};

template <class Traits, class TriangleMesh, class VertexPointMap>
bool is_degenerated(
typename boost::graph_traits<TriangleMesh>::halfedge_descriptor hd,
TriangleMesh& tmesh,
const VertexPointMap& vpmap,
const Traits& traits)
{
CGAL_assertion(!is_border(hd, tmesh));

const typename Traits::Point_3& p1 = get(vpmap, target( hd, tmesh) );
const typename Traits::Point_3& p2 = get(vpmap, target(next(hd, tmesh), tmesh) );
const typename Traits::Point_3& p3 = get(vpmap, source( hd, tmesh) );
return traits.collinear_3_object()(p1, p2, p3);
}

template <class Traits, class TriangleMesh, class VertexPointMap>
bool is_degenerated(
typename boost::graph_traits<TriangleMesh>::face_descriptor fd,
TriangleMesh& tmesh,
const VertexPointMap& vpmap,
const Traits& traits)
{
return is_degenerated(halfedge(fd,tmesh), tmesh, vpmap, traits);
}

///\cond SKIP_IN_MANUAL

Expand All @@ -163,7 +140,7 @@ degenerate_faces(const TriangleMesh& tm,
typedef typename boost::graph_traits<TriangleMesh>::face_descriptor face_descriptor;
BOOST_FOREACH(face_descriptor fd, faces(tm))
{
if ( is_degenerated(fd, tm, vpmap, traits) )
if ( is_degenerate_triangle_face(fd, tm, vpmap, traits) )
*out++=fd;
}
return out;
Expand Down Expand Up @@ -698,7 +675,7 @@ std::size_t remove_degenerate_faces(TriangleMesh& tmesh,
// Then, remove triangles made of 3 collinear points
std::set<face_descriptor> degenerate_face_set;
BOOST_FOREACH(face_descriptor fd, faces(tmesh))
if ( is_degenerated(fd, tmesh, vpmap, traits) )
if ( is_degenerate_triangle_face(fd, tmesh, vpmap, traits) )
degenerate_face_set.insert(fd);
nb_deg_faces+=degenerate_face_set.size();

Expand Down Expand Up @@ -778,14 +755,15 @@ std::size_t remove_degenerate_faces(TriangleMesh& tmesh,
{
face_descriptor adjacent_face = face( opposite(hd, tmesh), tmesh );
if ( adjacent_face==GT::null_face() ||
!degenerate_face_set.count(adjacent_face) )
degenerate_face_set.count(adjacent_face)==0 )
boundary_hedges.push_back(hd);
else
{
if (cc_faces.insert(adjacent_face).second)
{
inside_hedges.push_back(hd);
queue.push_back(adjacent_face);
}
if ( hd < opposite(hd, tmesh) )
inside_hedges.push_back(hd);
}
}
}

Expand Down Expand Up @@ -853,9 +831,10 @@ std::size_t remove_degenerate_faces(TriangleMesh& tmesh,
}
// remove degenerate faces
BOOST_FOREACH(face_descriptor f, cc_faces)
{
degenerate_face_set.erase(f);
BOOST_FOREACH(face_descriptor f, cc_faces)
remove_face(f, tmesh);
}
// remove interior edges
BOOST_FOREACH(halfedge_descriptor h, inside_hedges)
remove_edge(edge(h, tmesh), tmesh);
Expand Down Expand Up @@ -941,7 +920,7 @@ std::size_t remove_degenerate_faces(TriangleMesh& tmesh,
// since we reuse later the halfedge of the first refernce vertex
// we must set it as we need.
if ( source(h2,tmesh) == *ref_vertices.first)
set_halfedge(*ref_vertices.first, opposite( prev(side_two[hi], tmesh), tmesh), tmesh );
set_halfedge(*ref_vertices.first, opposite( h2, tmesh), tmesh );
// retriangulate the face
if ( face(h2, tmesh) != GT::null_face())
Euler::split_face(h2, next(side_two[hi], tmesh), tmesh);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2023,7 +2023,7 @@ bool Scene_polyhedron_selection_item_priv::canAddFace(Halfedge_handle hc, Halfed
boost::graph_traits<Polyhedron>::halfedge_descriptor res =
CGAL::Euler::add_face_to_border(t,hc, *item->polyhedron());

if(PMP::is_degenerated(res, *item->polyhedron(), get(CGAL::vertex_point, *item->polyhedron()), Kernel()))
if(CGAL::is_degenerate_triangle_face(res, *item->polyhedron(), get(CGAL::vertex_point, *item->polyhedron()), Kernel()))
{
CGAL::Euler::remove_face(res, *item->polyhedron());
tempInstructions("Edge not selected : resulting facet is degenerated.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ unsigned int nb_degenerate_faces(Polyhedron* poly, VPmap vpmap)
unsigned int nb = 0;
BOOST_FOREACH(face_descriptor f, faces(*poly))
{
if (CGAL::Polygon_mesh_processing::is_degenerated(f, *poly, vpmap, Kernel()))
if (CGAL::is_degenerate_triangle_face(f, *poly, vpmap, Kernel()))
++nb;
}
return nb;
Expand Down

0 comments on commit ab87eaf

Please sign in to comment.