Deferring write until this time allows both points and faces from multiple point views to be written.
| 348 | // Deferring write until this time allows both points and faces from multiple |
| 349 | // point views to be written. |
| 350 | void PlyWriter::doneFile() |
| 351 | { |
| 352 | point_count_t pointCount = 0; |
| 353 | point_count_t faceCount = 0; |
| 354 | for (auto& v : m_views) |
| 355 | { |
| 356 | pointCount += v->size(); |
| 357 | TriangularMesh* mesh = v->mesh(); |
| 358 | if (mesh) |
| 359 | faceCount += mesh->size(); |
| 360 | } |
| 361 | |
| 362 | if (pointCount > (std::numeric_limits<uint32_t>::max)()) |
| 363 | throwError("Can't write PLY file. Only " + |
| 364 | std::to_string((std::numeric_limits<uint32_t>::max)()) + |
| 365 | " points supported."); |
| 366 | |
| 367 | m_stream = Utils::createFile(m_curFilename, true); |
| 368 | if (!m_stream) |
| 369 | throwError("Couldn't open file '" + m_curFilename + "' for output."); |
| 370 | |
| 371 | writeHeader(m_layout, pointCount, faceCount); |
| 372 | for (auto& v : m_views) |
| 373 | { |
| 374 | PointRef point(*v, 0); |
| 375 | for (PointId idx = 0; idx < v->size(); ++idx) |
| 376 | { |
| 377 | point.setPointId(idx); |
| 378 | writePoint(point, m_layout); |
| 379 | } |
| 380 | } |
| 381 | if (m_faces) |
| 382 | { |
| 383 | PointId offset = 0; |
| 384 | for (auto& v : m_views) |
| 385 | { |
| 386 | TriangularMesh *mesh = v->mesh(); |
| 387 | if (mesh) |
| 388 | { |
| 389 | for (size_t id = 0; id < mesh->size(); ++id) |
| 390 | { |
| 391 | const Triangle& t = (*mesh)[id]; |
| 392 | writeTriangle(t, offset); |
| 393 | } |
| 394 | } |
| 395 | offset += v->size(); |
| 396 | } |
| 397 | } |
| 398 | Utils::closeFile(m_stream); |
| 399 | m_stream = nullptr; |
| 400 | m_views.clear(); |
| 401 | m_curFilename.clear(); |
| 402 | |
| 403 | Utils::writeProgress(m_progressFd, "DONEFILE", m_curFilename); |
| 404 | getMetadata().addList("filename", m_curFilename); |
| 405 | } |
| 406 | |
| 407 | } // namespace pdal |
nothing calls this directly
no test coverage detected