{ "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\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 }