Merge pull request #312 from sloriot/Polyhedron_demo-stl_io_plugin_safer-sloriot

Polyhedron demo: first check that the STL file is a polygon mesh before loading it

Conflicts:
	Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt
This commit is contained in:
Laurent Rineau 2015-09-04 11:36:13 +02:00
commit 1eab366954
3 changed files with 40 additions and 2 deletions

View File

@ -95,4 +95,5 @@ It can be made short to PM. And TriangleMesh (or TM) specifies when the paramete
\todo add in BGL `clear(pmesh)` and use it in `keep_largest_connected_components(pmesh, 0);`
\todo document BGL/include/CGAL/boost/graph/Dual.h and remove the example from dont_submit
\todo fix and restore remove_degenerate_faces in the user and the reference manual
\todo publish `is_polygon_soup_a_polygon_mesh` defined in `polygon_soup_to_polygon_mesh.h`
*/

View File

@ -14,7 +14,7 @@
//
// $URL$
// $Id$
//
//
//
// Author(s) : Laurent Rineau and Ilker O. Yaz
@ -91,6 +91,42 @@ public:
};
}//end namespace internal
/// \cond SKIP_IN_MANUAL
/**
* \ingroup PkgPolygonMeshProcessing
* returns `true` if the soup of polygons defines a valid polygon mesh
* that can be handled by `CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh()`.
*
* @tparam Polygon a `std::vector<std::size_t>` containing the indices
* of the points of the polygon face
*
* @param polygons each element in the vector describes a polygon using the index of the vertices
*
*/
template<class Polygon>
bool is_polygon_soup_a_polygon_mesh(const std::vector<Polygon>& polygons)
{
typedef typename std::iterator_traits<
typename Polygon::iterator >::value_type V_ID;
std::set< std::pair<V_ID, V_ID> > edge_set;
BOOST_FOREACH(const Polygon& polygon, polygons)
{
std::size_t nb_edges = polygon.size();
if (nb_edges<3) return false;
V_ID prev=polygon.back();
BOOST_FOREACH(V_ID id, polygon)
if (! edge_set.insert(std::pair<V_ID, V_ID>(prev,id)).second )
return false;
else
prev=id;
}
return true;
}
/// \endcond
/**
* \ingroup PkgPolygonMeshProcessing
* builds a polygon mesh from a soup of polygons.

View File

@ -59,7 +59,8 @@ Polyhedron_demo_stl_plugin::load(QFileInfo fileinfo) {
try{
// Try building a polyhedron
Polyhedron P;
CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(points, triangles, P);
if (CGAL::Polygon_mesh_processing::is_polygon_soup_a_polygon_mesh(triangles))
CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(points, triangles, P);
if(! P.is_valid() || P.empty()){
std::cerr << "Error: Invalid polyhedron" << std::endl;