Merge pull request #6376 from sloriot/Stream_support-fix_STL_binary

fix stl binary
This commit is contained in:
Laurent Rineau 2022-03-09 11:33:17 +01:00
commit 78f9324d13
3 changed files with 12 additions and 17 deletions

View File

@ -84,7 +84,6 @@ bool read_STL(std::istream& is,
) )
{ {
const bool verbose = parameters::choose_parameter(parameters::get_parameter(np, internal_np::verbose), false); const bool verbose = parameters::choose_parameter(parameters::get_parameter(np, internal_np::verbose), false);
const bool binary = CGAL::parameters::choose_parameter(CGAL::parameters::get_parameter(np, internal_np::use_binary_mode), true);
if(!is.good()) if(!is.good())
{ {
@ -93,7 +92,6 @@ bool read_STL(std::istream& is,
return false; return false;
} }
int pos = 0;
// Ignore all initial whitespace // Ignore all initial whitespace
unsigned char c; unsigned char c;
@ -104,23 +102,11 @@ bool read_STL(std::istream& is,
is.unget(); // move back to the first interesting char is.unget(); // move back to the first interesting char
break; break;
} }
++pos;
} }
if(!is.good()) // reached the end if(!is.good()) // reached the end
return true; return true;
// If we have gone beyond 80 characters and have not read anything yet,
// then this must be an ASCII file.
if(pos > 80)
{
if(binary)
return false;
return internal::parse_ASCII_STL(is, points, facets, verbose);
}
// We are within the first 80 characters, both ASCII and binary are possible
// Read the 5 first characters to check if the first word is "solid" // Read the 5 first characters to check if the first word is "solid"
std::string s; std::string s;
@ -133,7 +119,6 @@ bool read_STL(std::istream& is,
is.read(reinterpret_cast<char*>(&word[5]), sizeof(c))) is.read(reinterpret_cast<char*>(&word[5]), sizeof(c)))
{ {
s = std::string(word, 5); s = std::string(word, 5);
pos += 5;
} }
else else
{ {

View File

@ -79,8 +79,8 @@ int main(int argc, char** argv)
assert(ok); assert(ok);
std::cout << points.size() << " points and " << polygons.size() << " polygons" << std::endl; std::cout << points.size() << " points and " << polygons.size() << " polygons" << std::endl;
if(argc == 0) if(argc == 1)
assert(points.size() == 434 && polygons.size() == 864); assert(points.size() == 4 && polygons.size() == 4);
points.clear(); points.clear();
polygons.clear(); polygons.clear();
@ -129,6 +129,16 @@ int main(int argc, char** argv)
further_tests(); further_tests();
// issue 6374
if(argc == 1)
{
points.clear();
polygons.clear();
bool ok = CGAL::IO::read_STL("data/binary-issue-6374.stl", points, polygons, CGAL::parameters::verbose(true));
assert(ok);
assert(points.size()==8 && polygons.size()==12);
}
std::cout << "Done!" << std::endl; std::cout << "Done!" << std::endl;
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }