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;
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 std::istream& 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
163 label& nTrisEstimated
167 bool compressed =
false;
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 std::istream& is = streamPtr();
188 <<
"Cannot read file " << filename
189 <<
" or file " << filename +
".gz"
195 char header[STLHeaderSize];
196 is.read(header, STLHeaderSize);
204 <<
"problem reading header, perhaps file is not binary "
211 is.read(
reinterpret_cast<char*
>(&nTris),
sizeof(int32_t));
218 if (!is || nTris < 0)
222 else if (!compressed)
228 nTris <
int(dataFileSize - STLHeaderSize)/50
229 || nTris >
int(dataFileSize - STLHeaderSize)/25
241 <<
"problem reading number of triangles, perhaps file is not binary"
245 nTrisEstimated = nTris;
257 char header[STLHeaderSize];
258 sprintf(header,
"STL binary file %u facets", nTris);
261 for (
size_t i = strlen(header); i < STLHeaderSize; ++i)
266 os.write(header, STLHeaderSize);
267 os.write(
reinterpret_cast<char*
>(&nTris),
sizeof(uint32_t));
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
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).
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
word ext() const
Return file name extension (part after last .)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
void clear() noexcept
Delete managed object and set pointer to nullptr.
bool isspace(char c)
Test for horizontal whitespace.
dimensionedScalar pos(const dimensionedScalar &ds)