Go to the documentation of this file.
39 static constexpr
const unsigned STLHeaderSize = 80;
44 static bool startsWithSolid(
const char header[STLHeaderSize])
54 pos < (STLHeaderSize-5)
55 && std::toupper(header[
pos+0]) ==
'S'
56 && std::toupper(header[
pos+1]) ==
'O'
57 && std::toupper(header[
pos+2]) ==
'L'
58 && std::toupper(header[
pos+3]) ==
'I'
59 && std::toupper(header[
pos+4]) ==
'D'
75 format == STLFormat::UNKNOWN
76 ? (filename.
ext() ==
"stlb")
77 :
format == STLFormat::BINARY
93 bool compressed =
false;
94 std::unique_ptr<std::istream> streamPtr
96 new std::ifstream(filename, std::ios::binary)
100 if (!streamPtr->good() &&
isFile(filename +
".gz",
false))
103 streamPtr.reset(
new igzstream((filename +
".gz").c_str()));
105 auto& is = *streamPtr;
110 <<
"Cannot read file " << filename
111 <<
" or file " << filename +
".gz"
116 char header[STLHeaderSize];
117 is.read(header, STLHeaderSize);
120 if (!is.good() || startsWithSolid(header))
129 is.read(
reinterpret_cast<char*
>(&nTris),
sizeof(int32_t));
136 if (!is || nTris < 0)
140 else if (!compressed)
146 nTris <
int(dataFileSize - STLHeaderSize)/50
147 || nTris >
int(dataFileSize - STLHeaderSize)/25
159 std::unique_ptr<std::istream>
163 label& nTrisEstimated
167 bool compressed =
false;
170 std::unique_ptr<std::istream> streamPtr
172 new std::ifstream(filename, std::ios::binary)
176 if (!streamPtr->good() &&
isFile(filename +
".gz",
false))
179 streamPtr.reset(
new igzstream((filename +
".gz").c_str()));
181 auto& is = *streamPtr;
186 <<
"Cannot read file " << filename
187 <<
" or file " << filename +
".gz"
193 char header[STLHeaderSize];
194 is.read(header, STLHeaderSize);
200 <<
"problem reading header, perhaps file is not binary "
207 is.read(
reinterpret_cast<char*
>(&nTris),
sizeof(int32_t));
214 if (!is || nTris < 0)
218 else if (!compressed)
224 nTris <
int(dataFileSize - STLHeaderSize)/50
225 || nTris >
int(dataFileSize - STLHeaderSize)/25
235 <<
"problem reading number of triangles, perhaps file is not binary"
239 nTrisEstimated = nTris;
251 char header[STLHeaderSize];
252 sprintf(header,
"STL binary file %u facets", nTris);
255 for (
size_t i = strlen(header); i < STLHeaderSize; ++i)
260 os.write(header, STLHeaderSize);
261 os.write(
reinterpret_cast<char*
>(&nTris),
sizeof(uint32_t));
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
A class for handling file names.
bool isFile(const fileName &name, const bool checkGzip=true, const bool followLink=true)
Does the name exist as a FILE in the file system?
word format(conversionProperties.get< word >("format"))
off_t fileSize(const fileName &name, const bool followLink=true)
Return size of file or -1 on failure (normally follows symbolic links).
word ext() const
Return file name extension (part after last .)
errorManipArg< error, int > exit(error &err, const int errNo=1)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
bool isspace(char c)
Test for horizontal whitespace.
dimensionedScalar pos(const dimensionedScalar &ds)