From 0f3761150ed3ea8e0d6154b632b360447f39805d Mon Sep 17 00:00:00 2001 From: Marco Livesu Date: Sun, 19 Jan 2025 15:32:20 +0100 Subject: [PATCH] heat kernel signature --- include/cinolib/HKS.cpp | 93 +++++++++++++++++++++++++++++++++++++++++ include/cinolib/HKS.h | 61 +++++++++++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 include/cinolib/HKS.cpp create mode 100644 include/cinolib/HKS.h diff --git a/include/cinolib/HKS.cpp b/include/cinolib/HKS.cpp new file mode 100644 index 00000000..09326ac8 --- /dev/null +++ b/include/cinolib/HKS.cpp @@ -0,0 +1,93 @@ +/******************************************************************************** +* This file is part of CinoLib * +* Copyright(C) 2025: Marco Livesu * +* * +* The MIT License * +* * +* Permission is hereby granted, free of charge, to any person obtaining a * +* copy of this software and associated documentation files (the "Software"), * +* to deal in the Software without restriction, including without limitation * +* the rights to use, copy, modify, merge, publish, distribute, sublicense, * +* and/or sell copies of the Software, and to permit persons to whom the * +* Software is furnished to do so, subject to the following conditions: * +* * +* The above copyright notice and this permission notice shall be included in * +* all copies or substantial portions of the Software. * +* * +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * +* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE * +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * +* IN THE SOFTWARE. * +* * +* Author(s): * +* * +* Marco Livesu (marco.livesu@gmail.com) * +* http://pers.ge.imati.cnr.it/livesu/ * +* * +* Italian National Research Council (CNR) * +* Institute for Applied Mathematics and Information Technologies (IMATI) * +* Via de Marini, 6 * +* 16149 Genoa, * +* Italy * +*********************************************************************************/ +#include +#include +#include +#include +#include +#include + +namespace cinolib +{ + +template +CINO_INLINE +Eigen::MatrixXd HKS( AbstractMesh & m, + const std::vector & landmarks, + const uint n_timesteps, + const bool normalize_mesh, + const bool normalize_columns, + const bool verbose) +{ + if(normalize_mesh) m.normalize_bbox(); + + uint n_rows = m.num_verts(); + uint n_cols = landmarks.size()*n_timesteps; + Eigen::MatrixXd A(n_rows,n_cols); + + Eigen::SparseMatrix L = laplacian(m, COTANGENT); + Eigen::SparseMatrix MM = mass_matrix(m); + + // This is what Dorian Nogneng and Maks Ovsjanikov do in their reference code for the paper: + // + // Informative Descriptor Preservation via Commutativity for Shape Matching + // Eurographics 2017 + // + std::vector timesteps = sample_within_interval(log(0.005), log(0.2), n_timesteps); + for(uint i=0; i> solver(MM - t*L); + assert(solver.info() == Eigen::Success); + + for(auto v : landmarks) + { + if(verbose) std::cout << "column " << col << ": time step " << t << ", landmark " << v << std::endl; + + Eigen::VectorXd rhs = Eigen::VectorXd::Zero(m.num_verts()); + rhs[v] = 1.0; + ScalarField f = solver.solve(rhs).eval(); + if(normalize_columns) f.normalize_in_01(); // Useful for visualization but "physically wrong"... + for(uint vid=0; vid +#include + +namespace cinolib +{ + +// Heat Kernel Signature + +template +CINO_INLINE +Eigen::MatrixXd HKS( AbstractMesh & m, + const std::vector & landmarks, + const uint n_timesteps, + const bool normalize_mesh = false, + const bool normalize_columns = false, + const bool verbose = false); +} + +#ifndef CINO_STATIC_LIB +#include "HKS.cpp" +#endif + +#endif // CINO_HKS_H