Commit 2e6820a1 authored by Martin Schultz's avatar Martin Schultz
Browse files

added binary stl file size check after ascii check

parent cc373455
Pipeline #2438 passed with stage
in 79 minutes and 50 seconds
......@@ -478,9 +478,39 @@ check_stl_type(const std::string& _filename) const
return STLA;
//if the file does not start with solid it is STLB
return STLB;
//if the file does not start with solid it is probably STLB
//check the file size to verify it.
//open the file
FILE* in = fopen(_filename.c_str(), "rb");
if (!in) return NONE;
// determine endian mode
union { unsigned int i; unsigned char c[4]; } endian_test;
endian_test.i = 1;
bool swapFlag = (endian_test.c[3] == 1);
// read number of triangles
char dummy[100];
fread(dummy, 1, 80, in);
size_t nT = read_int(in, swapFlag);
// compute file size from nT
size_t binary_size = 84 + nT*50;
// get actual file size
size_t file_size(0);
while (!feof(in))
file_size += fread(dummy, 1, 100, in);
// if sizes match -> it's STLB
return (binary_size == file_size ? STLB : NONE);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment