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 info->solidNames[solidIndex] = sname.str();
393 inspectionError = inspectSolidASCII(
info->solidFacetCount.data() + solidIndex,
info->solidErrors.data() + solidIndex);
394 if (inspectionError != 0) {
398 info->solidVertexCount[solidIndex] = 3 *
info->solidFacetCount[solidIndex];
403 m_fileHandle.clear();
404 m_fileHandle.seekg(start_pos);
406 return inspectionError;
427int STLReader::inspectSolidASCII(std::size_t *nFacets, std::array<bool, 6> *errors)
434 if (!m_fileHandle.good()) {
440 std::streamoff last_valid_pos;
442 int inspectError = 0;
445 last_valid_pos = m_fileHandle.tellg();
446 m_lineStream.readLine(m_fileHandle);
447 if (!(m_lineStream >> word)) {
452 if (m_fileHandle.eof()) {
454 }
else if (word.compare(ASCII_SOLID_END) == 0) {
456 }
else if (word.compare(ASCII_SOLID_BEGIN) == 0) {
461 if (word.compare(ASCII_FACET_BEGIN) == 0) {
464 m_fileHandle.seekg(last_valid_pos);
465 inspectError = inspectFacetASCII(errors);
466 if (inspectError != 0) {
473 if (word.compare(ASCII_SOLID_END) != 0) {
475 m_fileHandle.clear();
476 m_fileHandle.seekg(last_valid_pos);
495int STLReader::inspectFacetASCII(std::array<bool, 6> *errors)
498 if (!m_fileHandle.good()) {
504 std::streamoff last_valid_pos;
506 last_valid_pos = m_fileHandle.tellg();
507 m_lineStream.readLine(m_fileHandle);
508 if ((!(m_lineStream >> word)) || (word.compare(ASCII_FACET_BEGIN) == 0)) {
513 bool normal_found =
false;
514 while ((!m_fileHandle.eof())
515 && ((word.compare(ASCII_FACET_END) != 0)
516 && (word.compare(ASCII_FACET_BEGIN) != 0)
517 && (word.compare(ASCII_SOLID_END) != 0)
518 && (word.compare(ASCII_SOLID_BEGIN) != 0))) {
521 if (word.compare(
"begin") == 0) {
522 if ((m_lineStream >> word) && (word.compare(
"normal") == 0)) {
526 while (m_lineStream >> word) {
535 else if (word.compare(
"vertex") == 0) {
539 while (m_lineStream >> word) {
549 last_valid_pos = m_fileHandle.tellg();
550 m_lineStream.readLine(m_fileHandle);
551 if (!(m_lineStream >> word)) {
557 if (word.compare(ASCII_FACET_END) != 0) {
559 m_fileHandle.clear(),
560 m_fileHandle.seekg(last_valid_pos);
585int STLReader::inspectBinary(InspectionInfo *info)
589 info->solidErrors.clear();
590 info->solidNames.clear();
591 info->solidFacetCount.clear();
592 info->solidVertexCount.clear();
595 if (!m_fileHandle.good()) {
600 m_fileHandle.clear();
601 std::streamoff start_pos = m_fileHandle.tellg();
602 m_fileHandle.seekg(0);
605 for (std::size_t i = 0; i < BINARY_HEADER_SIZE /
sizeof(BINARY_UINT8); ++i) {
606 BINARY_UINT8 headerCharacter;
607 m_fileHandle.read(
reinterpret_cast<char*
>(&headerCharacter),
sizeof(BINARY_UINT8));
610 if (m_fileHandle.eof()) {
611 info->solidErrors[0][0] =
true;
616 info->solidNames.push_back(
"");
619 BINARY_UINT32 nFacets;
620 m_fileHandle.read(
reinterpret_cast<char *
>(&nFacets),
sizeof(BINARY_UINT32));
621 info->solidFacetCount.push_back((std::size_t) nFacets);
622 info->solidVertexCount.push_back((std::size_t) (3 * nFacets));
624 if (m_fileHandle.eof()) {
625 info->solidErrors[0][0] =
true;
631 while ((!m_fileHandle.eof()) && (n < nFacets)) {
632 std::array<char, BINARY_FACET_SIZE> facetData;
633 m_fileHandle.read(facetData.data(), BINARY_FACET_SIZE);
639 info->solidErrors[0][1] =
true;
643 m_fileHandle.clear();
644 m_fileHandle.seekg(start_pos);
657 out <<
"Inspection info" <<
"\n";
662 if (format == FormatBinary) {
663 out <<
" Format : binary" <<
"\n";
665 out <<
" Format : ASCII" <<
"\n";
669 if (info.nSolids > 0) {
670 out <<
" Solid count : " << info.nSolids <<
"\n";
672 for (
int i = 0; i < info.nSolids; ++i) {
674 out <<
" Solid index : " << i <<
"\n";
675 out <<
" Solid name : " << info.solidNames[i] <<
"\n";
676 out <<
" Solid facets : " << info.solidFacetCount[i] <<
"\n";
677 out <<
" Solid vertices : " << info.solidVertexCount[i] <<
"\n";
679 if (info.solidErrors[i][0]) {
680 out <<
" **ERROR** Unterminated solid block." <<
"\n";
682 if (info.solidErrors[i][1]) {
683 out <<
" **ERROR** Unterminated facet block." <<
"\n";
685 if (info.solidErrors[i][2]) {
686 out <<
" **ERROR** Normal data are missing." <<
"\n";
688 if (info.solidErrors[i][3]) {
689 out <<
" **ERROR** Wrong number of components for normal data." <<
"\n";
691 if (info.solidErrors[i][4]) {
692 out <<
" **ERROR** Wrong number of vertices in facet block." <<
"\n";
694 if (info.solidErrors[i][5]) {
695 out <<
" **ERROR** Wrong number of coordinates for vertice." <<
"\n";
699 out <<
" STL file contains no solids." <<
"\n";
715 if (m_fileHandle.is_open()) {
719 m_fileHandle.open(
getFilename(), std::ifstream::in | std::ifstream::binary);
720 if (!m_fileHandle.good()) {
732 m_fileHandle.close();
759 std::vector<std::array<double, 3>> *V, std::vector<std::array<double, 3>> *N,
760 std::vector<std::array<std::size_t, 3>> *T)
762 return readSolid(
"", name, nV, nT, V, N, T);
790 std::vector<std::array<double, 3>> *V, std::vector<std::array<double, 3>> *N,
791 std::vector<std::array<std::size_t, 3>> *T)
794 std::size_t nSolidFacets;
795 int headerError =
readHeader(solid, name, &nSolidFacets);
796 if (headerError != 0) {
801 V->resize(*nV + 3 * nSolidFacets, {{0., 0., 0.}});
802 N->resize(*nT + nSolidFacets, {{0., 0., 0.}});
803 T->resize(*nT + nSolidFacets, {{0, 0, 0}});
805 for (std::size_t i = 0; i < *nT; ++i) {
807 std::array<double, 3> *V0 = V->data() + *nV + 3 * i;
808 std::array<double, 3> *V1 = V0 + 1;
809 std::array<double, 3> *V2 = V1 + 1;
811 int facetError =
readFacet(V0, V1, V2, N->data() + i);
812 if (facetError != 0) {
817 (*T)[i][0] = *nV + 3 * i;
818 (*T)[i][1] = (*T)[i][0] + 1;
819 (*T)[i][2] = (*T)[i][1] + 1;
824 if (footerError != 0) {
869 if (format == FormatASCII) {
870 error = readHeaderASCII(solid, name, nT);
872 std::string trimmedSolid = solid;
874 if (!trimmedSolid.empty()) {
875 log::cout() <<
"WARNING: loading solids with a specific name is only supported for ASCII files." << std::endl;
876 log::cout() <<
" The reader will read the next solid." << std::endl;
879 error = readHeaderBinary(name, nT);
917 if (format == FormatASCII) {
918 error = readFooterASCII(solid);
920 error = readFooterBinary();
942 std::array<double, 3> *V2, std::array<double, 3> *N)
947 if (format == FormatASCII) {
948 error = readFacetASCII(V0, V1, V2, N);
950 error = readFacetBinary(V0, V1, V2, N);
971int STLReader::readHeaderASCII(
const std::string &solid, std::string *name, std::size_t *nT)
974 if (!m_fileHandle.good()) {
979 std::string solidKey = solid;
981 solidKey = ASCII_SOLID_BEGIN +
" " + solidKey;
988 std::streamoff start_pos = m_fileHandle.tellg();
989 std::streamoff current_pos = start_pos + 1;
991 bool solidFound =
false;
992 bool wrapAround = solidKey.compare(ASCII_SOLID_BEGIN) != 0;
993 while (!solidFound && (start_pos != current_pos)) {
995 m_lineStream.
readLine(m_fileHandle);
998 if (m_fileHandle.eof()) {
1000 m_fileHandle.clear();
1001 m_fileHandle.seekg(0);
1008 current_pos = m_fileHandle.tellg();
1011 if ((m_lineStream >> word) && (word.compare(ASCII_SOLID_BEGIN) == 0)) {
1012 m_lineStream.copyLine(&line);
1013 if (solidKey.compare(ASCII_SOLID_BEGIN) == 0 || line.compare(solidKey) == 0) {
1014 *name = line.erase(0, ASCII_SOLID_BEGIN.size());
1017 start_pos = current_pos;
1029 m_fileHandle.clear();
1030 m_fileHandle.seekg(start_pos);
1032 std::array<bool, 6> solidErrors;
1033 inspectSolidASCII(nT, &solidErrors);
1035 m_fileHandle.clear();
1036 m_fileHandle.seekg(start_pos);
1053int STLReader::readFooterASCII(
const std::string &solid)
1056 if (!m_fileHandle.good()) {
1061 std::string solidKey = solid;
1063 solidKey = ASCII_SOLID_END +
" " + solidKey;
1072 m_lineStream.readLine(m_fileHandle);
1075 if (!(m_lineStream >> word)) {
1080 if (word.compare(ASCII_SOLID_END) == 0) {
1081 m_lineStream.copyLine(&line);
1082 if (line.compare(solidKey) != 0) {
1083 log::cout() <<
"WARNING: end-solid key does not match the solid name." << std::endl;
1084 log::cout() <<
" Expected end-solid key : " << solidKey << std::endl;
1085 log::cout() <<
" Current end-solid key : " << line << std::endl;
1089 }
else if (word.compare(ASCII_SOLID_BEGIN) == 0) {
1091 }
else if (m_fileHandle.eof()) {
1114int STLReader::readFacetASCII(std::array<double, 3> *V0, std::array<double, 3> *V1,
1115 std::array<double, 3> *V2, std::array<double, 3> *N)
1120 std::streamoff last_valid_pos;
1123 int nFacetVertices = 0;
1124 std::string target =
"facet";
1127 last_valid_pos = m_fileHandle.tellg();
1128 m_lineStream.readLine(m_fileHandle);
1129 if (!(m_lineStream >> word)) {
1138 if (word.compare(ASCII_FACET_BEGIN) == 0) {
1139 if (word.compare(target) == 0) {
1142 if (!(m_lineStream >> word)) {
1151 if (word.compare(ASCII_FACET_END) == 0) {
1152 if (word.compare(target) == 0) {
1158 }
else if (word.compare(
"normal") == 0) {
1159 if (word.compare(target) == 0) {
1160 for (
int k = 0; k < 3; ++k) {
1161 m_lineStream >> value;
1162 (*N)[k] = stod(value);
1169 }
else if (word.compare(
"vertex") == 0) {
1170 if (word.compare(target) == 0) {
1171 std::array<double, 3> *coords;
1172 if (nFacetVertices == 0) {
1174 }
else if (nFacetVertices == 1) {
1176 }
else if (nFacetVertices == 2) {
1178 target = ASCII_FACET_END;
1184 for (
int k = 0; k < 3; ++k) {
1185 m_lineStream >> value;
1186 (*coords)[k] = stod(value);
1194 }
else if (word.compare(ASCII_SOLID_BEGIN) == 0) {
1197 }
else if (word.compare(ASCII_SOLID_END) == 0) {
1200 }
else if (m_fileHandle.eof()) {
1208 m_fileHandle.clear();
1209 m_fileHandle.seekg(last_valid_pos);
1228int STLReader::readHeaderBinary(std::string *name, std::size_t *nT)
1231 if (!m_fileHandle.good()) {
1239 for (std::size_t i = 0; i < BINARY_HEADER_SIZE /
sizeof(BINARY_UINT8); ++i) {
1240 BINARY_UINT8 headerCharacter;
1241 m_fileHandle.read(
reinterpret_cast<char *
>(&headerCharacter),
sizeof(BINARY_UINT8));
1245 BINARY_UINT32 nSolidFacets;
1246 m_fileHandle.read(
reinterpret_cast<char *
>(&nSolidFacets),
sizeof(BINARY_UINT32));
1250 if (m_fileHandle.eof()) {
1266int STLReader::readFooterBinary()
1269 if (!m_fileHandle.good()) {
1291int STLReader::readFacetBinary(std::array<double, 3> *V0, std::array<double, 3> *V1,
1292 std::array<double, 3> *V2, std::array<double, 3> *N)
1295 if (!m_fileHandle.good()) {
1300 std::array<char, BINARY_FACET_SIZE> facetData;
1301 m_fileHandle.read(facetData.data(), BINARY_FACET_SIZE);
1302 int facetDataOffset = 0;
1305 for (
int k = 0; k < 3; ++k) {
1306 (*N)[k] = (double) *(
reinterpret_cast<BINARY_REAL32 *
>(facetData.data() + facetDataOffset));
1307 facetDataOffset +=
sizeof(BINARY_REAL32);
1311 for (
int k = 0; k < 3; ++k) {
1312 (*V0)[k] = (double) *(
reinterpret_cast<BINARY_REAL32 *
>(facetData.data() + facetDataOffset));
1313 facetDataOffset +=
sizeof(BINARY_REAL32);
1316 for (
int k = 0; k < 3; ++k) {
1317 (*V1)[k] = (double) *(
reinterpret_cast<BINARY_REAL32 *
>(facetData.data() + facetDataOffset));
1318 facetDataOffset +=
sizeof(BINARY_REAL32);
1321 for (
int k = 0; k < 3; ++k) {
1322 (*V2)[k] = (double) *(
reinterpret_cast<BINARY_REAL32 *
>(facetData.data() + facetDataOffset));
1323 facetDataOffset +=
sizeof(BINARY_REAL32);
1327 if (m_fileHandle.eof()) {
1348 if (format == FormatUnknown) {
1349 throw std::runtime_error(
"Invalid STL format.");
1363 if (m_fileHandle.is_open()) {
1369 std::ios_base::openmode openMode;
1370 if (format == FormatBinary) {
1371 if (writeMode == WriteOverwrite) {
1372 openMode = std::ofstream::out | std::ofstream::binary;
1373 }
else if (partialWrite && writeMode == WriteAppend) {
1374 openMode = std::ofstream::app | std::ofstream::binary;
1376 throw std::runtime_error(
"Specified write mode is not supported for binary files.");
1379 if (writeMode == WriteOverwrite) {
1380 openMode = std::ofstream::out;
1381 }
else if (writeMode == WriteAppend) {
1382 openMode = std::ofstream::app;
1384 throw std::runtime_error(
"Specified write mode is not supported for ASCII files.");
1389 if (!m_fileHandle.good()) {
1394 m_fileHandle << std::scientific;
1404 m_fileHandle.close();
1425int STLWriter::writeSolid(
const std::string &name, std::size_t nV, std::size_t nT,
1426 const std::vector<std::array<double,3>> &V,
const std::vector<std::array<double,3>> &N,
1427 const std::vector<std::array<std::size_t,3>> &T)
1430 if (V.size() < nV) {
1434 if (T.size() < nT) {
1438 if (N.size() < nT) {
1443 std::ios::fmtflags streamFlags(m_fileHandle.flags());
1447 if (headerError != 0) {
1452 for (std::size_t i = 0; i < nT; ++i) {
1454 for (
int k = 0; k < 3; ++k) {
1455 if (T[i][k] >= nV) {
1461 int facetError =
writeFacet(V[T[i][0]], V[T[i][1]], V[T[i][2]], N[i]);
1462 if (facetError != 0) {
1469 if (footerError != 0) {
1474 m_fileHandle.flags(streamFlags);
1495 if (format == FormatASCII) {
1496 error = writeHeaderASCII(name, nT);
1498 error = writeHeaderBinary(name, nT);
1519 if (format == FormatASCII) {
1520 error = writeFooterASCII(name);
1522 error = writeFooterBinary(name);
1542 const std::array<double, 3> &V2,
const std::array<double, 3> &N)
1547 if (format == FormatASCII) {
1548 error = writeFacetASCII(V0, V1, V2, N);
1550 error = writeFacetBinary(V0, V1, V2, N);
1567int STLWriter::writeHeaderASCII(
const std::string &name, std::size_t nT)
1572 if (!m_fileHandle.good()) {
1577 std::stringstream sheader;
1578 sheader << ASCII_SOLID_BEGIN <<
" " << name;
1581 std::string header = sheader.str();
1583 m_fileHandle << header <<
"\n";
1598int STLWriter::writeFooterASCII(
const std::string &name)
1603 if (!m_fileHandle.good()) {
1608 std::stringstream sfooter;
1609 sfooter << ASCII_SOLID_END <<
" " << name;
1612 footer = sfooter.str();
1614 m_fileHandle << footer <<
"\n";
1632int STLWriter::writeFacetASCII(
const std::array<double, 3> &V0,
const std::array<double, 3> &V1,
1633 const std::array<double, 3> &V2,
const std::array<double, 3> &N)
1636 if (!m_fileHandle.good()) {
1641 m_fileHandle <<
" " << ASCII_FACET_BEGIN;
1644 m_fileHandle <<
" normal ";
1645 m_fileHandle << N[0] <<
" ";
1646 m_fileHandle << N[1] <<
" ";
1647 m_fileHandle << N[2];
1648 m_fileHandle <<
"\n";
1651 m_fileHandle <<
" outer loop" <<
"\n";
1653 m_fileHandle <<
" vertex ";
1654 m_fileHandle << V0[0] <<
" ";
1655 m_fileHandle << V0[1] <<
" ";
1656 m_fileHandle << V0[2];
1657 m_fileHandle <<
"\n";
1659 m_fileHandle <<
" vertex ";
1660 m_fileHandle << V1[0] <<
" ";
1661 m_fileHandle << V1[1] <<
" ";
1662 m_fileHandle << V1[2];
1663 m_fileHandle <<
"\n";
1665 m_fileHandle <<
" vertex ";
1666 m_fileHandle << V2[0] <<
" ";
1667 m_fileHandle << V2[1] <<
" ";
1668 m_fileHandle << V2[2];
1669 m_fileHandle <<
"\n";
1671 m_fileHandle <<
" endloop" <<
"\n";
1674 m_fileHandle <<
" " << ASCII_FACET_END <<
"\n";
1690int STLWriter::writeHeaderBinary(
const std::string &name, std::size_t nT)
1695 if (!m_fileHandle.good()) {
1700 for (std::size_t i = 0; i < BINARY_HEADER_SIZE /
sizeof(BINARY_UINT8); ++i) {
1701 BINARY_UINT8 headerCharacter = 0;
1702 m_fileHandle.write(
reinterpret_cast<char*
>(&headerCharacter),
sizeof(BINARY_UINT8));
1706 BINARY_UINT32 nFacets = (BINARY_UINT32) nT;
1707 m_fileHandle.write(
reinterpret_cast<char *
>(&nFacets),
sizeof(BINARY_UINT32));
1722int STLWriter::writeFooterBinary(
const std::string &name)
1727 if (!m_fileHandle.good()) {
1748int STLWriter::writeFacetBinary(
const std::array<double, 3> &V0,
const std::array<double, 3> &V1,
1749 const std::array<double, 3> &V2,
const std::array<double, 3> &N)
1752 if (!m_fileHandle.good()) {
1757 for (
int k = 0; k < 3; ++k) {
1758 BINARY_REAL32 N_k = (BINARY_REAL32) N[k];
1759 m_fileHandle.write(
reinterpret_cast<char *
>(&N_k),
sizeof(BINARY_REAL32));
1763 for (
int k = 0; k < 3; ++k) {
1764 BINARY_REAL32 V_k = (BINARY_REAL32) V0[k];
1765 m_fileHandle.write(
reinterpret_cast<char *
>(&V_k),
sizeof(BINARY_REAL32));
1768 for (
int k = 0; k < 3; ++k) {
1769 BINARY_REAL32 V_k = (BINARY_REAL32) V1[k];
1770 m_fileHandle.write(
reinterpret_cast<char *
>(&V_k),
sizeof(BINARY_REAL32));
1773 for (
int k = 0; k < 3; ++k) {
1774 BINARY_REAL32 V_k = (BINARY_REAL32) V2[k];
1775 m_fileHandle.write(
reinterpret_cast<char *
>(&V_k),
sizeof(BINARY_REAL32));
1783 BINARY_UINT16 attributeByteCount = 0;
1784 m_fileHandle.write(
reinterpret_cast<char *
>(&attributeByteCount),
sizeof(BINARY_UINT16));
int readLine(std::ifstream &fileHandle)
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.