13 #include <boost/algorithm/string.hpp>
37 inline static std::vector<std::string>
testObjString(
const std::string& tString,
38 bool triMesh =
false) {
39 std::vector<std::string> errorStrings;
40 const std::string w =
"[ Invalid obj : ";
42 std::vector<std::string> passes = {
"#",
"usemtl",
"mtllib",
"o",
"g",
"s"};
44 auto ss = std::stringstream{tString};
46 auto fnbc = line.find_first_not_of(
" ", 0);
47 if (fnbc != std::string::npos) {
48 auto snbc = line.find_first_of(
" ", fnbc);
49 std::string stag = line.substr(fnbc, snbc - fnbc);
53 for (
const auto& ptag : passes) {
63 auto tnbc = line.find_first_not_of(
" ", snbc);
64 std::string body = line.substr(tnbc, line.size() - tnbc);
67 if (stag.find(
"v") != std::string::npos or
68 (stag == std::string(
"f") and triMesh)) {
69 std::vector<std::string> bodySplit;
70 boost::split(bodySplit, body, boost::is_any_of(
" "));
71 if (bodySplit.size() != 3 and stag != std::string(
"f")) {
72 errorStrings.push_back(w + line +
" ] " + stag +
73 " must only have three attributes!");
74 }
else if (bodySplit.size() != 3) {
75 errorStrings.push_back(
"[ not a triangular mesh : " + line +
" ]");
81 if (stag == std::string(
"f") or stag == std::string(
"l")) {
83 (body.find_first_not_of(
"0123456789/ ") == std::string::npos);
85 errorStrings.push_back(w + line +
" ] " + stag +
86 " can only have positive integers!");
88 std::vector<std::string> bodySplit;
89 boost::split(bodySplit, body, boost::is_any_of(
" "));
90 for (
auto& bs : bodySplit) {
92 errorStrings.push_back(w + line +
93 " ] vertex with index 0 detected!");
98 errorStrings.push_back(w + line +
" ] invalid syntax!");
121 inline static std::vector<std::string>
testPlyString(
const std::string& tString,
122 bool triMesh =
false) {
123 std::vector<std::string> errorStrings;
124 const std::string w =
"[ Invalid ply : ";
126 std::vector<std::string> hPasses = {
"format",
"comment"};
128 auto ss = std::stringstream{tString};
129 bool inHeader =
false;
133 std::vector<PlyElement> elements;
136 for (std::string line;
std::getline(ss, line,
'\n'); ++lNumber) {
138 if (lNumber == 0 and line !=
"ply") {
139 errorStrings.push_back(w + line +
" ] first line has to be 'ply");
140 }
else if (line ==
"ply") {
148 auto fnbc = line.find_first_not_of(
" ", 0);
149 if (fnbc != std::string::npos) {
150 auto snbc = line.find_first_of(
" ", fnbc);
151 std::string stag = line.substr(fnbc, snbc - fnbc);
152 if (stag ==
"comment" or stag ==
"format") {
155 if (stag ==
"end_header") {
157 elements.push_back(currentElement);
162 auto tnbc = line.find_first_not_of(
" ", snbc);
163 std::string body = line.substr(tnbc, line.size() - tnbc);
165 auto n0nbc = body.find_first_not_of(
" ", 0);
166 auto n1nbc = body.find_first_of(
" ", n0nbc);
167 std::string
name = body.substr(n0nbc, n1nbc);
169 if (stag ==
"element") {
171 if (currentElement.
name !=
"none" and currentElement.
copies > 0) {
172 elements.push_back(currentElement);
177 auto n2nbc = body.find_first_of(
" ", n1nbc);
178 std::string copies = body.substr(n1nbc, n2nbc);
179 currentElement.
copies = std::stoi(copies);
180 }
else if (stag ==
"property") {
181 if (name ==
"list") {
189 errorStrings.push_back(w + line +
" ] Unkown command.");
193 if (elements[cElement].copies == 0) {
196 if (cElement < elements.size()) {
197 elements[cElement].copies -= 1;
198 std::vector<std::string> lineSplit;
199 boost::split(lineSplit, line, boost::is_any_of(
" "));
200 if (elements[cElement].properties == -1) {
201 int nprops = std::stoi(lineSplit[0]);
202 if (nprops != (
int(lineSplit.size()) - 1)) {
203 errorStrings.push_back(w + line + std::string(
" ] List expected ") +
205 std::string(
" properties, while found ") +
209 }
else if (lineSplit.size() != size_t(elements[cElement].properties)) {
210 errorStrings.push_back(
211 w + line + std::string(
" ] Element expected ") +
213 std::string(
" propertes, while found ") +