diff --git a/BGL/include/CGAL/boost/graph/IO/GOCAD.h b/BGL/include/CGAL/boost/graph/IO/GOCAD.h index 25cdf0ce780..966e4f4219d 100644 --- a/BGL/include/CGAL/boost/graph/IO/GOCAD.h +++ b/BGL/include/CGAL/boost/graph/IO/GOCAD.h @@ -18,7 +18,7 @@ #include #include #include - +#include #include #include @@ -271,7 +271,7 @@ bool read_GOCAD(const std::string& fname, Graph& g, /// \cgalParamNBegin{stream_precision} /// \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} /// \cgalParamType{int} -/// \cgalParamDefault{`6`} +/// \cgalParamDefault{`the precision of the stream `os``} /// \cgalParamNEnd /// \cgalNamedParamsEnd /// @@ -303,8 +303,7 @@ bool write_GOCAD(std::ostream& os, if(!os.good()) return false; - const int precision = choose_parameter(get_parameter(np, internal_np::stream_precision), 6); - os.precision(precision); + set_stream_precision_from_NP(os, np); os << "GOCAD TSurf 1\n" "HEADER {\n" @@ -380,7 +379,7 @@ bool write_GOCAD(std::ostream& os, const char* name, const Graph& g, /// \cgalParamNBegin{stream_precision} /// \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} /// \cgalParamType{int} -/// \cgalParamDefault{`6`} +/// \cgalParamDefault{`the precision of the stream `os``} /// \cgalParamNEnd /// \cgalNamedParamsEnd /// @@ -454,6 +453,7 @@ bool write_GOCAD(const std::string& fname, { std::ofstream os(fname); CGAL::set_mode(os, CGAL::IO::ASCII); + return write_GOCAD(os, fname.c_str(), g, np); } diff --git a/BGL/include/CGAL/boost/graph/IO/Generic_facegraph_printer.h b/BGL/include/CGAL/boost/graph/IO/Generic_facegraph_printer.h index 4ab13c13192..5fb75be5363 100644 --- a/BGL/include/CGAL/boost/graph/IO/Generic_facegraph_printer.h +++ b/BGL/include/CGAL/boost/graph/IO/Generic_facegraph_printer.h @@ -117,8 +117,7 @@ public: if(!m_os.good()) return false; - const int precision = choose_parameter(get_parameter(np, internal_np::stream_precision), 6); - m_os.precision(precision); + set_stream_precision_from_NP(m_os, np); VPM vpm = choose_parameter(get_parameter(np, internal_np::vertex_point), get_const_property_map(CGAL::vertex_point, g)); diff --git a/BGL/include/CGAL/boost/graph/IO/OBJ.h b/BGL/include/CGAL/boost/graph/IO/OBJ.h index 8e1c9b5ea89..7d733c9f8b4 100644 --- a/BGL/include/CGAL/boost/graph/IO/OBJ.h +++ b/BGL/include/CGAL/boost/graph/IO/OBJ.h @@ -231,7 +231,7 @@ bool read_OBJ(const std::string& fname, Graph& g, \cgalParamNBegin{stream_precision} \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} \cgalParamType{int} - \cgalParamDefault{`6`} + \cgalParamDefault{`the precision of the stream `os``} \cgalParamNEnd \cgalNamedParamsEnd @@ -285,6 +285,11 @@ bool write_OBJ(std::ostream& os, const Graph& g, \cgalParamExtra{If this parameter is omitted, an internal property map for `CGAL::vertex_point_t` must be available in `Graph`.} \cgalParamNEnd + \cgalParamNBegin{stream_precision} + \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} + \cgalParamType{int} + \cgalParamDefault{`6`} + \cgalParamNEnd \cgalNamedParamsEnd \returns `true` if writing was successful, `false` otherwise. diff --git a/BGL/include/CGAL/boost/graph/IO/OFF.h b/BGL/include/CGAL/boost/graph/IO/OFF.h index 0c95c7ea570..57685046e79 100644 --- a/BGL/include/CGAL/boost/graph/IO/OFF.h +++ b/BGL/include/CGAL/boost/graph/IO/OFF.h @@ -284,9 +284,9 @@ bool read_OFF(const std::string& fname, Graph& g, \deprecated This function is deprecated since \cgal 5.2, `CGAL::read_OFF()` should be used instead. */ template -CGAL_DEPRECATED bool read_off(std::ostream& os, Graph& g, const CGAL_BGL_NP_CLASS& np) +CGAL_DEPRECATED bool read_off(std::istream& is, Graph& g, const CGAL_BGL_NP_CLASS& np) { - return read_OFF(os, g, np); + return read_OFF(is, g, np); } /*! @@ -300,6 +300,18 @@ CGAL_DEPRECATED bool read_off(const char* fname, Graph& g, const CGAL_BGL_NP_CLA return read_OFF(fname, g, np); } +template +CGAL_DEPRECATED bool read_off(std::istream& is, Graph& g) +{ + return read_off(is, g, parameters::all_default()); +} + +template +CGAL_DEPRECATED bool read_off(const char* fname, Graph& g) +{ + return read_off(fname, g, parameters::all_default()); +} + #endif // CGAL_NO_DEPRECATED_CODE //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -374,7 +386,7 @@ bool write_OFF_BGL(std::ostream& os, \cgalParamNBegin{stream_precision} \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} \cgalParamType{int} - \cgalParamDefault{`6`} + \cgalParamDefault{`the precision of the stream `os``} \cgalParamNEnd \cgalNamedParamsEnd @@ -483,6 +495,7 @@ bool write_OFF(const std::string& fname, std::cerr<<"Could not create file."; return false; } + return write_OFF(os, g, np); } @@ -510,6 +523,11 @@ CGAL_DEPRECATED bool write_off(std::ostream& os, const Graph& g, const CGAL_BGL_ return write_OFF(os, g, np); } +template +CGAL_DEPRECATED bool write_off(std::ostream& os, const Graph& g) +{ + return write_off(os, g, CGAL::parameters::all_default()); +} /*! \ingroup PkgBGLIOFctDeprecated @@ -521,6 +539,11 @@ CGAL_DEPRECATED bool write_off(const char* fname, const Graph& g, const CGAL_BGL return write_OFF(fname, g, np); } +template +CGAL_DEPRECATED bool write_off(const char* fname, const Graph& g) +{ + return write_off(fname, g, parameters::all_default()); +} #endif // CGAL_NO_DEPRECATED_CODE } // namespace CGAL diff --git a/BGL/include/CGAL/boost/graph/IO/PLY.h b/BGL/include/CGAL/boost/graph/IO/PLY.h index ff65a977f7b..c571c07d629 100644 --- a/BGL/include/CGAL/boost/graph/IO/PLY.h +++ b/BGL/include/CGAL/boost/graph/IO/PLY.h @@ -311,7 +311,7 @@ bool read_PLY(const std::string& fname, Graph& g, \cgalParamNBegin{stream_precision} \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} \cgalParamType{int} - \cgalParamDefault{`6`} + \cgalParamDefault{`the precision of the stream `os``} \cgalParamExtra{This parameter is only meaningful while using ASCII encoding.} \cgalParamNEnd \cgalNamedParamsEnd @@ -361,8 +361,7 @@ bool write_PLY(std::ostream& os, if(!os.good()) return false; - const int precision = choose_parameter(get_parameter(np, internal_np::stream_precision), 6); - os.precision(precision); + set_stream_precision_from_NP(os, np); // Write header os << "ply" << std::endl @@ -550,6 +549,7 @@ bool write_PLY(const std::string& fname, { std::ofstream os(fname); CGAL::set_mode(os, CGAL::IO::ASCII); + return write_PLY(os, g, comments, np); } } diff --git a/BGL/include/CGAL/boost/graph/IO/STL.h b/BGL/include/CGAL/boost/graph/IO/STL.h index de10a9a95a5..78bd1fcb588 100644 --- a/BGL/include/CGAL/boost/graph/IO/STL.h +++ b/BGL/include/CGAL/boost/graph/IO/STL.h @@ -231,7 +231,7 @@ bool read_STL(const std::string& fname, Graph& g) { return read_STL(fname, g, pa \cgalParamNBegin{stream_precision} \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} \cgalParamType{int} - \cgalParamDefault{`6`} + \cgalParamDefault{`the precision of the stream `os``} \cgalParamExtra{This parameter is only meaningful while using ASCII encoding.} \cgalParamNEnd \cgalNamedParamsEnd @@ -262,8 +262,7 @@ bool write_STL(std::ostream& os, if(!os.good()) return false; - const int precision = choose_parameter(get_parameter(np, internal_np::stream_precision), 6); - os.precision(precision); + set_stream_precision_from_NP(os, np); if(get_mode(os) == IO::BINARY) { @@ -372,6 +371,7 @@ bool write_STL(const std::string& fname, const Graph& g, const CGAL_BGL_NP_CLASS { std::ofstream os(fname); CGAL::set_mode(os, CGAL::IO::ASCII); + return write_STL(os, g, np); } } diff --git a/BGL/include/CGAL/boost/graph/IO/VTK.h b/BGL/include/CGAL/boost/graph/IO/VTK.h index 1ba37f19d6c..894b3598b09 100644 --- a/BGL/include/CGAL/boost/graph/IO/VTK.h +++ b/BGL/include/CGAL/boost/graph/IO/VTK.h @@ -420,7 +420,7 @@ void write_polys_points(std::ostream& os, * \cgalParamNBegin{stream_precision} * \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} * \cgalParamType{int} - * \cgalParamDefault{`6`} + * \cgalParamDefault{`the precision of the stream `os``} * \cgalParamNEnd * \cgalNamedParamsEnd * @@ -439,8 +439,7 @@ bool write_VTP(std::ostream& os, if(!os.good()) return false; - const int precision = choose_parameter(get_parameter(np, internal_np::stream_precision), 6); - os.precision(precision); + set_stream_precision_from_NP(os, np); os << "\n" << " +CGAL_DEPRECATED bool write_vtp(std::ostream& os, const Graph& g) +{ + return write_vtp(os, g, parameters::all_default()); +} + #endif // CGAL_NO_DEPRECATED_CODE } // namespace CGAL diff --git a/BGL/include/CGAL/boost/graph/IO/WRL.h b/BGL/include/CGAL/boost/graph/IO/WRL.h index c9d2f69b6b5..dc8186862c7 100644 --- a/BGL/include/CGAL/boost/graph/IO/WRL.h +++ b/BGL/include/CGAL/boost/graph/IO/WRL.h @@ -59,7 +59,7 @@ namespace CGAL { \cgalParamNBegin{stream_precision} \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} \cgalParamType{int} - \cgalParamDefault{`6`} + \cgalParamDefault{`the precision of the stream `os``} \cgalParamNEnd \cgalNamedParamsEnd @@ -70,7 +70,8 @@ bool write_WRL(std::ostream& os, const Graph& g, const CGAL_BGL_NP_CLASS& np) { - IO::internal::Generic_facegraph_printer printer(os); + CGAL::VRML_2_ostream vos(os); + IO::internal::Generic_facegraph_printer printer(vos); return printer(g, np); } @@ -108,8 +109,8 @@ bool write_WRL(std::ostream& os, template bool write_WRL(const std::string& fname, const Graph& g, const CGAL_BGL_NP_CLASS& np) { - std::ifstream is(fname); - return write_WRL(is, g, np); + std::ofstream os(fname); + return write_WRL(os, g, np); } template @@ -130,6 +131,12 @@ CGAL_DEPRECATED bool write_wrl(std::ostream& os, const Graph& g, const CGAL_BGL_ return write_WRL(os, g, np); } +template +CGAL_DEPRECATED bool write_wrl(std::ostream& os, const Graph& g) +{ + return write_wrl(os, g, parameters::all_default()); +} + #endif // CGAL_NO_DEPRECATED_CODE } // namespace CGAL diff --git a/BGL/include/CGAL/boost/graph/named_params_helper.h b/BGL/include/CGAL/boost/graph/named_params_helper.h index 0993fb05d69..cc38868738d 100644 --- a/BGL/include/CGAL/boost/graph/named_params_helper.h +++ b/BGL/include/CGAL/boost/graph/named_params_helper.h @@ -560,6 +560,21 @@ CGAL_DEF_GET_INITIALIZED_INDEX_MAP(face, typename boost::graph_traits::fa Alpha_expansion_boost_adjacency_list_tag >::type type; }; + + template + void set_stream_precision_from_NP(std::ostream& os, const NP& np) + { + using parameters::get_parameter; + using parameters::choose_parameter; + using parameters::is_default_parameter; + + if(!is_default_parameter(get_parameter(np, internal_np::stream_precision))) + { + const int precision = choose_parameter(get_parameter(np, + internal_np::stream_precision)); + os.precision(precision); + } + } } //namespace CGAL diff --git a/BGL/test/BGL/CMakeLists.txt b/BGL/test/BGL/CMakeLists.txt index d6ec47e9cae..3009a3ae873 100644 --- a/BGL/test/BGL/CMakeLists.txt +++ b/BGL/test/BGL/CMakeLists.txt @@ -98,6 +98,8 @@ create_single_source_cgal_program( create_single_source_cgal_program( "graph_traits_inheritance.cpp" ) +create_single_source_cgal_program("test_deprecated_io.cpp") + if(OpenMesh_FOUND) target_link_libraries(test_clear PRIVATE ${OPENMESH_LIBRARIES}) target_compile_definitions(test_clear PRIVATE -DCGAL_USE_OPENMESH) @@ -129,6 +131,8 @@ if (VTK_FOUND) if(VTK_LIBRARIES) target_link_libraries(test_bgl_read_write PRIVATE ${VTK_LIBRARIES}) target_compile_definitions(test_bgl_read_write PRIVATE -DCGAL_USE_VTK) + target_link_libraries(test_deprecated_io PRIVATE ${VTK_LIBRARIES}) + target_compile_definitions(test_deprecated_io PRIVATE -DCGAL_USE_VTK) else() message(STATUS "Tests that use VTK will not be compiled.") endif() diff --git a/BGL/test/BGL/test_deprecated_io.cpp b/BGL/test/BGL/test_deprecated_io.cpp new file mode 100644 index 00000000000..5bd037191cc --- /dev/null +++ b/BGL/test/BGL/test_deprecated_io.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include +#include + +#include +#include +#include + + +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point_3; +typedef CGAL::Surface_mesh SM; + +int main() +{ + // OFF + SM sm_in, sm_out; + Point_3 p0(0,0,0), p1(1,0,0), p2(0,1,0); + CGAL::make_triangle(p0, p1, p2, sm_out); + bool ok = CGAL::write_off("tmp.off", sm_out); + assert(ok); + ok = CGAL::read_off("tmp.off", sm_in); + assert(ok); + assert(num_vertices(sm_in) == 3 && num_faces(sm_in) == 1); + sm_in.clear(); + + std::ofstream os("tmp.off"); + ok = CGAL::write_off(os, sm_out); + assert(ok); + os.close(); + std::ifstream is("tmp.off"); + ok = CGAL::read_off(is, sm_in); + assert(ok); + assert(num_vertices(sm_in) == 3 && num_faces(sm_in) == 1); + is.close(); + sm_in.clear(); +#ifdef CGAL_USE_VTK + //vtk + os.open("tmp.vtp"); + ok = CGAL::write_vtp(os, sm_out); + assert(ok); + os.close(); + + ok = CGAL::read_VTP("tmp.vtp", sm_in); + assert(ok); + assert(num_vertices(sm_in) == 3 && num_faces(sm_in) == 1); + sm_in.clear(); +#endif + //wrl + os.open("tmp.wrl"); + ok = CGAL::write_wrl(os, sm_out); + assert(ok); + os.close(); + return EXIT_SUCCESS; +} diff --git a/Maintenance/infrastructure/cgal.geometryfactory.com/crontab b/Maintenance/infrastructure/cgal.geometryfactory.com/crontab index 34829fff40e..c023da89fcf 100644 --- a/Maintenance/infrastructure/cgal.geometryfactory.com/crontab +++ b/Maintenance/infrastructure/cgal.geometryfactory.com/crontab @@ -67,7 +67,7 @@ LC_CTYPE=en_US.UTF-8 18 * * * * $HOME/bin/dump_crontab # Docker check every hour -#0 * * * * docker inspect --format='{{json .State.Health.Status}}' cgal-mediawiki-docker_wiki_1 | grep -q '"healthy"' || docker logs cgal-mediawiki-docker_wiki_1 +0 * * * * docker inspect --format='{{json .State.Health.Status}}' cgal-mediawiki-docker_wiki_1 | grep -q '"healthy"' || docker logs cgal-mediawiki-docker_wiki_1 # cgal->cgal2 with git-multimail */5 * * * * cd $HOME/Git/cgal-dev-pusher.git && $HOME/bin/git-fetch-and-push-to-multimail cgal-dev cgal-dev-receiver diff --git a/Point_set_3/include/CGAL/Point_set_3/IO/OFF.h b/Point_set_3/include/CGAL/Point_set_3/IO/OFF.h index 5425fbfa4b9..b8882c97fdc 100644 --- a/Point_set_3/include/CGAL/Point_set_3/IO/OFF.h +++ b/Point_set_3/include/CGAL/Point_set_3/IO/OFF.h @@ -134,7 +134,7 @@ CGAL_DEPRECATED bool read_off_point_set(std::istream& is, ///< input stream. \cgalParamNBegin{stream_precision} \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} \cgalParamType{int} - \cgalParamDefault{`6`} + \cgalParamDefault{`the precision of the stream `os``} \cgalParamNEnd \cgalNamedParamsEnd diff --git a/Point_set_3/include/CGAL/Point_set_3/IO/PLY.h b/Point_set_3/include/CGAL/Point_set_3/IO/PLY.h index 1e60eac251f..4646ffbd974 100644 --- a/Point_set_3/include/CGAL/Point_set_3/IO/PLY.h +++ b/Point_set_3/include/CGAL/Point_set_3/IO/PLY.h @@ -456,7 +456,7 @@ CGAL_DEPRECATED bool read_ply_point_set(std::istream& is, ///< input stream. \cgalParamNBegin{stream_precision} \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} \cgalParamType{int} - \cgalParamDefault{`6`} + \cgalParamDefault{`the precision of the stream `os``} \cgalParamExtra{This parameter is only meaningful while using ASCII encoding.} \cgalParamNEnd \cgalNamedParamsEnd @@ -493,8 +493,7 @@ bool write_PLY(std::ostream& os, return false; } - const int precision = choose_parameter(get_parameter(np, internal_np::stream_precision), 6); - os.precision(precision); + set_stream_precision_from_NP(os, np); os << "ply" << std::endl << ((get_mode(os) == IO::BINARY) ? "format binary_little_endian 1.0" : "format ascii 1.0") << std::endl diff --git a/Point_set_3/include/CGAL/Point_set_3/IO/XYZ.h b/Point_set_3/include/CGAL/Point_set_3/IO/XYZ.h index 4f5ba04a550..a7b243fc192 100644 --- a/Point_set_3/include/CGAL/Point_set_3/IO/XYZ.h +++ b/Point_set_3/include/CGAL/Point_set_3/IO/XYZ.h @@ -132,7 +132,7 @@ CGAL_DEPRECATED bool read_xyz_point_set(std::istream& is, CGAL::Point_set_3 + +#include + +#include +#include +#include +#include + +#include +#include + + +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point_3; +typedef Kernel::Vector_3 Vector_3; + +int main() +{ + CGAL::Point_set_3 ps, ps2; + std::ifstream is("data/oni.pwn"); + std::ofstream os; + + if(!CGAL::read_xyz_point_set(is, ps)) + { + std::cerr<<"Error while reading input."< + +#include + +#include +#include +#include + +// Just to try and create ambiguities +#include +#include + +#include + +#include +#include +#include +#include + +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point_3; +typedef Kernel::Vector_3 Vector_3; +typedef std::array Color; +typedef std::pair PointWithColor; +typedef CGAL::Nth_of_tuple_property_map<1, PointWithColor> Color_map; + +struct GetRedMap{ + typedef PointWithColor key_type; + typedef unsigned short value_type; + typedef const value_type& reference; + typedef boost::lvalue_property_map_tag category; +}; +unsigned short get(const GetRedMap&, const PointWithColor& p) +{ + return p.second[0]; +} + +struct GetGreenMap{ + typedef PointWithColor key_type; + typedef unsigned short value_type; + typedef const value_type& reference; + typedef boost::lvalue_property_map_tag category; +}; +unsigned short get(const GetGreenMap&, const PointWithColor& p) +{ + return p.second[1]; +} + +struct GetBlueMap{ + typedef PointWithColor key_type; + typedef unsigned short value_type; + typedef const value_type& reference; + typedef boost::lvalue_property_map_tag category; +}; +unsigned short get(const GetBlueMap&, const PointWithColor& p) +{ + return p.second[2]; +} + +struct GetAlphaMap{ + typedef PointWithColor key_type; + typedef unsigned short value_type; + typedef const value_type& reference; + typedef boost::lvalue_property_map_tag category; +}; +unsigned short get(const GetAlphaMap&, const PointWithColor& p) +{ + return p.second[3]; +} + +int main() +{ + +std::vector points(3); +points[0] = std::make_pair(Point_3(1,0,0), Color{255,0,0,255}); +points[1] = std::make_pair(Point_3(0,1,0), Color{0,255,0,255}); +points[2] = std::make_pair(Point_3(0,0,1), Color{0,0,255,255}); + + +std::ofstream os; +std::ifstream is; +bool ok; +std::vector ps; +ps.push_back(Point_3(1,0,0)); +ps.push_back(Point_3(0,1,0)); +ps.push_back(Point_3(0,0,1)); +//LAS +#ifdef CGAL_LINKED_WITH_LASLIB +os.open("tmp.las", std::ios::binary); +ok = CGAL::write_las_points_with_properties(os, points, + CGAL::make_las_point_writer(CGAL::First_of_pair_property_map()), + std::make_pair(GetRedMap(),CGAL::LAS_property::R()), + std::make_pair(GetGreenMap(), CGAL::LAS_property::G()), + std::make_pair(GetBlueMap(), CGAL::LAS_property::B()), + std::make_pair(GetAlphaMap(), CGAL::LAS_property::I()) + ); +os.close(); +assert(ok); +points.clear(); +is.open("tmp.las", std::ios::binary); +ok = CGAL::read_las_points_with_properties(is, std::back_inserter (points), + CGAL::make_las_point_reader(CGAL::First_of_pair_property_map()), + std::make_tuple(CGAL::Second_of_pair_property_map(), + CGAL::Construct_array(), + CGAL::LAS_property::R(), + CGAL::LAS_property::G(), + CGAL::LAS_property::B(), + CGAL::LAS_property::I())); +is.close(); +assert(ok); +assert(points.size() == 3); +assert(points[1].second[1] == 255); + +os.open("tmp.las", std::ios_base::binary); +CGAL::write_las_points(os, ps, CGAL::parameters::all_default()); +os.close(); +assert(ok); +ps.clear(); +is.open("tmp.las", std::ios::binary); +ok = CGAL::read_las_points(is, std::back_inserter (ps),CGAL::parameters::all_default()); +is.close(); +assert(ok); +assert(ps.size() == 3); +#endif +//PLY +os.open("tmp.ply"); +ok = CGAL::write_ply_points_with_properties(os, points, + CGAL::make_ply_point_writer (CGAL::First_of_pair_property_map()), + std::make_pair(GetRedMap(),CGAL::PLY_property("red")), + std::make_pair(GetGreenMap(), CGAL::PLY_property("green")), + std::make_pair(GetBlueMap(), CGAL::PLY_property("blue")), + std::make_pair(GetAlphaMap(), CGAL::PLY_property("alpha")) + ); +os.close(); +assert(ok); + +is.open("tmp.ply"); +points.clear(); +ok = CGAL::read_ply_points_with_properties(is, std::back_inserter (points), + CGAL::make_ply_point_reader(CGAL::First_of_pair_property_map()), + std::make_tuple(CGAL::Second_of_pair_property_map(), + CGAL::Construct_array(), + CGAL::PLY_property("red"), + CGAL::PLY_property("green"), + CGAL::PLY_property("blue"), + CGAL::PLY_property("alpha"))); +is.close(); +assert(ok); +assert(points.size() == 3); +assert(points[1].second[1] == 255); + +os.open("tmp.ply"); +ok = CGAL::write_ply_points(os, ps, CGAL::parameters::all_default()); +os.close(); +assert(ok); + +is.open("tmp.ply"); +ps.clear(); +ok = CGAL::read_ply_points(is, std::back_inserter (ps), + CGAL::parameters::all_default()); +is.close(); +assert(ok); +assert(ps.size() == 3); + +//OFF +os.open("tmp.off"); +ok = CGAL::write_off_points(os, ps, CGAL::parameters::all_default()); +os.close(); +assert(ok); + +is.open("tmp.off"); +ps.clear(); +ok = CGAL::read_off_points(is, std::back_inserter (ps), + CGAL::parameters::all_default()); +is.close(); +assert(ok); +assert(ps.size() == 3); + +//XYZ +os.open("tmp.xyz"); +ok = CGAL::write_xyz_points(os, ps, CGAL::parameters::all_default()); +os.close(); +assert(ok); + +is.open("tmp.xyz"); +ps.clear(); +ok = CGAL::read_xyz_points(is, std::back_inserter (ps), + CGAL::parameters::all_default()); +is.close(); +assert(ok); +assert(ps.size() == 3); +} diff --git a/Stream_support/include/CGAL/IO/GOCAD.h b/Stream_support/include/CGAL/IO/GOCAD.h index d28f5fe5d9f..104a3c6cc54 100644 --- a/Stream_support/include/CGAL/IO/GOCAD.h +++ b/Stream_support/include/CGAL/IO/GOCAD.h @@ -299,8 +299,7 @@ bool write_GOCAD(std::ostream& os, set_ascii_mode(os); // GOCAD is ASCII only - const int precision = choose_parameter(get_parameter(np, internal_np::stream_precision), 6); - os.precision(precision); + set_stream_precision_from_NP(os, np); os << "GOCAD TSurf 1\n" "HEADER {\n" @@ -357,7 +356,7 @@ bool write_GOCAD(std::ostream& os, * \cgalParamNBegin{stream_precision} * \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} * \cgalParamType{int} - * \cgalParamDefault{`6`} + * \cgalParamDefault{`the precision of the stream `os``} * \cgalParamNEnd * \cgalNamedParamsEnd * diff --git a/Stream_support/include/CGAL/IO/Generic_writer.h b/Stream_support/include/CGAL/IO/Generic_writer.h index abf9077c49f..2f5d2a50d4a 100644 --- a/Stream_support/include/CGAL/IO/Generic_writer.h +++ b/Stream_support/include/CGAL/IO/Generic_writer.h @@ -49,8 +49,7 @@ public: if(!m_os.good()) return false; - const int precision = choose_parameter(get_parameter(np, internal_np::stream_precision), 6); - m_os.precision(precision); + set_stream_precision_from_NP(m_os, np); m_writer.write_header(m_os, points.size(), 0, polygons.size()); for(std::size_t i=0, end=points.size(); i #include +#include #include #include @@ -158,9 +159,9 @@ bool read_OBJ(std::istream& is, } if(norm_found && verbose) - std::cout<<"WARNING: normals were found in this file, but were discarded."< #include +#include // OpenInventor and VRML 1.0 are quite similar formats, so // output operators could be shared if they use the following @@ -89,6 +90,12 @@ private: } }; +template +void set_stream_precision_from_NP(Inventor_ostream_base& os, const NP& np) +{ + return set_stream_precision_from_NP(os.os(), np); +} + } // namespace CGAL #endif // CGAL_IO_INVENTOR_OSTREAM_H diff --git a/Stream_support/include/CGAL/IO/PLY.h b/Stream_support/include/CGAL/IO/PLY.h index dc6518096ca..bfcebbf8d7c 100644 --- a/Stream_support/include/CGAL/IO/PLY.h +++ b/Stream_support/include/CGAL/IO/PLY.h @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -444,7 +445,7 @@ bool read_PLY(const std::string& fname, PointRange& points, PolygonRange& polygo * \cgalParamNBegin{stream_precision} * \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} * \cgalParamType{int} - * \cgalParamDefault{`6`} + * \cgalParamDefault{`the precision of the stream `os``} * \cgalParamExtra{This parameter is only meaningful while using ASCII encoding.} * \cgalParamNEnd * \cgalNamedParamsEnd @@ -467,8 +468,7 @@ bool write_PLY(std::ostream& out, if(!out.good()) return false; - const int precision = parameters::choose_parameter(parameters::get_parameter(np, internal_np::stream_precision), 6); - out.precision(precision); + set_stream_precision_from_NP(out, np); // Write header out << "ply" << std::endl diff --git a/Stream_support/include/CGAL/IO/STL.h b/Stream_support/include/CGAL/IO/STL.h index 6865fd03464..009e90b1ad4 100644 --- a/Stream_support/include/CGAL/IO/STL.h +++ b/Stream_support/include/CGAL/IO/STL.h @@ -284,7 +284,7 @@ bool read_STL(const std::string& fname, PointRange& points, TriangleRange& facet * \cgalParamNBegin{stream_precision} * \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} * \cgalParamType{int} - * \cgalParamDefault{`6`} + * \cgalParamDefault{`the precision of the stream `os``} * \cgalParamExtra{This parameter is only meaningful while using ASCII encoding.} * \cgalParamNEnd * \cgalNamedParamsEnd @@ -317,8 +317,7 @@ bool write_STL(std::ostream& os, if(!os.good()) return false; - const int precision = choose_parameter(get_parameter(np, internal_np::stream_precision), 6); - os.precision(precision); + set_stream_precision_from_NP(os, np); if(get_mode(os) == IO::BINARY) { diff --git a/Stream_support/include/CGAL/IO/VRML/VRML_2_ostream.h b/Stream_support/include/CGAL/IO/VRML/VRML_2_ostream.h index 1de37df3967..08e8fdd7e49 100644 --- a/Stream_support/include/CGAL/IO/VRML/VRML_2_ostream.h +++ b/Stream_support/include/CGAL/IO/VRML/VRML_2_ostream.h @@ -21,6 +21,7 @@ #include #include +#include namespace CGAL { @@ -104,6 +105,11 @@ inline VRML_2_ostream& operator<<(VRML_2_ostream& os, return os; } +template +void set_stream_precision_from_NP(VRML_2_ostream& os, const NP& np) +{ + return set_stream_precision_from_NP(os.os(), np); +} } // namespace CGAL #endif // CGAL_IO_VRML_2_OSTREAM_H @@ -315,4 +321,5 @@ operator<<(VRML_2_ostream& os, } //namespace CGAL #endif // CGAL_IO_VRML_VRML_2_SEGMENT_3 + #endif // CGAL_SPHERE_3_H diff --git a/Stream_support/include/CGAL/IO/VTK.h b/Stream_support/include/CGAL/IO/VTK.h index 0723baceadd..d56dd2f0d11 100644 --- a/Stream_support/include/CGAL/IO/VTK.h +++ b/Stream_support/include/CGAL/IO/VTK.h @@ -19,6 +19,7 @@ #include #include +#include #ifdef CGAL_USE_VTK #include @@ -373,7 +374,7 @@ void write_soup_polys_points(std::ostream& os, * \cgalParamNBegin{stream_precision} * \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} * \cgalParamType{int} - * \cgalParamDefault{`6`} + * \cgalParamDefault{`the precision of the stream `os``} * \cgalParamNEnd * \cgalNamedParamsEnd * @@ -393,8 +394,7 @@ bool write_VTP(std::ostream& os, if(!os.good()) return false; - const int precision = choose_parameter(get_parameter(np, internal_np::stream_precision), 6); - os.precision(precision); + set_stream_precision_from_NP(os, np); os << "\n" << " #include #include -// #include #include #include -// #include #include -// #include #include #include diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO/OFF.h b/Surface_mesh/include/CGAL/Surface_mesh/IO/OFF.h index f4eb8ac375a..d8200a7592e 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO/OFF.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO/OFF.h @@ -556,7 +556,7 @@ bool write_OFF_with_or_without_vnormals(std::ostream& os, /// \cgalParamNBegin{stream_precision} /// \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} /// \cgalParamType{int} -/// \cgalParamDefault{`6`} +/// \cgalParamDefault{`the precision of the stream `os``} /// \cgalParamNEnd /// \cgalNamedParamsEnd /// diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h index 2682b5a899a..f19a3b9d9b2 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h @@ -899,7 +899,7 @@ CGAL_DEPRECATED bool read_ply(std::istream& is, Surface_mesh

