introduce edge constraints based on the dihedral angle

This commit is contained in:
Andreas Fabri 2015-02-18 15:58:33 +01:00
parent afb2ced556
commit 6af7aaeebb
2 changed files with 29 additions and 19 deletions

View File

@ -4,54 +4,64 @@
#include <iostream>
#include <fstream>
namespace PMP = CGAL::Polygon_mesh_processing;
typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_3 Point;
typedef CGAL::Surface_mesh<Point> Mesh;
typedef boost::graph_traits<Mesh>::vertex_descriptor vertex_descriptor;
typedef boost::graph_traits<Mesh>::face_descriptor face_descriptor;
typedef boost::graph_traits<Mesh>::halfedge_descriptor halfedge_descriptor;
typedef boost::graph_traits<Mesh>::edge_descriptor edge_descriptor;
typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_3 Point;
typedef Kernel::Compare_dihedral_angle_3 Compare_dihedral_angle_3;
typedef CGAL::Surface_mesh<Point> Mesh;
template <typename G>
struct Constraint {
Constraint() { }
typedef typename boost::graph_traits<G>::halfedge_descriptor halfedge_descriptor;
typedef typename boost::graph_traits<G>::edge_descriptor edge_descriptor;
Constraint(G & g) : g(&g) { }
Constraint()
{}
bool operator[](const edge_descriptor&) const {
return false; // no constraint
Constraint(G & g, double bound)
: g(&g), bound(bound)
{ }
bool operator[](edge_descriptor e) const {
return compare((*g).point(source(e,*g)),
(*g).point(target(e,*g)),
(*g).point(target(next(halfedge(e,*g),*g),*g)),
(*g).point(target(next(opposite(halfedge(e,*g),*g),*g),*g)),
bound) == CGAL::SMALLER;
}
G* g;
Compare_dihedral_angle_3 compare;
double bound;
};
int main(int, char* argv[])
{
typedef boost::graph_traits<Mesh>::face_descriptor face_descriptor;
const double bound = std::cos(0.7* CGAL_PI);
Mesh sm;
std::ifstream in(argv[1]);
in >> sm;
std::vector<face_descriptor> cc;
face_descriptor fd = *faces(sm).first;
CGAL::Polygon_mesh_processing::connected_component(fd,
sm,
std::back_inserter(cc));
std::cerr << "connected components without edge constraints" << std::endl;
std::cerr << cc.size() << " faces in the CC of " << fd << std::endl;
std::cerr << "\nconnected components with edge constraints (dihedral angle < 3/4 pi)" << std::endl;
Mesh::Property_map<face_descriptor,std::size_t> fccmap;
fccmap = sm.add_property_map<face_descriptor,std::size_t>("f:CC").first;
std::size_t num = PMP::connected_components(sm,
fccmap,
CGAL::parameters::edge_is_constrained_map(Constraint<Mesh>())
CGAL::parameters::edge_is_constrained_map(Constraint<Mesh>(sm,bound))
);
std::cerr << "The graph has " << num << " connected components (face connectivity)" << std::endl;
@ -59,7 +69,8 @@ int main(int, char* argv[])
std::cout << f << " in connected component " << fccmap[f] << std::endl;
}
CGAL::Polygon_mesh_processing::keep_largest_connected_components(sm,2);
std::cerr << "We keep the two largest components" << std::endl;
PMP::keep_largest_connected_components(sm,2,CGAL::parameters::edge_is_constrained_map(Constraint<Mesh>(sm,bound)));
std::cout << "mesh:\n" << sm << std::endl;
return 0;

View File

@ -620,7 +620,6 @@ std::size_t keep_largest_connected_components(PolygonMesh& pmesh,
// don't care about connectivity
// As vertices are not kept the faces and vertices will be removed later
remove_edge(e,pmesh);
std::cerr << "after remove_edge"<< std::endl;
} else if( keep_vertex[v] && keep_vertex[w]){
face_descriptor fh = face(h,pmesh), ofh = face(oh,pmesh);
if(is_border(h,pmesh) && is_border(oh,pmesh)){