| 332 | } |
| 333 | |
| 334 | ObjReader::VTN ObjReader::extractVertex(const std::string& vstring) |
| 335 | { |
| 336 | VTN vtn{ -1, -1, -1 }; |
| 337 | std::string s(vstring); |
| 338 | Utils::trim(s); |
| 339 | StringList parts = Utils::split(s, '/'); |
| 340 | for(auto& part : parts) |
| 341 | Utils::trim(part); |
| 342 | |
| 343 | if (parts.size() > 3) |
| 344 | throwError("Too many items in vertex specification."); |
| 345 | |
| 346 | char* p; |
| 347 | long index = std::strtol(parts[0].c_str(), &p, 10); |
| 348 | if (index == 0 || p != parts[0].c_str() + parts[0].size()) |
| 349 | throwError("Invalid index in face specification."); |
| 350 | else if (index < 0) |
| 351 | std::get<0>(vtn) = m_vertices.size() - index; |
| 352 | else |
| 353 | std::get<0>(vtn) = index; |
| 354 | |
| 355 | if (parts.size() > 1) |
| 356 | { |
| 357 | if (parts[1].length() > 0) |
| 358 | { |
| 359 | index = std::strtol(parts[1].c_str(), &p, 10); |
| 360 | if (index == 0 || p != parts[1].c_str() + parts[1].size()) |
| 361 | throwError("Invalid index in face specification."); |
| 362 | else if(index < 0) |
| 363 | std::get<1>(vtn) = m_vertices.size() - index; |
| 364 | else |
| 365 | std::get<1>(vtn) = index; |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | if (parts.size() > 2) |
| 370 | { |
| 371 | if (parts[2].length() > 0) |
| 372 | { |
| 373 | index = std::strtol(parts[2].c_str(), &p, 10); |
| 374 | if (index == 0 || p != parts[2].c_str() + parts[2].size()) |
| 375 | throwError("Invalid index in face specification."); |
| 376 | else if(index < 0) |
| 377 | std::get<2>(vtn) = m_vertices.size() - index; |
| 378 | else |
| 379 | std::get<2>(vtn) = index; |
| 380 | } |
| 381 | } |
| 382 | return vtn; |
| 383 | } |
| 384 | |
| 385 | } // namespace pdal |
| 386 | |