94 lines
2.3 KiB
C++
94 lines
2.3 KiB
C++
#include <CLI11.hpp>
|
|
|
|
#include "geometrycentral/surface/manifold_surface_mesh.h"
|
|
#include "geometrycentral/surface/meshio.h"
|
|
#include "geometrycentral/surface/vertex_position_geometry.h"
|
|
|
|
#include "polyscope/polyscope.h"
|
|
#include "polyscope/surface_mesh.h"
|
|
#include "polyscope/point_cloud.h"
|
|
|
|
using namespace geometrycentral;
|
|
using namespace geometrycentral::surface;
|
|
|
|
// == Geometry-central data
|
|
std::unique_ptr<ManifoldSurfaceMesh> mesh;
|
|
std::unique_ptr<VertexPositionGeometry> geometry;
|
|
|
|
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()
|
|
{
|
|
for(Vertex v : mesh->vertices()) {
|
|
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;
|
|
|
|
void myCallback()
|
|
{
|
|
if (ImGui::Button("Go!"))
|
|
go= !go;
|
|
|
|
if (go)
|
|
{
|
|
oneStep();
|
|
polyscope::getSurfaceMesh("Input obj")->updateVertexPositions(geometry->vertexPositions);
|
|
// polyscope::screenshot();
|
|
}
|
|
counter++;
|
|
}
|
|
|
|
|
|
|
|
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
|
|
polyscope::init();
|
|
|
|
// Load mesh
|
|
std::tie(mesh, geometry) = readManifoldSurfaceMesh(inputObj);
|
|
|
|
// Register the mesh with polyscope
|
|
polyscope::registerSurfaceMesh("Input obj",
|
|
geometry->inputVertexPositions,
|
|
mesh->getFaceVertexList(),
|
|
polyscopePermutations(*mesh));
|
|
|
|
|
|
geometry->requireVertexPositions();
|
|
|
|
// Specify the callback
|
|
polyscope::state::userCallback = myCallback;
|
|
|
|
// Give control to the polyscope gui
|
|
polyscope::show();
|
|
return EXIT_SUCCESS;
|
|
}
|