15 #include <boost/algorithm/string.hpp>
40 bool triMesh =
false) {
41 std::vector<std::string> errorStrings;
44 std::vector<std::string> passes = {
"#",
"usemtl",
"mtllib",
"o",
"g",
"s"};
46 auto ss = std::stringstream{tString};
48 auto fnbc =
line.find_first_not_of(
" ", 0);
49 if (fnbc != std::string::npos) {
50 auto snbc =
line.find_first_of(
" ", fnbc);
55 for (
const auto& ptag : passes) {
65 auto tnbc =
line.find_first_not_of(
" ", snbc);
69 if (stag.find(
"v") != std::string::npos or
71 std::vector<std::string> bodySplit;
72 boost::split(bodySplit, body, boost::is_any_of(
" "));
73 if (bodySplit.size() != 3 and stag !=
std::string(
"f")) {
74 errorStrings.push_back(w +
line +
" ] " + stag +
75 " must only have three attributes!");
76 }
else if (bodySplit.size() != 3) {
77 errorStrings.push_back(
"[ not a triangular mesh : " +
line +
" ]");
85 (body.find_first_not_of(
"0123456789/ ") == std::string::npos);
87 errorStrings.push_back(w +
line +
" ] " + stag +
88 " can only have positive integers!");
90 std::vector<std::string> bodySplit;
91 boost::split(bodySplit, body, boost::is_any_of(
" "));
92 for (
auto& bs : bodySplit) {
94 errorStrings.push_back(w +
line +
95 " ] vertex with index 0 detected!");
100 errorStrings.push_back(w +
line +
" ] invalid syntax!");
124 bool triMesh =
false) {
125 std::vector<std::string> errorStrings;
128 std::vector<std::string> hPasses = {
"format",
"comment"};
130 auto ss = std::stringstream{tString};
131 bool inHeader =
false;
135 std::vector<PlyElement> elements;
140 if (lNumber == 0 and
line !=
"ply") {
141 errorStrings.push_back(w +
line +
" ] first line has to be 'ply");
142 }
else if (
line ==
"ply") {
150 auto fnbc =
line.find_first_not_of(
" ", 0);
151 if (fnbc != std::string::npos) {
152 auto snbc =
line.find_first_of(
" ", fnbc);
154 if (stag ==
"comment" or stag ==
"format") {
157 if (stag ==
"end_header") {
159 elements.push_back(currentElement);
164 auto tnbc =
line.find_first_not_of(
" ", snbc);
167 auto n0nbc = body.find_first_not_of(
" ", 0);
168 auto n1nbc = body.find_first_of(
" ", n0nbc);
171 if (stag ==
"element") {
173 if (currentElement.
name !=
"none" and currentElement.
copies > 0) {
174 elements.push_back(currentElement);
179 auto n2nbc = body.find_first_of(
" ", n1nbc);
181 currentElement.
copies = std::stoi(copies);
182 }
else if (stag ==
"property") {
183 if (name ==
"list") {
191 errorStrings.push_back(w +
line +
" ] Unknown command.");
195 if (elements[cElement].copies == 0) {
198 if (cElement < elements.size()) {
199 elements[cElement].copies -= 1;
200 std::vector<std::string> lineSplit;
201 boost::split(lineSplit,
line, boost::is_any_of(
" "));
202 if (elements[cElement].properties == -1) {
203 int nprops = std::stoi(lineSplit[0]);
204 if (nprops != (
int(lineSplit.size()) - 1)) {
211 }
else if (lineSplit.size() != size_t(elements[cElement].properties)) {
212 errorStrings.push_back(