diff --git a/BGL/include/CGAL/boost/graph/IO/polygon_mesh_io.h b/BGL/include/CGAL/boost/graph/IO/polygon_mesh_io.h new file mode 100644 index 00000000000..2d54e7c7494 --- /dev/null +++ b/BGL/include/CGAL/boost/graph/IO/polygon_mesh_io.h @@ -0,0 +1,87 @@ +// Copyright (c) 2020 GeometryFactory Sarl (France). +// All rights reserved. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Mael Rouxel-Labbé + +#ifndef CGAL_BGL_IO_POLYGON_MESH_IO_H +#define CGAL_BGL_IO_POLYGON_MESH_IO_H + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace CGAL { + +// @todo also need named parameters overload +template +bool read_polygon_mesh(const std::string& filename, + FaceGraph& g) +{ + std::string::size_type dot(filename.rfind(".")); + if(dot == std::string::npos) + return false; + + std::string ext = filename.substr(dot+1, filename.length() - dot - 1); + std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); + + // extension determines reader + if(ext == "obj") + return read_OBJ(filename, g); + else if(ext == "off") // @fixme coff, stoff, etc. + return read_OFF(filename, g); + else if(ext == "ply") + return read_PLY(filename, g); + else if(ext == "stl") + return read_STL(filename, g); + + std::cerr << "Cannot open file with extension: " << ext << std::endl; + + return false; +} + +template +bool write_polygon_mesh(const std::string& filename, + const FaceGraph& g) +{ + std::string::size_type dot(filename.rfind(".")); + if(dot == std::string::npos) + return false; + + std::string ext = filename.substr(dot+1, filename.length()-dot-1); + std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); + + // extension determines writer + if(ext == "obj") + return write_OBJ(filename, g); + else if(ext == "off") // @fixme coff, stoff, etc. + return write_OFF(filename, g); + else if(ext == "ply") + return write_PLY(filename, g); + else if(ext == "stl") + return write_STL(filename, g); + + std::cerr << "Cannot open file with extension: " << ext << std::endl; + + return false; +} + +} // namespace CGAL + +#endif // CGAL_BGL_IO_POLYGON_MESH_IO_H diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h new file mode 100644 index 00000000000..43ab697af4b --- /dev/null +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h @@ -0,0 +1,67 @@ +// Copyright (c) 2020 GeometryFactory Sarl (France). +// All rights reserved. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Mael Rouxel-Labbé + +#ifndef CGAL_PMP_IO_POLYGON_MESH_IO_H +#define CGAL_PMP_IO_POLYGON_MESH_IO_H + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +namespace CGAL { +namespace Polygon_mesh_processing { +namespace IO { + +// @todo also need named parameters overload +template +bool read_polygon_mesh(const std::string& filename, + FaceGraph& g, + const CGAL_BGL_NP_CLASS& np) +{ + typedef typename CGAL::GetVertexPointMap::type VPM; + typedef typename boost::property_traits::value_type Point; + + bool ok = ::CGAL::read_polygon_mesh(filename, g, np); + + if(!ok) + { + std::vector points; + std::vector > faces; + ok = CGAL::read_polygon_soup(in, points, faces, np); + if(!ok) + return false; + + ok = CGAL::Polygon_mesh_processing::orient_polygon_soup(points, faces); + if(!ok) + return false; + + CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(points, faces, g); + } + + return true; +} + +} // namespace IO +} // namespace Polygon_mesh_processing +} // namespace CGAL + +#endif // CGAL_PMP_IO_POLYGON_MESH_IO_H diff --git a/Stream_support/include/CGAL/IO/polygon_soup_io.h b/Stream_support/include/CGAL/IO/polygon_soup_io.h new file mode 100644 index 00000000000..c3cbe81ce77 --- /dev/null +++ b/Stream_support/include/CGAL/IO/polygon_soup_io.h @@ -0,0 +1,91 @@ +// Copyright (c) 2020 GeometryFactory Sarl (France). +// All rights reserved. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// Author(s) : Mael Rouxel-Labbé + +#ifndef CGAL_IO_READ_POLYGON_SOUP_H +#define CGAL_IO_READ_POLYGON_SOUP_H + +// #include +#include +#include +// #include +#include +#include +// #include +// #include +// #include + +#include +#include +#include +#include + +namespace CGAL { + +template +bool read_polygon_soup(const std::string& filename, + PointRange& points, + PolygonRange& polygons) +{ + std::string::size_type dot(filename.rfind(".")); + if(dot == std::string::npos) + return false; + + std::string ext = filename.substr(dot+1, filename.length() - dot - 1); + std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); + + // extension determines reader + if(ext == "obj") + return read_OBJ(filename, points, polygons); + else if(ext == "off") // @fixme coff, stoff, etc. + return read_OFF(filename, points, polygons); + else if(ext == "ply") + return read_PLY(filename, points, polygons); + else if(ext == "stl") + return read_STL(filename, points, polygons); + + std::cerr << "Cannot open file with extension: " << ext << std::endl; + + return false; +} + +template +bool write_polygon_soup(const std::string& filename, + const PointRange& points, + const PolygonRange& polygons) +{ + std::string::size_type dot(filename.rfind(".")); + if(dot == std::string::npos) + return false; + + std::string ext = filename.substr(dot+1, filename.length()-dot-1); + std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower); + + // extension determines writer + if(ext == "obj") + return write_OBJ(filename, points, polygons); + else if(ext == "off") // @fixme coff, stoff, etc. + return write_OFF(filename, points, polygons); + else if(ext == "ply") + return write_PLY(filename, points, polygons); + else if(ext == "stl") + return write_STL(filename, points, polygons); + + std::cerr << "Cannot open file with extension: " << ext << std::endl; + + return false; +} + +} // namespace CGAL + +#endif // CGAL_IO_READ_POLYGON_SOUP_H