Merge branch 'stlTypeCheck' into 'master'
Stl type check implemented the suggested changes from #24 by checking stl files for the keyword solid instead of computing binary file size. closes #24 See merge request !83
This commit is contained in:
@@ -13,13 +13,18 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li>Fixed type pun warning with gcc-6</li>
|
<li>Fixed type pun warning with gcc-6</li>
|
||||||
<li>Fixed incorrect type of hash function for boost causing a warning with clang</li>
|
<li>Fixed incorrect type of hash function for boost causing a warning with clang</li>
|
||||||
</li>
|
</ul>
|
||||||
|
|
||||||
|
<b>IO</b>
|
||||||
|
<ul>
|
||||||
|
<li>STL Reader: Identify stl files containing solid keyword as ASCII type</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
<b>General</b>
|
<b>General</b>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Fixed undefined MSVC macro warning (Thanks to Xan for the patch)</li>
|
<li>Fixed undefined MSVC macro warning (Thanks to Xan for the patch)</li>
|
||||||
</li>
|
</ul>
|
||||||
|
|
||||||
<b>Build System</b>
|
<b>Build System</b>
|
||||||
<ul>
|
<ul>
|
||||||
|
|||||||
@@ -55,12 +55,20 @@
|
|||||||
|
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
// OpenMesh
|
// OpenMesh
|
||||||
#include <OpenMesh/Core/IO/BinaryHelper.hh>
|
#include <OpenMesh/Core/IO/BinaryHelper.hh>
|
||||||
#include <OpenMesh/Core/IO/reader/STLReader.hh>
|
#include <OpenMesh/Core/IO/reader/STLReader.hh>
|
||||||
#include <OpenMesh/Core/IO/IOManager.hh>
|
#include <OpenMesh/Core/IO/IOManager.hh>
|
||||||
|
|
||||||
|
//comppare strings crossplatform ignorign case
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define strnicmp _strnicmp
|
||||||
|
#else
|
||||||
|
#define strnicmp strncasecmp
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//=== NAMESPACES ==============================================================
|
//=== NAMESPACES ==============================================================
|
||||||
|
|
||||||
@@ -447,15 +455,38 @@ _STLReader_::STL_Type
|
|||||||
_STLReader_::
|
_STLReader_::
|
||||||
check_stl_type(const std::string& _filename) const
|
check_stl_type(const std::string& _filename) const
|
||||||
{
|
{
|
||||||
// assume it's binary stl, then file size is known from #triangles
|
|
||||||
// if size matches, it's really binary
|
|
||||||
|
|
||||||
|
|
||||||
// open file
|
// open file
|
||||||
|
std::ifstream ifs (_filename.c_str(), std::ifstream::binary);
|
||||||
|
if(!ifs.good())
|
||||||
|
{
|
||||||
|
omerr() << "could not open file" << _filename << std::endl;
|
||||||
|
return NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//find first non whitespace character
|
||||||
|
std::string line = "";
|
||||||
|
std::size_t firstChar;
|
||||||
|
while(line.empty() && ifs.good())
|
||||||
|
{
|
||||||
|
std::getline(ifs,line);
|
||||||
|
firstChar = line.find_first_not_of("\t ");
|
||||||
|
}
|
||||||
|
|
||||||
|
//check for ascii keyword solid
|
||||||
|
if(strnicmp("solid",&line[firstChar],5) == 0)
|
||||||
|
{
|
||||||
|
return STLA;
|
||||||
|
}
|
||||||
|
ifs.close();
|
||||||
|
|
||||||
|
//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");
|
FILE* in = fopen(_filename.c_str(), "rb");
|
||||||
if (!in) return NONE;
|
if (!in) return NONE;
|
||||||
|
|
||||||
|
|
||||||
// determine endian mode
|
// determine endian mode
|
||||||
union { unsigned int i; unsigned char c[4]; } endian_test;
|
union { unsigned int i; unsigned char c[4]; } endian_test;
|
||||||
endian_test.i = 1;
|
endian_test.i = 1;
|
||||||
@@ -471,7 +502,6 @@ check_stl_type(const std::string& _filename) const
|
|||||||
// compute file size from nT
|
// compute file size from nT
|
||||||
size_t binary_size = 84 + nT*50;
|
size_t binary_size = 84 + nT*50;
|
||||||
|
|
||||||
|
|
||||||
// get actual file size
|
// get actual file size
|
||||||
size_t file_size(0);
|
size_t file_size(0);
|
||||||
rewind(in);
|
rewind(in);
|
||||||
@@ -479,9 +509,8 @@ check_stl_type(const std::string& _filename) const
|
|||||||
file_size += fread(dummy, 1, 100, in);
|
file_size += fread(dummy, 1, 100, in);
|
||||||
fclose(in);
|
fclose(in);
|
||||||
|
|
||||||
|
|
||||||
// if sizes match -> it's STLB
|
// if sizes match -> it's STLB
|
||||||
return (binary_size == file_size ? STLB : STLA);
|
return (binary_size == file_size ? STLB : NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user