Skip to content

Commit

Permalink
fixed different types of indices, fixed degenerated normals
Browse files Browse the repository at this point in the history
  • Loading branch information
sevec committed Jul 2, 2020
1 parent 127033e commit f4be95b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
8 changes: 5 additions & 3 deletions PlyReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class PlyReader {

public:
PlyReader(std::istream& in)
: in_(in) {}
: in_(in) {
PVL_ASSERT(in);
}

std::vector<Vec3f> readCloud() {
std::string line;
Expand Down Expand Up @@ -50,8 +52,8 @@ class PlyReader {
}
}
TriangleMesh<Vec3f> 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);
Expand Down
10 changes: 4 additions & 6 deletions Refinement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
namespace Pvl {

template <typename ConcurrencyTag = SequentialTag, typename Vec>
void laplacianSmoothing(TriangleMesh<Vec>& mesh,
bool preserveBoundary = true,
float rer = 1.f) {
void laplacianSmoothing(TriangleMesh<Vec>& mesh, bool preserveBoundary = true, float rer = 1.f) {
std::vector<Vec> laplacian(mesh.numVertices(), Vec(0));
ParallelForEach<ConcurrencyTag>()(
mesh.vertexRange(), [&mesh, &laplacian, preserveBoundary](VertexHandle v1) {
Expand All @@ -28,8 +26,8 @@ void laplacianSmoothing(TriangleMesh<Vec>& mesh,
});
std::vector<Vec> biharmonic(mesh.numVertices(), Vec(0));
if (rer > 0.f) {
ParallelForEach<ConcurrencyTag>()(mesh.vertexRange(),
[&mesh, &laplacian, &biharmonic, preserveBoundary](VertexHandle v1) {
ParallelForEach<ConcurrencyTag>()(
mesh.vertexRange(), [&mesh, &laplacian, &biharmonic, preserveBoundary](VertexHandle v1) {
if (preserveBoundary && mesh.boundary(v1)) {
return;
}
Expand All @@ -48,7 +46,7 @@ void laplacianSmoothing(TriangleMesh<Vec>& mesh,
}

ParallelFor<ConcurrencyTag>()(
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]);
});
}
Expand Down
7 changes: 6 additions & 1 deletion TriangleMesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f4be95b

Please sign in to comment.