Do not open() and close() just one stream

This commit is contained in:
Andreas Fabri 2021-09-29 13:31:45 +01:00
parent 716dcaf6c9
commit 551ff77fb7
1 changed files with 125 additions and 109 deletions

View File

@ -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<Point_3> 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<PointWithColor>()),
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<PointWithColor>()),
std::make_tuple(CGAL::Second_of_pair_property_map<PointWithColor>(),
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<PointWithColor>()),
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<PointWithColor>()),
std::make_tuple(CGAL::Second_of_pair_property_map<PointWithColor>(),
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<PointWithColor>()),
std::make_pair(GetRedMap(),CGAL::PLY_property<unsigned short>("red")),
std::make_pair(GetGreenMap(), CGAL::PLY_property<unsigned short>("green")),
std::make_pair(GetBlueMap(), CGAL::PLY_property<unsigned short>("blue")),
std::make_pair(GetAlphaMap(), CGAL::PLY_property<unsigned short>("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<PointWithColor>()),
std::make_pair(GetRedMap(),CGAL::PLY_property<unsigned short>("red")),
std::make_pair(GetGreenMap(), CGAL::PLY_property<unsigned short>("green")),
std::make_pair(GetBlueMap(), CGAL::PLY_property<unsigned short>("blue")),
std::make_pair(GetAlphaMap(), CGAL::PLY_property<unsigned short>("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<PointWithColor>()),
std::make_tuple(CGAL::Second_of_pair_property_map<PointWithColor>(),
CGAL::Construct_array(),
CGAL::PLY_property<unsigned short>("red"),
CGAL::PLY_property<unsigned short>("green"),
CGAL::PLY_property<unsigned short>("blue"),
CGAL::PLY_property<unsigned short>("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<PointWithColor>()),
std::make_tuple(CGAL::Second_of_pair_property_map<PointWithColor>(),
CGAL::Construct_array(),
CGAL::PLY_property<unsigned short>("red"),
CGAL::PLY_property<unsigned short>("green"),
CGAL::PLY_property<unsigned short>("blue"),
CGAL::PLY_property<unsigned short>("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);
}
}