Add skeletons for CGAL::read_PS, CGAL::read_PM, PMP::read_PM

This commit is contained in:
Mael Rouxel-Labbé 2020-01-29 11:44:03 +01:00
parent ae1c28c885
commit 7f6bf9b3cb
3 changed files with 245 additions and 0 deletions

View File

@ -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 <CGAL/boost/graph/IO/GOCAD.h>
#include <CGAL/boost/graph/IO/INP.h>
#include <CGAL/boost/graph/IO/OBJ.h>
#include <CGAL/boost/graph/IO/OFF.h>
#include <CGAL/boost/graph/IO/STL.h>
#include <CGAL/boost/graph/IO/VTK.h>
#include <CGAL/boost/graph/IO/WRL.h>
#include <algorithm>
#include <iostream>
#include <string>
namespace CGAL {
// @todo also need named parameters overload
template <typename FaceGraph>
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 <typename FaceGraph>
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

View File

@ -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 <CGAL/Polygon_mesh_processing/orient_polygon_soup.h>
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h>
#include <CGAL/IO/polygon_soup_io.h>
#include <CGAL/boost/graph/IO/polygon_mesh_io.h>
#include <CGAL/boost/graph/Named_function_parameters.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
namespace CGAL {
namespace Polygon_mesh_processing {
namespace IO {
// @todo also need named parameters overload
template <typename FaceGraph, typename CGAL_BGL_NP_TEMPLATE_PARAMETERS>
bool read_polygon_mesh(const std::string& filename,
FaceGraph& g,
const CGAL_BGL_NP_CLASS& np)
{
typedef typename CGAL::GetVertexPointMap<FaceGraph, CGAL_BGL_NP_CLASS>::type VPM;
typedef typename boost::property_traits<VPM>::value_type Point;
bool ok = ::CGAL::read_polygon_mesh(filename, g, np);
if(!ok)
{
std::vector<Point> points;
std::vector<std::vector<std::size_t> > 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

View File

@ -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 <CGAL/IO/3MF.h>
#include <CGAL/IO/OBJ.h>
#include <CGAL/IO/OFF.h>
// #include <CGAL/IO/OI.h>
#include <CGAL/IO/PLY.h>
#include <CGAL/IO/STL.h>
// #include <CGAL/IO/VRML.h>
// #include <CGAL/IO/VTK.h>
// #include <CGAL/IO/WKT.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
namespace CGAL {
template <typename PointRange, typename PolygonRange>
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 <typename PointRange, typename PolygonRange>
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