Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision adc49abe10a97200a3a5735bd370e98560091a37 authored by Hsueh-Ti Derek Liu on 16 March 2023, 20:37:42 UTC, committed by GitHub on 16 March 2023, 20:37:42 UTC
Merge pull request #3 from alecjacobson/main
Remove `__1::`
2 parent s 46403a2 + 1c5e37e
  • Files
  • Changes
  • 337a0c0
  • /
  • 05_example_mean_curvature_flow
  • /
  • main.cpp
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:adc49abe10a97200a3a5735bd370e98560091a37
directory badge
swh:1:dir:a2f5c6c0ff19cb65d802cec9aa39c69501aab28e
content badge
swh:1:cnt:8cf3aecce6ae6d2ad9501aa61ac1dc01678417d9

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
main.cpp
#include <igl/read_triangle_mesh.h>
#include <igl/cotmatrix.h>
#include <igl/boundary_loop.h>
#include <igl/massmatrix.h>

#include <igl/opengl/glfw/Viewer.h>

#include <Eigen/Dense>
#include <Eigen/Core>
#include <Eigen/Sparse>

#include <iostream>
#include <vector>

#include <mg_data.h>
#include <mg_precompute.h>
#include <normalize_unit_area.h>
#include <min_quad_with_fixed_mg.h>

Eigen::MatrixXd V,U;
Eigen::MatrixXi F;
Eigen::SparseMatrix<double> L;
igl::opengl::glfw::Viewer viewer;
std::vector<mg_data> mg;

int main(int argc, char *argv[])
{
	using namespace Eigen;
	using namespace std;

	// load mesh
	igl::read_triangle_mesh("../../meshes/beard_man.obj", V, F);
	normalize_unit_area(V,F);
	cout << "original mesh: |V| " << V.rows() << ", |F|: " << F.rows() << endl;

	// construct multigrid hierarchy
	int min_coarsest_nV = 500;
	float coarsening_ratio = 0.25;
	int decimation_type = 1;
	mg_precompute(V,F,coarsening_ratio, min_coarsest_nV, decimation_type, mg);

	U = V;
	igl::cotmatrix(V,F,L);

	const auto &key_down = [](igl::opengl::glfw::Viewer &viewer,unsigned char key,int mod)->bool
	{
		switch(key)
		{
		case 'r':
		case 'R':
			U = V;
			break;
		case ' ':
		{
			// mean curvature flow [Kazhdan et al. 2012]
			// mg parameters
			double delta = 0.01;
			int maxIter = 20;
			double tolerance = 1e-16;
			double mg_tol = 5e-7;

			// save previous mesh
			MatrixXd Upre = U;

			// compute linear system
			SparseMatrix<double> M;
			igl::massmatrix(U, F, igl::MASSMATRIX_TYPE_BARYCENTRIC, M);
			SparseMatrix<double> LHS = M - delta * L;
			MatrixXd RHS = M*U;

			// mg solve
			min_quad_with_fixed_mg_data solverData;
			SimplicialLDLT<SparseMatrix<double>> coarseSolver;
			min_quad_with_fixed_mg_precompute(LHS, solverData, mg, coarseSolver);
			vector<double> rHis;
			min_quad_with_fixed_mg_solve(solverData, RHS, Upre, coarseSolver, mg_tol, mg, U, rHis);

			// rescale output 
			normalize_unit_area(U,F);
			break;
		}
		default:
			return false;
		}
		// Send new positions, update normals, recenter
		viewer.data().set_vertices(U);
		viewer.data().compute_normals();
		viewer.core().align_camera_center(U,F);
		return true;
	};

	// Use original normals as pseudo-colors
	MatrixXd N;
	igl::per_vertex_normals(V,F,N);
	MatrixXd C = N.rowwise().normalized().array()*0.5+0.5;

	// Initialize smoothing with base mesh
	viewer.data().set_mesh(U, F);
	viewer.data().set_colors(C);
	viewer.callback_key_down = key_down;

	// set background color
	Vector4f backColor;
	backColor << 208/255., 237/255., 227/255., 1.;
	viewer.core().background_color = backColor;

	// not showing edges
	viewer.data().show_lines = false;

	cout<<"Press [space] to smooth."<<endl;;
	cout<<"Press [r] to reset."<<endl;;
	return viewer.launch();
}
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API