Merge pull request #6018 from afabri/PSP-check_open_close-GF

Unset fail bit and add assertions about the state of a stream
This commit is contained in:
Laurent Rineau 2021-09-30 16:49:37 +02:00
commit a36fbb85d8
3 changed files with 134 additions and 94 deletions

View File

@ -190,12 +190,15 @@ bool read_OFF(std::istream& is,
put(normal_map, pwn, normal); // normal_map[&pwn] = normal put(normal_map, pwn, normal); // normal_map[&pwn] = normal
*output++ = pwn; *output++ = pwn;
pointsRead++; pointsRead++;
} }
// ...or skip comment line // ...or skip comment line
} }
// Skip remaining lines // Skip remaining lines
} }
if(is.eof()) {
is.clear(is.rdstate() & ~std::ios_base::failbit); // set by getline
}
return true; return true;
} }

View File

@ -179,6 +179,9 @@ bool read_XYZ(std::istream& is,
return false; return false;
} }
} }
if(is.eof()) {
is.clear(is.rdstate() & ~std::ios_base::failbit); // set by getline
}
return true; return true;
} }

View File

@ -77,116 +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"); {
ok = CGAL::write_ply_points_with_properties(os, points, std::ofstream os("tmp1.ply");
CGAL::make_ply_point_writer (CGAL::First_of_pair_property_map<PointWithColor>()), assert(os.good());
std::make_pair(GetRedMap(),CGAL::PLY_property<unsigned short>("red")), ok = CGAL::write_ply_points_with_properties(os, points,
std::make_pair(GetGreenMap(), CGAL::PLY_property<unsigned short>("green")), CGAL::make_ply_point_writer (CGAL::First_of_pair_property_map<PointWithColor>()),
std::make_pair(GetBlueMap(), CGAL::PLY_property<unsigned short>("blue")), std::make_pair(GetRedMap(),CGAL::PLY_property<unsigned short>("red")),
std::make_pair(GetAlphaMap(), CGAL::PLY_property<unsigned short>("alpha")) std::make_pair(GetGreenMap(), CGAL::PLY_property<unsigned short>("green")),
); std::make_pair(GetBlueMap(), CGAL::PLY_property<unsigned short>("blue")),
os.close(); std::make_pair(GetAlphaMap(), CGAL::PLY_property<unsigned short>("alpha"))
assert(ok); );
assert(! os.fail());
assert(ok);
}
is.open("tmp.ply"); {
points.clear(); std::ifstream is("tmp1.ply");
ok = CGAL::read_ply_points_with_properties(is, std::back_inserter (points), assert(is.good());
CGAL::make_ply_point_reader(CGAL::First_of_pair_property_map<PointWithColor>()), points.clear();
std::make_tuple(CGAL::Second_of_pair_property_map<PointWithColor>(), ok = CGAL::read_ply_points_with_properties(is, std::back_inserter (points),
CGAL::Construct_array(), CGAL::make_ply_point_reader(CGAL::First_of_pair_property_map<PointWithColor>()),
CGAL::PLY_property<unsigned short>("red"), std::make_tuple(CGAL::Second_of_pair_property_map<PointWithColor>(),
CGAL::PLY_property<unsigned short>("green"), CGAL::Construct_array(),
CGAL::PLY_property<unsigned short>("blue"), CGAL::PLY_property<unsigned short>("red"),
CGAL::PLY_property<unsigned short>("alpha"))); CGAL::PLY_property<unsigned short>("green"),
is.close(); CGAL::PLY_property<unsigned short>("blue"),
assert(ok); CGAL::PLY_property<unsigned short>("alpha")));
assert(points.size() == 3); assert(! is.fail());
assert(points[1].second[1] == 255); 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()); std::ofstream os("tmp2.ply");
os.close(); assert(os.good());
assert(ok); ok = CGAL::write_ply_points(os, ps, CGAL::parameters::all_default());
assert(! os.fail());
assert(ok);
}
is.open("tmp.ply"); {
ps.clear(); std::ifstream is("tmp2.ply");
ok = CGAL::read_ply_points(is, std::back_inserter (ps), assert(is.good());
CGAL::parameters::all_default()); ps.clear();
is.close(); ok = CGAL::read_ply_points(is, std::back_inserter (ps),
assert(ok); CGAL::parameters::all_default());
assert(ps.size() == 3); assert(! is.fail());
assert(ok);
assert(ps.size() == 3);
}
//OFF //OFF
os.open("tmp.off"); {
ok = CGAL::write_off_points(os, ps, CGAL::parameters::all_default()); std::ofstream os("tmp.off");
os.close(); assert(os.good());
assert(ok); ok = CGAL::write_off_points(os, ps, CGAL::parameters::all_default());
assert(! os.fail());
assert(ok);
}
is.open("tmp.off"); {
ps.clear(); std::ifstream is("tmp.off");
ok = CGAL::read_off_points(is, std::back_inserter (ps), assert(is.good());
CGAL::parameters::all_default()); ps.clear();
is.close(); ok = CGAL::read_off_points(is, std::back_inserter (ps),
assert(ok); CGAL::parameters::all_default());
assert(ps.size() == 3); assert(! is.fail());
assert(ok);
assert(ps.size() == 3);
}
//XYZ //XYZ
os.open("tmp.xyz"); {
ok = CGAL::write_xyz_points(os, ps, CGAL::parameters::all_default()); std::ofstream os("tmp.xyz");
os.close(); assert(os.good());
assert(ok); ok = CGAL::write_xyz_points(os, ps, CGAL::parameters::all_default());
assert(! os.fail());
assert(ok);
}
is.open("tmp.xyz"); {
ps.clear(); std::ifstream is("tmp.xyz");
ok = CGAL::read_xyz_points(is, std::back_inserter (ps), assert(is.good());
CGAL::parameters::all_default()); ps.clear();
is.close(); ok = CGAL::read_xyz_points(is, std::back_inserter (ps),
assert(ok); CGAL::parameters::all_default());
assert(ps.size() == 3); assert(! is.fail());
assert(ok);
assert(ps.size() == 3);
}
} }