Merge pull request #6329 from afabri/PSP-fix_IO-GF

PSP: ofstream -> sstream

# Conflicts:
#	Point_set_processing_3/test/Point_set_processing_3/test_deprecated_io_point_set.cpp
This commit is contained in:
Laurent Rineau 2022-02-24 09:52:51 +01:00
commit 9cbf8fa23c
1 changed files with 28 additions and 13 deletions

View File

@ -15,7 +15,7 @@
#include <vector> #include <vector>
#include <cassert> #include <cassert>
#include <string> #include <string>
#include <fstream> #include <sstream>
typedef CGAL::Simple_cartesian<double> Kernel; typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::Point_3 Point_3; typedef Kernel::Point_3 Point_3;
@ -86,10 +86,13 @@ int main()
ps.push_back(Point_3(0,1,0)); ps.push_back(Point_3(0,1,0));
ps.push_back(Point_3(0,0,1)); ps.push_back(Point_3(0,0,1));
std::string input;
//LAS //LAS
#ifdef CGAL_LINKED_WITH_LASLIB #ifdef CGAL_LINKED_WITH_LASLIB
{ {
std::ofstream os("tmp1.las", std::ios::binary); std::ostringstream os(std::ios::binary);
ok = CGAL::write_las_points_with_properties(os, points, ok = CGAL::write_las_points_with_properties(os, points,
CGAL::make_las_point_writer(CGAL::First_of_pair_property_map<PointWithColor>()), CGAL::make_las_point_writer(CGAL::First_of_pair_property_map<PointWithColor>()),
std::make_pair(GetRedMap(),CGAL::LAS_property::R()), std::make_pair(GetRedMap(),CGAL::LAS_property::R()),
@ -98,12 +101,14 @@ int main()
std::make_pair(GetAlphaMap(), CGAL::LAS_property::I()) std::make_pair(GetAlphaMap(), CGAL::LAS_property::I())
); );
assert(ok); assert(ok);
os.flush();
input = os.str();
} }
{ {
points.clear(); points.clear();
std::ifstream is("tmp1.las", std::ios::binary); std::istringstream is(input, std::ios::binary);
ok = CGAL::read_las_points_with_properties(is, std::back_inserter (points), ok = CGAL::read_las_points_with_properties(is, std::back_inserter (points),
CGAL::make_las_point_reader(CGAL::First_of_pair_property_map<PointWithColor>()), CGAL::make_las_point_reader(CGAL::First_of_pair_property_map<PointWithColor>()),
std::make_tuple(CGAL::Second_of_pair_property_map<PointWithColor>(), std::make_tuple(CGAL::Second_of_pair_property_map<PointWithColor>(),
@ -118,14 +123,16 @@ int main()
} }
{ {
std::ofstream os("tmp2.las", std::ios_base::binary); std::ostringstream os(std::ios_base::binary);
CGAL::write_las_points(os, ps); CGAL::write_las_points(os, ps);
assert(ok); assert(ok);
os.flush();
input = os.str();
} }
{ {
ps.clear(); ps.clear();
std::ifstream is("tmp2.las", std::ios::binary); std::istringstream is(input, std::ios::binary);
ok = CGAL::read_las_points(is, std::back_inserter (ps)); ok = CGAL::read_las_points(is, std::back_inserter (ps));
assert(ok); assert(ok);
assert(ps.size() == 3); assert(ps.size() == 3);
@ -134,7 +141,7 @@ int main()
//PLY //PLY
{ {
std::ofstream os("tmp1.ply"); std::ostringstream os;
assert(os.good()); assert(os.good());
ok = CGAL::write_ply_points_with_properties(os, points, ok = CGAL::write_ply_points_with_properties(os, points,
CGAL::make_ply_point_writer (CGAL::First_of_pair_property_map<PointWithColor>()), CGAL::make_ply_point_writer (CGAL::First_of_pair_property_map<PointWithColor>()),
@ -145,10 +152,12 @@ int main()
); );
assert(! os.fail()); assert(! os.fail());
assert(ok); assert(ok);
os.flush();
input = os.str();
} }
{ {
std::ifstream is("tmp1.ply"); std::istringstream is(input);
assert(is.good()); assert(is.good());
points.clear(); points.clear();
ok = CGAL::read_ply_points_with_properties(is, std::back_inserter (points), ok = CGAL::read_ply_points_with_properties(is, std::back_inserter (points),
@ -166,15 +175,17 @@ int main()
} }
{ {
std::ofstream os("tmp2.ply"); std::ostringstream os;
assert(os.good()); assert(os.good());
ok = CGAL::write_ply_points(os, ps); ok = CGAL::write_ply_points(os, ps);
assert(! os.fail()); assert(! os.fail());
assert(ok); assert(ok);
os.flush();
input = os.str();
} }
{ {
std::ifstream is("tmp2.ply"); std::istringstream is(input);
assert(is.good()); assert(is.good());
ps.clear(); ps.clear();
ok = CGAL::read_ply_points(is, std::back_inserter (ps)); ok = CGAL::read_ply_points(is, std::back_inserter (ps));
@ -185,15 +196,17 @@ int main()
//OFF //OFF
{ {
std::ofstream os("tmp.off"); std::ostringstream os;
assert(os.good()); assert(os.good());
ok = CGAL::write_off_points(os, ps); ok = CGAL::write_off_points(os, ps);
assert(! os.fail()); assert(! os.fail());
assert(ok); assert(ok);
os.flush();
input = os.str();
} }
{ {
std::ifstream is("tmp.off"); std::istringstream is(input);
assert(is.good()); assert(is.good());
ps.clear(); ps.clear();
ok = CGAL::read_off_points(is, std::back_inserter (ps)); ok = CGAL::read_off_points(is, std::back_inserter (ps));
@ -204,15 +217,17 @@ int main()
//XYZ //XYZ
{ {
std::ofstream os("tmp.xyz"); std::ostringstream os;
assert(os.good()); assert(os.good());
ok = CGAL::write_xyz_points(os, ps); ok = CGAL::write_xyz_points(os, ps);
assert(! os.fail()); assert(! os.fail());
assert(ok); assert(ok);
os.flush();
input = os.str();
} }
{ {
std::ifstream is("tmp.xyz"); std::istringstream is(input);
assert(is.good()); assert(is.good());
ps.clear(); ps.clear();
ok = CGAL::read_xyz_points(is, std::back_inserter (ps)); ok = CGAL::read_xyz_points(is, std::back_inserter (ps));