From 2d72f211072ae7d002a3138cc3c5c45937819cb6 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 20 Nov 2023 13:09:59 +0000 Subject: [PATCH 01/39] IO: read_PLY() for Epeck --- .../include/CGAL/IO/PLY/PLY_writer.h | 23 +++++++++++++++++++ .../include/CGAL/Surface_mesh/IO/PLY.h | 7 +++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Stream_support/include/CGAL/IO/PLY/PLY_writer.h b/Stream_support/include/CGAL/IO/PLY/PLY_writer.h index be015411a56f..af8d2fc3ea23 100644 --- a/Stream_support/include/CGAL/IO/PLY/PLY_writer.h +++ b/Stream_support/include/CGAL/IO/PLY/PLY_writer.h @@ -253,6 +253,29 @@ class Property_printer } }; +template +class Double_coordinate_printer + : public Abstract_property_printer +{ + PropertyMap m_pmap; +public: + Double_coordinate_printer(const PropertyMap& pmap) : m_pmap(pmap) { } + + virtual void print(std::ostream& stream, const Index& index) + { + write(stream, to_double(get(m_pmap, index).x())); + if (get_mode(stream) == CGAL::IO::ASCII) { + stream << " "; + } + write(stream, to_double(get(m_pmap, index).y())); + if (get_mode(stream) == CGAL::IO::ASCII) { + stream << " "; + } + write(stream, to_double(get(m_pmap, index).z())); + } +}; + + template ::value_type> diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h index 324b78a1af41..fe482b997c7d 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h @@ -449,14 +449,19 @@ bool fill_simplex_specific_header(std::ostream& os, os << "property float x" << std::endl << "property float y" << std::endl << "property float z" << std::endl; + + printers.push_back(new Property_printer(sm.points())); } else { os << "property double x" << std::endl << "property double y" << std::endl << "property double z" << std::endl; + + + printers.push_back(new Double_coordinate_printer(sm.points())); } - printers.push_back(new Property_printer(sm.points())); + return true; } From 40dee7d2a0bd8d63d3d148c476270d1b1809c4c5 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 20 Nov 2023 14:04:56 +0000 Subject: [PATCH 02/39] whitespace --- Stream_support/include/CGAL/IO/PLY/PLY_writer.h | 2 +- Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Stream_support/include/CGAL/IO/PLY/PLY_writer.h b/Stream_support/include/CGAL/IO/PLY/PLY_writer.h index af8d2fc3ea23..cec8e1b539eb 100644 --- a/Stream_support/include/CGAL/IO/PLY/PLY_writer.h +++ b/Stream_support/include/CGAL/IO/PLY/PLY_writer.h @@ -263,7 +263,7 @@ class Double_coordinate_printer virtual void print(std::ostream& stream, const Index& index) { - write(stream, to_double(get(m_pmap, index).x())); + write(stream, to_double(get(m_pmap, index).x())); if (get_mode(stream) == CGAL::IO::ASCII) { stream << " "; } diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h index fe482b997c7d..869de8aea91a 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h @@ -458,10 +458,10 @@ bool fill_simplex_specific_header(std::ostream& os, << "property double y" << std::endl << "property double z" << std::endl; - + printers.push_back(new Double_coordinate_printer(sm.points())); } - + return true; } @@ -957,6 +957,8 @@ namespace IO { /// \cgalNamedParamsEnd /// /// \returns `true` if writing was successful, `false` otherwise. + + template bool write_PLY(std::ostream& os, From 5eb93449c50f1b577e585351e1a60fef4e5822f8 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 22 Nov 2023 08:37:13 +0000 Subject: [PATCH 03/39] Fix ascii output --- .../doc/Stream_support/IOstream.txt | 25 +++++++++---------- .../include/CGAL/IO/PLY/PLY_writer.h | 12 ++++----- Stream_support/include/CGAL/IO/io.h | 10 ++++---- .../include/CGAL/Surface_mesh/IO/PLY.h | 3 --- 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/Stream_support/doc/Stream_support/IOstream.txt b/Stream_support/doc/Stream_support/IOstream.txt index cfdf25073ec2..4ea5245219d9 100644 --- a/Stream_support/doc/Stream_support/IOstream.txt +++ b/Stream_support/doc/Stream_support/IOstream.txt @@ -69,7 +69,7 @@ as a sequence of four byte. The format depends on the machine. The mode `PRETTY` serves mainly for debugging as the type of the geometric object is written, as well as the data defining the object. For example -for a point at the origin with Cartesian double coordinates, the output +for a point at the origin with %Cartesian double coordinates, the output would be `PointC2(0.0, 0.0)`. At the moment \cgal does not provide input operations for pretty printed data. By default a stream is in \ascii mode. @@ -94,25 +94,25 @@ bool is_pretty(std::ios& s); \subsection IOstreamInput Input Operator \cgal defines input operators for classes that are derived -from the class `istream`. This allows to read from istreams +from the class `std::istream`. This allows to read from istreams as `std::cin`, as well as from `std::istringstream` and `std::ifstream`. The input operator is defined for all classes in the \cgal `Kernel`. Let `is` be an input stream. \code{.cpp} // Extracts object `c` from the stream `is`. Returns `is`. -istream& operator>>(istream& is, Class c); +istream& operator>>(istream& is, Class& c); \endcode \code{.cpp} #include #include -#include +#include #include -typedef CGAL::Point_2< CGAL::Cartesian > Point; -typedef CGAL::Segment_2< CGAL::Cartesian > Segment; +typedef CGAL::Point_2< CGAL::Simple_cartesian > Point; +typedef CGAL::Segment_2< CGAL::Simple_cartesian > Segment; int main() @@ -123,7 +123,7 @@ main() CGAL::IO::set_ascii_mode(std::cin); std::cin >> p >> q; - std::ifstream f("data.txt"); + std::ifstream f("data.txt", std::ios::binary); CGAL::IO::set_binary_mode(f); f >> s >> p; @@ -150,11 +150,11 @@ ostream& operator<<(ostream& os, Class c); #include #include -#include +#include #include -typedef CGAL::Point_2< CGAL::Cartesian > Point; -typedef CGAL::Segment_2< CGAL::Cartesian > Segment; +typedef CGAL::Point_2< CGAL::Simple_cartesian > Point; +typedef CGAL::Segment_2< CGAL::Simple_cartesian > Segment; int main() { @@ -210,11 +210,11 @@ of `Output_rep`. If you do not specialize `Output_rep` for `T`, `T`'s stream output operator is called from within `Output_rep`, by -default. If you want another behaviour for your type `T`, you +default. If you want another behavior for your type `T`, you have to provide a specialization for that type. Furthermore, you can provide specializations with a second template parameter (a formatting tag). The second template parameter defaults to `Null_tag` and means -default behaviour. +default behavior. For example, specializing `Output_rep` for `CORE::BigRat` (without a formatting tag parameter) could look like this: @@ -519,4 +519,3 @@ which might look as follows: */ } /* namespace CGAL */ - diff --git a/Stream_support/include/CGAL/IO/PLY/PLY_writer.h b/Stream_support/include/CGAL/IO/PLY/PLY_writer.h index cec8e1b539eb..36656fa71801 100644 --- a/Stream_support/include/CGAL/IO/PLY/PLY_writer.h +++ b/Stream_support/include/CGAL/IO/PLY/PLY_writer.h @@ -263,15 +263,15 @@ class Double_coordinate_printer virtual void print(std::ostream& stream, const Index& index) { + if (get_mode(stream) == CGAL::IO::ASCII) { + stream << to_double(get(m_pmap, index).x()) << " " + << to_double(get(m_pmap, index).y()) << " " + << to_double(get(m_pmap, index).z()); + }else{ write(stream, to_double(get(m_pmap, index).x())); - if (get_mode(stream) == CGAL::IO::ASCII) { - stream << " "; - } write(stream, to_double(get(m_pmap, index).y())); - if (get_mode(stream) == CGAL::IO::ASCII) { - stream << " "; - } write(stream, to_double(get(m_pmap, index).z())); + } } }; diff --git a/Stream_support/include/CGAL/IO/io.h b/Stream_support/include/CGAL/IO/io.h index e287fe8e16f2..90eef79769b2 100644 --- a/Stream_support/include/CGAL/IO/io.h +++ b/Stream_support/include/CGAL/IO/io.h @@ -89,7 +89,7 @@ enum Mode {ASCII = 0, PRETTY, BINARY}; \brief Inserts object `c` in the stream `os`. Returns `os`. \cgal defines output operators for classes that are derived from the class `ostream`. This allows to write to ostreams -as `cout` or `cerr`, as well as to `std::ostringstream` +as `std::cout` or `std::cerr`, as well as to `std::ostringstream` and `std::ofstream`. The output operator is defined for all classes in the \cgal `Kernel` and for the class `Color` as well. @@ -150,7 +150,7 @@ typedef IO_rep_is_not_specialized_aux IO_rep_is_not_specialized; The purpose of `Output_rep` is to provide a way to control output formatting that works independently of the object's stream output operator. -If you dont specialize `Output_rep` for `T`, `T`'s stream output operator is called from within `Output_rep`, by default. If you want another behaviour for your type `T`, you have to provide a specialization for that type. Furthermore, you can provide specializations with a second template parameter (a formatting tag). The second template parameter defaults to `Null_tag` and means *default behaviour*. +If you dont specialize `Output_rep` for `T`, `T`'s stream output operator is called from within `Output_rep`, by default. If you want another behavior for your type `T`, you have to provide a specialization for that type. Furthermore, you can provide specializations with a second template parameter (a formatting tag). The second template parameter defaults to `Null_tag` and means *default behavior*. Specializations of `Output_rep` should provide the following features: @@ -190,8 +190,8 @@ class Output_rep \relates Output_rep \brief stream output of the \c Output_rep calls its \c operator(). - \cgal defines output operators for classes that are derived from the class `ostream`. - This enables to write to ostreams as `cout` or `cerr`, as well as to `std::ostringstream` + \cgal defines output operators for classes that are derived from the class `std::ostream`. + This enables to write to output streams as `std::cout` or `std::cerr`, as well as to `std::ostringstream` and `std::ofstream`. The output operator is defined for all classes in the \cgal `Kernel` and for the class `Color` as well. */ @@ -390,7 +390,7 @@ class Input_rep \brief stream input to the \c Input_rep calls its \c operator(). \brief \cgal defines input operators for classes that are derived -from the class `istream`. This allows to read from istreams +from the class `std::istream`. This allows to read from input streams as `std::cin`, as well as from `std::istringstream` and `std::ifstream`. The input operator is defined for all classes in the \cgal `Kernel`. */ diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h index 869de8aea91a..2f5f58becb15 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h @@ -449,7 +449,6 @@ bool fill_simplex_specific_header(std::ostream& os, os << "property float x" << std::endl << "property float y" << std::endl << "property float z" << std::endl; - printers.push_back(new Property_printer(sm.points())); } else @@ -457,8 +456,6 @@ bool fill_simplex_specific_header(std::ostream& os, os << "property double x" << std::endl << "property double y" << std::endl << "property double z" << std::endl; - - printers.push_back(new Double_coordinate_printer(sm.points())); } From d876fbab69e3dbec22ae8083319c03da3677229d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Wed, 22 Nov 2023 15:21:04 +0100 Subject: [PATCH 04/39] add missing include --- Stream_support/include/CGAL/IO/PLY/PLY_writer.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Stream_support/include/CGAL/IO/PLY/PLY_writer.h b/Stream_support/include/CGAL/IO/PLY/PLY_writer.h index 36656fa71801..38028ba13abe 100644 --- a/Stream_support/include/CGAL/IO/PLY/PLY_writer.h +++ b/Stream_support/include/CGAL/IO/PLY/PLY_writer.h @@ -12,6 +12,7 @@ #define CGAL_IO_PLY_PLY_WRITER_H #include +#include namespace CGAL { namespace IO { From 7a984104fa7c6d68b6ec23eed78f2d2f61339b25 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 7 Jun 2024 08:43:36 +0100 Subject: [PATCH 05/39] Add code that shows the issue --- .../test/Stream_support/issue_7874.cpp | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Stream_support/test/Stream_support/issue_7874.cpp diff --git a/Stream_support/test/Stream_support/issue_7874.cpp b/Stream_support/test/Stream_support/issue_7874.cpp new file mode 100644 index 000000000000..1ce00e3cd8ca --- /dev/null +++ b/Stream_support/test/Stream_support/issue_7874.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include +#include +#include + +typedef CGAL::Surface_mesh Surface_mesh; +typedef CGAL::Polyhedron_3 Polyhedron_3; +typedef CGAL::Epeck::Point_3 Point_3; + +int main() +{ + Point_3 p(0.3, 0.3454, 0), q(0.6694, 0,0), r(0,0,0); + Surface_mesh sm; + Polyhedron_3 po; + CGAL::make_triangle(p,q,r,sm); + CGAL::make_triangle(p,q,r,po); + + // from + // https://doc.cgal.org/latest/BGL/group__PkgBGLIoFuncsPLY.html#ga959dcd88ca979d3b6b0806d883a0247f + CGAL::IO::write_polygon_mesh("write_polygon_mesh_sm.ply", sm, + CGAL::parameters::stream_precision(17).use_binary_mode(true)); + + CGAL::IO::write_polygon_mesh("write_polygon_mesh_po.ply", po, + CGAL::parameters::stream_precision(17).use_binary_mode(true)); + + // from #include + // https://doc.cgal.org/latest/BGL/group__PkgBGLIoFuncsPLY.html#ga959dcd88ca979d3b6b0806d883a0247f + CGAL::IO::write_PLY("generic_write_PLY.ply", sm, "generic write_PLY(Surface_mesh)", + CGAL::parameters::stream_precision(17).use_binary_mode(true)); + + CGAL::IO::write_PLY("generic_write_PLY_po.ply", sm, "generic write_PLY(Polyhedron)", + CGAL::parameters::stream_precision(17).use_binary_mode(true)); + + // from #include + // https://doc.cgal.org/latest/Surface_mesh/group__PkgSurfaceMeshIOFuncPLY.html#ga50f0e9f2b293855d2c7f1a62939cbe8d + std::ofstream out("sm_write_PLY.ply", std::ios::binary); + CGAL::IO::write_PLY(out, sm, "sm_write_PLY"); + + return 0; +} From fe86a79bdce5ff4511cecb16ca063ec3d8313b31 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 7 Jun 2024 09:01:29 +0100 Subject: [PATCH 06/39] Fix the test --- Stream_support/test/Stream_support/issue_7874.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Stream_support/test/Stream_support/issue_7874.cpp b/Stream_support/test/Stream_support/issue_7874.cpp index 1ce00e3cd8ca..a84168d9bd34 100644 --- a/Stream_support/test/Stream_support/issue_7874.cpp +++ b/Stream_support/test/Stream_support/issue_7874.cpp @@ -23,21 +23,25 @@ int main() CGAL::IO::write_polygon_mesh("write_polygon_mesh_sm.ply", sm, CGAL::parameters::stream_precision(17).use_binary_mode(true)); + // ERROR this produces an invalid plyfile CGAL::IO::write_polygon_mesh("write_polygon_mesh_po.ply", po, CGAL::parameters::stream_precision(17).use_binary_mode(true)); + // OK // from #include // https://doc.cgal.org/latest/BGL/group__PkgBGLIoFuncsPLY.html#ga959dcd88ca979d3b6b0806d883a0247f - CGAL::IO::write_PLY("generic_write_PLY.ply", sm, "generic write_PLY(Surface_mesh)", + CGAL::IO::write_PLY("generic_write_PLY_sm.ply", sm, "generic write_PLY(Surface_mesh)", CGAL::parameters::stream_precision(17).use_binary_mode(true)); - CGAL::IO::write_PLY("generic_write_PLY_po.ply", sm, "generic write_PLY(Polyhedron)", + // ERROR this produces an invalid plyfile + CGAL::IO::write_PLY("generic_write_PLY_po.ply", po, "generic write_PLY(Polyhedron)", CGAL::parameters::stream_precision(17).use_binary_mode(true)); + // OK // from #include // https://doc.cgal.org/latest/Surface_mesh/group__PkgSurfaceMeshIOFuncPLY.html#ga50f0e9f2b293855d2c7f1a62939cbe8d - std::ofstream out("sm_write_PLY.ply", std::ios::binary); - CGAL::IO::write_PLY(out, sm, "sm_write_PLY"); + std::ofstream out("overloaded_write_PLY_sm.ply", std::ios::binary); + CGAL::IO::write_PLY(out, sm, "overloaded_write_PLY)Surface_mesh)"); return 0; } From 6cba601ff3f1fd710734c692db541e002871428e Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 7 Jun 2024 15:06:37 +0100 Subject: [PATCH 07/39] WIP just to get it working --- BGL/include/CGAL/boost/graph/IO/PLY.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/BGL/include/CGAL/boost/graph/IO/PLY.h b/BGL/include/CGAL/boost/graph/IO/PLY.h index 290543ecdef2..42244e342be7 100644 --- a/BGL/include/CGAL/boost/graph/IO/PLY.h +++ b/BGL/include/CGAL/boost/graph/IO/PLY.h @@ -232,6 +232,21 @@ bool read_PLY(const std::string& fname, //////////////////////////////////////////////////////////////////////////////////////////////////// // Write +template +struct To_double_property_map_no_lvalue +{ + typedef T key_type; ///< typedef to `T` + typedef Simple_cartesian::Point_3 value_type; ///< typedef to `T` + typedef value_type reference; ///< typedef to `T` + typedef boost::readable_property_map_tag category; ///< `boost::readable_property_map_tag` + + typedef To_double_property_map_no_lvalue Self; + + friend value_type get(const Self&, const key_type& k) { + return Simple_cartesian::Point_3(to_double(k.x()), to_double(k.y()), to_double(k.z()));} +}; + + /*! \ingroup PkgBGLIoFuncsPLY @@ -379,7 +394,7 @@ bool write_PLY(std::ostream& os, for(vertex_descriptor vd : vertices(g)) { const Point_3& p = get(vpm, vd); - internal::output_properties(os, &p, make_ply_point_writer (CGAL::Identity_property_map())); + internal::output_properties(os, &p, make_ply_point_writer (To_double_property_map_no_lvalue())); if(has_vcolor) { const CGAL::IO::Color& c = get(vcm, vd); From c58286d71640f8d1978b8037ba84a407437f571c Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 7 Jun 2024 15:30:25 +0100 Subject: [PATCH 08/39] Add #include --- BGL/include/CGAL/boost/graph/IO/PLY.h | 1 + 1 file changed, 1 insertion(+) diff --git a/BGL/include/CGAL/boost/graph/IO/PLY.h b/BGL/include/CGAL/boost/graph/IO/PLY.h index 42244e342be7..4079c0f689de 100644 --- a/BGL/include/CGAL/boost/graph/IO/PLY.h +++ b/BGL/include/CGAL/boost/graph/IO/PLY.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include From 710666a51bc111069b93f6d37b9befd1b2a1f05e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Mon, 10 Jun 2024 13:57:38 +0200 Subject: [PATCH 09/39] Use the normal computation function that uses approximate_sqrt As to be able to write even for kernels that do not offer sqrt --- Stream_support/include/CGAL/IO/STL.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Stream_support/include/CGAL/IO/STL.h b/Stream_support/include/CGAL/IO/STL.h index d2c31b00cf85..bc74e20799b4 100644 --- a/Stream_support/include/CGAL/IO/STL.h +++ b/Stream_support/include/CGAL/IO/STL.h @@ -317,7 +317,7 @@ bool write_STL(std::ostream& os, const Point& q = get(point_map, points[face[1]]); const Point& r = get(point_map, points[face[2]]); - const Vector_3 n = collinear(p,q,r) ? Vector_3(1,0,0) : unit_normal(p,q,r); + const Vector_3 n = internal::construct_normal_of_STL_face(p, q, r, k); const float coords[12] = { static_cast(n.x()), static_cast(n.y()), static_cast(n.z()), static_cast(p.x()), static_cast(p.y()), static_cast(p.z()), From c5a688590a16d6862d098abed7fe0a6556b325de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Mon, 10 Jun 2024 14:00:28 +0200 Subject: [PATCH 10/39] Test the write output --- .../test/Stream_support/issue_7874.cpp | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/Stream_support/test/Stream_support/issue_7874.cpp b/Stream_support/test/Stream_support/issue_7874.cpp index a84168d9bd34..e2691ee12387 100644 --- a/Stream_support/test/Stream_support/issue_7874.cpp +++ b/Stream_support/test/Stream_support/issue_7874.cpp @@ -23,25 +23,52 @@ int main() CGAL::IO::write_polygon_mesh("write_polygon_mesh_sm.ply", sm, CGAL::parameters::stream_precision(17).use_binary_mode(true)); + Surface_mesh osm; + if(!CGAL::IO::read_polygon_mesh("write_polygon_mesh_sm.ply", osm)) + { + std::cerr << "Error: failed to read 'write_polygon_mesh_sm.ply'" << std::endl; + return EXIT_FAILURE; + } + // ERROR this produces an invalid plyfile CGAL::IO::write_polygon_mesh("write_polygon_mesh_po.ply", po, CGAL::parameters::stream_precision(17).use_binary_mode(true)); + if(!CGAL::IO::read_polygon_mesh("write_polygon_mesh_po.ply", osm)) + { + std::cerr << "Error: failed to read 'write_polygon_mesh_po.ply'" << std::endl; + return EXIT_FAILURE; + } // OK // from #include // https://doc.cgal.org/latest/BGL/group__PkgBGLIoFuncsPLY.html#ga959dcd88ca979d3b6b0806d883a0247f CGAL::IO::write_PLY("generic_write_PLY_sm.ply", sm, "generic write_PLY(Surface_mesh)", CGAL::parameters::stream_precision(17).use_binary_mode(true)); + if(!CGAL::IO::read_polygon_mesh("generic_write_PLY_sm.ply", osm)) + { + std::cerr << "Error: failed to read 'generic_write_PLY_sm.ply'" << std::endl; + return EXIT_FAILURE; + } // ERROR this produces an invalid plyfile CGAL::IO::write_PLY("generic_write_PLY_po.ply", po, "generic write_PLY(Polyhedron)", CGAL::parameters::stream_precision(17).use_binary_mode(true)); + if(!CGAL::IO::read_polygon_mesh("generic_write_PLY_po.ply", osm)) + { + std::cerr << "Error: failed to read 'generic_write_PLY_po.ply'" << std::endl; + return EXIT_FAILURE; + } // OK // from #include // https://doc.cgal.org/latest/Surface_mesh/group__PkgSurfaceMeshIOFuncPLY.html#ga50f0e9f2b293855d2c7f1a62939cbe8d std::ofstream out("overloaded_write_PLY_sm.ply", std::ios::binary); - CGAL::IO::write_PLY(out, sm, "overloaded_write_PLY)Surface_mesh)"); + CGAL::IO::write_PLY(out, sm, "overloaded_write_PLY(Surface_mesh)"); + if(!CGAL::IO::read_polygon_mesh("overloaded_write_PLY_sm.ply", osm)) + { + std::cerr << "Error: failed to read 'overloaded_write_PLY_sm.ply'" << std::endl; + return EXIT_FAILURE; + } return 0; } From cfcc90d64983a9cb31d0983c2b415440f2e24490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Mon, 10 Jun 2024 14:00:45 +0200 Subject: [PATCH 11/39] Add extra lines to clarify that the blocks aren't related --- BGL/include/CGAL/boost/graph/IO/PLY.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/BGL/include/CGAL/boost/graph/IO/PLY.h b/BGL/include/CGAL/boost/graph/IO/PLY.h index 4079c0f689de..c29b3332e08e 100644 --- a/BGL/include/CGAL/boost/graph/IO/PLY.h +++ b/BGL/include/CGAL/boost/graph/IO/PLY.h @@ -369,6 +369,7 @@ bool write_PLY(std::ostream& os, os << "element vertex " << vertices(g).size() << std::endl; internal::output_property_header(os, make_ply_point_writer (CGAL::Identity_property_map())); + //if vcm is not default add v:color property if(has_vcolor) { @@ -382,6 +383,7 @@ bool write_PLY(std::ostream& os, internal::output_property_header( os, std::make_pair(CGAL::Identity_property_map >(), PLY_property >("vertex_indices"))); + //if fcm is not default add f:color property if(has_fcolor) { From 969062e3df4a850d72c6ee314cab51968a449241 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 11 Jun 2024 13:15:04 +0100 Subject: [PATCH 12/39] Add the possibility to pass a vertex normal map --- BGL/include/CGAL/boost/graph/IO/PLY.h | 2 +- Property_map/include/CGAL/property_map.h | 1 - .../include/CGAL/IO/PLY/PLY_writer.h | 22 ------- .../test/Stream_support/issue_7874.cpp | 61 ++++++++++++++++--- .../include/CGAL/Surface_mesh/IO/PLY.h | 54 ++++++++++++---- 5 files changed, 95 insertions(+), 45 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/IO/PLY.h b/BGL/include/CGAL/boost/graph/IO/PLY.h index c29b3332e08e..4018fcb198f5 100644 --- a/BGL/include/CGAL/boost/graph/IO/PLY.h +++ b/BGL/include/CGAL/boost/graph/IO/PLY.h @@ -397,7 +397,7 @@ bool write_PLY(std::ostream& os, for(vertex_descriptor vd : vertices(g)) { const Point_3& p = get(vpm, vd); - internal::output_properties(os, &p, make_ply_point_writer (To_double_property_map_no_lvalue())); + internal::output_properties(os, &p, make_ply_point_writer (Identity_property_map())); if(has_vcolor) { const CGAL::IO::Color& c = get(vcm, vd); diff --git a/Property_map/include/CGAL/property_map.h b/Property_map/include/CGAL/property_map.h index 0da2528a3da5..58175cd95a6f 100644 --- a/Property_map/include/CGAL/property_map.h +++ b/Property_map/include/CGAL/property_map.h @@ -709,7 +709,6 @@ struct Cartesian_converter_property_map { return CGAL::Cartesian_converter()(get(pm.vpm, k)); } - friend void put(Cartesian_converter_property_map& pm, const key_type& k, const value_type& v) { put(pm.vpm, k, CGAL::Cartesian_converter()(v)); diff --git a/Stream_support/include/CGAL/IO/PLY/PLY_writer.h b/Stream_support/include/CGAL/IO/PLY/PLY_writer.h index 38028ba13abe..c32e77fdd276 100644 --- a/Stream_support/include/CGAL/IO/PLY/PLY_writer.h +++ b/Stream_support/include/CGAL/IO/PLY/PLY_writer.h @@ -254,28 +254,6 @@ class Property_printer } }; -template -class Double_coordinate_printer - : public Abstract_property_printer -{ - PropertyMap m_pmap; -public: - Double_coordinate_printer(const PropertyMap& pmap) : m_pmap(pmap) { } - - virtual void print(std::ostream& stream, const Index& index) - { - if (get_mode(stream) == CGAL::IO::ASCII) { - stream << to_double(get(m_pmap, index).x()) << " " - << to_double(get(m_pmap, index).y()) << " " - << to_double(get(m_pmap, index).z()); - }else{ - write(stream, to_double(get(m_pmap, index).x())); - write(stream, to_double(get(m_pmap, index).y())); - write(stream, to_double(get(m_pmap, index).z())); - } - } -}; - template #include #include +#include typedef CGAL::Surface_mesh Surface_mesh; +typedef boost::graph_traits::vertex_descriptor vertex_descriptor; typedef CGAL::Polyhedron_3 Polyhedron_3; +typedef boost::graph_traits::vertex_descriptor pvertex_descriptor; typedef CGAL::Epeck::Point_3 Point_3; +typedef CGAL::Epeck::Vector_3 Vector_3; +typedef CGAL::Simple_cartesian SC; +typedef Surface_mesh::template Property_map VNMap; +typedef CGAL::Cartesian_converter_property_map< SC::Vector_3, VNMap> ScSmVertexNormalMap; + +typedef std::map PolyhedronVN; +typedef boost::associative_property_map PolyhedronVNMap; +typedef CGAL::Cartesian_converter_property_map< SC::Vector_3, PolyhedronVNMap> ScPolyhedronVertexNormalMap; + +typedef boost::property_map::type SmVertexPointMap; +typedef CGAL::Cartesian_converter_property_map< SC::Point_3, SmVertexPointMap> ScSmVertexPointMap; + +typedef boost::property_map::type PolyhedronVertexPointMap; +typedef CGAL::Cartesian_converter_property_map< SC::Point_3, PolyhedronVertexPointMap> ScPolyhedronVertexPointMap; int main() { @@ -18,57 +35,83 @@ int main() CGAL::make_triangle(p,q,r,sm); CGAL::make_triangle(p,q,r,po); + VNMap smvnpm = sm.template add_property_map("v:normal", CGAL::NULL_VECTOR).first; + + CGAL::Polygon_mesh_processing::compute_vertex_normals(sm, smvnpm); + + ScSmVertexNormalMap scsmvnpm(smvnpm); + + SmVertexPointMap smvpm = get(CGAL::vertex_point_t(), sm); + ScSmVertexPointMap scsmvpm(smvpm); + PolyhedronVertexPointMap povpm = get(CGAL::vertex_point_t(), po); + ScPolyhedronVertexPointMap scpovpm(povpm); + // from // https://doc.cgal.org/latest/BGL/group__PkgBGLIoFuncsPLY.html#ga959dcd88ca979d3b6b0806d883a0247f CGAL::IO::write_polygon_mesh("write_polygon_mesh_sm.ply", sm, - CGAL::parameters::stream_precision(17).use_binary_mode(true)); + CGAL::parameters::stream_precision(17).use_binary_mode(true).vertex_point_map(scsmvpm).vertex_normal_map(scsmvnpm) ); Surface_mesh osm; + /* if(!CGAL::IO::read_polygon_mesh("write_polygon_mesh_sm.ply", osm)) { std::cerr << "Error: failed to read 'write_polygon_mesh_sm.ply'" << std::endl; return EXIT_FAILURE; } +*/ + + PolyhedronVN vn; + PolyhedronVNMap povnpm(vn); + ScPolyhedronVertexNormalMap scpovnpm(povnpm); + + + CGAL::Polygon_mesh_processing::compute_vertex_normals(po, povnpm); // ERROR this produces an invalid plyfile CGAL::IO::write_polygon_mesh("write_polygon_mesh_po.ply", po, - CGAL::parameters::stream_precision(17).use_binary_mode(true)); + CGAL::parameters::stream_precision(17).use_binary_mode(true).vertex_point_map(scpovpm).vertex_normal_map(scpovnpm)) ; + /* if(!CGAL::IO::read_polygon_mesh("write_polygon_mesh_po.ply", osm)) { std::cerr << "Error: failed to read 'write_polygon_mesh_po.ply'" << std::endl; return EXIT_FAILURE; } - +*/ // OK // from #include // https://doc.cgal.org/latest/BGL/group__PkgBGLIoFuncsPLY.html#ga959dcd88ca979d3b6b0806d883a0247f CGAL::IO::write_PLY("generic_write_PLY_sm.ply", sm, "generic write_PLY(Surface_mesh)", - CGAL::parameters::stream_precision(17).use_binary_mode(true)); + CGAL::parameters::stream_precision(17).use_binary_mode(true).vertex_point_map(scsmvpm)); + /* if(!CGAL::IO::read_polygon_mesh("generic_write_PLY_sm.ply", osm)) { std::cerr << "Error: failed to read 'generic_write_PLY_sm.ply'" << std::endl; return EXIT_FAILURE; } - +*/ // ERROR this produces an invalid plyfile CGAL::IO::write_PLY("generic_write_PLY_po.ply", po, "generic write_PLY(Polyhedron)", - CGAL::parameters::stream_precision(17).use_binary_mode(true)); + CGAL::parameters::stream_precision(17).use_binary_mode(true).vertex_point_map(scpovpm)); + /* if(!CGAL::IO::read_polygon_mesh("generic_write_PLY_po.ply", osm)) { std::cerr << "Error: failed to read 'generic_write_PLY_po.ply'" << std::endl; return EXIT_FAILURE; } - +*/ // OK // from #include // https://doc.cgal.org/latest/Surface_mesh/group__PkgSurfaceMeshIOFuncPLY.html#ga50f0e9f2b293855d2c7f1a62939cbe8d std::ofstream out("overloaded_write_PLY_sm.ply", std::ios::binary); - CGAL::IO::write_PLY(out, sm, "overloaded_write_PLY(Surface_mesh)"); + CGAL::set_binary_mode(out); + CGAL::IO::write_PLY(out, sm, "overloaded_write_PLY(Surface_mesh)",CGAL::parameters::stream_precision(17).use_binary_mode(true) + .vertex_point_map(scsmvpm).vertex_normal_map(scsmvnpm) ); + /* if(!CGAL::IO::read_polygon_mesh("overloaded_write_PLY_sm.ply", osm)) { std::cerr << "Error: failed to read 'overloaded_write_PLY_sm.ply'" << std::endl; return EXIT_FAILURE; } - +*/ return 0; } diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h index 2f5f58becb15..30e149300114 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h @@ -423,22 +423,28 @@ class Surface_mesh_filler } }; -template +template bool fill_simplex_specific_header(std::ostream& os, const Surface_mesh& sm, std::vector::Vertex_index>*>& printers, - const std::string& prop) + const std::string& prop, + const NamedParameter& np) { + using CGAL::parameters::choose_parameter; + using CGAL::parameters::get_parameter; typedef Surface_mesh SMesh; typedef typename SMesh::Vertex_index VIndex; typedef typename Kernel_traits::Kernel Kernel; typedef typename Kernel::FT FT; typedef typename Kernel::Vector_3 Vector; - typedef typename SMesh::template Property_map Point_map; + + typedef typename GetVertexPointMap, NamedParameter>::const_type Point_map; typedef typename SMesh::template Property_map Vector_map; typedef typename SMesh::template Property_map Vcolor_map; + Point_map vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), + get_const_property_map(CGAL::vertex_point, sm)); if(prop == "v:connectivity" || prop == "v:removed") return true; @@ -449,19 +455,40 @@ bool fill_simplex_specific_header(std::ostream& os, os << "property float x" << std::endl << "property float y" << std::endl << "property float z" << std::endl; - printers.push_back(new Property_printer(sm.points())); + printers.push_back(new Property_printer(vpm)); } else { os << "property double x" << std::endl << "property double y" << std::endl << "property double z" << std::endl; - printers.push_back(new Double_coordinate_printer(sm.points())); + printers.push_back(new Property_printer(vpm)); } return true; } + if constexpr (!parameters::is_default_parameter::value) + { + auto vnm = get_parameter(np, internal_np::vertex_normal_map); + typedef decltype(vnm) Normal_map; + typedef Kernel_traits::Kernel::FT FloatDouble; + if(std::is_same::value) + { + os << "property float nx" << std::endl + << "property float ny" << std::endl + << "property float nz" << std::endl; + } + else + { + os << "property double nx" << std::endl + << "property double ny" << std::endl + << "property double nz" << std::endl; + } + printers.push_back(new Property_printer(vnm)); + return true; + } + bool okay = false; if(prop == "v:normal") { @@ -505,12 +532,13 @@ bool fill_simplex_specific_header(std::ostream& os, return false; } -template +template bool fill_simplex_specific_header(std::ostream& os, const Surface_mesh& sm, std::vector::Face_index>*>& printers, - const std::string& prop) + const std::string& prop, + const NamedParameter&) { typedef typename Surface_mesh::Face_index FIndex; typedef CGAL::IO::Color Color; @@ -538,12 +566,13 @@ bool fill_simplex_specific_header(std::ostream& os, return false; } -template +template bool fill_simplex_specific_header(std::ostream&, const Surface_mesh& , std::vector::Edge_index>*>& , - const std::string& prop) + const std::string& prop, + const NamedParameter&) { if(prop == "e:removed") return true; @@ -551,12 +580,13 @@ bool fill_simplex_specific_header(std::ostream&, return false; } -template +template bool fill_simplex_specific_header(std::ostream&, const Surface_mesh& , std::vector::Halfedge_index>*>& , - const std::string& prop) + const std::string& prop, + const NamedParameter&) { if(prop == "h:connectivity") return true; @@ -746,7 +776,7 @@ void fill_header(std::ostream& os, const Surface_mesh& sm, if (has_fcolor && prop[i] == "f:color") continue; - if(fill_simplex_specific_header(os, sm, printers, prop[i])) + if(fill_simplex_specific_header(os, sm, printers, prop[i], np)) continue; fill_header_impl::value>(Type_tuple(), type_strings, sm, prop[i], os, printers); From a08388c4e392d6cd3f4b3436bf4fecd7b22324d5 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 11 Jun 2024 14:02:31 +0100 Subject: [PATCH 13/39] Also write normals in the generic code --- BGL/include/CGAL/boost/graph/IO/PLY.h | 32 +++++++++++++++++++ .../test/Stream_support/issue_7874.cpp | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/BGL/include/CGAL/boost/graph/IO/PLY.h b/BGL/include/CGAL/boost/graph/IO/PLY.h index 4018fcb198f5..d4986001cd10 100644 --- a/BGL/include/CGAL/boost/graph/IO/PLY.h +++ b/BGL/include/CGAL/boost/graph/IO/PLY.h @@ -342,6 +342,11 @@ bool write_PLY(std::ostream& os, bool has_vcolor = !is_default_parameter::value; bool has_fcolor = !is_default_parameter::value; + bool has_vnormal = false; + if constexpr (!parameters::is_default_parameter::value) + { + has_vnormal = true; + } VIMap vim = CGAL::get_initialized_vertex_index_map(g, np); Vpm vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), get_const_property_map(boost::vertex_point, g)); @@ -379,6 +384,25 @@ bool write_PLY(std::ostream& os, << "property uchar alpha" << std::endl; } + if constexpr (!parameters::is_default_parameter::value) + { + auto vnm = get_parameter(np, internal_np::vertex_normal_map); + typedef decltype(vnm) Normal_map; + typedef Kernel_traits::Kernel::FT FloatDouble; + if(std::is_same::value) + { + os << "property float nx" << std::endl + << "property float ny" << std::endl + << "property float nz" << std::endl; + } + else + { + os << "property double nx" << std::endl + << "property double ny" << std::endl + << "property double nz" << std::endl; + } + } + os << "element face " << faces(g).size() << std::endl; internal::output_property_header( os, std::make_pair(CGAL::Identity_property_map >(), @@ -398,6 +422,14 @@ bool write_PLY(std::ostream& os, { const Point_3& p = get(vpm, vd); internal::output_properties(os, &p, make_ply_point_writer (Identity_property_map())); + if constexpr (!parameters::is_default_parameter::value) + { + auto vnm = get_parameter(np, internal_np::vertex_normal_map); + typedef decltype(vnm) Normal_map; + typedef typename Normal_map::value_type Vector_3; + Vector_3 vec = get(vnm,vd); + internal::output_properties(os, &vec, make_ply_normal_writer (Identity_property_map())); + } if(has_vcolor) { const CGAL::IO::Color& c = get(vcm, vd); diff --git a/Stream_support/test/Stream_support/issue_7874.cpp b/Stream_support/test/Stream_support/issue_7874.cpp index 461cc8e281ac..fac43dd223ac 100644 --- a/Stream_support/test/Stream_support/issue_7874.cpp +++ b/Stream_support/test/Stream_support/issue_7874.cpp @@ -81,7 +81,7 @@ int main() // from #include // https://doc.cgal.org/latest/BGL/group__PkgBGLIoFuncsPLY.html#ga959dcd88ca979d3b6b0806d883a0247f CGAL::IO::write_PLY("generic_write_PLY_sm.ply", sm, "generic write_PLY(Surface_mesh)", - CGAL::parameters::stream_precision(17).use_binary_mode(true).vertex_point_map(scsmvpm)); + CGAL::parameters::stream_precision(17).use_binary_mode(true).vertex_point_map(scsmvpm).vertex_normal_map(scsmvnpm)); /* if(!CGAL::IO::read_polygon_mesh("generic_write_PLY_sm.ply", osm)) { From ba87b5c2e5e591104c0e58ff23114b39f0aaacfc Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 11 Jun 2024 14:10:56 +0100 Subject: [PATCH 14/39] typename --- BGL/include/CGAL/boost/graph/IO/PLY.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BGL/include/CGAL/boost/graph/IO/PLY.h b/BGL/include/CGAL/boost/graph/IO/PLY.h index d4986001cd10..20883ffdfd3d 100644 --- a/BGL/include/CGAL/boost/graph/IO/PLY.h +++ b/BGL/include/CGAL/boost/graph/IO/PLY.h @@ -388,7 +388,7 @@ bool write_PLY(std::ostream& os, { auto vnm = get_parameter(np, internal_np::vertex_normal_map); typedef decltype(vnm) Normal_map; - typedef Kernel_traits::Kernel::FT FloatDouble; + typedef typename Kernel_traits::Kernel::FT FloatDouble; if(std::is_same::value) { os << "property float nx" << std::endl From 7ab9468594fda86f9b1dcc91e5c9709eddeb6b07 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 11 Jun 2024 14:24:03 +0100 Subject: [PATCH 15/39] typename --- Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h index 6fb38dc66d76..ed2bc63b7105 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h @@ -472,7 +472,7 @@ bool fill_simplex_specific_header(std::ostream& os, { auto vnm = get_parameter(np, internal_np::vertex_normal_map); typedef decltype(vnm) Normal_map; - typedef Kernel_traits::Kernel::FT FloatDouble; + typedef typename Kernel_traits::Kernel::FT FloatDouble; if(std::is_same::value) { os << "property float nx" << std::endl From 0e27e7632cbb6d90f0494ad57f10aebd5568f4a1 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 11 Jun 2024 15:36:07 +0100 Subject: [PATCH 16/39] cleanup --- BGL/include/CGAL/boost/graph/IO/PLY.h | 16 ---------------- .../test/Stream_support/issue_7874.cpp | 1 + 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/IO/PLY.h b/BGL/include/CGAL/boost/graph/IO/PLY.h index 20883ffdfd3d..649e4a931398 100644 --- a/BGL/include/CGAL/boost/graph/IO/PLY.h +++ b/BGL/include/CGAL/boost/graph/IO/PLY.h @@ -18,7 +18,6 @@ #include #include #include -#include #include #include @@ -233,21 +232,6 @@ bool read_PLY(const std::string& fname, //////////////////////////////////////////////////////////////////////////////////////////////////// // Write -template -struct To_double_property_map_no_lvalue -{ - typedef T key_type; ///< typedef to `T` - typedef Simple_cartesian::Point_3 value_type; ///< typedef to `T` - typedef value_type reference; ///< typedef to `T` - typedef boost::readable_property_map_tag category; ///< `boost::readable_property_map_tag` - - typedef To_double_property_map_no_lvalue Self; - - friend value_type get(const Self&, const key_type& k) { - return Simple_cartesian::Point_3(to_double(k.x()), to_double(k.y()), to_double(k.z()));} -}; - - /*! \ingroup PkgBGLIoFuncsPLY diff --git a/Stream_support/test/Stream_support/issue_7874.cpp b/Stream_support/test/Stream_support/issue_7874.cpp index fac43dd223ac..ca44c65a13aa 100644 --- a/Stream_support/test/Stream_support/issue_7874.cpp +++ b/Stream_support/test/Stream_support/issue_7874.cpp @@ -6,6 +6,7 @@ #include #include #include +#include typedef CGAL::Surface_mesh Surface_mesh; typedef boost::graph_traits::vertex_descriptor vertex_descriptor; From 05014378d659f38ce8b1d0073946b2a568f397a6 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 11 Jun 2024 15:50:21 +0100 Subject: [PATCH 17/39] Add doxygen --- BGL/include/CGAL/boost/graph/IO/PLY.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/BGL/include/CGAL/boost/graph/IO/PLY.h b/BGL/include/CGAL/boost/graph/IO/PLY.h index 649e4a931398..565c0e17b444 100644 --- a/BGL/include/CGAL/boost/graph/IO/PLY.h +++ b/BGL/include/CGAL/boost/graph/IO/PLY.h @@ -259,6 +259,15 @@ bool read_PLY(const std::string& fname, must be available in `Graph`.} \cgalParamNEnd + \cgalParamNBegin{vertex_normal_map} + \cgalParamDescription{a property map associating normals to the vertices of `g`} + \cgalParamType{a class model of `ReadablePropertyMap` with `boost::graph_traits::%vertex_descriptor` + as key type and `%Vector_3` as value type} + \cgalParamDefault{`boost::get(CGAL::vertex_point, g)`} + \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t` + must be available in `Graph`.} + \cgalParamNEnd + \cgalParamNBegin{vertex_index_map} \cgalParamDescription{a property map associating to each vertex of `graph` a unique index} \cgalParamType{a class model of `WritablePropertyMap` with `boost::graph_traits::%vertex_descriptor` @@ -288,6 +297,10 @@ bool read_PLY(const std::string& fname, \cgalParamNEnd \cgalNamedParamsEnd +\note The point and vector types of the point and normal property map must be `double`or `float` + in order to respect the specification of the PLY file format. + A `Cartesian_converter_property_map` can be used to convert the points and vectors on the fly. + \returns `true` if writing was successful, `false` otherwise. */ template @@ -489,6 +502,15 @@ bool write_PLY(std::ostream& os, const Graph& g, const CGAL_NP_CLASS& np = param must be available in `Graph`.} \cgalParamNEnd + \cgalParamNBegin{vertex_normal_map} + \cgalParamDescription{a property map associating normals to the vertices of `g`} + \cgalParamType{a class model of `ReadablePropertyMap` with `boost::graph_traits::%vertex_descriptor` + as key type and `%Vector_3` as value type} + \cgalParamDefault{`boost::get(CGAL::vertex_point, g)`} + \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t` + must be available in `Graph`.} + \cgalParamNEnd + \cgalParamNBegin{vertex_index_map} \cgalParamDescription{a property map associating to each vertex of `graph` a unique index between `0` and `num_vertices(graph) - 1`} \cgalParamType{a class model of `ReadablePropertyMap` with `boost::graph_traits::%vertex_descriptor` @@ -518,6 +540,10 @@ bool write_PLY(std::ostream& os, const Graph& g, const CGAL_NP_CLASS& np = param \cgalParamNEnd \cgalNamedParamsEnd +\note The point and vector types of the point and normal property map must be `double`or `float` + in order to respect the specification of the PLY file format. + A `Cartesian_converter_property_map` can be used to convert the points and vectors on the fly. + \returns `true` if writing was successful, `false` otherwise. */ template From 5171477b2640c23ac1ba9188d33b39afe76f026f Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 17 Jun 2024 15:57:38 +0100 Subject: [PATCH 18/39] Fix tests --- BGL/include/CGAL/boost/graph/IO/PLY.h | 46 +++++++++++++-- Stream_support/include/CGAL/IO/PLY.h | 45 +++++++++++++-- .../test/Stream_support/issue_7874.cpp | 56 +++++++++++++++---- .../include/CGAL/Surface_mesh/IO/PLY.h | 24 +++++++- 4 files changed, 147 insertions(+), 24 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/IO/PLY.h b/BGL/include/CGAL/boost/graph/IO/PLY.h index 565c0e17b444..c58c228d58cb 100644 --- a/BGL/include/CGAL/boost/graph/IO/PLY.h +++ b/BGL/include/CGAL/boost/graph/IO/PLY.h @@ -44,7 +44,7 @@ class PLY_builder typedef typename Base::Face_container Face_container; public: - PLY_builder(std::istream& is) : Base(is) { } + PLY_builder(std::istream& is, std::string& comments) : Base(is), comments(comments) { } template bool read(std::istream& is, @@ -52,19 +52,22 @@ class PLY_builder Face_container& faces, const NamedParameters& np) { - return read_PLY(is, points, faces, np); + return read_PLY(is, points, faces, comments, np); } + + std::string& comments; }; template bool read_PLY_BGL(std::istream& is, Graph& g, + std::string& comments, const CGAL_NP_CLASS& np = parameters::default_values()) { typedef typename CGAL::GetVertexPointMap::type VPM; typedef typename boost::property_traits::value_type Point; - internal::PLY_builder builder(is); + internal::PLY_builder builder(is, comments); return builder(g, np); } @@ -128,6 +131,20 @@ bool read_PLY_BGL(std::istream& is, \sa Overloads of this function for specific models of the concept `FaceGraph`. */ +template +bool read_PLY(std::istream& is, + Graph& g, + std::string& comments, + const CGAL_NP_CLASS& np = parameters::default_values() +#ifndef DOXYGEN_RUNNING + , std::enable_if_t::value>* = nullptr +#endif + ) +{ + return internal::read_PLY_BGL(is, g, comments, np); +} + template bool read_PLY(std::istream& is, @@ -138,9 +155,12 @@ bool read_PLY(std::istream& is, #endif ) { - return internal::read_PLY_BGL(is, g, np); + std::string unused_comments; + return internal::read_PLY_BGL(is, g, unused_comments, np); } + + /*! \ingroup PkgBGLIoFuncsPLY @@ -207,6 +227,7 @@ template bool read_PLY(const std::string& fname, Graph& g, + std::string& comments, const CGAL_NP_CLASS& np = parameters::default_values() #ifndef DOXYGEN_RUNNING , std::enable_if_t::value>* = nullptr @@ -218,16 +239,29 @@ bool read_PLY(const std::string& fname, { std::ifstream is(fname, std::ios::binary); CGAL::IO::set_mode(is, CGAL::IO::BINARY); - return internal::read_PLY_BGL(is, g, np); + return read_PLY(is, g, comments, np); } else { std::ifstream is(fname); CGAL::IO::set_mode(is, CGAL::IO::ASCII); - return internal::read_PLY_BGL(is, g, np); + return read_PLY(is, g, comments, np); } } +template +bool read_PLY(const std::string& fname, + Graph& g, + const CGAL_NP_CLASS& np = parameters::default_values() +#ifndef DOXYGEN_RUNNING + , std::enable_if_t::value>* = nullptr +#endif + ) +{ + std::string unused_comment; + return read_PLY(fname, g, unused_comment, np); +} //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// // Write diff --git a/Stream_support/include/CGAL/IO/PLY.h b/Stream_support/include/CGAL/IO/PLY.h index 7f72b37a3f59..101aa81aafe2 100644 --- a/Stream_support/include/CGAL/IO/PLY.h +++ b/Stream_support/include/CGAL/IO/PLY.h @@ -47,6 +47,7 @@ template ::value>* = nullptr) { - return internal::read_PLY(is, points, polygons, + return internal::read_PLY(is, points, polygons, comments, std::back_inserter(hedges), std::back_inserter(fcolors), std::back_inserter(vcolors), @@ -247,6 +251,7 @@ template bool read_PLY(std::istream& is, PointRange& points, PolygonRange& polygons, + std::string& comments, ColorRange& fcolors, ColorRange& vcolors, const bool verbose = false) @@ -254,7 +259,7 @@ bool read_PLY(std::istream& is, std::vector > dummy_pui; std::vector > dummy_pf; - return internal::read_PLY(is, points, polygons, + return internal::read_PLY(is, points, polygons, comments, std::back_inserter(dummy_pui), std::back_inserter(fcolors), std::back_inserter(vcolors), @@ -307,6 +312,7 @@ template ::value>* = nullptr @@ -319,7 +325,7 @@ bool read_PLY(std::istream& is, std::vector > dummy_pui; std::vector > dummy_pf; - return internal::read_PLY(is, points, polygons, std::back_inserter(dummy_pui), + return internal::read_PLY(is, points, polygons, comments, std::back_inserter(dummy_pui), choose_parameter(get_parameter(np, internal_np::face_color_output_iterator), CGAL::Emptyset_iterator()), choose_parameter(get_parameter(np, internal_np::vertex_color_output_iterator), @@ -328,6 +334,20 @@ bool read_PLY(std::istream& is, choose_parameter(get_parameter(np, internal_np::verbose), true)); } +template +bool read_PLY(std::istream& is, + PointRange& points, + PolygonRange& polygons, + const CGAL_NP_CLASS& np = parameters::default_values() +#ifndef DOXYGEN_RUNNING + , std::enable_if_t::value>* = nullptr +#endif + ) +{ + std::string unused_comments; + return read_PLY(is, points, polygons, unused_comments, np); +} + /*! * \ingroup PkgStreamSupportIoFuncsPLY * @@ -367,6 +387,7 @@ template ::value>* = nullptr @@ -378,16 +399,30 @@ bool read_PLY(const std::string& fname, { std::ifstream is(fname, std::ios::binary); CGAL::IO::set_mode(is, CGAL::IO::BINARY); - return read_PLY(is, points, polygons, np); + return read_PLY(is, points, polygons, comments, np); } else { std::ifstream is(fname); CGAL::IO::set_mode(is, CGAL::IO::ASCII); - return read_PLY(is, points, polygons, np); + return read_PLY(is, points, polygons, comments, np); } } +template +bool read_PLY(const std::string& fname, + PointRange& points, + PolygonRange& polygons, + const CGAL_NP_CLASS& np = parameters::default_values() +#ifndef DOXYGEN_RUNNING + , std::enable_if_t::value>* = nullptr +#endif + ) +{ + std::string unused_comments; + return read_PLY(fname, points, polygons, unused_comments, np); +} + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// // Write diff --git a/Stream_support/test/Stream_support/issue_7874.cpp b/Stream_support/test/Stream_support/issue_7874.cpp index ca44c65a13aa..313060691baa 100644 --- a/Stream_support/test/Stream_support/issue_7874.cpp +++ b/Stream_support/test/Stream_support/issue_7874.cpp @@ -52,14 +52,19 @@ int main() CGAL::IO::write_polygon_mesh("write_polygon_mesh_sm.ply", sm, CGAL::parameters::stream_precision(17).use_binary_mode(true).vertex_point_map(scsmvpm).vertex_normal_map(scsmvnpm) ); +{ Surface_mesh osm; - /* + if(!CGAL::IO::read_polygon_mesh("write_polygon_mesh_sm.ply", osm)) { std::cerr << "Error: failed to read 'write_polygon_mesh_sm.ply'" << std::endl; return EXIT_FAILURE; + }else{ + for(const std::string& s : osm.properties()){ + std::cout << s << std::endl; + } } -*/ +} PolyhedronVN vn; PolyhedronVNMap povnpm(vn); @@ -71,35 +76,58 @@ int main() // ERROR this produces an invalid plyfile CGAL::IO::write_polygon_mesh("write_polygon_mesh_po.ply", po, CGAL::parameters::stream_precision(17).use_binary_mode(true).vertex_point_map(scpovpm).vertex_normal_map(scpovnpm)) ; - /* + +{ + Surface_mesh osm; + if(!CGAL::IO::read_polygon_mesh("write_polygon_mesh_po.ply", osm)) { std::cerr << "Error: failed to read 'write_polygon_mesh_po.ply'" << std::endl; return EXIT_FAILURE; + }else{ + for(const std::string& s : osm.properties()){ + std::cout << s << std::endl; + } } -*/ +} // OK // from #include // https://doc.cgal.org/latest/BGL/group__PkgBGLIoFuncsPLY.html#ga959dcd88ca979d3b6b0806d883a0247f CGAL::IO::write_PLY("generic_write_PLY_sm.ply", sm, "generic write_PLY(Surface_mesh)", CGAL::parameters::stream_precision(17).use_binary_mode(true).vertex_point_map(scsmvpm).vertex_normal_map(scsmvnpm)); - /* + +{ + Surface_mesh osm; + if(!CGAL::IO::read_polygon_mesh("generic_write_PLY_sm.ply", osm)) { std::cerr << "Error: failed to read 'generic_write_PLY_sm.ply'" << std::endl; return EXIT_FAILURE; + }else{ + for(const std::string& s : osm.properties()){ + std::cout << s << std::endl; + } } -*/ +} + // ERROR this produces an invalid plyfile CGAL::IO::write_PLY("generic_write_PLY_po.ply", po, "generic write_PLY(Polyhedron)", CGAL::parameters::stream_precision(17).use_binary_mode(true).vertex_point_map(scpovpm)); - /* + +{ + Surface_mesh osm; + if(!CGAL::IO::read_polygon_mesh("generic_write_PLY_po.ply", osm)) { std::cerr << "Error: failed to read 'generic_write_PLY_po.ply'" << std::endl; return EXIT_FAILURE; + }else{ + for(const std::string& s : osm.properties()){ + std::cout << s << std::endl; + } } -*/ +} +{ // OK // from #include // https://doc.cgal.org/latest/Surface_mesh/group__PkgSurfaceMeshIOFuncPLY.html#ga50f0e9f2b293855d2c7f1a62939cbe8d @@ -107,12 +135,20 @@ int main() CGAL::set_binary_mode(out); CGAL::IO::write_PLY(out, sm, "overloaded_write_PLY(Surface_mesh)",CGAL::parameters::stream_precision(17).use_binary_mode(true) .vertex_point_map(scsmvpm).vertex_normal_map(scsmvnpm) ); - /* +} +{ + Surface_mesh osm; + if(!CGAL::IO::read_polygon_mesh("overloaded_write_PLY_sm.ply", osm)) { std::cerr << "Error: failed to read 'overloaded_write_PLY_sm.ply'" << std::endl; return EXIT_FAILURE; + }else{ + for(const std::string& s : osm.properties()){ + std::cout << s << std::endl; + } } -*/ +} + return 0; } diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h index ed2bc63b7105..a251b8e23fd1 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h @@ -815,14 +815,22 @@ void fill_header(std::ostream& os, const Surface_mesh& sm, /// /// \returns `true` if reading was successful, `false` otherwise. /// -template +template bool read_PLY(std::istream& is, Surface_mesh

& sm, std::string& comments, - bool verbose = true) + const CGAL_NP_CLASS& np = parameters::default_values()) { typedef typename Surface_mesh

::size_type size_type; + // not yet supported: this function only uses the Surface_mesh's internal pmaps + // to make it work, it'd be sufficient to modify Surface_mesh_filler's maps + static_assert(CGAL::parameters::is_default_parameter::value); + static_assert(CGAL::parameters::is_default_parameter::value); + static_assert(CGAL::parameters::is_default_parameter::value); + + const bool verbose = CGAL::parameters::choose_parameter(CGAL::parameters::get_parameter(np, internal_np::verbose), true); + if(!is.good()) { if(verbose) @@ -909,6 +917,17 @@ bool read_PLY(std::istream& is, /// \cond SKIP_IN_MANUAL + +// for backward compatibility +template +bool read_PLY(std::istream& is, + Surface_mesh

& sm, + std::string& comments, + bool verbose = true) +{ + return read_PLY(is, sm, comments, CGAL::parameters::verbose(verbose)); +} + template bool read_PLY(std::istream& is, Surface_mesh

& sm) { @@ -990,7 +1009,6 @@ bool write_PLY(std::ostream& os, typedef typename SMesh::Face_index FIndex; typedef typename SMesh::Edge_index EIndex; typedef typename SMesh::Halfedge_index HIndex; - if(!os.good()) return false; From b97c4b78c3592fc666cf0f7cc5e5bb2cbf625818 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 29 Sep 2025 13:55:26 +0100 Subject: [PATCH 19/39] Convert on the fly to double --- .../include/CGAL/Surface_mesh/IO/PLY.h | 44 +++--- Surface_mesh/test/Surface_mesh/issue_7327.cpp | 126 ++++++++++++++++++ Surface_mesh/test/Surface_mesh/sm_ply_io.cpp | 4 +- 3 files changed, 154 insertions(+), 20 deletions(-) create mode 100644 Surface_mesh/test/Surface_mesh/issue_7327.cpp diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h index 9d37fe09fa87..fb2e3bf7d0cb 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -447,7 +448,7 @@ bool fill_simplex_specific_header(std::ostream& os, if(prop == "v:point") { - if(std::is_same::value) + if constexpr(std::is_same::value) { os << "property float x" << std::endl << "property float y" << std::endl @@ -459,7 +460,8 @@ bool fill_simplex_specific_header(std::ostream& os, os << "property double x" << std::endl << "property double y" << std::endl << "property double z" << std::endl; - printers.push_back(new Property_printer(vpm)); + auto fvpm = CGAL::make_cartesian_converter_property_map(vpm); + printers.push_back(new Property_printer(fvpm)); } return true; @@ -470,23 +472,25 @@ bool fill_simplex_specific_header(std::ostream& os, auto vnm = get_parameter(np, internal_np::vertex_normal_map); typedef decltype(vnm) Normal_map; typedef typename Kernel_traits::Kernel::FT FloatDouble; - if(std::is_same::value) - { - os << "property float nx" << std::endl - << "property float ny" << std::endl - << "property float nz" << std::endl; - } - else - { - os << "property double nx" << std::endl - << "property double ny" << std::endl - << "property double nz" << std::endl; - } - printers.push_back(new Property_printer(vnm)); + if constexpr (std::is_same::value) + { + os << "property float nx" << std::endl + << "property float ny" << std::endl + << "property float nz" << std::endl; + printers.push_back(new Property_printer(vnm)); + } + else + { + os << "property double nx" << std::endl + << "property double ny" << std::endl + << "property double nz" << std::endl; + auto fvnm = CGAL::make_cartesian_converter_property_map(vnm); + printers.push_back(new Property_printer(fvnm)); + } return true; } - if(prop == "v:normal") + else if(prop == "v:normal") { auto pmap = sm.template property_map(prop); if(pmap.has_value()) @@ -496,14 +500,17 @@ bool fill_simplex_specific_header(std::ostream& os, os << "property float nx" << std::endl << "property float ny" << std::endl << "property float nz" << std::endl; + printers.push_back(new Property_printer(*pmap)); } else { os << "property double nx" << std::endl << "property double ny" << std::endl << "property double nz" << std::endl; + auto fvnm = CGAL::make_cartesian_converter_property_map(*pmap); + printers.push_back(new Property_printer(fvnm)); } - printers.push_back(new Property_printer(*pmap)); + // printers.push_back(new Property_printer(*pmap)); return true; } } @@ -914,7 +921,7 @@ bool read_PLY(std::istream& is, /// \cond SKIP_IN_MANUAL - +#if 0 // for backward compatibility template bool read_PLY(std::istream& is, @@ -924,6 +931,7 @@ bool read_PLY(std::istream& is, { return read_PLY(is, sm, comments, CGAL::parameters::verbose(verbose)); } +#endif template bool read_PLY(std::istream& is, Surface_mesh

& sm) diff --git a/Surface_mesh/test/Surface_mesh/issue_7327.cpp b/Surface_mesh/test/Surface_mesh/issue_7327.cpp new file mode 100644 index 000000000000..c147a7c6a869 --- /dev/null +++ b/Surface_mesh/test/Surface_mesh/issue_7327.cpp @@ -0,0 +1,126 @@ +#include +#include + +#include +#include +#include + +typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; +typedef Kernel::Point_3 Point; + +typedef CGAL::Surface_mesh SMesh; +typedef boost::graph_traits::vertex_descriptor vertex_descriptor; +typedef boost::graph_traits::face_descriptor face_descriptor; + +int main() +{ + std::ifstream in(CGAL::data_file_path("meshes/colored_tetra.ply")); + SMesh mesh; + CGAL::IO::read_PLY(in, mesh); + + std::cerr << "Read mesh with " << mesh.number_of_vertices() << " vertices and " + << mesh.number_of_faces() << " faces" << std::endl; + + std::cerr << "Properties associated with vertices:" << std::endl; + std::vector properties = mesh.properties(); + for(std::size_t i = 0; i < properties.size(); ++ i) + std::cerr << " * " << properties[i] << std::endl; + + std::cerr << "Properties associated with faces:" << std::endl; + properties = mesh.properties(); + for(std::size_t i = 0; i < properties.size(); ++ i) + std::cerr << " * " << properties[i] << std::endl; + + mesh.add_property_map("id", 42); + mesh.add_property_map("u", 13.f); + mesh.add_property_map("v", 37.f); + + // Append second mesh + std::ifstream in2("epeck_tetra.ply"); + CGAL::IO::read_PLY(in2, mesh); + + std::ofstream out("epeck_out.ply"); +// CGAL::IO::set_binary_mode(out); + CGAL::IO::write_PLY(out, mesh); + + // extra test for read/write of properties + mesh = SMesh(); + in.close(); + in.open(CGAL::data_file_path("meshes/colored_tetra.ply")); + CGAL::IO::read_PLY(in, mesh); + float fvalue=1001; + auto v_uvmap = mesh.add_property_map>("v:uv").first; + auto v_umap = mesh.add_property_map("v:u").first; + auto v_vmap = mesh.add_property_map("v:v").first; + for (SMesh::Vertex_index v : vertices(mesh)) + { + v_uvmap[v]={fvalue, -fvalue}; + v_umap[v]=fvalue; + v_vmap[v]=-fvalue; + ++fvalue; + } + + double dvalue=2001; + auto f_uvmap = mesh.add_property_map>("f:uv").first; + auto f_umap = mesh.add_property_map("f:u").first; + auto f_vmap = mesh.add_property_map("f:v").first; + for (SMesh::Face_index f : faces(mesh)) + { + f_uvmap[f]={dvalue, -dvalue}; + f_umap[f]=dvalue; + f_vmap[f]=-dvalue; + ++dvalue; + } + + out.close(); + out.open("epeck_out_ascii.ply"); + CGAL::IO::write_PLY(out, mesh); + out.close(); + out.open("epeck_out_binary.ply", std::ios::binary); + CGAL::IO::set_binary_mode(out); + CGAL::IO::write_PLY(out, mesh); + out.close(); + mesh.clear(); + + const std::array fnames = {"epeck_out_ascii.ply", "epeck_out_binary.ply"}; + for (std::string fn : fnames) + { + std::cout << "Reading " << fn << "\n"; + in.close(); + in.open(fn, std::ios::binary); + SMesh mesh_bis; + CGAL::IO::read_PLY(in, mesh_bis); + + v_uvmap = mesh_bis.property_map>("v:uv").value(); + v_umap = mesh_bis.property_map("v:u").value(); + v_vmap = mesh_bis.property_map("v:v").value(); + + fvalue=1001; + for (SMesh::Vertex_index v : vertices(mesh_bis)) + { + assert(v_uvmap[v].size()==2); + assert(v_uvmap[v][0]==fvalue); + assert(v_uvmap[v][1]==-fvalue); + assert(v_umap[v]==fvalue); + assert(v_vmap[v]==-fvalue); + ++fvalue; + } + + f_uvmap = mesh_bis.property_map>("f:uv").value(); + f_umap = mesh_bis.property_map("f:u").value(); + f_vmap = mesh_bis.property_map("f:v").value(); + + dvalue=2001; + for (SMesh::Face_index f : faces(mesh_bis)) + { + assert(f_uvmap[f].size()==2); + assert(f_uvmap[f][0]==dvalue); + assert(f_uvmap[f][1]==-dvalue); + assert(f_umap[f]==dvalue); + assert(f_vmap[f]==-dvalue); + ++dvalue; + } + } + + return 0; +} diff --git a/Surface_mesh/test/Surface_mesh/sm_ply_io.cpp b/Surface_mesh/test/Surface_mesh/sm_ply_io.cpp index d982630c89bd..e0de7b67aa96 100644 --- a/Surface_mesh/test/Surface_mesh/sm_ply_io.cpp +++ b/Surface_mesh/test/Surface_mesh/sm_ply_io.cpp @@ -76,7 +76,7 @@ int main() out.open("out_ascii.ply"); CGAL::IO::write_PLY(out, mesh); out.close(); - out.open("out_binary.ply"); + out.open("out_binary.ply", std::ios::binary); CGAL::IO::set_binary_mode(out); CGAL::IO::write_PLY(out, mesh); out.close(); @@ -87,7 +87,7 @@ int main() { std::cout << "Reading " << fn << "\n"; in.close(); - in.open(fn); + in.open(fn, std::ios::binary); SMesh mesh_bis; CGAL::IO::read_PLY(in, mesh_bis); From 3567ba14565932fb16dd88eed4894ce69e133e3b Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 29 Sep 2025 15:08:02 +0100 Subject: [PATCH 20/39] Fix plugin --- Lab/demo/Lab/Plugins/IO/PLY_io_plugin.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Lab/demo/Lab/Plugins/IO/PLY_io_plugin.cpp b/Lab/demo/Lab/Plugins/IO/PLY_io_plugin.cpp index 63abb1e52695..4bead23b4331 100644 --- a/Lab/demo/Lab/Plugins/IO/PLY_io_plugin.cpp +++ b/Lab/demo/Lab/Plugins/IO/PLY_io_plugin.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -131,9 +132,10 @@ load(QFileInfo fileinfo, bool& ok, bool add_to_scene) { std::vector > polygons; std::vector fcolors; std::vector vcolors; - - if (!(CGAL::IO::read_PLY (in, points, polygons, fcolors, vcolors))) + std::string comments; + if (!(CGAL::IO::read_PLY (in, points, polygons, comments, fcolors, vcolors))) { + CGAL_USE(comments); QApplication::restoreOverrideCursor(); ok = false; return QList(); From 3be4ffce378f768ce39553790348e914f3fcc1b4 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 29 Sep 2025 15:42:59 +0100 Subject: [PATCH 21/39] Fix plugin --- Lab/demo/Lab/Plugins/IO/PLY_io_plugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lab/demo/Lab/Plugins/IO/PLY_io_plugin.cpp b/Lab/demo/Lab/Plugins/IO/PLY_io_plugin.cpp index 4bead23b4331..eec3cbb8cd00 100644 --- a/Lab/demo/Lab/Plugins/IO/PLY_io_plugin.cpp +++ b/Lab/demo/Lab/Plugins/IO/PLY_io_plugin.cpp @@ -132,7 +132,7 @@ load(QFileInfo fileinfo, bool& ok, bool add_to_scene) { std::vector > polygons; std::vector fcolors; std::vector vcolors; - std::string comments; + if (!(CGAL::IO::read_PLY (in, points, polygons, comments, fcolors, vcolors))) { CGAL_USE(comments); From e652a7976a5412f16f00d4b03182a5819b1bc04f Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 29 Sep 2025 16:21:33 +0100 Subject: [PATCH 22/39] fix doxygen warning --- Stream_support/include/CGAL/IO/PLY.h | 6 ++++-- Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Stream_support/include/CGAL/IO/PLY.h b/Stream_support/include/CGAL/IO/PLY.h index 101aa81aafe2..229094602691 100644 --- a/Stream_support/include/CGAL/IO/PLY.h +++ b/Stream_support/include/CGAL/IO/PLY.h @@ -289,7 +289,8 @@ bool read_PLY(std::istream& is, * \param is the input stream * \param points points of the soup of polygons * \param polygons a range of polygons. Each element in it describes a polygon - * using the indices of the points in `points`. + * using the indices of the points in `points` + * \param comments a string that will contain all the comments found in the PLY file * \param np optional \ref bgl_namedparameters "Named Parameters" described below * * \cgalNamedParamsBegin @@ -364,7 +365,8 @@ bool read_PLY(std::istream& is, * \param fname the path to the input file * \param points points of the soup of polygons * \param polygons a range of polygons. Each element in it describes a polygon - * using the indices of the points in `points`. + * using the indices of the points in `points` + * \param comments a string that will contain all the comments found in the PLY file * \param np optional \ref bgl_namedparameters "Named Parameters" described below * * \cgalNamedParamsBegin diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h index fb2e3bf7d0cb..b27e5ebefa16 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h @@ -812,7 +812,6 @@ void fill_header(std::ostream& os, const Surface_mesh& sm, /// \param comments a string used to store the potential comments found in the PLY header. /// Each line starting by "comment " in the header is appended to the `comments` string /// (without the "comment " word). -/// \param verbose whether extra information is printed when an incident occurs during reading /// /// \pre The data in the stream must represent a two-manifold. If this is not the case /// the `failbit` of `is` is set and the mesh cleared. From 33bd58bbefc3c4ee93056ecfd0a5c6c7bbde3805 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 30 Sep 2025 06:47:14 +0100 Subject: [PATCH 23/39] fix doxygen warning --- BGL/include/CGAL/boost/graph/IO/PLY.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/BGL/include/CGAL/boost/graph/IO/PLY.h b/BGL/include/CGAL/boost/graph/IO/PLY.h index c58c228d58cb..6b5f5237801e 100644 --- a/BGL/include/CGAL/boost/graph/IO/PLY.h +++ b/BGL/include/CGAL/boost/graph/IO/PLY.h @@ -87,6 +87,7 @@ bool read_PLY_BGL(std::istream& is, \param is the input stream \param g the graph to be built from the input data + \param comments a string included line by line in the header of the PLY stream (each line will be precedeed by "comment ") \param np optional \ref bgl_namedparameters "Named Parameters" described below \cgalNamedParamsBegin @@ -173,6 +174,7 @@ bool read_PLY(std::istream& is, \param fname the name of the input file \param g the graph to be built from the input data + \param comments a string included line by line in the header of the PLY stream (each line will be precedeed by "comment \param np optional \ref bgl_namedparameters "Named Parameters" described below \cgalNamedParamsBegin From 89ba13f97725cb49e8086aae2cf04c7e795e6704 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 30 Sep 2025 08:13:22 +0100 Subject: [PATCH 24/39] fix doxygen warning --- BGL/include/CGAL/boost/graph/IO/PLY.h | 2 +- Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/IO/PLY.h b/BGL/include/CGAL/boost/graph/IO/PLY.h index 6b5f5237801e..c069ef7e96ef 100644 --- a/BGL/include/CGAL/boost/graph/IO/PLY.h +++ b/BGL/include/CGAL/boost/graph/IO/PLY.h @@ -174,7 +174,7 @@ bool read_PLY(std::istream& is, \param fname the name of the input file \param g the graph to be built from the input data - \param comments a string included line by line in the header of the PLY stream (each line will be precedeed by "comment + \param comments a string included line by line in the header of the PLY stream (each line will be precedeed by "comment" ) \param np optional \ref bgl_namedparameters "Named Parameters" described below \cgalNamedParamsBegin diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h index b27e5ebefa16..248088795421 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h @@ -821,8 +821,11 @@ void fill_header(std::ostream& os, const Surface_mesh& sm, template bool read_PLY(std::istream& is, Surface_mesh

& sm, - std::string& comments, - const CGAL_NP_CLASS& np = parameters::default_values()) + std::string& comments +#ifndef DOXYGEN_RUNNING + , const CGAL_NP_CLASS& np = parameters::default_values() +#endif + ) { typedef typename Surface_mesh

::size_type size_type; From 36b66946b81daa0f6c94880a1d4383bf6bfdbac6 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 30 Sep 2025 08:30:55 +0100 Subject: [PATCH 25/39] after Mael's review --- BGL/include/CGAL/boost/graph/IO/PLY.h | 23 ++++++------------- .../include/CGAL/Surface_mesh/IO/PLY.h | 10 ++++---- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/IO/PLY.h b/BGL/include/CGAL/boost/graph/IO/PLY.h index c069ef7e96ef..6d16eaee686b 100644 --- a/BGL/include/CGAL/boost/graph/IO/PLY.h +++ b/BGL/include/CGAL/boost/graph/IO/PLY.h @@ -161,7 +161,6 @@ bool read_PLY(std::istream& is, } - /*! \ingroup PkgBGLIoFuncsPLY @@ -333,10 +332,6 @@ bool read_PLY(const std::string& fname, \cgalParamNEnd \cgalNamedParamsEnd -\note The point and vector types of the point and normal property map must be `double`or `float` - in order to respect the specification of the PLY file format. - A `Cartesian_converter_property_map` can be used to convert the points and vectors on the fly. - \returns `true` if writing was successful, `false` otherwise. */ template @@ -456,13 +451,13 @@ bool write_PLY(std::ostream& os, const Point_3& p = get(vpm, vd); internal::output_properties(os, &p, make_ply_point_writer (Identity_property_map())); if constexpr (!parameters::is_default_parameter::value) - { - auto vnm = get_parameter(np, internal_np::vertex_normal_map); - typedef decltype(vnm) Normal_map; - typedef typename Normal_map::value_type Vector_3; - Vector_3 vec = get(vnm,vd); - internal::output_properties(os, &vec, make_ply_normal_writer (Identity_property_map())); - } + { + auto vnm = get_parameter(np, internal_np::vertex_normal_map); + typedef decltype(vnm) Normal_map; + typedef typename Normal_map::value_type Vector_3; + Vector_3 vec = get(vnm,vd); + internal::output_properties(os, &vec, make_ply_normal_writer (Identity_property_map())); + } if(has_vcolor) { const CGAL::IO::Color& c = get(vcm, vd); @@ -576,10 +571,6 @@ bool write_PLY(std::ostream& os, const Graph& g, const CGAL_NP_CLASS& np = param \cgalParamNEnd \cgalNamedParamsEnd -\note The point and vector types of the point and normal property map must be `double`or `float` - in order to respect the specification of the PLY file format. - A `Cartesian_converter_property_map` can be used to convert the points and vectors on the fly. - \returns `true` if writing was successful, `false` otherwise. */ template diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h index 248088795421..1b8cccd58f43 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h @@ -475,15 +475,15 @@ bool fill_simplex_specific_header(std::ostream& os, if constexpr (std::is_same::value) { os << "property float nx" << std::endl - << "property float ny" << std::endl - << "property float nz" << std::endl; + << "property float ny" << std::endl + << "property float nz" << std::endl; printers.push_back(new Property_printer(vnm)); } else { os << "property double nx" << std::endl - << "property double ny" << std::endl - << "property double nz" << std::endl; + << "property double ny" << std::endl + << "property double nz" << std::endl; auto fvnm = CGAL::make_cartesian_converter_property_map(vnm); printers.push_back(new Property_printer(fvnm)); } @@ -989,7 +989,6 @@ namespace IO { /// /// \returns `true` if writing was successful, `false` otherwise. - template bool write_PLY(std::ostream& os, @@ -1002,6 +1001,7 @@ bool write_PLY(std::ostream& os, typedef typename SMesh::Face_index FIndex; typedef typename SMesh::Edge_index EIndex; typedef typename SMesh::Halfedge_index HIndex; + if(!os.good()) return false; From 0a743e6a1a4b9ddaf03dd2ac9ef67f34ecce7ad5 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 30 Sep 2025 08:41:58 +0100 Subject: [PATCH 26/39] Document named parameter verbose --- Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h index 1b8cccd58f43..a6ccb769f7e5 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h @@ -812,6 +812,15 @@ void fill_header(std::ostream& os, const Surface_mesh& sm, /// \param comments a string used to store the potential comments found in the PLY header. /// Each line starting by "comment " in the header is appended to the `comments` string /// (without the "comment " word). +/// \param np optional \ref bgl_namedparameters "Named Parameters" described below +/// +/// \cgalNamedParamsBegin +/// \cgalParamNBegin{verbose} +/// \cgalParamDescription{whether extra information is printed when an incident occurs during reading} +/// \cgalParamType{Boolean} +/// \cgalParamDefault{`false`} +/// \cgalParamNEnd +/// \cgalNamedParamsEnd /// /// \pre The data in the stream must represent a two-manifold. If this is not the case /// the `failbit` of `is` is set and the mesh cleared. @@ -821,11 +830,8 @@ void fill_header(std::ostream& os, const Surface_mesh& sm, template bool read_PLY(std::istream& is, Surface_mesh

& sm, - std::string& comments -#ifndef DOXYGEN_RUNNING - , const CGAL_NP_CLASS& np = parameters::default_values() -#endif - ) + std::string& comments, + const CGAL_NP_CLASS& np = parameters::default_values()) { typedef typename Surface_mesh

::size_type size_type; From 737079e5305feba9676bec3f6ebf04fd0a81ffb3 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 1 Oct 2025 09:15:54 +0100 Subject: [PATCH 27/39] Fix warning --- BGL/include/CGAL/boost/graph/IO/PLY.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/BGL/include/CGAL/boost/graph/IO/PLY.h b/BGL/include/CGAL/boost/graph/IO/PLY.h index 6d16eaee686b..406bf87c6031 100644 --- a/BGL/include/CGAL/boost/graph/IO/PLY.h +++ b/BGL/include/CGAL/boost/graph/IO/PLY.h @@ -370,11 +370,15 @@ bool write_PLY(std::ostream& os, bool has_vcolor = !is_default_parameter::value; bool has_fcolor = !is_default_parameter::value; - bool has_vnormal = false; + bool has_vnormal; if constexpr (!parameters::is_default_parameter::value) { has_vnormal = true; } + else + { + has_vnormal = false; + } VIMap vim = CGAL::get_initialized_vertex_index_map(g, np); Vpm vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), get_const_property_map(boost::vertex_point, g)); From 9a99df4a9d305e519d928fa24162cbd890b356e6 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 1 Oct 2025 09:38:38 +0100 Subject: [PATCH 28/39] Comment static_assert --- Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h index a6ccb769f7e5..0ccb978a0e45 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h @@ -837,9 +837,9 @@ bool read_PLY(std::istream& is, // not yet supported: this function only uses the Surface_mesh's internal pmaps // to make it work, it'd be sufficient to modify Surface_mesh_filler's maps - static_assert(CGAL::parameters::is_default_parameter::value); - static_assert(CGAL::parameters::is_default_parameter::value); - static_assert(CGAL::parameters::is_default_parameter::value); + // static_assert(CGAL::parameters::is_default_parameter::value); + // static_assert(CGAL::parameters::is_default_parameter::value); + // static_assert(CGAL::parameters::is_default_parameter::value); const bool verbose = CGAL::parameters::choose_parameter(CGAL::parameters::get_parameter(np, internal_np::verbose), true); From 39531baac810694bb7a4aba61fe6ce0a7737af3b Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 2 Oct 2025 07:23:22 +0100 Subject: [PATCH 29/39] Use has_vnormal --- BGL/include/CGAL/boost/graph/IO/PLY.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/IO/PLY.h b/BGL/include/CGAL/boost/graph/IO/PLY.h index 406bf87c6031..f44128e8d9cc 100644 --- a/BGL/include/CGAL/boost/graph/IO/PLY.h +++ b/BGL/include/CGAL/boost/graph/IO/PLY.h @@ -370,15 +370,11 @@ bool write_PLY(std::ostream& os, bool has_vcolor = !is_default_parameter::value; bool has_fcolor = !is_default_parameter::value; - bool has_vnormal; + bool has_vnormal = false; if constexpr (!parameters::is_default_parameter::value) { has_vnormal = true; } - else - { - has_vnormal = false; - } VIMap vim = CGAL::get_initialized_vertex_index_map(g, np); Vpm vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), get_const_property_map(boost::vertex_point, g)); @@ -416,7 +412,7 @@ bool write_PLY(std::ostream& os, << "property uchar alpha" << std::endl; } - if constexpr (!parameters::is_default_parameter::value) + if(has_vnormal) { auto vnm = get_parameter(np, internal_np::vertex_normal_map); typedef decltype(vnm) Normal_map; From 24024424efef47a0b5ffc26a8fd72d5f25470ed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 2 Oct 2025 15:09:48 +0200 Subject: [PATCH 30/39] use constexpr --- BGL/include/CGAL/boost/graph/IO/PLY.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/IO/PLY.h b/BGL/include/CGAL/boost/graph/IO/PLY.h index f44128e8d9cc..ca773333875d 100644 --- a/BGL/include/CGAL/boost/graph/IO/PLY.h +++ b/BGL/include/CGAL/boost/graph/IO/PLY.h @@ -370,11 +370,8 @@ bool write_PLY(std::ostream& os, bool has_vcolor = !is_default_parameter::value; bool has_fcolor = !is_default_parameter::value; - bool has_vnormal = false; - if constexpr (!parameters::is_default_parameter::value) - { - has_vnormal = true; - } + constexpr bool has_vnormal = (!parameters::is_default_parameter::value); + VIMap vim = CGAL::get_initialized_vertex_index_map(g, np); Vpm vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), get_const_property_map(boost::vertex_point, g)); @@ -412,7 +409,7 @@ bool write_PLY(std::ostream& os, << "property uchar alpha" << std::endl; } - if(has_vnormal) + if constexpr (has_vnormal) { auto vnm = get_parameter(np, internal_np::vertex_normal_map); typedef decltype(vnm) Normal_map; From 865c1d2ed7e3681acf17365f5309ed656db62ebd Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 6 Oct 2025 13:05:21 +0100 Subject: [PATCH 31/39] Fix error in test case --- Stream_support/test/Stream_support/issue_7874.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Stream_support/test/Stream_support/issue_7874.cpp b/Stream_support/test/Stream_support/issue_7874.cpp index 313060691baa..95d2a7283360 100644 --- a/Stream_support/test/Stream_support/issue_7874.cpp +++ b/Stream_support/test/Stream_support/issue_7874.cpp @@ -132,7 +132,7 @@ int main() // from #include // https://doc.cgal.org/latest/Surface_mesh/group__PkgSurfaceMeshIOFuncPLY.html#ga50f0e9f2b293855d2c7f1a62939cbe8d std::ofstream out("overloaded_write_PLY_sm.ply", std::ios::binary); - CGAL::set_binary_mode(out); + CGAL::IO::set_binary_mode(out); CGAL::IO::write_PLY(out, sm, "overloaded_write_PLY(Surface_mesh)",CGAL::parameters::stream_precision(17).use_binary_mode(true) .vertex_point_map(scsmvpm).vertex_normal_map(scsmvnpm) ); } From 878ba3fc537a4f665c3c9861d11e686b5c4d113f Mon Sep 17 00:00:00 2001 From: Sebastien Loriot Date: Fri, 17 Oct 2025 10:28:57 +0200 Subject: [PATCH 32/39] suggestions from Mael Co-authored-by: Mael --- Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h index 0ccb978a0e45..ed2f33981b0b 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h @@ -431,13 +431,14 @@ bool fill_simplex_specific_header(std::ostream& os, { using CGAL::parameters::choose_parameter; using CGAL::parameters::get_parameter; + typedef Surface_mesh SMesh; typedef typename SMesh::Vertex_index VIndex; typedef typename Kernel_traits::Kernel Kernel; typedef typename Kernel::FT FT; typedef typename Kernel::Vector_3 Vector; - typedef typename GetVertexPointMap, NamedParameter>::const_type Point_map; + typedef typename GetVertexPointMap::const_type Point_map; typedef typename SMesh::template Property_map Vector_map; typedef typename SMesh::template Property_map Vcolor_map; @@ -510,7 +511,6 @@ bool fill_simplex_specific_header(std::ostream& os, auto fvnm = CGAL::make_cartesian_converter_property_map(*pmap); printers.push_back(new Property_printer(fvnm)); } - // printers.push_back(new Property_printer(*pmap)); return true; } } From 3706528a0ceb9e9b6f5acf822be27c9f0be9ff89 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 17 Oct 2025 11:20:06 +0200 Subject: [PATCH 33/39] Update Stream_support/include/CGAL/IO/PLY/PLY_writer.h Co-authored-by: Mael --- Stream_support/include/CGAL/IO/PLY/PLY_writer.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Stream_support/include/CGAL/IO/PLY/PLY_writer.h b/Stream_support/include/CGAL/IO/PLY/PLY_writer.h index 64ce6b1def25..0bd1df89d2d2 100644 --- a/Stream_support/include/CGAL/IO/PLY/PLY_writer.h +++ b/Stream_support/include/CGAL/IO/PLY/PLY_writer.h @@ -254,7 +254,6 @@ class Property_printer } }; - template ::value_type> From da011b2abe5c386118d693ef7fd02ec5917851e0 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 17 Oct 2025 10:43:33 +0100 Subject: [PATCH 34/39] No longer #if 0 --- Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h index ed2f33981b0b..4eafcdbf1377 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h @@ -929,13 +929,13 @@ bool read_PLY(std::istream& is, /// \cond SKIP_IN_MANUAL -#if 0 +#ifndef CGAL_NO_DEPRECATED_CODE // for backward compatibility template bool read_PLY(std::istream& is, Surface_mesh

& sm, std::string& comments, - bool verbose = true) + bool verbose) { return read_PLY(is, sm, comments, CGAL::parameters::verbose(verbose)); } From 98a3051235fd41fb66b716504accdc6934fb3b94 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 17 Oct 2025 10:48:26 +0100 Subject: [PATCH 35/39] copy style --- BGL/include/CGAL/boost/graph/IO/PLY.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BGL/include/CGAL/boost/graph/IO/PLY.h b/BGL/include/CGAL/boost/graph/IO/PLY.h index ca773333875d..bd2a59e9843b 100644 --- a/BGL/include/CGAL/boost/graph/IO/PLY.h +++ b/BGL/include/CGAL/boost/graph/IO/PLY.h @@ -370,7 +370,7 @@ bool write_PLY(std::ostream& os, bool has_vcolor = !is_default_parameter::value; bool has_fcolor = !is_default_parameter::value; - constexpr bool has_vnormal = (!parameters::is_default_parameter::value); + bool has_vnormal = !is_default_parameter::value; VIMap vim = CGAL::get_initialized_vertex_index_map(g, np); Vpm vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), From d9ba43a9ba4d21e76dcdef9f760b571056a0ade4 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 17 Oct 2025 12:40:30 +0100 Subject: [PATCH 36/39] Make it constexpr to avoid error in CI --- BGL/include/CGAL/boost/graph/IO/PLY.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BGL/include/CGAL/boost/graph/IO/PLY.h b/BGL/include/CGAL/boost/graph/IO/PLY.h index bd2a59e9843b..f2acf33ccabe 100644 --- a/BGL/include/CGAL/boost/graph/IO/PLY.h +++ b/BGL/include/CGAL/boost/graph/IO/PLY.h @@ -370,7 +370,7 @@ bool write_PLY(std::ostream& os, bool has_vcolor = !is_default_parameter::value; bool has_fcolor = !is_default_parameter::value; - bool has_vnormal = !is_default_parameter::value; + constexpr bool has_vnormal = !is_default_parameter::value; VIMap vim = CGAL::get_initialized_vertex_index_map(g, np); Vpm vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), From 00f5ae061dcf0339d5e0e256cbd9ac30707caae2 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 30 Oct 2025 09:36:53 +0100 Subject: [PATCH 37/39] Use Simple_cartesian --- Stream_support/test/Stream_support/issue_7874.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Stream_support/test/Stream_support/issue_7874.cpp b/Stream_support/test/Stream_support/issue_7874.cpp index 95d2a7283360..fa040cac9d0e 100644 --- a/Stream_support/test/Stream_support/issue_7874.cpp +++ b/Stream_support/test/Stream_support/issue_7874.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -8,12 +9,14 @@ #include #include -typedef CGAL::Surface_mesh Surface_mesh; +// typedef CGAL::Exact_predicates_exact_constructions_kernel Epeck; +typedef CGAL::Simple_cartesian Epeck; +typedef CGAL::Surface_mesh Surface_mesh; typedef boost::graph_traits::vertex_descriptor vertex_descriptor; -typedef CGAL::Polyhedron_3 Polyhedron_3; +typedef CGAL::Polyhedron_3 Polyhedron_3; typedef boost::graph_traits::vertex_descriptor pvertex_descriptor; -typedef CGAL::Epeck::Point_3 Point_3; -typedef CGAL::Epeck::Vector_3 Vector_3; +typedef Epeck::Point_3 Point_3; +typedef Epeck::Vector_3 Vector_3; typedef CGAL::Simple_cartesian SC; typedef Surface_mesh::template Property_map VNMap; typedef CGAL::Cartesian_converter_property_map< SC::Vector_3, VNMap> ScSmVertexNormalMap; From 35613b984f553ce0cd52a19e256d7e5918e4f81e Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 30 Oct 2025 11:45:28 +0100 Subject: [PATCH 38/39] Deal with generic version --- BGL/include/CGAL/boost/graph/IO/PLY.h | 74 ++++++++++++++----- .../test/Stream_support/issue_7874.cpp | 22 ++++-- 2 files changed, 73 insertions(+), 23 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/IO/PLY.h b/BGL/include/CGAL/boost/graph/IO/PLY.h index f2acf33ccabe..1191f94c2ea7 100644 --- a/BGL/include/CGAL/boost/graph/IO/PLY.h +++ b/BGL/include/CGAL/boost/graph/IO/PLY.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -397,8 +398,19 @@ bool write_PLY(std::ostream& os, } } + os << "element vertex " << vertices(g).size() << std::endl; - internal::output_property_header(os, make_ply_point_writer (CGAL::Identity_property_map())); + if constexpr (std::is_same::Kernel::FT, float>::value) + { + internal::output_property_header(os, make_ply_point_writer (CGAL::Identity_property_map())); + } + else + { + typedef typename Kernel_traits::Kernel K; + typedef decltype(std::declval >().operator()(std::declval())) Target_point; + auto fvpm = CGAL::make_cartesian_converter_property_map(vpm); + internal::output_property_header(os, make_ply_point_writer (fvpm)); + } //if vcm is not default add v:color property if(has_vcolor) @@ -413,19 +425,19 @@ bool write_PLY(std::ostream& os, { auto vnm = get_parameter(np, internal_np::vertex_normal_map); typedef decltype(vnm) Normal_map; - typedef typename Kernel_traits::Kernel::FT FloatDouble; - if(std::is_same::value) - { - os << "property float nx" << std::endl - << "property float ny" << std::endl - << "property float nz" << std::endl; - } - else - { - os << "property double nx" << std::endl - << "property double ny" << std::endl - << "property double nz" << std::endl; - } + typedef typename Normal_map::value_type Vector_3; + typedef typename Kernel_traits::Kernel K; + typedef typename K::FT FT; + if constexpr (std::is_same::value) + { + internal::output_property_header(os, make_ply_normal_writer (CGAL::Identity_property_map())); + } + else + { + typedef decltype(std::declval >().operator()(std::declval())) Target_vector; + auto fvnm = CGAL::make_cartesian_converter_property_map(vnm); + internal::output_property_header(os, make_ply_normal_writer (fvnm)); + } } os << "element face " << faces(g).size() << std::endl; @@ -445,15 +457,41 @@ bool write_PLY(std::ostream& os, for(vertex_descriptor vd : vertices(g)) { - const Point_3& p = get(vpm, vd); - internal::output_properties(os, &p, make_ply_point_writer (Identity_property_map())); + if constexpr (std::is_same::Kernel::FT, float>::value) + { + decltype(auto) p = get(vpm, vd); + internal::output_properties(os, &p, make_ply_point_writer (CGAL::Identity_property_map())); + } + else + { + typedef typename Kernel_traits::Kernel K; + typedef CGAL::cpp20::remove_cvref_t >().operator()(std::declval()))> Target_point; + CGAL::Cartesian_converter_property_map fvpm = CGAL::make_cartesian_converter_property_map(vpm); + decltype(auto) fp = get(fvpm, vd); + internal::output_properties(os, &fp, make_ply_point_writer (CGAL::Identity_property_map())); + } + + std::cout << "using generic writer" << std::endl; + if constexpr (!parameters::is_default_parameter::value) { auto vnm = get_parameter(np, internal_np::vertex_normal_map); typedef decltype(vnm) Normal_map; typedef typename Normal_map::value_type Vector_3; - Vector_3 vec = get(vnm,vd); - internal::output_properties(os, &vec, make_ply_normal_writer (Identity_property_map())); + + if constexpr (std::is_same::Kernel::FT, float>::value) + { + decltype(auto) vec = get(vnm,vd); + internal::output_properties(os, &vec, make_ply_normal_writer (CGAL::Identity_property_map())); + } + else + { + typedef typename Kernel_traits::Kernel K; + typedef CGAL::cpp20::remove_cvref_t >().operator()(std::declval()))> Target_vector; + auto fvnm = CGAL::make_cartesian_converter_property_map(vnm); + decltype(auto) fvec = get(fvnm, vd); + internal::output_properties(os, &fvec, make_ply_normal_writer (CGAL::Identity_property_map())); + } } if(has_vcolor) { diff --git a/Stream_support/test/Stream_support/issue_7874.cpp b/Stream_support/test/Stream_support/issue_7874.cpp index fa040cac9d0e..4700957c822f 100644 --- a/Stream_support/test/Stream_support/issue_7874.cpp +++ b/Stream_support/test/Stream_support/issue_7874.cpp @@ -69,16 +69,28 @@ int main() } } +{ PolyhedronVN vn; PolyhedronVNMap povnpm(vn); - ScPolyhedronVertexNormalMap scpovnpm(povnpm); - - CGAL::Polygon_mesh_processing::compute_vertex_normals(po, povnpm); - // ERROR this produces an invalid plyfile CGAL::IO::write_polygon_mesh("write_polygon_mesh_po.ply", po, + CGAL::parameters::stream_precision(17).use_binary_mode(true).vertex_point_map(povpm).vertex_normal_map(povnpm)) ; + if (!CGAL::IO::read_polygon_mesh("write_polygon_mesh_po.ply", po)) + { + std::cerr << "Error: failed to read 'write_polygon_mesh_po.ply'" << std::endl; + return EXIT_FAILURE; + } + + ScPolyhedronVertexNormalMap scpovnpm(povnpm); + CGAL::IO::write_polygon_mesh("write_polygon_mesh_po_sc.ply", po, CGAL::parameters::stream_precision(17).use_binary_mode(true).vertex_point_map(scpovpm).vertex_normal_map(scpovnpm)) ; + if (!CGAL::IO::read_polygon_mesh("write_polygon_mesh_po_sc.ply", po)) + { + std::cerr << "Error: failed to read 'write_polygon_mesh_po_sc.ply'" << std::endl; + return EXIT_FAILURE; + } +} { Surface_mesh osm; @@ -115,7 +127,7 @@ int main() // ERROR this produces an invalid plyfile CGAL::IO::write_PLY("generic_write_PLY_po.ply", po, "generic write_PLY(Polyhedron)", - CGAL::parameters::stream_precision(17).use_binary_mode(true).vertex_point_map(scpovpm)); + CGAL::parameters::stream_precision(17).use_binary_mode(true).vertex_point_map(povpm)); { Surface_mesh osm; From 622b652652ef482d78880e77fffe8079c8510fc3 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 30 Oct 2025 13:54:35 +0100 Subject: [PATCH 39/39] Add to BGL dependencies --- BGL/package_info/BGL/dependencies | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/BGL/package_info/BGL/dependencies b/BGL/package_info/BGL/dependencies index 7cf027b2c486..351c042ea63b 100644 --- a/BGL/package_info/BGL/dependencies +++ b/BGL/package_info/BGL/dependencies @@ -1,13 +1,19 @@ Algebraic_foundations +Arithmetic_kernel BGL Cartesian_kernel Circulator Distance_2 Distance_3 +Filtered_kernel +Homogeneous_kernel Hash_map Installation +Intersections_2 +Intersections_3 Interval_support Kernel_23 +Kernel_d Modular_arithmetic Number_types Profiling_tools @@ -15,3 +21,4 @@ Property_map Random_numbers STL_Extension Stream_support +CGAL_Core