Disabled external gits
This commit is contained in:
@@ -0,0 +1,482 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "47a1752b-1db4-4004-9991-164388c0fd5d",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import meshplot as mp"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "0f4900fe-ce65-410a-b8d3-088e7e0804a5",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import igl\n",
|
||||
"import scipy as sp\n",
|
||||
"import numpy as np\n",
|
||||
"from meshplot import plot, subplot, interact\n",
|
||||
"import time\n",
|
||||
"import copy\n",
|
||||
"import matplotlib.pyplot as plt"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"id": "9c83b851-d0aa-4fb0-9030-a285ca6b2b64",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import sys\n",
|
||||
"sys.path.append('../src')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"id": "43cb9cef-4959-4c9b-98ef-3a603f57bcb2",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import importlib, utils, laplacian_utils, mean_curvature_flow, remesher_helper\n",
|
||||
"importlib.reload(utils)\n",
|
||||
"importlib.reload(laplacian_utils)\n",
|
||||
"importlib.reload(mean_curvature_flow)\n",
|
||||
"importlib.reload(remesher_helper)\n",
|
||||
"from utils import parse_input_mesh, normalize_area, get_diverging_colors, remesh\n",
|
||||
"from mean_curvature_flow import MCF"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"id": "2570faf5-9582-42ac-ace4-ca82c781a806",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"epsilon1 = 5e-2\n",
|
||||
"epsilon2 = 1e-3\n",
|
||||
"mesh_color = np.array([0,0.7,1])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "e8d2f669-864f-4c8e-8519-5672862cc024",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Example 1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"id": "7a65d5c7-d774-4d5a-946c-69d730f19519",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"v1, f1, num_bdry_vx, num_intr_vx = parse_input_mesh(\"../data/two_rings_remesh.obj\")\n",
|
||||
"curr_mcf = MCF(num_bdry_vx, num_intr_vx)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"id": "a82f1487-56e3-4ecb-b71c-b3f59d4070be",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "TypeError",
|
||||
"evalue": "unsupported operand type(s) for /: 'NoneType' and 'NoneType'",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
|
||||
"\u001b[0;32m/tmp/ipykernel_12039/3840203228.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mstart\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mvs1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maverage_mean_curvature_list1\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcurr_mcf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun_mean_curvature_flow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mv1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mf1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1000\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m5e-2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1e-3\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Run {} iterations of unstable mean curvature flow\"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0maverage_mean_curvature_list1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"took {} seconds\"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mstart\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;32m/opt/notebooks/assignment_3_2/notebook/../src/mean_curvature_flow.py\u001b[0m in \u001b[0;36mrun_mean_curvature_flow\u001b[0;34m(self, v, f, max_iter, epsilon1, epsilon2)\u001b[0m\n\u001b[1;32m 83\u001b[0m \u001b[0mYour\u001b[0m \u001b[0mcode\u001b[0m \u001b[0mhere\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 84\u001b[0m '''\n\u001b[0;32m---> 85\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msolve_laplace_equation\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mv\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 86\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupdate_system\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mv\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 87\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;32m/opt/notebooks/assignment_3_2/notebook/../src/mean_curvature_flow.py\u001b[0m in \u001b[0;36msolve_laplace_equation\u001b[0;34m(self, v, f)\u001b[0m\n\u001b[1;32m 44\u001b[0m '''\n\u001b[1;32m 45\u001b[0m \u001b[0;31m# Construct the LHS and RHS of the linear solve.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 46\u001b[0;31m \u001b[0mlhs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mL\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mM\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnum_bdry_vx\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 47\u001b[0m \u001b[0mrhs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mzeros\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnum_intr_vx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 48\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for /: 'NoneType' and 'NoneType'"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"start = time.time()\n",
|
||||
"vs1, average_mean_curvature_list1 = curr_mcf.run_mean_curvature_flow(v1, f1, 1000, 5e-2, 1e-3)\n",
|
||||
"print(\"Run {} iterations of unstable mean curvature flow\".format(len(average_mean_curvature_list1)))\n",
|
||||
"print(\"took {} seconds\".format(time.time() - start))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "652d1fa7-ad74-4c50-85c1-6a9e622b7ec8",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plt.plot(average_mean_curvature_list1)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "14411752-e879-40f4-a3ce-928cfa2e888e",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"p1 = mp.plot(vs1[0], f1, shading={\"wireframe\": False,\"width\": 900, \"height\": 600}, return_plot=True, c=mesh_color)\n",
|
||||
"\n",
|
||||
"@interact(level=(0, len(vs1)-1))\n",
|
||||
"def mcf(level=0):\n",
|
||||
" p1.update_object(vertices=vs1[level])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "baf4bc95-68df-4a4b-967f-a2b555d4947c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Example 2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "147b044e-4491-4e45-bf91-df58f870429f",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"v2, f2, num_bdry_vx, num_intr_vx = parse_input_mesh(\"../data/half_cube_remesh.obj\")\n",
|
||||
"curr_mcf = MCF(num_bdry_vx, num_intr_vx)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "dbc8d3df-ac70-4c75-a6e7-d624595d5a59",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"start = time.time()\n",
|
||||
"vs2, average_mean_curvature_list2 = curr_mcf.run_mean_curvature_flow(v2, f2, 1000, epsilon1, epsilon2)\n",
|
||||
"print(\"Run {} iterations of unstable mean curvature flow\".format(len(average_mean_curvature_list2)))\n",
|
||||
"print(\"took {} seconds\".format(time.time() - start))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "87c6c46b-36e4-4206-96da-b3f10d897387",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plt.plot(average_mean_curvature_list2)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "db07878e-9438-413d-9eb5-a2ffb8f02118",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"p2 = mp.plot(vs2[0], f2, shading={\"wireframe\": False, \"flat\": True}, c=mesh_color)\n",
|
||||
"\n",
|
||||
"@interact(level=(0, len(vs2)-2))\n",
|
||||
"def mcf(level=0):\n",
|
||||
" p2.update_object(vertices=vs2[level])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "613b0257-40c3-4f8f-8840-ea9dccccefa9",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Example 3"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "ddd60020-bc75-4984-937f-ab30359b559c",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"v3, f3, num_bdry_vx, num_intr_vx = parse_input_mesh(\"../data/cube_remesh.obj\")\n",
|
||||
"curr_mcf = MCF(num_bdry_vx, num_intr_vx)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "661c1cfb-3ac6-434a-b385-a94be86f2802",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"start = time.time()\n",
|
||||
"vs3, average_mean_curvature_list3 = curr_mcf.run_mean_curvature_flow(v3, f3, 1000, epsilon1, epsilon2)\n",
|
||||
"print(\"Run {} iterations of unstable mean curvature flow\".format(len(average_mean_curvature_list3)))\n",
|
||||
"print(\"took {} seconds\".format(time.time() - start))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "06d71f4a-214a-4fbc-84ee-aad174ac104f",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plt.plot(average_mean_curvature_list3)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "4e3faeb6-3f38-43d1-a4a0-047b62e11bf3",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"p3 = mp.plot(vs3[0], f3, shading={\"wireframe\": False, \"flat\": True}, c=mesh_color)\n",
|
||||
"\n",
|
||||
"@interact(level=(0, len(vs3)-2))\n",
|
||||
"def mcf(level=0):\n",
|
||||
" p3.update_object(vertices=vs3[level])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "d92f7eea-e7f0-4a92-b557-21637eb7f939",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Your Own Minimal Surface!"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "242feed4-775d-4c68-aadb-707382dde2f5",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Visualize your blender output\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"id": "105532b3-69ab-4835-9768-5a03df5051af",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"blender_input_filename = \"../data/mesh.obj\""
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"id": "c9e2c901-d3f9-4a2f-bb3b-27a8be7b2311",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Warning: readOBJ() ignored non-comment line 3:\n",
|
||||
" o BezierCircle.002_Mesh.002\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"application/vnd.jupyter.widget-view+json": {
|
||||
"model_id": "c3305f3372914f049d1f00b95e75db4c",
|
||||
"version_major": 2,
|
||||
"version_minor": 0
|
||||
},
|
||||
"text/plain": [
|
||||
"Renderer(camera=PerspectiveCamera(aspect=1.5, children=(DirectionalLight(color='white', intensity=0.6, positio…"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"v,f = igl.read_triangle_mesh(blender_input_filename)\n",
|
||||
"p1 = plot(v, f, shading={\"wireframe\": True,\"width\": 900, \"height\": 600}, return_plot=True, c=mesh_color)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "264e0ee7-8a7d-44b0-8221-fc15b38ce77e",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Remesh"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "b6905f01-bc8b-4421-b2fb-5fa2b0b79a90",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"The input should be a triangle mesh or a quad mesh. This might takes a while depends on your design. You can adjust the `mesh_size` parameter in the `remesh` function."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"id": "4ba2345b-dac3-45e6-a28e-123929f70b93",
|
||||
"metadata": {
|
||||
"scrolled": true,
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Info : Classifying surfaces (angle: 180)...\n",
|
||||
"Info : Splitting triangulations to make them parametrizable:\n",
|
||||
"Info : - Level 0 partition with 3978 triangles split in 2 parts because poincare characteristic 2 is not 0\n",
|
||||
"Info : Model has 0 non manifold mesh edges and 3786 boundary mesh edges\n",
|
||||
"Info : Found 2 model surfaces\n",
|
||||
"Info : Found 3 model curves\n",
|
||||
"Info : Done classifying surfaces (Wall 0.0693158s, CPU 0.069573s)\n",
|
||||
"Info : Creating geometry of discrete curves...\n",
|
||||
"Info : Done creating geometry of discrete curves (Wall 0.000228139s, CPU 0.000371s)\n",
|
||||
"Info : Creating geometry of discrete surfaces...\n",
|
||||
"Info : [ 0%] Creating geometry \r",
|
||||
"Info : [ 50%] Creating geometry \r",
|
||||
"Info : Done creating geometry of discrete surfaces (Wall 0.0322831s, CPU 0.032606s)\n",
|
||||
"Info : Meshing 1D...\n",
|
||||
"Info : [ 0%] Meshing curve 5 (Discrete curve)\n",
|
||||
"Info : [ 20%] Meshing curve 6 (Discrete curve)\n",
|
||||
"Info : [ 40%] Meshing curve 7 (Discrete curve)\n",
|
||||
"Info : [ 50%] Meshing curve 8 (Discrete curve)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Warning : Poor input mesh quality (min gamma = 0.000204069) for computing parametrization\n",
|
||||
"Warning : Poor input mesh quality (min gamma = 0.000204069) for computing parametrization\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Info : [ 70%] Meshing curve 9 (Discrete curve)\n",
|
||||
"Info : [ 90%] Meshing curve 10 (Discrete curve)\n",
|
||||
"Info : Done meshing 1D (Wall 0.100252s, CPU 0.100165s)\n",
|
||||
"Info : Meshing 2D...\n",
|
||||
"Info : [ 0%] Meshing surface 2 (Discrete surface, Frontal-Delaunay)\n",
|
||||
"Info : [ 0%] Meshing surface 2 (Discrete surface, MeshAdapt)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Warning : 4752 elements remain invalid in surface 2\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Info : [ 50%] Meshing surface 3 (Discrete surface, Frontal-Delaunay)\n",
|
||||
"Info : Done meshing 2D (Wall 20.1908s, CPU 20.176s)\n",
|
||||
"Info : 12214 nodes 24512 elements\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Warning : ------------------------------\n",
|
||||
"Warning : Mesh generation error summary\n",
|
||||
"Warning : 1 warning\n",
|
||||
"Warning : 0 errors\n",
|
||||
"Warning : Check the full log for details\n",
|
||||
"Warning : ------------------------------\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"remesh_output_name = \"../data/remesh.obj\"\n",
|
||||
"remesh(blender_input_filename, remesh_output_name)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"id": "245e2f45-c1ee-4f9f-86cd-e7fd9a0404de",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"application/vnd.jupyter.widget-view+json": {
|
||||
"model_id": "ddb1c83810f241d69cfb63f6c5fda32e",
|
||||
"version_major": 2,
|
||||
"version_minor": 0
|
||||
},
|
||||
"text/plain": [
|
||||
"Renderer(camera=PerspectiveCamera(aspect=1.5, children=(DirectionalLight(color='white', intensity=0.6, positio…"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"v,f = igl.read_triangle_mesh(remesh_output_name)\n",
|
||||
"p2 = plot(v, f, shading={\"wireframe\": True,\"width\": 900, \"height\": 600}, return_plot=True, c=mesh_color)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "117e73d7-f291-4aa1-b783-cf8e2ae70a21",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Run optimization"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "632ea182-feb9-46b0-b2b5-83b32e65f9b7",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.9.7"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
375
cs457-gc/assignment_3_2/notebook/fitting.ipynb
Normal file
375
cs457-gc/assignment_3_2/notebook/fitting.ipynb
Normal file
@@ -0,0 +1,375 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "bcb9c6df-0417-4d0a-9990-185ce07b918b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import meshplot as mp"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "45981306-4fde-431e-9240-3d153a016863",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import igl\n",
|
||||
"import scipy as sp\n",
|
||||
"import numpy as np\n",
|
||||
"from meshplot import plot, subplot, interact\n",
|
||||
"import time\n",
|
||||
"import copy\n",
|
||||
"import matplotlib.pyplot as plt"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "c39ddea4-e782-4c2b-a942-ec11610a4ceb",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import sys\n",
|
||||
"sys.path.append('../src')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "f58fb451-bdcf-49d7-a928-4992ab599761",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import importlib, utils, laplacian_utils, mean_curvature_flow, remesher_helper\n",
|
||||
"importlib.reload(utils)\n",
|
||||
"importlib.reload(laplacian_utils)\n",
|
||||
"importlib.reload(mean_curvature_flow)\n",
|
||||
"importlib.reload(remesher_helper)\n",
|
||||
"from utils import parse_input_mesh, normalize_area, get_diverging_colors, plot_directions\n",
|
||||
"from mean_curvature_flow import MCF\n",
|
||||
"import smooth_surfaces"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"id": "bb26ed62-f404-437f-977a-8ff22a19f840",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from fitting import compute_mesh_principal_curvatures"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "8b12d84d-06a1-4315-87b2-d8bb4a6b4360",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Closed Surface Example"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"id": "cf187b60-2fbf-4f0b-9924-efe4939bafae",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Warning: readOBJ() ignored non-comment line 3:\n",
|
||||
" o Mesh\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"v, f, num_bdry_vx, num_intr_vx = parse_input_mesh(\"../data/bob_tri.obj\")\n",
|
||||
"curr_mcf = MCF(num_bdry_vx, num_intr_vx)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"id": "dcf12908-b20c-4a1c-adcf-492d23a54011",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"k1, k2, d1, d2 = compute_mesh_principal_curvatures(v, f)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "b3294e38-ccac-4fbc-8661-71403e472cc6",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Gaussian Curvature"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"id": "cf601268-72af-4964-940d-211719f3123c",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "TypeError",
|
||||
"evalue": "unsupported operand type(s) for +: 'NoneType' and 'NoneType'",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
|
||||
"\u001b[0;32m/tmp/ipykernel_12120/1640637150.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mgaussian_curvature\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mk1\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mk2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mgaussian_curvature\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0mnum_bdry_vx\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m*=\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mgp\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mv\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mget_diverging_colors\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mgaussian_curvature\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'NoneType' and 'NoneType'"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"gaussian_curvature = k1+k2\n",
|
||||
"gaussian_curvature[:num_bdry_vx] *= 0\n",
|
||||
"gp = mp.plot(v, f, get_diverging_colors(gaussian_curvature))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "4a3a46af-15b0-4b8c-afd4-14159774a646",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Mean Curvature"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "003d4541-fff5-414d-bacf-36a8a45fb412",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"mean_curvature = (k1+k2)/2\n",
|
||||
"mean_curvature[:num_bdry_vx] *= 0\n",
|
||||
"gp = mp.plot(v, f, get_diverging_colors(mean_curvature))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "3e30eb7f-4c81-461a-a9db-c1df00eb30ec",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Principal Curvature Direction"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "433424ef-f93c-485f-9929-17b84fd96026",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plot_directions(v, f, d1, d2, scale=0.08)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "5a8c19a9-a4ff-4fcf-99f8-017c4cc97b7b",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Asymptotic Direction"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "08194caa-c825-4445-afcb-c11ae7c87b10",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"a1, a2 = smooth_surfaces.compute_asymptotic_directions(k1, k2, d1, d2)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "d2b75928-f37e-4342-bebc-bcf00fcd9fbb",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plot_directions(v, f, a1, a2, scale=0.08)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "c6675cc3-281d-4de0-96e9-b679c19bea56",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Minimal Surface Example"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "10519def-3402-401f-ad08-8c2e120d11e2",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"epsilon1 = 5e-2\n",
|
||||
"epsilon2 = 1e-3"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "9d97b409-968f-4398-a28e-749ae1af28d3",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"v2, f2, num_bdry_vx, num_intr_vx = parse_input_mesh(\"../data/two_rings_remesh.obj\")\n",
|
||||
"curr_mcf = MCF(num_bdry_vx, num_intr_vx)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "887806bf-1c10-44b7-b0f8-acd398187678",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"start = time.time()\n",
|
||||
"vs, average_mean_curvature_list1 = curr_mcf.run_mean_curvature_flow(v2, f2, 1000, epsilon1, epsilon2)\n",
|
||||
"print(\"Run {} iterations of unstable mean curvature flow\".format(len(average_mean_curvature_list1)))\n",
|
||||
"print(\"took {} seconds\".format(time.time() - start))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "d0cd92a5-8848-4a7e-9b93-34b4b9d0967b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"k1, k2, d1, d2 = compute_mesh_principal_curvatures(vs[-1], f2)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "6c3bb956-62d0-43f7-a0a0-30571933c97a",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Gaussian Curvature"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "785540b8-03ed-4620-9a8f-ad7f9ec4d154",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"gaussian_curvature = k1+k2\n",
|
||||
"gaussian_curvature[:num_bdry_vx] *= 0\n",
|
||||
"gp = mp.plot(vs[-1], f2, get_diverging_colors(gaussian_curvature, percentile=80))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "a84dcd14-6dd4-44fe-93e8-440d78127643",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Mean Curvature"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "b3333375-fc84-4e10-85e0-5b744a3e585a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"mean_curvature = (k1+k2)/2\n",
|
||||
"mean_curvature[:num_bdry_vx] *= 0\n",
|
||||
"gp = mp.plot(vs[-1], f2, get_diverging_colors(mean_curvature))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "4345e08f-cd16-4644-915d-270d5788bf88",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"source": [
|
||||
"### Principal Curvature Direction"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "d7b85256-915e-489f-ad7b-f9d2faa9036f",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plot_directions(vs[-1], f2, d1, d2, scale=0.08)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "8f7831fe-b870-4ee5-b1e8-6a1081bd17f7",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Asymptotic Direction"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "9674731a-d083-46cf-8ddd-f135538e8217",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"a1, a2 = smooth_surfaces.compute_asymptotic_directions(k1, k2, d1, d2)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "634c2079-e22a-4458-a126-851a87562015",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plot_directions(v2, f2, a1, a2, scale=0.08)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "8fd20a1f-fa62-4762-9697-864874c55a7a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.9.7"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
749
cs457-gc/assignment_3_2/notebook/mean_curvature_flow.ipynb
Normal file
749
cs457-gc/assignment_3_2/notebook/mean_curvature_flow.ipynb
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user