Files
epfl-archive/cs457-gc/assignment_3_2/notebook/fitting.ipynb
T
2022-04-07 18:46:57 +02:00

9.7 KiB

In [1]:
import numpy as np
import meshplot as mp
In [2]:
import igl
import scipy as sp
import numpy as np
from meshplot import plot, subplot, interact
import time
import copy
import matplotlib.pyplot as plt
In [3]:
import sys
sys.path.append('../src')
In [4]:
import importlib, utils, laplacian_utils, mean_curvature_flow, remesher_helper
importlib.reload(utils)
importlib.reload(laplacian_utils)
importlib.reload(mean_curvature_flow)
importlib.reload(remesher_helper)
from utils import parse_input_mesh, normalize_area, get_diverging_colors, plot_directions
from mean_curvature_flow import MCF
import smooth_surfaces
In [5]:
from fitting import compute_mesh_principal_curvatures

Closed Surface Example

In [6]:
v, f, num_bdry_vx, num_intr_vx = parse_input_mesh("../data/bob_tri.obj")
curr_mcf = MCF(num_bdry_vx, num_intr_vx)
Warning: readOBJ() ignored non-comment line 3:
  o Mesh
In [7]:
k1, k2, d1, d2 = compute_mesh_principal_curvatures(v, f)

Gaussian Curvature

In [8]:
gaussian_curvature = k1+k2
gaussian_curvature[:num_bdry_vx] *= 0
gp = mp.plot(v, f, get_diverging_colors(gaussian_curvature))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_12120/1640637150.py in <module>
----> 1 gaussian_curvature = k1+k2
      2 gaussian_curvature[:num_bdry_vx] *= 0
      3 gp = mp.plot(v, f, get_diverging_colors(gaussian_curvature))

TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'

Mean Curvature

In [ ]:
mean_curvature = (k1+k2)/2
mean_curvature[:num_bdry_vx] *= 0
gp = mp.plot(v, f, get_diverging_colors(mean_curvature))

Principal Curvature Direction

In [ ]:
plot_directions(v, f, d1, d2, scale=0.08)

Asymptotic Direction

In [ ]:
a1, a2 = smooth_surfaces.compute_asymptotic_directions(k1, k2, d1, d2)
In [ ]:
plot_directions(v, f, a1, a2, scale=0.08)

Minimal Surface Example

In [ ]:
epsilon1 = 5e-2
epsilon2 = 1e-3
In [ ]:
v2, f2, num_bdry_vx, num_intr_vx = parse_input_mesh("../data/two_rings_remesh.obj")
curr_mcf = MCF(num_bdry_vx, num_intr_vx)
In [ ]:
start = time.time()
vs, average_mean_curvature_list1 = curr_mcf.run_mean_curvature_flow(v2, f2, 1000, epsilon1, epsilon2)
print("Run {} iterations of unstable mean curvature flow".format(len(average_mean_curvature_list1)))
print("took {} seconds".format(time.time() - start))
In [ ]:
k1, k2, d1, d2 = compute_mesh_principal_curvatures(vs[-1], f2)

Gaussian Curvature

In [ ]:
gaussian_curvature = k1+k2
gaussian_curvature[:num_bdry_vx] *= 0
gp = mp.plot(vs[-1], f2, get_diverging_colors(gaussian_curvature, percentile=80))

Mean Curvature

In [ ]:
mean_curvature = (k1+k2)/2
mean_curvature[:num_bdry_vx] *= 0
gp = mp.plot(vs[-1], f2, get_diverging_colors(mean_curvature))

Principal Curvature Direction

In [ ]:
plot_directions(vs[-1], f2, d1, d2, scale=0.08)

Asymptotic Direction

In [ ]:
a1, a2 = smooth_surfaces.compute_asymptotic_directions(k1, k2, d1, d2)
In [ ]:
plot_directions(v2, f2, a1, a2, scale=0.08)
In [ ]: