move OM.h IO header to BGL package

adapt demo and examples
BGL example TriMesh.cpp does not compile
This commit is contained in:
Jane Tournois 2024-10-23 11:58:02 +02:00
parent b7b48b107c
commit cddb3d5c56
6 changed files with 170 additions and 129 deletions

View File

@ -1,16 +1,13 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
#include <CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h>
#include <CGAL/boost/graph/iterator.h>
#include <CGAL/IO/polygon_mesh_io.h>
#include <CGAL/IO/OM.h>
#include <CGAL/property_map.h>
#include <CGAL/Surface_mesh.h>
#include <iostream>
#include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;

View File

@ -1,17 +1,18 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
#include <CGAL/boost/graph/graph_traits_TriMesh_ArrayKernelT.h>
#include <CGAL/boost/graph/properties_TriMesh_ArrayKernelT.h>
#include <CGAL/boost/graph/iterator.h>
#include <CGAL/boost/graph/Euler_operations.h>
#include <CGAL/IO/polygon_mesh_io.h>
#include <CGAL/boost/graph/Euler_operations.h>
#include <CGAL/mesh_segmentation.h>
#include <CGAL/property_map.h>
#include <iostream>
#include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;

View File

@ -17,6 +17,7 @@
#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/OM.h>
#include <CGAL/boost/graph/IO/PLY.h>
#include <CGAL/boost/graph/IO/STL.h>
#include <CGAL/boost/graph/IO/VTK.h>
@ -80,6 +81,7 @@ bool read_polygon_mesh(std::istream& is,
* Supported file formats are the following:
* - \ref IOStreamOFF (`.off`)
* - \ref IOStreamOBJ (`.obj`)
* - \ref IOStreamOM (`.om`)
* - \ref IOStreamSTL (`.stl`)
* - \ref IOStreamPLY (`.ply`)
* - \ref IOStreamGocad (`.ts`)
@ -138,6 +140,10 @@ bool read_polygon_mesh(const std::string& fname,
return read_OBJ(fname, g, np);
else if(ext == "off")
return read_OFF(fname, g, np);
#ifdef CGAL_USE_OPENMESH
else if(ext == "om")
return read_OM(fname, g, np);
#endif
else if(ext == "ply")
return read_PLY(fname, g, np);
else if(ext == "stl")

View File

@ -0,0 +1,150 @@
// Copyright (c) 2024 GeometryFactory
//
// This file is part of CGAL (www.cgal.org);
//
// $URL$
// $Id$
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
//
// Author(s) : Andreas Fabri
#ifndef CGAL_BGL_IO_OM_H
#define CGAL_BGL_IO_OM_H
#if defined(CGAL_USE_OPENMESH) || defined(DOXYGEN_RUNNING)
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
#include <CGAL/boost/graph/copy_face_graph.h>
#include <CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h>
#include <CGAL/boost/graph/iterator.h>
#include <CGAL/property_map.h>
#include <CGAL/Named_function_parameters.h>
#include <CGAL/boost/graph/named_params_helper.h>
#include <iostream>
#include <fstream>
#include <map>
namespace CGAL {
namespace IO {
template <typename Graph, typename VFeaturePM, typename EFeaturePM>
bool read_OM(const std::string& fname, Graph& g, VFeaturePM vfpm, EFeaturePM efpm)
{
typedef OpenMesh::PolyMesh_ArrayKernelT<> OMesh;
typedef typename boost::graph_traits<OMesh>::vertex_descriptor om_vertex_descriptor;
typedef typename boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor;
typedef typename boost::graph_traits<OMesh>::halfedge_descriptor om_halfedge_descriptor;
typedef typename boost::graph_traits<Graph>::halfedge_descriptor halfedge_descriptor;
OMesh omesh;
OpenMesh::IO::Options options = OpenMesh::IO::Options::Status;
bool ok = OpenMesh::IO::read_mesh(omesh, fname, options);
if(! ok){
return false;
}
std::map<om_vertex_descriptor, vertex_descriptor> v2v;
auto v2vpmap = boost::make_assoc_property_map(v2v);
std::map<om_halfedge_descriptor, halfedge_descriptor> h2h;
auto h2hpmap = boost::make_assoc_property_map(h2h);
CGAL::copy_face_graph<OMesh,Graph>(omesh, g,
CGAL::parameters::vertex_to_vertex_map(v2vpmap)
.halfedge_to_halfedge_map(h2hpmap));
if(options.vertex_has_status()){
for(auto v : vertices(omesh)){
put(vfpm, v2v[v], omesh.status(v).feature());
}
}
if(options.edge_has_status()){
for(auto e : edges(omesh)){
auto sme = edge(h2h[halfedge(e,omesh)], g);
put(efpm, sme , omesh.status(OpenMesh::EdgeHandle(e.idx())).feature());
}
}
return true;
}
template <typename Graph, typename CGAL_NP_TEMPLATE_PARAMETERS>
bool read_OM(const std::string& fname,
Graph& g,
const CGAL_NP_CLASS& np = parameters::default_values())
{
using vertex_descriptor = typename boost::graph_traits<Graph>::vertex_descriptor;
using edge_descriptor = typename boost::graph_traits<Graph>::edge_descriptor;
using CGAL::parameters::get_parameter;
using CGAL::parameters::choose_parameter;
auto vfpm = choose_parameter(get_parameter(np, internal_np::vertex_is_constrained),
CGAL::Constant_property_map<vertex_descriptor, bool>(false));
auto efpm = choose_parameter(get_parameter(np, internal_np::edge_is_constrained),
CGAL::Constant_property_map<edge_descriptor, bool>(false));
return read_OM(fname, g, vfpm, efpm);
}
template <typename Graph, typename VFeaturePM, typename EFeaturePM>
bool write_OM(std::string fname, Graph& g, VFeaturePM vfpm, EFeaturePM efpm)
{
typedef OpenMesh::PolyMesh_ArrayKernelT<> OMesh;
typedef typename boost::graph_traits<OMesh>::vertex_descriptor om_vertex_descriptor;
typedef typename boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor;
typedef typename boost::graph_traits<OMesh>::halfedge_descriptor om_halfedge_descriptor;
typedef typename boost::graph_traits<Graph>::halfedge_descriptor halfedge_descriptor;
std::map<vertex_descriptor, om_vertex_descriptor> v2v;
auto v2vpmap = boost::make_assoc_property_map(v2v);
std::map<halfedge_descriptor, om_halfedge_descriptor> h2h;
auto h2hpmap = boost::make_assoc_property_map(h2h);
OMesh omesh;
CGAL::copy_face_graph<Graph, OMesh>(g, omesh,
CGAL::parameters::vertex_to_vertex_map(v2vpmap)
.halfedge_to_halfedge_map(h2hpmap));
omesh.request_edge_status();
omesh.request_vertex_status();
for (auto h : halfedges(g))
{
om_halfedge_descriptor omh = h2h.at(h);
const bool isfeature = get(efpm, edge(h, g));
omesh.status(omesh.edge_handle(omh)).set_feature(isfeature);
}
for (auto v : vertices(g))
{
auto omv = v2v.at(v);
const bool isfeature = get(vfpm, v);
omesh.status(omv).set_feature(isfeature);
}
return OpenMesh::IO::write_mesh(omesh, fname, OpenMesh::IO::Options::Status);
}
template <typename Graph, typename CGAL_NP_TEMPLATE_PARAMETERS>
bool write_OM(const std::string& fname,
Graph& g,
const CGAL_NP_CLASS& np = parameters::default_values())
{
using vertex_descriptor = typename boost::graph_traits<Graph>::vertex_descriptor;
using edge_descriptor = typename boost::graph_traits<Graph>::edge_descriptor;
using CGAL::parameters::get_parameter;
using CGAL::parameters::choose_parameter;
auto vfpm = choose_parameter(get_parameter(np, internal_np::vertex_is_constrained),
CGAL::Constant_property_map<vertex_descriptor, bool>(false));
auto efpm = choose_parameter(get_parameter(np, internal_np::edge_is_constrained),
CGAL::Constant_property_map<edge_descriptor, bool>(false));
return write_OM(fname, g, vfpm, efpm);
}
} // namespace IO
} // namespace CGAL
#endif // CGAL_USE_OPENMESH || DOXYGEN_RUNNING
#endif // CGAL_IO_OM

View File

@ -8,7 +8,7 @@
#include <CGAL/Three/Three.h>
#include "Scene_polyhedron_selection_item.h"
#include <CGAL/IO/OM.h>
#include <CGAL/boost/graph/IO/OM.h>
#include <CGAL/boost/graph/io.h>
#include <QColor>
@ -89,7 +89,10 @@ load(QFileInfo fileinfo, bool& ok, bool add_to_scene){
// Try building a surface_mesh
SMesh* sm = new SMesh();
ok = CGAL::IO::read_OM((const char*)fileinfo.filePath().toUtf8(), *sm, sm_vfeature_pmap, sm_efeature_pmap);
ok = CGAL::IO::read_OM((const char*)fileinfo.filePath().toUtf8(),
*sm,
CGAL::parameters::vertex_is_constrained_map(sm_vfeature_pmap)
.edge_is_constrained_map(sm_efeature_pmap));
if(!ok || !sm->is_valid() || sm->is_empty()){
std::cerr << "Error: Invalid facegraph" << std::endl;
@ -176,18 +179,13 @@ save(QFileInfo fileinfo, QList<CGAL::Three::Scene_item*>& items)
{
res = CGAL::IO::write_OM((const char*)fileinfo.filePath().toUtf8()
, *sm_item->face_graph()
, selection_item->constrained_vertices_pmap()
, selection_item->constrained_edges_pmap());
, CGAL::parameters::vertex_is_constrained_map(selection_item->constrained_vertices_pmap())
.edge_is_constrained_map(selection_item->constrained_edges_pmap()));
}
else
{
using edge_descriptor = boost::graph_traits<SMesh>::edge_descriptor;
using vertex_descriptor = boost::graph_traits<SMesh>::vertex_descriptor;
res = CGAL::IO::write_OM((const char*)fileinfo.filePath().toUtf8()
, *sm_item->face_graph()
, CGAL::Constant_property_map<vertex_descriptor, bool>(false)
, CGAL::Constant_property_map<edge_descriptor, bool>(false));
, *sm_item->face_graph());
}
if (res)

View File

@ -1,111 +0,0 @@
// Copyright (c) 2024 GeometryFactory
//
// This file is part of CGAL (www.cgal.org);
//
// $URL$
// $Id$
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
//
// Author(s) : Andreas Fabri
#ifndef CGAL_IO_OM_H
#define CGAL_IO_OM_H
#if defined(CGAL_USE_OPENMESH) || defined(DOXYGEN_RUNNING)
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
#include <CGAL/boost/graph/copy_face_graph.h>
#include <CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h>
#include <CGAL/boost/graph/iterator.h>
#include <CGAL/property_map.h>
#include <iostream>
#include <fstream>
#include <map>
namespace CGAL {
namespace IO {
template <typename SM, typename VFeaturePM, typename EFeaturePM>
bool read_OM(std::string fname, SM& sm, VFeaturePM vfpm, EFeaturePM efpm)
{
typedef OpenMesh::PolyMesh_ArrayKernelT<> OMesh;
typedef typename boost::graph_traits<OMesh>::vertex_descriptor om_vertex_descriptor;
typedef typename boost::graph_traits<SM>::vertex_descriptor sm_vertex_descriptor;
typedef typename boost::graph_traits<OMesh>::halfedge_descriptor om_halfedge_descriptor;
typedef typename boost::graph_traits<SM>::halfedge_descriptor sm_halfedge_descriptor;
OMesh omesh;
OpenMesh::IO::Options options = OpenMesh::IO::Options::Status;
bool ok = OpenMesh::IO::read_mesh(omesh, fname, options);
if(! ok){
return false;
}
std::map<om_vertex_descriptor,sm_vertex_descriptor> v2v;
auto v2vpmap = boost::make_assoc_property_map(v2v);
std::map<om_halfedge_descriptor,sm_halfedge_descriptor> h2h;
auto h2hpmap = boost::make_assoc_property_map(h2h);
CGAL::copy_face_graph<OMesh,SM>(omesh, sm, CGAL::parameters::vertex_to_vertex_map(v2vpmap).halfedge_to_halfedge_map(h2hpmap));
if(options.vertex_has_status()){
for(auto v : vertices(omesh)){
put(vfpm, v2v[v], omesh.status(v).feature());
}
}
if(options.edge_has_status()){
for(auto e : edges(omesh)){
auto sme = edge(h2h[halfedge(e,omesh)], sm);
put(efpm, sme , omesh.status(OpenMesh::EdgeHandle(e.idx())).feature());
}
}
return true;
}
template <typename SM, typename VFeaturePM, typename EFeaturePM>
bool write_OM(std::string fname, SM& sm, VFeaturePM vfpm, EFeaturePM efpm)
{
typedef OpenMesh::PolyMesh_ArrayKernelT<> OMesh;
typedef typename boost::graph_traits<OMesh>::vertex_descriptor om_vertex_descriptor;
typedef typename boost::graph_traits<SM>::vertex_descriptor sm_vertex_descriptor;
typedef typename boost::graph_traits<OMesh>::halfedge_descriptor om_halfedge_descriptor;
typedef typename boost::graph_traits<SM>::halfedge_descriptor sm_halfedge_descriptor;
std::map<sm_vertex_descriptor, om_vertex_descriptor> v2v;
auto v2vpmap = boost::make_assoc_property_map(v2v);
std::map<sm_halfedge_descriptor, om_halfedge_descriptor> h2h;
auto h2hpmap = boost::make_assoc_property_map(h2h);
OMesh omesh;
CGAL::copy_face_graph<SM, OMesh>(sm, omesh,
CGAL::parameters::vertex_to_vertex_map(v2vpmap).halfedge_to_halfedge_map(h2hpmap));
omesh.request_edge_status();
omesh.request_vertex_status();
for (auto h : halfedges(sm))
{
om_halfedge_descriptor omh = h2h.at(h);
const bool isfeature = get(efpm, edge(h, sm));
omesh.status(omesh.edge_handle(omh)).set_feature(isfeature);
}
for (auto v : vertices(sm))
{
auto omv = v2v.at(v);
const bool isfeature = get(vfpm, v);
omesh.status(omv).set_feature(isfeature);
}
return OpenMesh::IO::write_mesh(omesh, fname, OpenMesh::IO::Options::Status);
}
} // namespace IO
} // namespace CGAL
#endif // CGAL_USE_OPENMESH || DOXYGEN_RUNNING
#endif // CGAL_IO_OM