mirror of https://github.com/CGAL/cgal
improve examples for user manual (Pierre's review)
This commit is contained in:
parent
6e621f037d
commit
d52ce62167
|
|
@ -12,7 +12,7 @@ typedef K::Vector_3 Vector;
|
|||
|
||||
typedef CGAL::Surface_mesh<Point> Surface_mesh;
|
||||
typedef boost::graph_traits<Surface_mesh>::vertex_descriptor vertex_descriptor;
|
||||
typedef boost::graph_traits<Surface_mesh>::face_descriptor face_descriptor;
|
||||
typedef boost::graph_traits<Surface_mesh>::face_descriptor face_descriptor;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
|
@ -25,13 +25,12 @@ int main(int argc, char* argv[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
Surface_mesh::Property_map<face_descriptor, Vector> fnormals;
|
||||
Surface_mesh::Property_map<vertex_descriptor, Vector> vnormals;
|
||||
bool created;
|
||||
boost::tie(fnormals, created)
|
||||
= mesh.add_property_map<face_descriptor, Vector>("f:normals", Vector(0, 0, 0));
|
||||
boost::tie(vnormals, created)
|
||||
= mesh.add_property_map<vertex_descriptor, Vector>("v:normals", Vector(0, 0, 0));
|
||||
Surface_mesh::Property_map<face_descriptor, Vector> fnormals =
|
||||
mesh.add_property_map<face_descriptor, Vector>
|
||||
("f:normals", CGAL::NULL_VECTOR).first;
|
||||
Surface_mesh::Property_map<vertex_descriptor, Vector> vnormals =
|
||||
mesh.add_property_map<vertex_descriptor, Vector>
|
||||
("v:normals", CGAL::NULL_VECTOR).first;
|
||||
|
||||
CGAL::Polygon_mesh_processing::compute_normals(mesh,
|
||||
vnormals,
|
||||
|
|
@ -43,7 +42,7 @@ int main(int argc, char* argv[])
|
|||
BOOST_FOREACH(face_descriptor fd, faces(mesh)){
|
||||
std::cout << fnormals[fd] << std::endl;
|
||||
}
|
||||
std::cout << "Normals at vertices :" << std::endl;
|
||||
std::cout << "Vertex normals :" << std::endl;
|
||||
BOOST_FOREACH(vertex_descriptor vd, vertices(mesh)){
|
||||
std::cout << vnormals[vd] << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ typedef Kernel::Compare_dihedral_angle_3 Compare_dihedral_ang
|
|||
|
||||
typedef CGAL::Surface_mesh<Point> Mesh;
|
||||
|
||||
namespace PMP = CGAL::Polygon_mesh_processing;
|
||||
|
||||
template <typename G>
|
||||
struct Constraint : public boost::put_get_helper<bool,Constraint<G> >
|
||||
|
|
@ -29,16 +30,17 @@ struct Constraint : public boost::put_get_helper<bool,Constraint<G> >
|
|||
:g_(NULL)
|
||||
{}
|
||||
|
||||
Constraint(G & g, double bound)
|
||||
Constraint(G& g, double bound)
|
||||
: g_(&g), bound_(bound)
|
||||
{}
|
||||
|
||||
bool operator[](edge_descriptor e) const {
|
||||
bool operator[](edge_descriptor e) const
|
||||
{
|
||||
const G& g = *g_;
|
||||
return compare_(g.point(source(e,g)),
|
||||
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)),
|
||||
g.point(target(next(halfedge(e, g), g), g)),
|
||||
g.point(target(next(opposite(halfedge(e, g), g), g), g)),
|
||||
bound_) == CGAL::SMALLER;
|
||||
}
|
||||
|
||||
|
|
@ -49,7 +51,8 @@ struct Constraint : public boost::put_get_helper<bool,Constraint<G> >
|
|||
|
||||
|
||||
template <typename PM>
|
||||
struct Put_true {
|
||||
struct Put_true
|
||||
{
|
||||
Put_true(const PM pm)
|
||||
:pm(pm)
|
||||
{}
|
||||
|
|
@ -80,29 +83,28 @@ int main(int argc, char* argv[])
|
|||
|
||||
std::vector<face_descriptor> cc;
|
||||
face_descriptor fd = *faces(mesh).first;
|
||||
CGAL::Polygon_mesh_processing::connected_component(fd,
|
||||
mesh,
|
||||
std::back_inserter(cc));
|
||||
PMP::connected_component(fd,
|
||||
mesh,
|
||||
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;
|
||||
|
||||
|
||||
|
||||
// Instead of writing the faces into a container, you can set a face property to true
|
||||
typedef Mesh::Property_map<face_descriptor, bool> F_select_map;
|
||||
F_select_map fselect_map;
|
||||
fselect_map = mesh.add_property_map<face_descriptor, bool>("f:select", false).first;
|
||||
CGAL::Polygon_mesh_processing::connected_component(fd,
|
||||
mesh,
|
||||
boost::make_function_output_iterator(Put_true<F_select_map>(fselect_map)));
|
||||
F_select_map fselect_map =
|
||||
mesh.add_property_map<face_descriptor, bool>("f:select", false).first;
|
||||
PMP::connected_component(fd,
|
||||
mesh,
|
||||
boost::make_function_output_iterator(Put_true<F_select_map>(fselect_map)));
|
||||
|
||||
|
||||
std::cerr << "\nConnected components with edge constraints (dihedral angle < 3/4 pi)" << std::endl;
|
||||
Mesh::Property_map<face_descriptor, std::size_t> fccmap;
|
||||
fccmap = mesh.add_property_map<face_descriptor, std::size_t>("f:CC").first;
|
||||
std::size_t num = CGAL::Polygon_mesh_processing::connected_components(mesh,
|
||||
fccmap,
|
||||
CGAL::Polygon_mesh_processing::parameters::edge_is_constrained_map(Constraint<Mesh>(mesh, bound)));
|
||||
Mesh::Property_map<face_descriptor, std::size_t> fccmap =
|
||||
mesh.add_property_map<face_descriptor, std::size_t>("f:CC").first;
|
||||
std::size_t num = PMP::connected_components(mesh,
|
||||
fccmap,
|
||||
PMP::parameters::edge_is_constrained_map(Constraint<Mesh>(mesh, bound)));
|
||||
|
||||
std::cerr << "- The graph has " << num << " connected components (face connectivity)" << std::endl;
|
||||
typedef std::map<std::size_t/*index of CC*/, unsigned int/*nb*/> Components_size;
|
||||
|
|
@ -116,9 +118,9 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
|
||||
std::cerr << "- We keep the two largest components" << std::endl;
|
||||
CGAL::Polygon_mesh_processing::keep_largest_connected_components(mesh,
|
||||
2,
|
||||
CGAL::Polygon_mesh_processing::parameters::edge_is_constrained_map(Constraint<Mesh>(mesh, bound)));
|
||||
PMP::keep_largest_connected_components(mesh,
|
||||
2,
|
||||
PMP::parameters::edge_is_constrained_map(Constraint<Mesh>(mesh, bound)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,15 +41,14 @@ int main(int argc, char* argv[])
|
|||
if (!CGAL::Polygon_mesh_processing::is_outward_oriented(mesh))
|
||||
CGAL::Polygon_mesh_processing::reverse_face_orientations(mesh);
|
||||
|
||||
std::ofstream out("mesh-oriented.off");
|
||||
std::ofstream out("elephant-oriented1.off");
|
||||
out << mesh;
|
||||
out.close();
|
||||
|
||||
CGAL::Polygon_mesh_processing::reverse_face_orientations(mesh);
|
||||
{
|
||||
std::ofstream out("elephant-oriented2.off");
|
||||
out << mesh;
|
||||
out.close();
|
||||
}
|
||||
CGAL::Polygon_mesh_processing::reverse_face_orientations(mesh);
|
||||
std::ofstream out2("elephant-oriented2.off");
|
||||
out2 << mesh;
|
||||
out2.close();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ int main(int argc, char* argv[])
|
|||
std::size_t nb
|
||||
= CGAL::Polygon_mesh_processing::remove_degenerate_faces(mesh);
|
||||
|
||||
std::cerr << "There were " << nb << " degenerate faces in this mesh" << std::endl;
|
||||
std::cerr << nb << " degenerate faces removed" << std::endl;
|
||||
mesh.collect_garbage();
|
||||
std::cout << mesh << std::endl;
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -7,9 +7,11 @@
|
|||
#include <fstream>
|
||||
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
|
||||
typedef CGAL::Surface_mesh<K::Point_3> Mesh;
|
||||
typedef CGAL::Surface_mesh<K::Point_3> Mesh;
|
||||
typedef boost::graph_traits<Mesh>::face_descriptor face_descriptor;
|
||||
|
||||
namespace PMP = CGAL::Polygon_mesh_processing;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
const char* filename = (argc > 1) ? argv[1] : "data/pig.off";
|
||||
|
|
@ -22,19 +24,19 @@ int main(int argc, char* argv[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
bool intersecting = CGAL::Polygon_mesh_processing::does_self_intersect(mesh,
|
||||
CGAL::Polygon_mesh_processing::parameters::vertex_point_map(get(CGAL::vertex_point, mesh)));
|
||||
bool intersecting = PMP::does_self_intersect(mesh,
|
||||
PMP::parameters::vertex_point_map(get(CGAL::vertex_point, mesh)));
|
||||
|
||||
std::cout
|
||||
<< (intersecting ? "There are self-intersections." : "There is no self-intersection.")
|
||||
<< std::endl;
|
||||
|
||||
std::vector<std::pair<face_descriptor, face_descriptor> > intersected_tris;
|
||||
CGAL::Polygon_mesh_processing::self_intersections(mesh,
|
||||
PMP::self_intersections(mesh,
|
||||
std::back_inserter(intersected_tris),
|
||||
CGAL::Polygon_mesh_processing::parameters::vertex_point_map(get(CGAL::vertex_point, mesh)));
|
||||
PMP::parameters::vertex_point_map(get(CGAL::vertex_point, mesh)));
|
||||
|
||||
std::cout << intersected_tris.size() << " pairs of triangles are intersecting." << std::endl;
|
||||
std::cout << intersected_tris.size() << " pairs of triangles intersect." << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue