27 #include <OpenFOAM/gzstream.h>
33 #undef DEBUG_STLBINARY
43 int Foam::fileFormats::STLsurfaceFormatCore::detectBINARY
45 const fileName& filename
51 istream& is = str().stdStream();
66 is.read(reinterpret_cast<char*>(&nTris),
sizeof(
unsigned int));
89 bool Foam::fileFormats::STLsurfaceFormatCore::readBINARY
92 const off_t dataFileSize
98 char header[headerSize];
99 is.read(header, headerSize);
106 "fileFormats::STLsurfaceFormatCore::readBINARY(IFstream&)"
108 <<
"problem reading header, perhaps file is not binary "
115 is.read(reinterpret_cast<char*>(&nTris),
sizeof(
unsigned int));
126 || nTris <
int(dataFileSize - headerSize)/50
127 || nTris >
int(dataFileSize - headerSize)/25
132 "fileFormats::STLsurfaceFormatCore::readBINARY(istream&)"
134 <<
"problem reading number of triangles, perhaps file is not binary"
138 #ifdef DEBUG_STLBINARY
139 Info<<
"# " << nTris <<
" facets" <<
endl;
143 points_.setSize(3*nTris);
144 zoneIds_.setSize(nTris);
147 DynamicList<label> dynSizes;
154 STLtriangle stlTri(is);
157 points_[ptI++] = stlTri.a();
158 points_[ptI++] = stlTri.b();
159 points_[ptI++] = stlTri.c();
162 const label origId = stlTri.attrib();
165 if (fnd != lookup.end())
176 zoneI = dynSizes.size();
177 lookup.insert(origId, zoneI);
181 zoneIds_[faceI] = zoneI;
184 #ifdef DEBUG_STLBINARY
185 if (prevZone != zoneI)
189 Info<<
"endsolid zone" << prevZone <<
nl;
193 Info<<
"solid zone" << prevZone <<
nl;
196 Info<<
" facet normal " << stlTri.normal() <<
nl
197 <<
" outer loop" <<
nl
198 <<
" vertex " << stlTri.a() <<
nl
199 <<
" vertex " << stlTri.b() <<
nl
200 <<
" vertex " << stlTri.c() <<
nl
201 <<
" outer loop" <<
nl
202 <<
" endfacet" <<
endl;
207 sizes_.transfer(dynSizes);
215 Foam::fileFormats::STLsurfaceFormatCore::STLsurfaceFormatCore
229 if (detectBINARY(filename))
263 char header[headerSize];
264 sprintf(header,
"STL binary file %u facets", nTris);
267 for (
size_t i = strlen(header); i < headerSize; ++i)
272 os.write(header, headerSize);
273 os.write(reinterpret_cast<char*>(&nTris),
sizeof(
unsigned int));