mirror of https://github.com/CGAL/cgal
Do not open() and close() just one stream
This commit is contained in:
parent
716dcaf6c9
commit
551ff77fb7
|
|
@ -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});
|
points[2] = std::make_pair(Point_3(0,0,1), Color{0,0,255,255});
|
||||||
|
|
||||||
|
|
||||||
std::ofstream os;
|
|
||||||
std::ifstream is;
|
|
||||||
bool ok;
|
bool ok;
|
||||||
std::vector<Point_3> ps;
|
std::vector<Point_3> ps;
|
||||||
ps.push_back(Point_3(1,0,0));
|
ps.push_back(Point_3(1,0,0));
|
||||||
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));
|
||||||
|
|
||||||
|
|
||||||
//LAS
|
//LAS
|
||||||
#ifdef CGAL_LINKED_WITH_LASLIB
|
#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());
|
std::ofstream os("tmp1.las", std::ios::binary);
|
||||||
os.close();
|
ok = CGAL::write_las_points_with_properties(os, points,
|
||||||
assert(ok);
|
CGAL::make_las_point_writer(CGAL::First_of_pair_property_map<PointWithColor>()),
|
||||||
ps.clear();
|
std::make_pair(GetRedMap(),CGAL::LAS_property::R()),
|
||||||
is.open("tmp.las", std::ios::binary);
|
std::make_pair(GetGreenMap(), CGAL::LAS_property::G()),
|
||||||
ok = CGAL::read_las_points(is, std::back_inserter (ps),CGAL::parameters::all_default());
|
std::make_pair(GetBlueMap(), CGAL::LAS_property::B()),
|
||||||
is.close();
|
std::make_pair(GetAlphaMap(), CGAL::LAS_property::I())
|
||||||
assert(ok);
|
);
|
||||||
assert(ps.size() == 3);
|
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
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//PLY
|
//PLY
|
||||||
os.open("tmp.ply");
|
{
|
||||||
assert(os.good());
|
std::ofstream os("tmp1.ply");
|
||||||
ok = CGAL::write_ply_points_with_properties(os, points,
|
assert(os.good());
|
||||||
CGAL::make_ply_point_writer (CGAL::First_of_pair_property_map<PointWithColor>()),
|
ok = CGAL::write_ply_points_with_properties(os, points,
|
||||||
std::make_pair(GetRedMap(),CGAL::PLY_property<unsigned short>("red")),
|
CGAL::make_ply_point_writer (CGAL::First_of_pair_property_map<PointWithColor>()),
|
||||||
std::make_pair(GetGreenMap(), CGAL::PLY_property<unsigned short>("green")),
|
std::make_pair(GetRedMap(),CGAL::PLY_property<unsigned short>("red")),
|
||||||
std::make_pair(GetBlueMap(), CGAL::PLY_property<unsigned short>("blue")),
|
std::make_pair(GetGreenMap(), CGAL::PLY_property<unsigned short>("green")),
|
||||||
std::make_pair(GetAlphaMap(), CGAL::PLY_property<unsigned short>("alpha"))
|
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(! os.fail());
|
||||||
assert(ok);
|
assert(ok);
|
||||||
|
}
|
||||||
|
|
||||||
is.open("tmp.ply");
|
{
|
||||||
assert(is.good());
|
std::ifstream is("tmp1.ply");
|
||||||
points.clear();
|
assert(is.good());
|
||||||
ok = CGAL::read_ply_points_with_properties(is, std::back_inserter (points),
|
points.clear();
|
||||||
CGAL::make_ply_point_reader(CGAL::First_of_pair_property_map<PointWithColor>()),
|
ok = CGAL::read_ply_points_with_properties(is, std::back_inserter (points),
|
||||||
std::make_tuple(CGAL::Second_of_pair_property_map<PointWithColor>(),
|
CGAL::make_ply_point_reader(CGAL::First_of_pair_property_map<PointWithColor>()),
|
||||||
CGAL::Construct_array(),
|
std::make_tuple(CGAL::Second_of_pair_property_map<PointWithColor>(),
|
||||||
CGAL::PLY_property<unsigned short>("red"),
|
CGAL::Construct_array(),
|
||||||
CGAL::PLY_property<unsigned short>("green"),
|
CGAL::PLY_property<unsigned short>("red"),
|
||||||
CGAL::PLY_property<unsigned short>("blue"),
|
CGAL::PLY_property<unsigned short>("green"),
|
||||||
CGAL::PLY_property<unsigned short>("alpha")));
|
CGAL::PLY_property<unsigned short>("blue"),
|
||||||
is.close();
|
CGAL::PLY_property<unsigned short>("alpha")));
|
||||||
assert(! is.fail());
|
assert(! is.fail());
|
||||||
assert(ok);
|
assert(ok);
|
||||||
assert(points.size() == 3);
|
assert(points.size() == 3);
|
||||||
assert(points[1].second[1] == 255);
|
assert(points[1].second[1] == 255);
|
||||||
|
}
|
||||||
|
|
||||||
os.open("tmp.ply");
|
{
|
||||||
assert(os.good());
|
std::ofstream os("tmp2.ply");
|
||||||
ok = CGAL::write_ply_points(os, ps, CGAL::parameters::all_default());
|
assert(os.good());
|
||||||
os.close();
|
ok = CGAL::write_ply_points(os, ps, CGAL::parameters::all_default());
|
||||||
assert(! os.fail());
|
assert(! os.fail());
|
||||||
assert(ok);
|
assert(ok);
|
||||||
|
}
|
||||||
|
|
||||||
is.open("tmp.ply");
|
{
|
||||||
assert(is.good());
|
std::ifstream is("tmp2.ply");
|
||||||
ps.clear();
|
assert(is.good());
|
||||||
ok = CGAL::read_ply_points(is, std::back_inserter (ps),
|
ps.clear();
|
||||||
CGAL::parameters::all_default());
|
ok = CGAL::read_ply_points(is, std::back_inserter (ps),
|
||||||
is.close();
|
CGAL::parameters::all_default());
|
||||||
assert(! is.fail());
|
assert(! is.fail());
|
||||||
assert(ok);
|
assert(ok);
|
||||||
assert(ps.size() == 3);
|
assert(ps.size() == 3);
|
||||||
|
}
|
||||||
|
|
||||||
//OFF
|
//OFF
|
||||||
os.open("tmp.off");
|
{
|
||||||
assert(os.good());
|
std::ofstream os("tmp.off");
|
||||||
ok = CGAL::write_off_points(os, ps, CGAL::parameters::all_default());
|
assert(os.good());
|
||||||
os.close();
|
ok = CGAL::write_off_points(os, ps, CGAL::parameters::all_default());
|
||||||
assert(! os.fail());
|
assert(! os.fail());
|
||||||
assert(ok);
|
assert(ok);
|
||||||
|
}
|
||||||
|
|
||||||
is.open("tmp.off");
|
{
|
||||||
assert(is.good());
|
std::ifstream is("tmp.off");
|
||||||
ps.clear();
|
assert(is.good());
|
||||||
ok = CGAL::read_off_points(is, std::back_inserter (ps),
|
ps.clear();
|
||||||
CGAL::parameters::all_default());
|
ok = CGAL::read_off_points(is, std::back_inserter (ps),
|
||||||
is.close();
|
CGAL::parameters::all_default());
|
||||||
assert(! is.fail());
|
assert(! is.fail());
|
||||||
assert(ok);
|
assert(ok);
|
||||||
assert(ps.size() == 3);
|
assert(ps.size() == 3);
|
||||||
|
}
|
||||||
|
|
||||||
//XYZ
|
//XYZ
|
||||||
os.open("tmp.xyz");
|
{
|
||||||
assert(os.good());
|
std::ofstream os("tmp.xyz");
|
||||||
ok = CGAL::write_xyz_points(os, ps, CGAL::parameters::all_default());
|
assert(os.good());
|
||||||
os.close();
|
ok = CGAL::write_xyz_points(os, ps, CGAL::parameters::all_default());
|
||||||
assert(! os.fail());
|
assert(! os.fail());
|
||||||
assert(ok);
|
assert(ok);
|
||||||
|
}
|
||||||
|
|
||||||
is.open("tmp.xyz");
|
{
|
||||||
assert(is.good());
|
std::ifstream is("tmp.xyz");
|
||||||
ps.clear();
|
assert(is.good());
|
||||||
ok = CGAL::read_xyz_points(is, std::back_inserter (ps),
|
ps.clear();
|
||||||
CGAL::parameters::all_default());
|
ok = CGAL::read_xyz_points(is, std::back_inserter (ps),
|
||||||
is.close();
|
CGAL::parameters::all_default());
|
||||||
assert(! is.fail());
|
assert(! is.fail());
|
||||||
assert(ok);
|
assert(ok);
|
||||||
assert(ps.size() == 3);
|
assert(ps.size() == 3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue