1#!/usr/bin/env python 2# 3# This file is part of libigl, a simple c++ geometry processing library. 4# 5# Copyright (C) 2017 Sebastian Koch <s.koch@tu-berlin.de> and Daniele Panozzo <daniele.panozzo@gmail.com> 6# 7# This Source Code Form is subject to the terms of the Mozilla Public License 8# v. 2.0. If a copy of the MPL was not distributed with this file, You can 9# obtain one at http://mozilla.org/MPL/2.0/. 10import sys, os 11 12# Add the igl library to the modules search path 13sys.path.insert(0, os.getcwd() + "/../") 14import pyigl as igl 15 16from shared import TUTORIAL_SHARED_PATH, check_dependencies 17 18dependencies = ["glfw"] 19check_dependencies(dependencies) 20 21 22V = igl.eigen.MatrixXd() 23F = igl.eigen.MatrixXi() 24igl.read_triangle_mesh(TUTORIAL_SHARED_PATH + "fertility.off", V, F) 25 26# Alternative discrete mean curvature 27HN = igl.eigen.MatrixXd() 28L = igl.eigen.SparseMatrixd() 29M = igl.eigen.SparseMatrixd() 30Minv = igl.eigen.SparseMatrixd() 31 32igl.cotmatrix(V, F, L) 33igl.massmatrix(V, F, igl.MASSMATRIX_TYPE_VORONOI, M) 34 35igl.invert_diag(M, Minv) 36 37# Laplace-Beltrami of position 38HN = -Minv * (L * V) 39 40# Extract magnitude as mean curvature 41H = HN.rowwiseNorm() 42 43# Compute curvature directions via quadric fitting 44PD1 = igl.eigen.MatrixXd() 45PD2 = igl.eigen.MatrixXd() 46 47PV1 = igl.eigen.MatrixXd() 48PV2 = igl.eigen.MatrixXd() 49 50igl.principal_curvature(V, F, PD1, PD2, PV1, PV2) 51 52# Mean curvature 53H = 0.5 * (PV1 + PV2) 54 55viewer = igl.glfw.Viewer() 56viewer.data().set_mesh(V, F) 57 58# Compute pseudocolor 59C = igl.eigen.MatrixXd() 60igl.parula(H, True, C) 61 62viewer.data().set_colors(C) 63 64# Average edge length for sizing 65avg = igl.avg_edge_length(V, F) 66 67# Draw a blue segment parallel to the minimal curvature direction 68red = igl.eigen.MatrixXd([[0.8, 0.2, 0.2]]) 69blue = igl.eigen.MatrixXd([[0.2, 0.2, 0.8]]) 70 71viewer.data().add_edges(V + PD1 * avg, V - PD1 * avg, blue) 72 73# Draw a red segment parallel to the maximal curvature direction 74viewer.data().add_edges(V + PD2 * avg, V - PD2 * avg, red) 75 76# Hide wireframe 77viewer.data().show_lines = False 78 79viewer.launch() 80