& sm, std::string /// \cgalParamNBegin{stream_precision} /// \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} /// \cgalParamType{int} -/// \cgalParamDefault{`6`} +/// \cgalParamDefault{`the precision of the stream `os``} /// \cgalParamExtra{This parameter is only meaningful while using ASCII encoding.} /// \cgalParamNEnd /// \cgalNamedParamsEnd @@ -921,8 +921,7 @@ bool write_PLY(std::ostream& os, if(!os.good()) return false; - const int precision = parameters::choose_parameter(parameters::get_parameter(np, internal_np::stream_precision), 6); - os.precision(precision); + set_stream_precision_from_NP(os, np); os << "ply" << std::endl << ((get_mode(os) == IO::BINARY) ? "format binary_little_endian 1.0" : "format ascii 1.0") << std::endl diff --git a/Surface_mesh/test/Surface_mesh/CMakeLists.txt b/Surface_mesh/test/Surface_mesh/CMakeLists.txt index 81a2d0ae980..6527c9bb721 100644 --- a/Surface_mesh/test/Surface_mesh/CMakeLists.txt +++ b/Surface_mesh/test/Surface_mesh/CMakeLists.txt @@ -14,3 +14,16 @@ file( foreach(cppfile ${cppfiles}) create_single_source_cgal_program("${cppfile}") endforeach() + +find_path(3MF_INCLUDE_DIR + NAMES Model/COM/NMR_DLLInterfaces.h + DOC "Path to lib3MF headers" + ) +find_library(3MF_LIBRARIES NAMES 3MF DOC "Path to the lib3MF library") +if(3MF_LIBRARIES AND 3MF_INCLUDE_DIR AND EXISTS "${3MF_INCLUDE_DIR}/Model/COM/NMR_DLLInterfaces.h") + include_directories(${3MF_INCLUDE_DIR}) + target_link_libraries(test_deprecated_io_sm PRIVATE ${3MF_LIBRARIES}) + target_compile_definitions(test_deprecated_io_sm PRIVATE -DCGAL_LINKED_WITH_3MF) +else() + message(STATUS "NOTICE : read_3mf requires the lib3MF library, and will not be tested.") +endif() diff --git a/Surface_mesh/test/Surface_mesh/test.3mf b/Surface_mesh/test/Surface_mesh/test.3mf new file mode 100644 index 00000000000..8e8d5e004f2 Binary files /dev/null and b/Surface_mesh/test/Surface_mesh/test.3mf differ diff --git a/Surface_mesh/test/Surface_mesh/test_deprecated_io_sm.cpp b/Surface_mesh/test/Surface_mesh/test_deprecated_io_sm.cpp new file mode 100644 index 00000000000..8607ccba9d7 --- /dev/null +++ b/Surface_mesh/test/Surface_mesh/test_deprecated_io_sm.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point_3; +typedef CGAL::Surface_mesh SM; + +int main() +{ + // OFF + SM sm_in, sm_out; + Point_3 p0(0,0,0), p1(1,0,0), p2(0,1,0); + CGAL::make_triangle(p0, p1, p2, sm_out); + bool ok = CGAL::write_off(sm_out, "tmp.off"); + assert(ok); + ok = CGAL::read_off(sm_in, "tmp.off"); + assert(ok); + assert(num_vertices(sm_in) == 3 && num_faces(sm_in) == 1); + sm_in.clear(); + + std::ofstream os("tmp.off"); + ok = CGAL::write_off(os, sm_out); + assert(ok); + os.close(); + std::ifstream is("tmp.off"); + ok = CGAL::read_off(is, sm_in); + assert(ok); + assert(num_vertices(sm_in) == 3 && num_faces(sm_in) == 1); + is.close(); + sm_in.clear(); + + //PLY + os.open("tmp.ply"); + std::string comments; + ok = CGAL::write_ply(os, sm_out, comments); + assert(ok); + os.close(); + is.open("tmp.ply"); + ok = CGAL::read_ply(is, sm_in, comments); + assert(ok); + assert(num_vertices(sm_in) == 3 && num_faces(sm_in) == 1); + is.close(); + sm_in.clear(); + +#ifdef CGAL_LINKED_WITH_3MF + // 3mf + std::vector output_3mf; + ok = CGAL::read_3mf("test.3mf", output_3mf); + assert(ok); + assert(output_3mf.size() == 2); + sm_in.clear(); +#endif + + //others + ok = CGAL::write_mesh(sm_out, "tmp.off"); + assert(ok); + ok = CGAL::read_mesh(sm_in, "tmp.ply"); + assert(ok); + assert(num_vertices(sm_in) == 3 && num_faces(sm_in) == 1); + sm_in.clear(); + return EXIT_SUCCESS; +}