From 551ff77fb7315f012398003aef7213355f614f7a Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 29 Sep 2021 13:31:45 +0100 Subject: [PATCH] Do not open() and close() just one stream --- .../test_deprecated_io_point_set.cpp | 234 ++++++++++-------- 1 file changed, 125 insertions(+), 109 deletions(-) diff --git a/Point_set_processing_3/test/Point_set_processing_3/test_deprecated_io_point_set.cpp b/Point_set_processing_3/test/Point_set_processing_3/test_deprecated_io_point_set.cpp index adad74c7dd0..5383be04e5a 100644 --- a/Point_set_processing_3/test/Point_set_processing_3/test_deprecated_io_point_set.cpp +++ b/Point_set_processing_3/test/Point_set_processing_3/test_deprecated_io_point_set.cpp @@ -77,134 +77,150 @@ 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); + { + std::ofstream os("tmp1.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()) + ); + assert(ok); + + } + + { + points.clear(); + std::ifstream is("tmp1.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())); + assert(ok); + assert(points.size() == 3); + assert(points[1].second[1] == 255); + } + + { + std::ofstream os("tmp2.las", std::ios_base::binary); + CGAL::write_las_points(os, ps, CGAL::parameters::all_default()); + assert(ok); + } + + { + ps.clear(); + std::ifstream is("tmp2.las", std::ios::binary); + ok = CGAL::read_las_points(is, std::back_inserter (ps),CGAL::parameters::all_default()); + assert(ok); + assert(ps.size() == 3); + } #endif //PLY -os.open("tmp.ply"); -assert(os.good()); -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(! os.fail()); -assert(ok); + { + std::ofstream os("tmp1.ply"); + assert(os.good()); + 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")) + ); + assert(! os.fail()); + assert(ok); + } -is.open("tmp.ply"); -assert(is.good()); -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(! is.fail()); -assert(ok); -assert(points.size() == 3); -assert(points[1].second[1] == 255); + { + std::ifstream is("tmp1.ply"); + assert(is.good()); + 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"))); + assert(! is.fail()); + assert(ok); + assert(points.size() == 3); + assert(points[1].second[1] == 255); + } -os.open("tmp.ply"); -assert(os.good()); -ok = CGAL::write_ply_points(os, ps, CGAL::parameters::all_default()); -os.close(); -assert(! os.fail()); -assert(ok); + { + std::ofstream os("tmp2.ply"); + assert(os.good()); + ok = CGAL::write_ply_points(os, ps, CGAL::parameters::all_default()); + assert(! os.fail()); + assert(ok); + } -is.open("tmp.ply"); -assert(is.good()); -ps.clear(); -ok = CGAL::read_ply_points(is, std::back_inserter (ps), - CGAL::parameters::all_default()); -is.close(); -assert(! is.fail()); -assert(ok); -assert(ps.size() == 3); + { + std::ifstream is("tmp2.ply"); + assert(is.good()); + ps.clear(); + ok = CGAL::read_ply_points(is, std::back_inserter (ps), + CGAL::parameters::all_default()); + assert(! is.fail()); + assert(ok); + assert(ps.size() == 3); + } //OFF -os.open("tmp.off"); -assert(os.good()); -ok = CGAL::write_off_points(os, ps, CGAL::parameters::all_default()); -os.close(); -assert(! os.fail()); -assert(ok); + { + std::ofstream os("tmp.off"); + assert(os.good()); + ok = CGAL::write_off_points(os, ps, CGAL::parameters::all_default()); + assert(! os.fail()); + assert(ok); + } -is.open("tmp.off"); -assert(is.good()); -ps.clear(); -ok = CGAL::read_off_points(is, std::back_inserter (ps), - CGAL::parameters::all_default()); -is.close(); -assert(! is.fail()); -assert(ok); -assert(ps.size() == 3); + { + std::ifstream is("tmp.off"); + assert(is.good()); + ps.clear(); + ok = CGAL::read_off_points(is, std::back_inserter (ps), + CGAL::parameters::all_default()); + assert(! is.fail()); + assert(ok); + assert(ps.size() == 3); + } //XYZ -os.open("tmp.xyz"); -assert(os.good()); -ok = CGAL::write_xyz_points(os, ps, CGAL::parameters::all_default()); -os.close(); -assert(! os.fail()); -assert(ok); + { + std::ofstream os("tmp.xyz"); + assert(os.good()); + ok = CGAL::write_xyz_points(os, ps, CGAL::parameters::all_default()); + assert(! os.fail()); + assert(ok); + } -is.open("tmp.xyz"); -assert(is.good()); -ps.clear(); -ok = CGAL::read_xyz_points(is, std::back_inserter (ps), - CGAL::parameters::all_default()); -is.close(); -assert(! is.fail()); -assert(ok); -assert(ps.size() == 3); + { + std::ifstream is("tmp.xyz"); + assert(is.good()); + ps.clear(); + ok = CGAL::read_xyz_points(is, std::back_inserter (ps), + CGAL::parameters::all_default()); + assert(! is.fail()); + assert(ok); + assert(ps.size() == 3); + } }