Add Laplacian smoothing
This commit is contained in:
parent
e7f7e77acd
commit
dd8c20757e
@ -1,3 +1,4 @@
|
|||||||
|
#include <CLI11.hpp>
|
||||||
|
|
||||||
#include "geometrycentral/surface/manifold_surface_mesh.h"
|
#include "geometrycentral/surface/manifold_surface_mesh.h"
|
||||||
#include "geometrycentral/surface/meshio.h"
|
#include "geometrycentral/surface/meshio.h"
|
||||||
@ -15,11 +16,31 @@ std::unique_ptr<ManifoldSurfaceMesh> mesh;
|
|||||||
std::unique_ptr<VertexPositionGeometry> geometry;
|
std::unique_ptr<VertexPositionGeometry> geometry;
|
||||||
|
|
||||||
int counter=0;
|
int counter=0;
|
||||||
|
float lambda = 0.5;
|
||||||
|
|
||||||
|
Vector3 vertAverage(std::vector<Vector3> vertexPositions) {
|
||||||
|
assert(vertexPositions.size() > 0);
|
||||||
|
|
||||||
|
Vector3 out = {0, 0, 0};
|
||||||
|
for (auto i=0; i < vertexPositions.size(); i++) {
|
||||||
|
out = out + vertexPositions.at(i);
|
||||||
|
}
|
||||||
|
return out/vertexPositions.size();
|
||||||
|
}
|
||||||
|
|
||||||
void oneStep()
|
void oneStep()
|
||||||
{
|
{
|
||||||
for(size_t i = 0; i < mesh->nVertices(); ++i)
|
for(Vertex v : mesh->vertices()) {
|
||||||
geometry->vertexPositions[i] = geometry->vertexPositions[i] + Vector3::constant(0.01*sin(i*counter/(2.0*M_PI)));
|
std::vector<Vector3> adjVert;
|
||||||
|
adjVert.push_back(geometry->vertexPositions[v]);
|
||||||
|
for (Vertex v_adj : v.adjacentVertices()) {
|
||||||
|
adjVert.push_back(geometry->vertexPositions[v_adj]);
|
||||||
|
}
|
||||||
|
Vector3 avgPos = vertAverage(adjVert);
|
||||||
|
avgPos -= geometry->vertexPositions[v];
|
||||||
|
|
||||||
|
geometry->vertexPositions[v] += lambda*avgPos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool go=false;
|
bool go=false;
|
||||||
@ -41,12 +62,18 @@ void myCallback()
|
|||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
CLI::App app{"laplacian"};
|
||||||
|
std::string inputObj;
|
||||||
|
app.add_option("-i,--input", inputObj, "Source Obj")->required()->check(CLI::ExistingFile);;
|
||||||
|
app.add_option("-l,--lambda", lambda, "Lambda (speed of transformation).");
|
||||||
|
CLI11_PARSE(app, argc, argv);
|
||||||
|
assert (lambda <= 1 && lambda > 0);
|
||||||
|
|
||||||
// Initialize polyscope
|
// Initialize polyscope
|
||||||
polyscope::init();
|
polyscope::init();
|
||||||
|
|
||||||
// Load mesh
|
// Load mesh
|
||||||
std::tie(mesh, geometry) = readManifoldSurfaceMesh(argv[1]);
|
std::tie(mesh, geometry) = readManifoldSurfaceMesh(inputObj);
|
||||||
|
|
||||||
// Register the mesh with polyscope
|
// Register the mesh with polyscope
|
||||||
polyscope::registerSurfaceMesh("Input obj",
|
polyscope::registerSurfaceMesh("Input obj",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user