Misc minor code improvements

This commit is contained in:
Mael Rouxel-Labbé 2020-05-26 19:33:27 +02:00
parent fcf0fa4273
commit 3ea5fc5a10
6 changed files with 221 additions and 216 deletions

View File

@ -5,7 +5,7 @@
// Max-Planck-Institute Saarbruecken (Germany), // Max-Planck-Institute Saarbruecken (Germany),
// and Tel-Aviv University (Israel). All rights reserved. // and Tel-Aviv University (Israel). All rights reserved.
// //
// This file is part of CGAL (www.cgal.org); // This file is part of CGAL (www.cgal.org).
// //
// $URL$ // $URL$
// $Id$ // $Id$

View File

@ -222,14 +222,15 @@ bool write_OFF_BGL(std::ostream& os,
\cgalParamBegin{face_color_map} the property map with the colors associated to the faces of `g`.\cgalParamEnd \cgalParamBegin{face_color_map} the property map with the colors associated to the faces of `g`.\cgalParamEnd
\cgalNamedParamsEnd \cgalNamedParamsEnd
\sa Overloads of this function for specific models of the concept `FaceGraph`. \returns `true` if writing was successful.
\sa Overloads of this function for specific models of the concept `FaceGraph`.
\see \ref IOStreamOFF \see \ref IOStreamOFF
*/ */
template <typename FaceGraph, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS> template <typename FaceGraph, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_OFF(std::ostream& os, const FaceGraph& g, const CGAL_BGL_NP_CLASS& np, bool write_OFF(std::ostream& os, const FaceGraph& g, const CGAL_BGL_NP_CLASS& np,
typename boost::disable_if< typename boost::disable_if<
typename boost::has_range_const_iterator<FaceGraph>::type typename boost::has_range_const_iterator<FaceGraph>::type
>::type* =0) >::type* =0)
{ {
return IO::internal::write_OFF_BGL(os, g, np); return IO::internal::write_OFF_BGL(os, g, np);
@ -263,9 +264,9 @@ bool write_OFF(std::ostream& os, const FaceGraph& g, const CGAL_BGL_NP_CLASS& np
\see \ref IOStreamOFF \see \ref IOStreamOFF
*/ */
template <typename FaceGraph, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS> template <typename FaceGraph, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_OFF(const char* fname, const FaceGraph& g, const CGAL_BGL_NP_CLASS& np bool write_OFF(const char* fname, const FaceGraph& g, const CGAL_BGL_NP_CLASS& np,
,typename boost::disable_if< typename boost::disable_if<
typename boost::has_range_const_iterator<FaceGraph>::type typename boost::has_range_const_iterator<FaceGraph>::type
>::type* =0) >::type* =0)
{ {
std::ofstream out(fname); std::ofstream out(fname);
@ -273,9 +274,9 @@ bool write_OFF(const char* fname, const FaceGraph& g, const CGAL_BGL_NP_CLASS& n
} }
template <typename FaceGraph, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS> template <typename FaceGraph, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool write_OFF(const std::string& fname, const FaceGraph& g, const CGAL_BGL_NP_CLASS& np bool write_OFF(const std::string& fname, const FaceGraph& g, const CGAL_BGL_NP_CLASS& np,
,typename boost::disable_if< typename boost::disable_if<
typename boost::has_range_const_iterator<FaceGraph>::type typename boost::has_range_const_iterator<FaceGraph>::type
>::type* =0) >::type* =0)
{ {
return write_OFF(fname.c_str(), g, np); return write_OFF(fname.c_str(), g, np);

View File

@ -19,10 +19,10 @@
#include <CGAL/boost/graph/named_params_helper.h> #include <CGAL/boost/graph/named_params_helper.h>
#include <fstream> #include <fstream>
#include <string>
namespace CGAL { namespace CGAL {
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
/// Read /// Read
@ -44,7 +44,7 @@ class PLY_builder
public: public:
PLY_builder(std::istream& is_, bool verbose) : Base(is_, verbose) { } PLY_builder(std::istream& is_, bool verbose) : Base(is_, verbose) { }
//! TODO: use vertex_point_map
template <typename NamedParameters> template <typename NamedParameters>
bool read(std::istream& input, bool read(std::istream& input,
Point_container& points, Point_container& points,

View File

@ -21,6 +21,10 @@
namespace CGAL { namespace CGAL {
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
/// Write
/*! /*!
\ingroup PkgBGLIOFct \ingroup PkgBGLIOFct

View File

@ -95,55 +95,43 @@ bool read_polygon_mesh(const std::string& fname,
FaceGraph& g, FaceGraph& g,
const NamedParameters& np) const NamedParameters& np)
{ {
if(fname.find(".obj") != std::string::npos)
if (fname.find(".obj") != std::string::npos) {
return read_OBJ(fname, g, np); return read_OBJ(fname, g, np);
}
if (fname.find(".off") != std::string::npos) { if(fname.find(".off") != std::string::npos)
return read_OFF(fname, g, np); return read_OFF(fname, g, np);
}
if (fname.find(".ply") != std::string::npos) { if(fname.find(".ply") != std::string::npos)
return read_PLY(fname, g, np); return read_PLY(fname, g, np);
}
if (fname.find(".stl") != std::string::npos) { if(fname.find(".stl") != std::string::npos)
return read_STL(fname, g, np); return read_STL(fname, g, np);
}
#ifdef CGAL_USE_VTK #ifdef CGAL_USE_VTK
if (fname.find(".vtp") != std::string::npos) { if(fname.find(".vtp") != std::string::npos)
return read_VTP(fname, g, np); return read_VTP(fname, g, np);
}
#endif #endif
if (fname.find(".ts") != std::string::npos) { if(fname.find(".ts") != std::string::npos)
return read_GOCAD(fname, g, np); return read_GOCAD(fname, g, np);
}
return false; return false;
} }
template <class FaceGraph> template <class FaceGraph>
bool read_polygon_mesh(const std::string& fname, bool read_polygon_mesh(const std::string& fname, FaceGraph& g)
FaceGraph& g)
{ {
return read_polygon_mesh(fname, g, parameters::all_default()); return read_polygon_mesh(fname, g, parameters::all_default());
} }
template <class FaceGraph, typename NamedParameters> template <class FaceGraph, typename NamedParameters>
bool read_polygon_mesh(const char* fname, bool read_polygon_mesh(const char* fname, FaceGraph& g, const NamedParameters& np)
FaceGraph& g,
const NamedParameters& np)
{ {
return read_polygon_mesh(std::string(fname), g, np); return read_polygon_mesh(std::string(fname), g, np);
} }
template <class FaceGraph> template <class FaceGraph>
bool read_polygon_mesh(const char* fname, bool read_polygon_mesh(const char* fname, FaceGraph& g)
FaceGraph& g)
{ {
return read_polygon_mesh(fname, g, parameters::all_default()); return read_polygon_mesh(fname, g, parameters::all_default());
} }
@ -154,83 +142,76 @@ bool read_polygon_mesh(const char* fname,
/*! /*!
* \ingroup PkgBGLIOFct * \ingroup PkgBGLIOFct
*
* \brief writes a polygon mesh in a file. * \brief writes a polygon mesh in a file.
* \tparam FaceGraph a model of `FaceGraph` *
* \tparam FaceGraph a model of `FaceListGraph` and `HalfedgeListGraph`
* \tparam NamedParameters a sequence of \ref pmp_namedparameters "Named Parameters" * \tparam NamedParameters a sequence of \ref pmp_namedparameters "Named Parameters"
* *
* \param fname the name of the file. Its extension must be one of the following : * \param fname the name of the file. Its extension must be one of the following :
* `.off` (\ref IOStreamOFF "OFF file format") , `.obj` (\ref IOStreamOBJ "OBJ file format"), * `.off` (\ref IOStreamOFF "OFF file format") , `.obj` (\ref IOStreamOBJ "OBJ file format"),
* `.stl` (\ref IOStreamSTL "STL file format"), `.ply` (\ref IOStreamPLY "PLY file format"), * `.stl` (\ref IOStreamSTL "STL file format"), `.ply` (\ref IOStreamPLY "PLY file format"),
* `.vtp`(\ref IOStreamVTK "VTP file format") or `.ts`(\ref IOStreamGocad "GOCAD file format"). * `.vtp`(\ref IOStreamVTK "VTP file format") or `.ts`(\ref IOStreamGocad "GOCAD file format").
* \param g the mesh * \param g the mesh to be output
* \param np optional \ref pmp_namedparameters "Named Parameters" described below * \param np optional \ref pmp_namedparameters "Named Parameters" described below
* *
* \cgalNamedParamsBegin * \cgalNamedParamsBegin
* \cgalParamBegin{vertex_point_map} the property map with the points associated to the vertices of `g`. * \cgalParamBegin{vertex_point_map} the property map with the points associated to the vertices of `g`.
* If this parameter is omitted, an internal property map for * If this parameter is omitted, an internal property map for
* `CGAL::vertex_point_t` should be available in `FaceGraph`\cgalParamEnd * `CGAL::vertex_point_t` should be available in `FaceGraph`
* \cgalParamEnd
* \cgalNamedParamsEnd * \cgalNamedParamsEnd
* Other named parameters may be used according to the file extension.
* See `PkgBGLIOFct` for an exhaustive list.
* \return `true` if the writing worked, `false` otherwise.
* *
* \see \ref IOStreamOFF * Other named parameters may be used according to the file extension, see \ref PkgBGLIOFct for an exhaustive list.
*
* \return `true` if writing was successful, `false` otherwise.
*/ */
template <class FaceGraph, typename NamedParameters> template <class FaceGraph, typename NamedParameters>
bool write_polygon_mesh(const std::string& fname, bool write_polygon_mesh(const std::string& fname,
FaceGraph& g, FaceGraph& g,
const NamedParameters& np) const NamedParameters& np)
{ {
if (fname.find(".ts") != std::string::npos) { if(fname.find(".obj") != std::string::npos) // @fixme what about my_super_file.obj.off
return write_GOCAD(fname, g, np);
}
if (fname.find(".obj") != std::string::npos) {
return write_OBJ(fname, g, np); return write_OBJ(fname, g, np);
}
if (fname.find(".off") != std::string::npos) { if(fname.find(".off") != std::string::npos) // @fixme case sensitivity
return write_OFF(fname, g, np); return write_OFF(fname, g, np);
}
if (fname.find(".ply") != std::string::npos) { if(fname.find(".ply") != std::string::npos)
return write_PLY(fname, g, np); return write_PLY(fname, g, np);
}
if (fname.find(".stl") != std::string::npos) { if(fname.find(".stl") != std::string::npos)
return write_STL(fname, g, np); return write_STL(fname, g, np);
}
if(fname.find(".ts") != std::string::npos)
return write_GOCAD(fname, g, np);
#ifdef CGAL_USE_VTK #ifdef CGAL_USE_VTK
if (fname.find(".vtp") != std::string::npos) { if(fname.find(".vtp") != std::string::npos)
return write_VTP(fname, g, np); return write_VTP(fname, g, np);
}
#endif #endif
return false; return false;
} }
template <class FaceGraph> template <class FaceGraph>
bool write_polygon_mesh(const std::string& fname, bool write_polygon_mesh(const std::string& fname, FaceGraph& g)
FaceGraph& g)
{ {
return write_polygon_mesh(fname, g, parameters::all_default()); return write_polygon_mesh(fname, g, parameters::all_default());
} }
template <class FaceGraph, typename NamedParameters> template <class FaceGraph, typename NamedParameters>
bool write_polygon_mesh(const char* fname, bool write_polygon_mesh(const char* fname, FaceGraph& g, const NamedParameters& np)
FaceGraph& g,
const NamedParameters& np)
{ {
return write_polygon_mesh(std::string(fname), g, np); return write_polygon_mesh(std::string(fname), g, np);
} }
template <class FaceGraph> template <class FaceGraph>
bool write_polygon_mesh(const char* fname, bool write_polygon_mesh(const char* fname, FaceGraph& g)
FaceGraph& g)
{ {
return write_polygon_mesh(fname, g, parameters::all_default()); return write_polygon_mesh(fname, g, parameters::all_default());
} }
}//end CGAL } // namespace CGAL
#endif // CGAL_BOOST_GRAPH_POLYGON_MESH_IO_H #endif // CGAL_BOOST_GRAPH_POLYGON_MESH_IO_H

View File

@ -25,20 +25,19 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
typedef CGAL::Simple_cartesian<double> Kernel; typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_3 Point; typedef Kernel::Point_3 Point;
typedef CGAL::Polyhedron_3<Kernel, CGAL::Polyhedron_items_with_id_3> Polyhedron; typedef CGAL::Polyhedron_3<Kernel, CGAL::Polyhedron_items_with_id_3> Polyhedron;
typedef CGAL::Surface_mesh<Point> SM; typedef CGAL::Surface_mesh<Point> SM;
typedef CGAL::Linear_cell_complex_traits<3, Kernel> MyTraits; typedef CGAL::Linear_cell_complex_traits<3, Kernel> MyTraits;
typedef CGAL::Linear_cell_complex_for_bgl_combinatorial_map_helper typedef CGAL::Linear_cell_complex_for_bgl_combinatorial_map_helper<2, 3, MyTraits>::type LCC;
<2, 3, MyTraits>::type LCC;
#if defined(CGAL_USE_OPENMESH) #if defined(CGAL_USE_OPENMESH)
typedef OpenMesh::PolyMesh_ArrayKernelT</* MyTraits*/> OMesh; typedef OpenMesh::PolyMesh_ArrayKernelT</* MyTraits*/> OMesh;
#endif #endif
@ -70,7 +69,6 @@ void fill_soup(PointRange& points, PolygonRange& polygons)
polygons[3] = poly; polygons[3] = poly;
} }
void test_polygon_soup_io() void test_polygon_soup_io()
{ {
std::vector<Point> points; std::vector<Point> points;
@ -79,9 +77,7 @@ void test_polygon_soup_io()
std::string filenames[5] = {"soup.obj", "soup.off", "soup.stl", "soup.ts", "soup.ply"}; std::string filenames[5] = {"soup.obj", "soup.off", "soup.stl", "soup.ts", "soup.ply"};
for(const std::string& name : filenames) for(const std::string& name : filenames)
{
CGAL_assertion(CGAL::write_polygon_soup(name, points, polygons)); CGAL_assertion(CGAL::write_polygon_soup(name, points, polygons));
}
for(const std::string& name : filenames) for(const std::string& name : filenames)
{ {
@ -134,36 +130,37 @@ void test_bgl_OFF_with_np()
{ {
Mesh fg; Mesh fg;
std::ifstream in("data/full.off"); std::ifstream in("data/full.off");
typedef typename boost::property_map<Mesh, CGAL::dynamic_vertex_property_t<Kernel::Vector_3> >::type VertexNormalMap; typedef typename boost::property_map<Mesh, CGAL::dynamic_vertex_property_t<Kernel::Vector_3> >::type VertexNormalMap;
VertexNormalMap vnm = get(CGAL::dynamic_vertex_property_t<Kernel::Vector_3>(), fg); VertexNormalMap vnm = get(CGAL::dynamic_vertex_property_t<Kernel::Vector_3>(), fg);
typedef typename boost::property_map<Mesh, CGAL::dynamic_vertex_property_t<CGAL::Color> >::type VertexColorMap; typedef typename boost::property_map<Mesh, CGAL::dynamic_vertex_property_t<CGAL::Color> >::type VertexColorMap;
VertexColorMap vcm = get(CGAL::dynamic_vertex_property_t<CGAL::Color>(), fg); VertexColorMap vcm = get(CGAL::dynamic_vertex_property_t<CGAL::Color>(), fg);
typedef typename boost::property_map<Mesh, CGAL::dynamic_vertex_property_t<Kernel::Point_2> >::type VertexTextureMap; typedef typename boost::property_map<Mesh, CGAL::dynamic_vertex_property_t<Kernel::Point_2> >::type VertexTextureMap;
VertexTextureMap vtm = get(CGAL::dynamic_vertex_property_t<Kernel::Point_2>(), fg); VertexTextureMap vtm = get(CGAL::dynamic_vertex_property_t<Kernel::Point_2>(), fg);
typedef typename boost::property_map<Mesh, CGAL::dynamic_face_property_t<CGAL::Color> >::type FaceColorMap; typedef typename boost::property_map<Mesh, CGAL::dynamic_face_property_t<CGAL::Color> >::type FaceColorMap;
FaceColorMap fcm = get(CGAL::dynamic_face_property_t<CGAL::Color>(), fg); FaceColorMap fcm = get(CGAL::dynamic_face_property_t<CGAL::Color>(), fg);
bool ok = CGAL::read_OFF(in, fg, CGAL::parameters::vertex_normal_map(vnm) bool ok = CGAL::read_OFF(in, fg, CGAL::parameters::vertex_normal_map(vnm)
.vertex_color_map(vcm) .vertex_color_map(vcm)
.vertex_texture_map(vtm) .vertex_texture_map(vtm)
.face_color_map(fcm)); .face_color_map(fcm));
CGAL_assertion(ok); CGAL_assertion(ok);
fg.clear(); fg.clear();
vnm = get(CGAL::dynamic_vertex_property_t<Kernel::Vector_3>(), fg); vnm = get(CGAL::dynamic_vertex_property_t<Kernel::Vector_3>(), fg);
ok = CGAL::read_polygon_mesh("data/full.off", fg, CGAL::parameters::vertex_normal_map(vnm) ok = CGAL::read_polygon_mesh("data/full.off", fg, CGAL::parameters::vertex_normal_map(vnm)
.vertex_color_map(vcm) .vertex_color_map(vcm)
.vertex_texture_map(vtm) .vertex_texture_map(vtm)
.face_color_map(fcm)); .face_color_map(fcm));
CGAL_assertion(ok); CGAL_assertion(ok);
ok = CGAL::write_OFF(std::cout, fg, CGAL::parameters::vertex_normal_map(vnm) ok = CGAL::write_OFF(std::cout, fg, CGAL::parameters::vertex_normal_map(vnm)
.vertex_color_map(vcm) .vertex_color_map(vcm)
.vertex_texture_map(vtm) .vertex_texture_map(vtm)
.face_color_map(fcm)); .face_color_map(fcm));
CGAL_assertion(ok); CGAL_assertion(ok);
} }
@ -172,6 +169,7 @@ void test_soup_off(const char* filename)
std::vector<Point> points; std::vector<Point> points;
std::vector<std::vector<std::size_t> > polygons; std::vector<std::vector<std::size_t> > polygons;
std::ifstream in(filename); std::ifstream in(filename);
CGAL::read_OFF(in,points, polygons); CGAL::read_OFF(in,points, polygons);
CGAL::write_OFF(std::cout, points, polygons); CGAL::write_OFF(std::cout, points, polygons);
} }
@ -182,19 +180,22 @@ bool test_bgl_OBJ()
Mesh fg; Mesh fg;
CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0), CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0),
Point(2, 0, 1), Point(3, 0, 0), fg); Point(2, 0, 1), Point(3, 0, 0), fg);
std::ostringstream out; std::ostringstream out;
CGAL::write_OBJ(out, fg); CGAL::write_OBJ(out, fg);
std::istringstream in( out.str());
std::istringstream in(out.str());
fg.clear(); fg.clear();
CGAL::read_OBJ(in, fg); CGAL::read_OBJ(in, fg);
CGAL_assertion(num_vertices(fg) == 4); CGAL_assertion(num_vertices(fg) == 4);
CGAL_assertion(num_faces(fg) == 4); CGAL_assertion(num_faces(fg) == 4);
fg.clear(); fg.clear();
CGAL::read_polygon_mesh("data/sphere.obj", fg); CGAL::read_polygon_mesh("data/sphere.obj", fg);
CGAL_assertion(num_vertices(fg) == 162); CGAL_assertion(num_vertices(fg) == 162);
CGAL_assertion(num_faces(fg) == 320); CGAL_assertion(num_faces(fg) == 320);
return true; return true;
} }
@ -204,25 +205,26 @@ bool test_bgl_OBJ_with_np()
Mesh fg, fg2; Mesh fg, fg2;
CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0), CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0),
Point(2, 0, 1), Point(3, 0, 0), fg); Point(2, 0, 1), Point(3, 0, 0), fg);
typedef typename boost::property_map<Mesh, CGAL::dynamic_vertex_property_t<Kernel::Vector_3> >::type VertexNormalMap;
VertexNormalMap vnm = get(CGAL::dynamic_vertex_property_t<Kernel::Vector_3>(), fg);
VertexNormalMap vnm2 = get(CGAL::dynamic_vertex_property_t<Kernel::Vector_3>(), fg2);
typedef typename boost::property_map<Mesh, CGAL::dynamic_vertex_property_t<Kernel::Vector_3> >::type VertexNormalMap;
VertexNormalMap vnm = get(CGAL::dynamic_vertex_property_t<Kernel::Vector_3>(), fg);
VertexNormalMap vnm2 = get(CGAL::dynamic_vertex_property_t<Kernel::Vector_3>(), fg2);
for(const auto& v : vertices(fg)) for(const auto& v : vertices(fg))
put(vnm, v, Kernel::Vector_3(0.0,1.0,0.0)); put(vnm, v, Kernel::Vector_3(0.0,1.0,0.0));
std::ostringstream out; std::ostringstream out;
CGAL::write_OBJ(out, fg, CGAL::parameters::vertex_normal_map(vnm)); CGAL::write_OBJ(out, fg, CGAL::parameters::vertex_normal_map(vnm));
std::istringstream in( out.str());
std::istringstream in(out.str());
CGAL::read_OBJ(in, fg2, CGAL::parameters::vertex_normal_map(vnm2)); CGAL::read_OBJ(in, fg2, CGAL::parameters::vertex_normal_map(vnm2));
CGAL_assertion(num_vertices(fg2) == 4); CGAL_assertion(num_vertices(fg2) == 4);
CGAL_assertion(num_faces(fg2) == 4); CGAL_assertion(num_faces(fg2) == 4);
typename boost::graph_traits<Mesh>::vertex_iterator vit, vit2; typename boost::graph_traits<Mesh>::vertex_iterator vit, vit2;
for( vit = vertices(fg).begin(), vit2 = vertices(fg2).begin(); for(vit = vertices(fg).begin(), vit2 = vertices(fg2).begin();
vit != vertices(fg).end(), vit2 != vertices(fg2).end(); vit != vertices(fg).end(), vit2 != vertices(fg2).end();
++vit, ++vit2) ++vit, ++vit2)
{ {
CGAL_assertion(get(vnm, *vit) == get(vnm2, *vit2)); CGAL_assertion(get(vnm, *vit) == get(vnm2, *vit2));
} }
@ -234,18 +236,20 @@ void test_bgl_soup_obj()
{ {
std::vector<Point> points; std::vector<Point> points;
std::vector<std::vector<std::size_t> > polygons; std::vector<std::vector<std::size_t> > polygons;
std::ostringstream out;
fill_soup(points, polygons); fill_soup(points, polygons);
std::ostringstream out;
CGAL::write_OBJ(out, points, polygons); CGAL::write_OBJ(out, points, polygons);
points.clear(); points.clear();
polygons.clear(); polygons.clear();
std::istringstream in( out.str());
std::istringstream in(out.str());
CGAL::read_OBJ(in,points, polygons); CGAL::read_OBJ(in,points, polygons);
CGAL_assertion(points.size() == 4); CGAL_assertion(points.size() == 4);
CGAL_assertion(polygons.size() == 4); CGAL_assertion(polygons.size() == 4);
} }
#ifdef CGAL_USE_VTK #ifdef CGAL_USE_VTK
template<typename Mesh> template<typename Mesh>
bool test_bgl_vtp(bool binary = false) bool test_bgl_vtp(bool binary = false)
@ -258,20 +262,21 @@ bool test_bgl_vtp(bool binary = false)
CGAL::write_VTP(os, fg, CGAL::parameters::use_binary_mode(binary)); CGAL::write_VTP(os, fg, CGAL::parameters::use_binary_mode(binary));
if(!os) if(!os)
{ {
std::cerr<<"vtp writing failed."<<std::endl; std::cerr << "vtp writing failed." << std::endl;
return false; return false;
} }
os.close(); os.close();
Mesh fg2; Mesh fg2;
if(!CGAL::read_polygon_mesh("tetrahedron.vtp", fg2)) if(!CGAL::read_polygon_mesh("tetrahedron.vtp", fg2))
{ {
std::cerr<<"vtp reading failed."<<std::endl; std::cerr << "vtp reading failed." << std::endl;
return false; return false;
} }
if(num_vertices(fg) != num_vertices(fg2)
|| num_faces(fg) != num_faces(fg2)) if(num_vertices(fg) != num_vertices(fg2) || num_faces(fg) != num_faces(fg2))
{ {
std::cerr<<"Coherence problem. Wrong number of vertices or faces."<<std::endl; std::cerr << "Coherence problem. Wrong number of vertices or faces." << std::endl;
return false; return false;
} }
@ -286,30 +291,33 @@ bool test_bgl_vtp<Polyhedron>(bool binary)
Point(2, 0, 1), Point(3, 0, 0), fg); Point(2, 0, 1), Point(3, 0, 0), fg);
typedef boost::property_map<Polyhedron, CGAL::dynamic_vertex_property_t<std::size_t> >::type VertexIdMap; typedef boost::property_map<Polyhedron, CGAL::dynamic_vertex_property_t<std::size_t> >::type VertexIdMap;
VertexIdMap vid = get(CGAL::dynamic_vertex_property_t<std::size_t>(), fg); VertexIdMap vid = get(CGAL::dynamic_vertex_property_t<std::size_t>(), fg);
std::size_t id = 0; std::size_t id = 0;
for(auto v : vertices(fg)) for(auto v : vertices(fg))
put(vid,v, id++); put(vid,v, id++);
std::ofstream os("tetrahedron.vtp"); std::ofstream os("tetrahedron.vtp");
CGAL::write_VTP(os, fg, CGAL::parameters::vertex_index_map(vid).use_binary_mode(binary)); CGAL::write_VTP(os, fg, CGAL::parameters::vertex_index_map(vid).use_binary_mode(binary));
if(!os) if(!os)
{ {
std::cerr<<"vtp writing failed."<<std::endl; std::cerr << "vtp writing failed." << std::endl;
return false; return false;
} }
os.close(); os.close();
Polyhedron fg2; Polyhedron fg2;
if(!CGAL::read_polygon_mesh("tetrahedron.vtp", fg2)) if(!CGAL::read_polygon_mesh("tetrahedron.vtp", fg2))
{ {
std::cerr<<"vtp reading failed."<<std::endl; std::cerr << "vtp reading failed." << std::endl;
return false; return false;
} }
if(num_vertices(fg) != num_vertices(fg2)
|| num_faces(fg) != num_faces(fg2)) if(num_vertices(fg) != num_vertices(fg2) || num_faces(fg) != num_faces(fg2))
{ {
std::cerr<<"Coherence problem. Wrong number of vertices or faces."<<std::endl; std::cerr << "Coherence problem. Wrong number of vertices or faces." << std::endl;
return false; return false;
} }
return true; return true;
} }
@ -324,19 +332,17 @@ bool test_soup_vtp(bool binary = false)
CGAL::write_VTP(os, points, polys, CGAL::parameters::use_binary_mode(binary)); CGAL::write_VTP(os, points, polys, CGAL::parameters::use_binary_mode(binary));
if(!os) if(!os)
{ {
std::cerr<<"vtp writing failed."<<std::endl; std::cerr << "vtp writing failed." << std::endl;
return false; return false;
} }
os.close(); os.close();
std::vector<Point> soup_points; std::vector<Point> soup_points;
std::vector<std::vector<std::size_t> > soup_polygons; std::vector<std::vector<std::size_t> > soup_polygons;
CGAL::read_VTP("tetrahedron_soup.vtp", soup_points, soup_polygons); CGAL::read_VTP("tetrahedron_soup.vtp", soup_points, soup_polygons);
if(4 != soup_points.size() if(4 != soup_points.size() || 4 != soup_polygons.size())
|| 4 != soup_polygons.size())
{ {
std::cerr<<"Coherence problem. Wrong number of vertices or faces."<<std::endl; std::cerr << "Coherence problem. Wrong number of vertices or faces." << std::endl;
return false; return false;
} }
@ -351,39 +357,46 @@ bool test_bgl_gocad()
FaceGraph fg; FaceGraph fg;
CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0), CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0),
Point(2, 0, 1), Point(3, 0, 0), fg); Point(2, 0, 1), Point(3, 0, 0), fg);
std::ostringstream out; std::ostringstream out;
CGAL::write_GOCAD(out, "tetrahedron", fg); CGAL::write_GOCAD(out, "tetrahedron", fg);
if(out.fail()) if(out.fail())
{ {
std::cerr<<"Tetrahedron writing failed."<<std::endl; std::cerr << "Tetrahedron writing failed." << std::endl;
return false; return false;
} }
FaceGraph fg2; FaceGraph fg2;
std::istringstream in( out.str()); std::istringstream in(out.str());
std::pair<std::string, std::string> cnn; std::pair<std::string, std::string> cnn;
CGAL::read_GOCAD(in, cnn, fg2); CGAL::read_GOCAD(in, cnn, fg2);
if(cnn.first != "tetrahedron"){ if(cnn.first != "tetrahedron")
std::cerr<<"reading error: tetrahedron != "<<cnn.first<<std::endl;
return 1;
}
if( !cnn.second.empty()){
std::cerr<<"reading error: there should be no color."<<std::endl;
return 1;
}
if(in.fail()){
std::cerr<<"Tetrahedron reading failed."<<std::endl;
return false;
}
if(num_vertices(fg2) != 4){
std::cerr<<"Wrong number of vertices: 4 != "<<num_vertices(fg2)<<std::endl;
return false;
}
if(num_faces(fg2) != 4)
{ {
std::cerr<<"Wrong number of faces: 4 != "<<num_faces(fg2)<<std::endl; std::cerr << "reading error: tetrahedron != " <<cnn.first<< std::endl;
return false;
}
if(!cnn.second.empty())
{
std::cerr << "reading error: there should be no color." << std::endl;
return false;
}
if(in.fail())
{
std::cerr << "Tetrahedron reading failed." << std::endl;
return false;
}
if(num_vertices(fg2) != 4)
{
std::cerr << "Wrong number of vertices: 4 != " << num_vertices(fg2) << std::endl;
return false;
}
if(num_faces(fg2) != 4)
{
std::cerr << "Wrong number of faces: 4 != " << num_faces(fg2) << std::endl;
return false; return false;
} }
@ -392,7 +405,6 @@ bool test_bgl_gocad()
template<class FaceGraph> template<class FaceGraph>
bool test_bgl_gocad_with_np() bool test_bgl_gocad_with_np()
{ {
typedef typename boost::property_map<FaceGraph,CGAL::vertex_point_t>::type VertexPointMap; typedef typename boost::property_map<FaceGraph,CGAL::vertex_point_t>::type VertexPointMap;
FaceGraph fg; FaceGraph fg;
CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0), CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0),
@ -403,36 +415,41 @@ bool test_bgl_gocad_with_np()
CGAL::write_GOCAD(out, "tetrahedron", fg, CGAL::parameters::vertex_point_map(vpm)); CGAL::write_GOCAD(out, "tetrahedron", fg, CGAL::parameters::vertex_point_map(vpm));
if(out.fail()) if(out.fail())
{ {
std::cerr<<"Tetrahedron writing failed."<<std::endl; std::cerr << "Tetrahedron writing failed." << std::endl;
return false; return false;
} }
FaceGraph fg2; FaceGraph fg2;
VertexPointMap vpm2 = get(CGAL::vertex_point, fg2); VertexPointMap vpm2 = get(CGAL::vertex_point, fg2);
std::istringstream in( out.str()); std::istringstream in(out.str());
std::pair<std::string, std::string> cnn; std::pair<std::string, std::string> cnn;
CGAL::read_GOCAD(in, cnn, fg2, CGAL::parameters::vertex_point_map(vpm2)); CGAL::read_GOCAD(in, cnn, fg2, CGAL::parameters::vertex_point_map(vpm2));
if(cnn.first != "tetrahedron"){ if(cnn.first != "tetrahedron")
std::cerr<<"reading error: tetrahedron != "<<cnn.first<<std::endl;
return 1;
}
if( !cnn.second.empty()){
std::cerr<<"reading error: there should be no color."<<std::endl;
return 1;
}
if(in.fail()){
std::cerr<<"Tetrahedron reading failed."<<std::endl;
return false;
}
if(num_vertices(fg2) != 4){
std::cerr<<"Wrong number of vertices: 4 != "<<num_vertices(fg2)<<std::endl;
return false;
}
if(num_faces(fg2) != 4)
{ {
std::cerr<<"Wrong number of faces: 4 != "<<num_faces(fg2)<<std::endl; std::cerr << "reading error: tetrahedron != " <<cnn.first<< std::endl;
return false;
}
if(!cnn.second.empty())
{
std::cerr << "reading error: there should be no color." << std::endl;
return false;
}
if(in.fail())
{
std::cerr << "Tetrahedron reading failed." << std::endl;
return false;
}
if(num_vertices(fg2) != 4)
{
std::cerr << "Wrong number of vertices: 4 != " << num_vertices(fg2) << std::endl;
return false;
}
if(num_faces(fg2) != 4)
{
std::cerr << "Wrong number of faces: 4 != " << num_faces(fg2) << std::endl;
return false; return false;
} }
@ -470,7 +487,7 @@ bool test_soup_gocad()
CGAL::write_GOCAD(os, points, polys); CGAL::write_GOCAD(os, points, polys);
if(!os) if(!os)
{ {
std::cerr<<"gocad writing failed."<<std::endl; std::cerr << "gocad writing failed." << std::endl;
return false; return false;
} }
os.close(); os.close();
@ -482,7 +499,7 @@ bool test_soup_gocad()
if(4 != soup_points.size() if(4 != soup_points.size()
|| 4 != soup_polygons.size()) || 4 != soup_polygons.size())
{ {
std::cerr<<"Coherence problem. Wrong number of vertices or faces."<<std::endl; std::cerr << "Coherence problem. Wrong number of vertices or faces." << std::endl;
return false; return false;
} }
@ -499,24 +516,24 @@ bool test_bgl_stl()
CGAL::write_STL(out, fg); CGAL::write_STL(out, fg);
if(out.fail()) if(out.fail())
{ {
std::cerr<<"Tetrahedron writing failed."<<std::endl; std::cerr << "Tetrahedron writing failed." << std::endl;
return false; return false;
} }
FaceGraph fg2; FaceGraph fg2;
std::istringstream in(out.str()); std::istringstream in(out.str());
if(!CGAL::read_STL(in, fg2)){ if(!CGAL::read_STL(in, fg2)){
std::cerr<<"Tetrahedron reading failed."<<std::endl; std::cerr << "Tetrahedron reading failed." << std::endl;
return false; return false;
} }
if(num_vertices(fg2) != 4){ if(num_vertices(fg2) != 4){
std::cerr<<"Wrong number of vertices: 4 != "<<num_vertices(fg2)<<std::endl; std::cerr << "Wrong number of vertices: 4 != " << num_vertices(fg2) << std::endl;
return false; return false;
} }
if(num_faces(fg2) != 4) if(num_faces(fg2) != 4)
{ {
std::cerr<<"Wrong number of faces: 4 != "<<num_faces(fg2)<<std::endl; std::cerr << "Wrong number of faces: 4 != " << num_faces(fg2) << std::endl;
return false; return false;
} }
@ -537,7 +554,7 @@ bool test_bgl_PLY(bool binary = false)
CGAL::write_PLY(out, fg, "hello"); CGAL::write_PLY(out, fg, "hello");
if(out.fail()) if(out.fail())
{ {
std::cerr<<"Tetrahedron writing failed."<<std::endl; std::cerr << "Tetrahedron writing failed." << std::endl;
return false; return false;
} }
std::istringstream in(out.str()); std::istringstream in(out.str());
@ -546,12 +563,14 @@ bool test_bgl_PLY(bool binary = false)
CGAL::set_mode(in, CGAL::IO::BINARY); CGAL::set_mode(in, CGAL::IO::BINARY);
fg.clear(); fg.clear();
if(!CGAL::read_PLY(in, fg)){ if(!CGAL::read_PLY(in, fg))
std::cerr<<"Tetrahedron reading failed."<<std::endl; {
std::cerr << "Tetrahedron reading failed." << std::endl;
return false; return false;
} }
CGAL_assertion(num_vertices(fg) == 4); CGAL_assertion(num_vertices(fg) == 4);
CGAL_assertion(num_faces(fg) == 4); CGAL_assertion(num_faces(fg) == 4);
return true; return true;
} }
@ -561,6 +580,7 @@ bool test_bgl_PLY_with_np(bool binary)
FaceGraph fg; FaceGraph fg;
CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0), CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0),
Point(2, 0, 1), Point(3, 0, 0), fg); Point(2, 0, 1), Point(3, 0, 0), fg);
typedef typename boost::property_map<FaceGraph, CGAL::dynamic_vertex_property_t<CGAL::Color> >::type VertexColorMap; typedef typename boost::property_map<FaceGraph, CGAL::dynamic_vertex_property_t<CGAL::Color> >::type VertexColorMap;
typedef typename boost::property_map<FaceGraph, CGAL::dynamic_face_property_t<CGAL::Color> >::type FaceColorMap; typedef typename boost::property_map<FaceGraph, CGAL::dynamic_face_property_t<CGAL::Color> >::type FaceColorMap;
FaceColorMap fcm = get(CGAL::dynamic_face_property_t<CGAL::Color>(), fg); FaceColorMap fcm = get(CGAL::dynamic_face_property_t<CGAL::Color>(), fg);
@ -582,15 +602,14 @@ bool test_bgl_PLY_with_np(bool binary)
if(binary) if(binary)
CGAL::set_mode(out, CGAL::IO::BINARY); CGAL::set_mode(out, CGAL::IO::BINARY);
CGAL::write_PLY(out, fg, "hello", CGAL::parameters::vertex_color_map(vcm) CGAL::write_PLY(out, fg, "hello", CGAL::parameters::vertex_color_map(vcm).face_color_map(fcm));
.face_color_map(fcm));
if(out.fail()) if(out.fail())
{ {
std::cerr<<"Tetrahedron writing failed."<<std::endl; std::cerr << "Tetrahedron writing failed." << std::endl;
return false; return false;
} }
std::istringstream in(out.str());
std::istringstream in(out.str());
if(binary) if(binary)
CGAL::set_mode(in, CGAL::IO::BINARY); CGAL::set_mode(in, CGAL::IO::BINARY);
@ -599,11 +618,12 @@ bool test_bgl_PLY_with_np(bool binary)
VertexColorMap vcm2 = get(CGAL::dynamic_vertex_property_t<CGAL::Color>(), fg); VertexColorMap vcm2 = get(CGAL::dynamic_vertex_property_t<CGAL::Color>(), fg);
FaceColorMap fcm2 = get(CGAL::dynamic_face_property_t<CGAL::Color>(), fg); FaceColorMap fcm2 = get(CGAL::dynamic_face_property_t<CGAL::Color>(), fg);
if(!CGAL::read_PLY(in, fg, CGAL::parameters::vertex_color_map(vcm2).face_color_map(fcm2))){ if(!CGAL::read_PLY(in, fg, CGAL::parameters::vertex_color_map(vcm2).face_color_map(fcm2))){
std::cerr<<"Tetrahedron reading failed."<<std::endl; std::cerr << "Tetrahedron reading failed." << std::endl;
return false; return false;
} }
CGAL_assertion(num_vertices(fg) == 4); CGAL_assertion(num_vertices(fg) == 4);
CGAL_assertion(num_faces(fg) == 4); CGAL_assertion(num_faces(fg) == 4);
vit = vertices(fg).begin(); vit = vertices(fg).begin();
CGAL_assertion(get(vcm2, *vit++) == CGAL::Color(255,0,0)); CGAL_assertion(get(vcm2, *vit++) == CGAL::Color(255,0,0));
CGAL_assertion(get(vcm2, *vit++) == CGAL::Color(0,255,0)); CGAL_assertion(get(vcm2, *vit++) == CGAL::Color(0,255,0));
@ -616,7 +636,6 @@ bool test_bgl_PLY_with_np(bool binary)
CGAL_assertion(get(fcm2,*fit++)==CGAL::Color(0,0,155)); CGAL_assertion(get(fcm2,*fit++)==CGAL::Color(0,0,155));
CGAL_assertion(get(fcm2,*fit++)==CGAL::Color(155,0,155)); CGAL_assertion(get(fcm2,*fit++)==CGAL::Color(155,0,155));
return true; return true;
} }
@ -626,22 +645,24 @@ int main(int argc, char** argv)
test_polygon_mesh_io<Polyhedron>(); test_polygon_mesh_io<Polyhedron>();
test_polygon_mesh_io<SM>(); test_polygon_mesh_io<SM>();
test_polygon_mesh_io<LCC>(); test_polygon_mesh_io<LCC>();
const char* filename=(argc>1) ? argv[1] : "data/prim.off";
// OFF // OFF
const char* filename = (argc>1) ? argv[1] : "data/prim.off";
test_bgl_OFF<Polyhedron>(filename); test_bgl_OFF<Polyhedron>(filename);
test_bgl_OFF<SM>(filename); test_bgl_OFF<SM>(filename);
test_bgl_OFF<LCC>(filename); test_bgl_OFF<LCC>(filename);
#ifdef CGAL_USE_OPENMESH #ifdef CGAL_USE_OPENMESH
test_bgl_OFF<OMesh>(filename); test_bgl_OFF<OMesh>(filename);
#endif #endif
//polyhedron's overload doesn't care for any np that is not vpm
// polyhedron's overload doesn't care for any np that is not vpm
test_bgl_OFF_with_np<Polyhedron>(); test_bgl_OFF_with_np<Polyhedron>();
test_bgl_OFF_with_np<SM>(); test_bgl_OFF_with_np<SM>();
test_bgl_OFF_with_np<LCC>(); test_bgl_OFF_with_np<LCC>();
#ifdef CGAL_USE_OPENMESH #ifdef CGAL_USE_OPENMESH
test_bgl_OFF_with_np<OMesh>(); test_bgl_OFF_with_np<OMesh>();
#endif #endif
test_soup_off(filename); test_soup_off(filename);
// OBJ // OBJ
test_bgl_OBJ<Polyhedron>(); test_bgl_OBJ<Polyhedron>();
@ -659,70 +680,68 @@ int main(int argc, char** argv)
test_bgl_OBJ_with_np<OMesh>(); test_bgl_OBJ_with_np<OMesh>();
#endif #endif
// PLY
//PLY
if(!test_bgl_PLY<Polyhedron>()) if(!test_bgl_PLY<Polyhedron>())
return 1; return EXIT_FAILURE;
if(!test_bgl_PLY<Polyhedron>(true)) if(!test_bgl_PLY<Polyhedron>(true))
return 1; return EXIT_FAILURE;
if(!test_bgl_PLY<SM>()) if(!test_bgl_PLY<SM>())
return 1; return EXIT_FAILURE;
if(!test_bgl_PLY<SM>(true)) if(!test_bgl_PLY<SM>(true))
return 1; return EXIT_FAILURE;
if(!test_bgl_PLY_with_np<Polyhedron>(false)) if(!test_bgl_PLY_with_np<Polyhedron>(false))
return 1; return EXIT_FAILURE;
if(!test_bgl_PLY_with_np<Polyhedron>(true)) if(!test_bgl_PLY_with_np<Polyhedron>(true))
return 1; return EXIT_FAILURE;
if(!test_bgl_PLY_with_np<SM>(false)) if(!test_bgl_PLY_with_np<SM>(false))
return 1; return EXIT_FAILURE;
if(!test_bgl_PLY_with_np<SM>(true)) if(!test_bgl_PLY_with_np<SM>(true))
return 1; return EXIT_FAILURE;
// GOCAD // GOCAD
if(!test_bgl_gocad<Polyhedron>()) if(!test_bgl_gocad<Polyhedron>())
return 1; return EXIT_FAILURE;
if(!test_bgl_gocad<SM>()) if(!test_bgl_gocad<SM>())
return 1; return EXIT_FAILURE;
if(!test_bgl_gocad<LCC>()) if(!test_bgl_gocad<LCC>())
return 1; return EXIT_FAILURE;
if(!test_bgl_gocad_with_np<Polyhedron>()) if(!test_bgl_gocad_with_np<Polyhedron>())
return 1; return EXIT_FAILURE;
if(!test_bgl_gocad_with_np<SM>()) if(!test_bgl_gocad_with_np<SM>())
return 1; return EXIT_FAILURE;
if(!test_bgl_gocad_with_np<LCC>()) if(!test_bgl_gocad_with_np<LCC>())
return 1; return EXIT_FAILURE;
if(!test_soup_gocad()) if(!test_soup_gocad())
return 1; return EXIT_FAILURE;
// STL // STL
if(!test_bgl_stl<Polyhedron>()) if(!test_bgl_stl<Polyhedron>())
return 1; return EXIT_FAILURE;
if(!test_bgl_stl<SM>()) if(!test_bgl_stl<SM>())
return 1; return EXIT_FAILURE;
if(!test_bgl_stl<LCC>()) if(!test_bgl_stl<LCC>())
return 1; return EXIT_FAILURE;
// VTP // VTP
#ifdef CGAL_USE_VTK #ifdef CGAL_USE_VTK
if(!test_bgl_vtp<Polyhedron>(false)) if(!test_bgl_vtp<Polyhedron>(false))
return 1; return EXIT_FAILURE;
if(!test_bgl_vtp<SM>(false)) if(!test_bgl_vtp<SM>(false))
return 1; return EXIT_FAILURE;
if(!test_bgl_vtp<LCC>(false)) if(!test_bgl_vtp<LCC>(false))
return 1; return EXIT_FAILURE;
if(!test_soup_vtp(false)) if(!test_soup_vtp(false))
return 1; return EXIT_FAILURE;
if(!test_bgl_vtp<Polyhedron>(true)) if(!test_bgl_vtp<Polyhedron>(true))
return 1; return EXIT_FAILURE;
if(!test_bgl_vtp<SM>(true)) if(!test_bgl_vtp<SM>(true))
return 1; return EXIT_FAILURE;
if(!test_bgl_vtp<LCC>(true)) if(!test_bgl_vtp<LCC>(true))
return 1; return EXIT_FAILURE;
if(!test_soup_vtp(true)) if(!test_soup_vtp(true))
return 1; return EXIT_FAILURE;
#endif #endif
return EXIT_SUCCESS; return EXIT_SUCCESS;