From f4be95b0784597cb63c75463d674d6a929e78af9 Mon Sep 17 00:00:00 2001 From: pavel Date: Thu, 2 Jul 2020 17:19:22 +0200 Subject: [PATCH] fixed different types of indices, fixed degenerated normals --- PlyReader.hpp | 8 +++++--- Refinement.hpp | 10 ++++------ TriangleMesh.hpp | 7 ++++++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/PlyReader.hpp b/PlyReader.hpp index 3d91175..7f38fd3 100644 --- a/PlyReader.hpp +++ b/PlyReader.hpp @@ -14,7 +14,9 @@ class PlyReader { public: PlyReader(std::istream& in) - : in_(in) {} + : in_(in) { + PVL_ASSERT(in); + } std::vector readCloud() { std::string line; @@ -50,8 +52,8 @@ class PlyReader { } } TriangleMesh mesh; - std::cout << "Loading mesh with " << numVertices << " vertices and " << numFaces - << " faces" << std::endl; + std::cout << "Loading mesh with " << numVertices << " vertices and " << numFaces << " faces" + << std::endl; for (std::size_t i = 0; i < numVertices; ++i) { std::getline(in_, line); std::stringstream ss(line); diff --git a/Refinement.hpp b/Refinement.hpp index 9284d14..d0d5d47 100644 --- a/Refinement.hpp +++ b/Refinement.hpp @@ -7,9 +7,7 @@ namespace Pvl { template -void laplacianSmoothing(TriangleMesh& mesh, - bool preserveBoundary = true, - float rer = 1.f) { +void laplacianSmoothing(TriangleMesh& mesh, bool preserveBoundary = true, float rer = 1.f) { std::vector laplacian(mesh.numVertices(), Vec(0)); ParallelForEach()( mesh.vertexRange(), [&mesh, &laplacian, preserveBoundary](VertexHandle v1) { @@ -28,8 +26,8 @@ void laplacianSmoothing(TriangleMesh& mesh, }); std::vector biharmonic(mesh.numVertices(), Vec(0)); if (rer > 0.f) { - ParallelForEach()(mesh.vertexRange(), - [&mesh, &laplacian, &biharmonic, preserveBoundary](VertexHandle v1) { + ParallelForEach()( + mesh.vertexRange(), [&mesh, &laplacian, &biharmonic, preserveBoundary](VertexHandle v1) { if (preserveBoundary && mesh.boundary(v1)) { return; } @@ -48,7 +46,7 @@ void laplacianSmoothing(TriangleMesh& mesh, } ParallelFor()( - 0, mesh.numVertices(), [&mesh, &laplacian, &biharmonic, &rer](std::size_t i) { + std::size_t(0), mesh.numVertices(), [&mesh, &laplacian, &biharmonic, &rer](std::size_t i) { mesh.points[i] += 0.5 * (rer * biharmonic[i] + (1.f - rer) * laplacian[i]); }); } diff --git a/TriangleMesh.hpp b/TriangleMesh.hpp index 2788a68..6f0a7d9 100644 --- a/TriangleMesh.hpp +++ b/TriangleMesh.hpp @@ -38,7 +38,12 @@ class TriangleMesh : public Graph { // normalized normal Point normal(FaceHandle fh) const { - return normalize(areaNormal(fh)); + Point n = areaNormal(fh); + if (norm(n) > 1.e-20) { + return normalize(n); + } else { + return Point(0, 0, 1); + } } float area(FaceHandle fh) const {