Skip to content

Commit

Permalink
IO of OpenMesh files - use doubles instead of floats (#8612)
Browse files Browse the repository at this point in the history
## Summary of Changes

The default OpenMesh point type is made of `float`s. This PR changes the
traits we use in CGAL to you `double`s and ensure that reading an
off/writing an om/reading om gives the same result back.
This PR completes #8427

## Release Management

* Affected package(s): BGL, Demo
* License and copyright ownership: unchanged
  • Loading branch information
sloriot authored Nov 20, 2024
2 parents 4b1c130 + 7632a01 commit 0957261
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
19 changes: 14 additions & 5 deletions BGL/include/CGAL/boost/graph/IO/OM.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
#include <OpenMesh/Core/Mesh/Traits.hh>

#include <CGAL/boost/graph/copy_face_graph.h>
#include <CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h>
Expand All @@ -34,7 +35,7 @@ namespace internal {
template <typename Graph, typename VPM, typename VFeaturePM, typename EFeaturePM>
bool read_OM(const std::string& fname, Graph& g, VPM vpm, VFeaturePM vfpm, EFeaturePM efpm)
{
typedef OpenMesh::PolyMesh_ArrayKernelT<> OMesh;
typedef OpenMesh::PolyMesh_ArrayKernelT<OpenMesh::DefaultTraitsDouble> 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;
Expand Down Expand Up @@ -73,9 +74,10 @@ bool read_OM(const std::string& fname, Graph& g, VPM vpm, VFeaturePM vfpm, EFeat
}

template <typename Graph, typename VPM, typename VFeaturePM, typename EFeaturePM>
bool write_OM(std::string fname, const Graph& g, VPM vpm, VFeaturePM vfpm, EFeaturePM efpm)
bool write_OM(std::string fname, const Graph& g, VPM vpm, VFeaturePM vfpm, EFeaturePM efpm,
const std::streamsize precision)
{
typedef OpenMesh::PolyMesh_ArrayKernelT<> OMesh;
typedef OpenMesh::PolyMesh_ArrayKernelT<OpenMesh::DefaultTraitsDouble> 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;
Expand Down Expand Up @@ -108,7 +110,7 @@ bool write_OM(std::string fname, const Graph& g, VPM vpm, VFeaturePM vfpm, EFeat
omesh.status(omv).set_feature(isfeature);
}

return OpenMesh::IO::write_mesh(omesh, fname, OpenMesh::IO::Options::Status);
return OpenMesh::IO::write_mesh(omesh, fname, OpenMesh::IO::Options::Status, precision);
}
} // end of internal namespace

Expand Down Expand Up @@ -208,6 +210,11 @@ bool read_OM(const std::string& fname,
\cgalParamType{a class model of `ReadablePropertyMap` with `boost::graph_traits<Graph>::%vertex_descriptor`
as key type and `bool` as value type.}
\cgalParamNEnd
\cgalParamNBegin{stream_precision}
\cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream}
\cgalParamType{int}
\cgalParamDefault{the precision of the stream `os`}
\cgalParamNEnd
\cgalNamedParamsEnd
\returns `true` if writing was successful, `false` otherwise.
Expand All @@ -228,7 +235,9 @@ bool write_OM(const std::string& fname,
CGAL::Constant_property_map<edge_descriptor, bool>(false));
auto vpm = choose_parameter(get_parameter(np, internal_np::vertex_point),
get_const_property_map(vertex_point, g));
return internal::write_OM(fname, g, vpm, vfpm, efpm);
std::streamsize precision = choose_parameter(get_parameter(np, internal_np::stream_precision),
18);
return internal::write_OM(fname, g, vpm, vfpm, efpm, precision);
}


Expand Down
6 changes: 4 additions & 2 deletions Lab/demo/Lab/Plugins/IO/OM_io_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,14 @@ save(QFileInfo fileinfo, QList<CGAL::Three::Scene_item*>& items)
res = CGAL::IO::write_OM((const char*)fileinfo.filePath().toUtf8()
, *sm_item->face_graph()
, CGAL::parameters::vertex_is_constrained_map(selection_item->constrained_vertices_pmap())
.edge_is_constrained_map(selection_item->constrained_edges_pmap()));
.edge_is_constrained_map(selection_item->constrained_edges_pmap())
.stream_precision(17));
}
else
{
res = CGAL::IO::write_OM((const char*)fileinfo.filePath().toUtf8()
, *sm_item->face_graph());
, *sm_item->face_graph()
, CGAL::parameters::stream_precision(17));
}

if (res)
Expand Down

0 comments on commit 0957261

Please sign in to comment.