29#include "bitpit_common.hpp"
30#include "bitpit_operators.hpp"
43const std::size_t STLBase::BINARY_HEADER_SIZE = 80 *
sizeof(STLBase::BINARY_UINT8);
47const std::size_t STLBase::BINARY_MINIMUM_SIZE = STLBase::BINARY_HEADER_SIZE +
sizeof(STLBase::BINARY_UINT32);
53const std::size_t STLBase::BINARY_FACET_SIZE = 3 *
sizeof(BINARY_REAL32) + 3 * 3 *
sizeof(BINARY_REAL32) +
sizeof(BINARY_UINT16);
55const std::string STLBase::ASCII_SOLID_BEGIN =
"solid";
56const std::string STLBase::ASCII_SOLID_END =
"endsolid";
57const std::string STLBase::ASCII_FACET_BEGIN =
"facet";
58const std::string STLBase::ASCII_FACET_END =
"endfacet";
59const std::string STLBase::ASCII_FILE_BEGIN = STLBase::ASCII_SOLID_BEGIN;
60const std::string STLBase::ASCII_FILE_END = STLBase::ASCII_SOLID_END;
61const std::size_t STLBase::ASCII_MINIMUM_SIZE = STLBase::ASCII_FILE_BEGIN.length() + STLBase::ASCII_FILE_END.length();
103 m_filename = filename;
140 if (format == FormatUnknown) {
144 if (format == FormatUnknown) {
145 throw std::runtime_error(
"Invalid STL format.");
169 std::ifstream fileStream;
172 fileStream.open(filename, std::ifstream::ate | std::ifstream::binary);
173 if (!fileStream.good()) {
175 throw std::runtime_error(
"Invalid STL.");
178 std::size_t fileSize = fileStream.tellg();
190 if (fileSize < ASCII_MINIMUM_SIZE) {
191 return FormatUnknown;
200 std::size_t bufferPos;
203 std::string beginString(ASCII_FILE_BEGIN.size(),
' ');
204 fileStream.open(filename, std::ifstream::binary);
205 while (fileStream.get(c)) {
206 if (bufferPos == 0 && (std::isblank(c) || std::isspace(c))) {
210 beginString.at(bufferPos) = tolower(c);
212 if (bufferPos == ASCII_FILE_BEGIN.size()) {
219 bool maybeASCII = (beginString.compare(ASCII_FILE_BEGIN) == 0);
222 fileStream.open(filename, std::ifstream::ate | std::ifstream::binary);
226 fileStream.seekg(-1, std::ios_base::cur);
227 while (fileStream.get(c)) {
235 empty = (!std::isblank(c) && !std::isspace(c));
238 fileStream.seekg(-2, std::ios_base::cur);
243 std::string endString(ASCII_SOLID_END.size(),
' ');
244 while (fileStream.get(c)) {
245 if (bufferPos == 0 && (std::isblank(c) || std::isspace(c))) {
249 endString.at(bufferPos) = tolower(c);
251 if (bufferPos == ASCII_SOLID_END.size()) {
261 bool isASCII = (endString.compare(ASCII_SOLID_END) == 0);
275 if (fileSize < BINARY_MINIMUM_SIZE) {
276 return FormatUnknown;
280 std::uint32_t nFacets;
282 fileStream.open(filename, std::ifstream::binary);
283 fileStream.seekg(BINARY_HEADER_SIZE);
284 fileStream.read(
reinterpret_cast<char *
>(&nFacets),
sizeof(BINARY_UINT32));
289 std::size_t expectedFileSize = BINARY_HEADER_SIZE +
sizeof(BINARY_UINT32) + (nFacets * BINARY_FACET_SIZE);
290 if (fileSize == expectedFileSize) {
294 return FormatUnknown;
311 if (beginError != 0) {
320 if (format == FormatASCII) {
321 inspectionError = inspectASCII(info);
323 inspectionError = inspectBinary(info);
330 if (inspectionError != 0) {
331 return inspectionError;
332 }
else if (endError != 0) {
348int STLReader::inspectASCII(InspectionInfo *info)
352 info->solidErrors.clear();
353 info->solidNames.clear();
354 info->solidFacetCount.clear();
355 info->solidVertexCount.clear();
358 if (!m_fileHandle.good()) {
363 m_fileHandle.clear();
364 std::streamoff start_pos = m_fileHandle.tellg();
365 m_fileHandle.seekg(0);
369 std::stringstream sname;
371 int inspectionError = 0;
372 while (m_lineStream.
readLine(m_fileHandle) >= 0) {
374 if ((m_lineStream >> word) && (word.compare(ASCII_SOLID_BEGIN) == 0)) {
376 int solidIndex = info->nSolids;
379 info->solidErrors.emplace_back();
380 info->solidNames.emplace_back(
"");
381 info->solidFacetCount.emplace_back(0);
382 info->solidVertexCount.emplace_back(0);
386 while (m_lineStream >> word) {
387 sname << word <<
" ";
389 std::string name = sname.str();
391 info->solidNames[solidIndex] = name;
394 inspectionError = inspectSolidASCII(
info->solidFacetCount.data() + solidIndex,
info->solidErrors.data() + solidIndex);
395 if (inspectionError != 0) {
399 info->solidVertexCount[solidIndex] = 3 *
info->solidFacetCount[solidIndex];
404 m_fileHandle.clear();
405 m_fileHandle.seekg(start_pos);
407 return inspectionError;
428int STLReader::inspectSolidASCII(std::size_t *nFacets, std::array<bool, 6> *errors)
435 if (!m_fileHandle.good()) {
441 std::streamoff last_valid_pos;
443 int inspectError = 0;
446 last_valid_pos = m_fileHandle.tellg();
447 m_lineStream.
readLine(m_fileHandle);
448 if (!(m_lineStream >> word)) {
453 if (m_fileHandle.eof()) {
455 }
else if (word.compare(ASCII_SOLID_END) == 0) {
457 }
else if (word.compare(ASCII_SOLID_BEGIN) == 0) {
462 if (word.compare(ASCII_FACET_BEGIN) == 0) {
465 m_fileHandle.seekg(last_valid_pos);
466 inspectError = inspectFacetASCII(errors);
467 if (inspectError != 0) {
474 if (word.compare(ASCII_SOLID_END) != 0) {
476 m_fileHandle.clear();
477 m_fileHandle.seekg(last_valid_pos);
496int STLReader::inspectFacetASCII(std::array<bool, 6> *errors)
499 if (!m_fileHandle.good()) {
505 std::streamoff last_valid_pos;
507 last_valid_pos = m_fileHandle.tellg();
508 m_lineStream.
readLine(m_fileHandle);
509 if ((!(m_lineStream >> word)) || (word.compare(ASCII_FACET_BEGIN) == 0)) {
514 bool normal_found =
false;
515 while ((!m_fileHandle.eof())
516 && ((word.compare(ASCII_FACET_END) != 0)
517 && (word.compare(ASCII_FACET_BEGIN) != 0)
518 && (word.compare(ASCII_SOLID_END) != 0)
519 && (word.compare(ASCII_SOLID_BEGIN) != 0))) {
522 if (word.compare(
"begin") == 0) {
523 if ((m_lineStream >> word) && (word.compare(
"normal") == 0)) {
527 while (m_lineStream >> word) {
536 else if (word.compare(
"vertex") == 0) {
540 while (m_lineStream >> word) {
550 last_valid_pos = m_fileHandle.tellg();
551 m_lineStream.
readLine(m_fileHandle);
552 if (!(m_lineStream >> word)) {
558 if (word.compare(ASCII_FACET_END) != 0) {
560 m_fileHandle.clear(),
561 m_fileHandle.seekg(last_valid_pos);
586int STLReader::inspectBinary(InspectionInfo *info)
590 info->solidErrors.clear();
591 info->solidNames.clear();
592 info->solidFacetCount.clear();
593 info->solidVertexCount.clear();
596 if (!m_fileHandle.good()) {
601 m_fileHandle.clear();
602 std::streamoff start_pos = m_fileHandle.tellg();
603 m_fileHandle.seekg(0);
606 for (std::size_t i = 0; i < BINARY_HEADER_SIZE /
sizeof(BINARY_UINT8); ++i) {
607 BINARY_UINT8 headerCharacter;
608 m_fileHandle.read(
reinterpret_cast<char*
>(&headerCharacter),
sizeof(BINARY_UINT8));
611 if (m_fileHandle.eof()) {
612 info->solidErrors[0][0] =
true;
617 info->solidNames.push_back(
"");
620 BINARY_UINT32 nFacets;
621 m_fileHandle.read(
reinterpret_cast<char *
>(&nFacets),
sizeof(BINARY_UINT32));
622 info->solidFacetCount.push_back((std::size_t) nFacets);
623 info->solidVertexCount.push_back((std::size_t) (3 * nFacets));
625 if (m_fileHandle.eof()) {
626 info->solidErrors[0][0] =
true;
632 while ((!m_fileHandle.eof()) && (n < nFacets)) {
633 std::array<char, BINARY_FACET_SIZE> facetData;
634 m_fileHandle.read(facetData.data(), BINARY_FACET_SIZE);
640 info->solidErrors[0][1] =
true;
644 m_fileHandle.clear();
645 m_fileHandle.seekg(start_pos);
658 out <<
"Inspection info" <<
"\n";
663 if (format == FormatBinary) {
664 out <<
" Format : binary" <<
"\n";
666 out <<
" Format : ASCII" <<
"\n";
670 if (info.nSolids > 0) {
671 out <<
" Solid count : " << info.nSolids <<
"\n";
673 for (
int i = 0; i < info.nSolids; ++i) {
675 out <<
" Solid index : " << i <<
"\n";
676 out <<
" Solid name : " << info.solidNames[i] <<
"\n";
677 out <<
" Solid facets : " << info.solidFacetCount[i] <<
"\n";
678 out <<
" Solid vertices : " << info.solidVertexCount[i] <<
"\n";
680 if (info.solidErrors[i][0]) {
681 out <<
" **ERROR** Unterminated solid block." <<
"\n";
683 if (info.solidErrors[i][1]) {
684 out <<
" **ERROR** Unterminated facet block." <<
"\n";
686 if (info.solidErrors[i][2]) {
687 out <<
" **ERROR** Normal data are missing." <<
"\n";
689 if (info.solidErrors[i][3]) {
690 out <<
" **ERROR** Wrong number of components for normal data." <<
"\n";
692 if (info.solidErrors[i][4]) {
693 out <<
" **ERROR** Wrong number of vertices in facet block." <<
"\n";
695 if (info.solidErrors[i][5]) {
696 out <<
" **ERROR** Wrong number of coordinates for vertice." <<
"\n";
700 out <<
" STL file contains no solids." <<
"\n";
716 if (m_fileHandle.is_open()) {
720 m_fileHandle.open(
getFilename(), std::ifstream::in | std::ifstream::binary);
721 if (!m_fileHandle.good()) {
733 m_fileHandle.close();
760 std::vector<std::array<double, 3>> *V, std::vector<std::array<double, 3>> *N,
761 std::vector<std::array<std::size_t, 3>> *T)
763 return readSolid(
"", name, nV, nT, V, N, T);
791 std::vector<std::array<double, 3>> *V, std::vector<std::array<double, 3>> *N,
792 std::vector<std::array<std::size_t, 3>> *T)
795 std::size_t nSolidFacets;
796 int headerError =
readHeader(solid, name, &nSolidFacets);
797 if (headerError != 0) {
802 V->resize(*nV + 3 * nSolidFacets, {{0., 0., 0.}});
803 N->resize(*nT + nSolidFacets, {{0., 0., 0.}});
804 T->resize(*nT + nSolidFacets, {{0, 0, 0}});
806 for (std::size_t i = 0; i < *nT; ++i) {
808 std::array<double, 3> *V0 = V->data() + *nV + 3 * i;
809 std::array<double, 3> *V1 = V0 + 1;
810 std::array<double, 3> *V2 = V1 + 1;
812 int facetError =
readFacet(V0, V1, V2, N->data() + i);
813 if (facetError != 0) {
818 (*T)[i][0] = *nV + 3 * i;
819 (*T)[i][1] = (*T)[i][0] + 1;
820 (*T)[i][2] = (*T)[i][1] + 1;
825 if (footerError != 0) {
870 if (format == FormatASCII) {
871 error = readHeaderASCII(solid, name, nT);
873 std::string trimmedSolid = solid;
875 if (!trimmedSolid.empty()) {
876 log::cout() <<
"WARNING: loading solids with a specific name is only supported for ASCII files." << std::endl;
877 log::cout() <<
" The reader will read the next solid." << std::endl;
880 error = readHeaderBinary(name, nT);
918 if (format == FormatASCII) {
919 error = readFooterASCII(solid);
921 error = readFooterBinary();
943 std::array<double, 3> *V2, std::array<double, 3> *N)
948 if (format == FormatASCII) {
949 error = readFacetASCII(V0, V1, V2, N);
951 error = readFacetBinary(V0, V1, V2, N);
972int STLReader::readHeaderASCII(
const std::string &solid, std::string *name, std::size_t *nT)
975 if (!m_fileHandle.good()) {
980 std::string solidKey = solid;
982 solidKey = ASCII_SOLID_BEGIN +
" " + solidKey;
989 std::streamoff start_pos = m_fileHandle.tellg();
990 std::streamoff current_pos = start_pos + 1;
992 bool solidFound =
false;
993 bool wrapAround = solidKey.compare(ASCII_SOLID_BEGIN) != 0;
994 while (!solidFound && (start_pos != current_pos)) {
996 m_lineStream.
readLine(m_fileHandle);
999 if (m_fileHandle.eof()) {
1001 m_fileHandle.clear();
1002 m_fileHandle.seekg(0);
1009 current_pos = m_fileHandle.tellg();
1012 if ((m_lineStream >> word) && (word.compare(ASCII_SOLID_BEGIN) == 0)) {
1014 if (solidKey.compare(ASCII_SOLID_BEGIN) == 0 || line.compare(solidKey) == 0) {
1015 *name = line.erase(0, ASCII_SOLID_BEGIN.size());
1018 start_pos = current_pos;
1030 m_fileHandle.clear();
1031 m_fileHandle.seekg(start_pos);
1033 std::array<bool, 6> solidErrors;
1034 inspectSolidASCII(nT, &solidErrors);
1036 m_fileHandle.clear();
1037 m_fileHandle.seekg(start_pos);
1054int STLReader::readFooterASCII(
const std::string &solid)
1057 if (!m_fileHandle.good()) {
1062 std::string solidKey = solid;
1064 solidKey = ASCII_SOLID_END +
" " + solidKey;
1073 m_lineStream.
readLine(m_fileHandle);
1076 if (!(m_lineStream >> word)) {
1081 if (word.compare(ASCII_SOLID_END) == 0) {
1083 if (line.compare(solidKey) != 0) {
1084 log::cout() <<
"WARNING: end-solid key does not match the solid name." << std::endl;
1085 log::cout() <<
" Expected end-solid key : " << solidKey << std::endl;
1086 log::cout() <<
" Current end-solid key : " << line << std::endl;
1090 }
else if (word.compare(ASCII_SOLID_BEGIN) == 0) {
1092 }
else if (m_fileHandle.eof()) {
1115int STLReader::readFacetASCII(std::array<double, 3> *V0, std::array<double, 3> *V1,
1116 std::array<double, 3> *V2, std::array<double, 3> *N)
1121 std::streamoff last_valid_pos;
1124 int nFacetVertices = 0;
1125 std::string target =
"facet";
1128 last_valid_pos = m_fileHandle.tellg();
1129 m_lineStream.
readLine(m_fileHandle);
1130 if (!(m_lineStream >> word)) {
1139 if (word.compare(ASCII_FACET_BEGIN) == 0) {
1140 if (word.compare(target) == 0) {
1143 if (!(m_lineStream >> word)) {
1152 if (word.compare(ASCII_FACET_END) == 0) {
1153 if (word.compare(target) == 0) {
1159 }
else if (word.compare(
"normal") == 0) {
1160 if (word.compare(target) == 0) {
1161 for (
int k = 0; k < 3; ++k) {
1162 m_lineStream >> value;
1163 (*N)[k] = stod(value);
1170 }
else if (word.compare(
"vertex") == 0) {
1171 if (word.compare(target) == 0) {
1172 std::array<double, 3> *coords;
1173 if (nFacetVertices == 0) {
1175 }
else if (nFacetVertices == 1) {
1177 }
else if (nFacetVertices == 2) {
1179 target = ASCII_FACET_END;
1185 for (
int k = 0; k < 3; ++k) {
1186 m_lineStream >> value;
1187 (*coords)[k] = stod(value);
1195 }
else if (word.compare(ASCII_SOLID_BEGIN) == 0) {
1198 }
else if (word.compare(ASCII_SOLID_END) == 0) {
1201 }
else if (m_fileHandle.eof()) {
1209 m_fileHandle.clear();
1210 m_fileHandle.seekg(last_valid_pos);
1229int STLReader::readHeaderBinary(std::string *name, std::size_t *nT)
1232 if (!m_fileHandle.good()) {
1240 for (std::size_t i = 0; i < BINARY_HEADER_SIZE /
sizeof(BINARY_UINT8); ++i) {
1241 BINARY_UINT8 headerCharacter;
1242 m_fileHandle.read(
reinterpret_cast<char *
>(&headerCharacter),
sizeof(BINARY_UINT8));
1246 BINARY_UINT32 nSolidFacets;
1247 m_fileHandle.read(
reinterpret_cast<char *
>(&nSolidFacets),
sizeof(BINARY_UINT32));
1251 if (m_fileHandle.eof()) {
1267int STLReader::readFooterBinary()
1270 if (!m_fileHandle.good()) {
1292int STLReader::readFacetBinary(std::array<double, 3> *V0, std::array<double, 3> *V1,
1293 std::array<double, 3> *V2, std::array<double, 3> *N)
1296 if (!m_fileHandle.good()) {
1301 std::array<char, BINARY_FACET_SIZE> facetData;
1302 m_fileHandle.read(facetData.data(), BINARY_FACET_SIZE);
1303 int facetDataOffset = 0;
1306 for (
int k = 0; k < 3; ++k) {
1307 (*N)[k] = (double) *(
reinterpret_cast<BINARY_REAL32 *
>(facetData.data() + facetDataOffset));
1308 facetDataOffset +=
sizeof(BINARY_REAL32);
1312 for (
int k = 0; k < 3; ++k) {
1313 (*V0)[k] = (double) *(
reinterpret_cast<BINARY_REAL32 *
>(facetData.data() + facetDataOffset));
1314 facetDataOffset +=
sizeof(BINARY_REAL32);
1317 for (
int k = 0; k < 3; ++k) {
1318 (*V1)[k] = (double) *(
reinterpret_cast<BINARY_REAL32 *
>(facetData.data() + facetDataOffset));
1319 facetDataOffset +=
sizeof(BINARY_REAL32);
1322 for (
int k = 0; k < 3; ++k) {
1323 (*V2)[k] = (double) *(
reinterpret_cast<BINARY_REAL32 *
>(facetData.data() + facetDataOffset));
1324 facetDataOffset +=
sizeof(BINARY_REAL32);
1328 if (m_fileHandle.eof()) {
1349 if (format == FormatUnknown) {
1350 throw std::runtime_error(
"Invalid STL format.");
1364 if (m_fileHandle.is_open()) {
1370 std::ios_base::openmode openMode;
1371 if (format == FormatBinary) {
1372 if (writeMode == WriteOverwrite) {
1373 openMode = std::ofstream::out | std::ofstream::binary;
1374 }
else if (partialWrite && writeMode == WriteAppend) {
1375 openMode = std::ofstream::app | std::ofstream::binary;
1377 throw std::runtime_error(
"Specified write mode is not supported for binary files.");
1380 if (writeMode == WriteOverwrite) {
1381 openMode = std::ofstream::out;
1382 }
else if (writeMode == WriteAppend) {
1383 openMode = std::ofstream::app;
1385 throw std::runtime_error(
"Specified write mode is not supported for ASCII files.");
1390 if (!m_fileHandle.good()) {
1395 m_fileHandle << std::scientific;
1405 m_fileHandle.close();
1426int STLWriter::writeSolid(
const std::string &name, std::size_t nV, std::size_t nT,
1427 const std::vector<std::array<double,3>> &V,
const std::vector<std::array<double,3>> &N,
1428 const std::vector<std::array<std::size_t,3>> &T)
1431 if (V.size() < nV) {
1435 if (T.size() < nT) {
1439 if (N.size() < nT) {
1444 std::ios::fmtflags streamFlags(m_fileHandle.flags());
1448 if (headerError != 0) {
1453 for (std::size_t i = 0; i < nT; ++i) {
1455 for (
int k = 0; k < 3; ++k) {
1456 if (T[i][k] >= nV) {
1462 int facetError =
writeFacet(V[T[i][0]], V[T[i][1]], V[T[i][2]], N[i]);
1463 if (facetError != 0) {
1470 if (footerError != 0) {
1475 m_fileHandle.flags(streamFlags);
1496 if (format == FormatASCII) {
1497 error = writeHeaderASCII(name, nT);
1499 error = writeHeaderBinary(name, nT);
1520 if (format == FormatASCII) {
1521 error = writeFooterASCII(name);
1523 error = writeFooterBinary(name);
1543 const std::array<double, 3> &V2,
const std::array<double, 3> &N)
1548 if (format == FormatASCII) {
1549 error = writeFacetASCII(V0, V1, V2, N);
1551 error = writeFacetBinary(V0, V1, V2, N);
1568int STLWriter::writeHeaderASCII(
const std::string &name, std::size_t nT)
1573 if (!m_fileHandle.good()) {
1578 std::stringstream sheader;
1579 sheader << ASCII_SOLID_BEGIN <<
" " << name;
1582 std::string header = sheader.str();
1584 m_fileHandle << header <<
"\n";
1599int STLWriter::writeFooterASCII(
const std::string &name)
1604 if (!m_fileHandle.good()) {
1609 std::stringstream sfooter;
1610 sfooter << ASCII_SOLID_END <<
" " << name;
1613 footer = sfooter.str();
1615 m_fileHandle << footer <<
"\n";
1633int STLWriter::writeFacetASCII(
const std::array<double, 3> &V0,
const std::array<double, 3> &V1,
1634 const std::array<double, 3> &V2,
const std::array<double, 3> &N)
1637 if (!m_fileHandle.good()) {
1642 m_fileHandle <<
" " << ASCII_FACET_BEGIN;
1645 m_fileHandle <<
" normal ";
1646 m_fileHandle << N[0] <<
" ";
1647 m_fileHandle << N[1] <<
" ";
1648 m_fileHandle << N[2];
1649 m_fileHandle <<
"\n";
1652 m_fileHandle <<
" outer loop" <<
"\n";
1654 m_fileHandle <<
" vertex ";
1655 m_fileHandle << V0[0] <<
" ";
1656 m_fileHandle << V0[1] <<
" ";
1657 m_fileHandle << V0[2];
1658 m_fileHandle <<
"\n";
1660 m_fileHandle <<
" vertex ";
1661 m_fileHandle << V1[0] <<
" ";
1662 m_fileHandle << V1[1] <<
" ";
1663 m_fileHandle << V1[2];
1664 m_fileHandle <<
"\n";
1666 m_fileHandle <<
" vertex ";
1667 m_fileHandle << V2[0] <<
" ";
1668 m_fileHandle << V2[1] <<
" ";
1669 m_fileHandle << V2[2];
1670 m_fileHandle <<
"\n";
1672 m_fileHandle <<
" endloop" <<
"\n";
1675 m_fileHandle <<
" " << ASCII_FACET_END <<
"\n";
1691int STLWriter::writeHeaderBinary(
const std::string &name, std::size_t nT)
1696 if (!m_fileHandle.good()) {
1701 for (std::size_t i = 0; i < BINARY_HEADER_SIZE /
sizeof(BINARY_UINT8); ++i) {
1702 BINARY_UINT8 headerCharacter = 0;
1703 m_fileHandle.write(
reinterpret_cast<char*
>(&headerCharacter),
sizeof(BINARY_UINT8));
1707 BINARY_UINT32 nFacets = (BINARY_UINT32) nT;
1708 m_fileHandle.write(
reinterpret_cast<char *
>(&nFacets),
sizeof(BINARY_UINT32));
1723int STLWriter::writeFooterBinary(
const std::string &name)
1728 if (!m_fileHandle.good()) {
1749int STLWriter::writeFacetBinary(
const std::array<double, 3> &V0,
const std::array<double, 3> &V1,
1750 const std::array<double, 3> &V2,
const std::array<double, 3> &N)
1753 if (!m_fileHandle.good()) {
1758 for (
int k = 0; k < 3; ++k) {
1759 BINARY_REAL32 N_k = (BINARY_REAL32) N[k];
1760 m_fileHandle.write(
reinterpret_cast<char *
>(&N_k),
sizeof(BINARY_REAL32));
1764 for (
int k = 0; k < 3; ++k) {
1765 BINARY_REAL32 V_k = (BINARY_REAL32) V0[k];
1766 m_fileHandle.write(
reinterpret_cast<char *
>(&V_k),
sizeof(BINARY_REAL32));
1769 for (
int k = 0; k < 3; ++k) {
1770 BINARY_REAL32 V_k = (BINARY_REAL32) V1[k];
1771 m_fileHandle.write(
reinterpret_cast<char *
>(&V_k),
sizeof(BINARY_REAL32));
1774 for (
int k = 0; k < 3; ++k) {
1775 BINARY_REAL32 V_k = (BINARY_REAL32) V2[k];
1776 m_fileHandle.write(
reinterpret_cast<char *
>(&V_k),
sizeof(BINARY_REAL32));
1784 BINARY_UINT16 attributeByteCount = 0;
1785 m_fileHandle.write(
reinterpret_cast<char *
>(&attributeByteCount),
sizeof(BINARY_UINT16));
int readLine(std::ifstream &fileHandle)
void copyLine(std::string *line) const
Base class for the STL writer and the STL reader.
void setFormat(Format format)
void setFilename(const std::string &filename)
STLBase(const std::string &filename)
const std::string & getFilename() const
int readFacet(std::array< double, 3 > *V0, std::array< double, 3 > *V1, std::array< double, 3 > *V2, std::array< double, 3 > *N)
int inspect(InspectionInfo *info)
void displayInspectionInfo(const InspectionInfo &info, std::ostream &out) const
int readHeader(std::string *name, std::size_t *nT)
STLReader(const std::string &filename, Format format=FormatUnknown)
int readSolid(std::string *name, std::size_t *nV, std::size_t *nT, std::vector< std::array< double, 3 > > *V, std::vector< std::array< double, 3 > > *N, std::vector< std::array< std::size_t, 3 > > *T)
static Format detectFormat(const std::string &filename)
int writeFacet(const std::array< double, 3 > &V0, const std::array< double, 3 > &V1, const std::array< double, 3 > &V2, const std::array< double, 3 > &N)
int writeFooter(const std::string &name)
int writeHeader(const std::string &name, std::size_t nT)
STLWriter(const std::string &filename, Format format)
int writeBegin(WriteMode writeMode, bool partialWrite=false)
#define BITPIT_UNUSED(variable)
std::string & trim(std::string &s)
Logger & cout(log::Level defaultSeverity, log::Visibility defaultVisibility)
Logger & error(log::Visibility defaultVisibility)
Logger & info(log::Visibility defaultVisibility)
Structure holding inspection information.