Disabled external gits

This commit is contained in:
2022-04-07 18:46:57 +02:00
parent 88cb3426ad
commit 15e7120d6d
5316 changed files with 4563444 additions and 6 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
[[[0.2, 0.0, 0], [0.5270624654048792, 0.09293533316960212, 0], [0.11285295279178453, 0.04107511566525849, 0], [0.537347324533129, 0.3102376224675271, 0], [0.5376274099831806, 0.4511229614276831, 0], [0.3475414767429655, 0.41418380348392614, 0], [0.5632041314409677, 0.975498170688456, 0], [0.13777413649311007, 0.37853132899967884, 0], [0.15821749037280028, 0.8972959766968018, 0], [3.3663921360634227e-17, 0.5497735573076639, 0], [-0.25677616861861896, 1.4562500167978654, 0], [-0.45300365061759007, 1.2446173010023398, 0], [-0.4963687859959057, 0.8597359566361923, 0], [-0.7100275174261769, 0.8461778447333945, 0], [-0.6706959498524094, 0.5627807241532525, 0], [-0.9912140281389583, 0.5722776859705607, 0], [-1.1871787691243278, 0.4320977347140436, 0], [-1.6954303253313614, 0.29895011026725005, 0], [-0.2, 2.4492935982947065e-17, 0], [0, 0, 0]], [[19, 0, 1], [19, 1, 2], [19, 2, 3], [19, 3, 4], [19, 4, 5], [19, 5, 6], [19, 6, 7], [19, 7, 8], [19, 8, 9], [19, 9, 10], [19, 10, 11], [19, 11, 12], [19, 12, 13], [19, 13, 14], [19, 14, 15], [19, 15, 16], [19, 16, 17], [19, 17, 18]]]

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,311 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import meshplot as mp\n",
"import numpy as np\n",
"import sys\n",
"import json\n",
"from matplotlib import pyplot as plt\n",
"sys.path.append(\"../src/\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 1. Load OBJ model"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"with open('../data/gym.json', 'r') as infile:\n",
" [V, F] = json.load(infile)\n",
" V = np.array(V)\n",
" F = np.array(F)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 2. Mesh Plotting"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def draw_mesh(V, F):\n",
" shading = {\"flat\":True, # Flat or smooth shading of triangles\n",
" \"wireframe\":True, \"wire_width\": 0.03, \"wire_color\": \"black\", # Wireframe rendering\n",
" \"width\": 600, \"height\": 600, # Size of the viewer canvas\n",
" \"antialias\": True, # Antialising, might not work on all GPUs\n",
" \"scale\": 2.0, # Scaling of the model\n",
" \"side\": \"DoubleSide\", # FrontSide, BackSide or DoubleSide rendering of the triangles\n",
" \"colormap\": \"viridis\", \"normalize\": [None, None], # Colormap and normalization for colors\n",
" \"background\": \"#ffffff\", # Background color of the canvas\n",
" \"line_width\": 1.0, \"line_color\": \"black\", # Line properties of overlay lines\n",
" \"bbox\": False, # Enable plotting of bounding box\n",
" \"point_color\": \"red\", \"point_size\": 0.01 # Point properties of overlay points\n",
" }\n",
" #p = mp.plot(V, F, shading=shading, return_plot=True)\n",
" mp.plot(V, F)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/sora/.local/lib/python3.9/site-packages/jupyter_client/session.py:716: UserWarning: Message serialization failed with:\n",
"Out of range float values are not JSON compliant\n",
"Supporting this message is deprecated in jupyter-client 7, please make sure your message is JSON-compliant\n",
" content = self.pack(content)\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c463e93a5b0044fbba0746c52a887176",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(0.5660395…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"draw_mesh(V, F)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 3. Mesh Centroid Plotting"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"from geometry import compute_mesh_centroid\n",
"def draw_mesh_with_centroid(V, F):\n",
" shading = {\"flat\":True, # Flat or smooth shading of triangles\n",
" \"wireframe\":True, \"wire_width\": 0.03, \"wire_color\": \"black\", # Wireframe rendering\n",
" \"width\": 600, \"height\": 600, # Size of the viewer canvas\n",
" \"antialias\": True, # Antialising, might not work on all GPUs\n",
" \"scale\": 2.0, # Scaling of the model\n",
" \"side\": \"DoubleSide\", # FrontSide, BackSide or DoubleSide rendering of the triangles\n",
" \"colormap\": \"viridis\", \"normalize\": [None, None], # Colormap and normalization for colors\n",
" \"background\": \"#ffffff\", # Background color of the canvas\n",
" \"line_width\": 1.0, \"line_color\": \"black\", # Line properties of overlay lines\n",
" \"bbox\": False, # Enable plotting of bounding box\n",
" \"point_color\": \"red\", \"point_size\": 0.01 # Point properties of overlay points\n",
" }\n",
" mesh_plot = mp.plot(V, F, shading=shading, return_plot=True)\n",
" center0 = np.array(compute_mesh_centroid(V, F))\n",
" center1 = center0.copy()\n",
" center1[1] = 0\n",
" vertices = np.vstack([center0, center1])\n",
" mesh_plot.add_points(vertices, shading={\"point_color\": \"black\", \"point_size\": 0.1})\n",
" mesh_plot.add_edges(vertices, np.array([[0, 1]]), shading={\"line_color\": \"black\", \"line_width\" : 0.5});"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4f0181b991864ebe91e419ff21dbb932",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(0.5660395…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0.70220297 0.14449098 0. ]\n"
]
}
],
"source": [
"draw_mesh_with_centroid(V, F)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 4. Shearing Transformation"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"from ipywidgets import interact, interactive, fixed, interact_manual\n",
"import ipywidgets as widgets\n",
"from shear import shear_transformation\n",
"def draw_mesh_after_shear_transformation(V, F, nu):\n",
" V1 = shear_transformation(V, nu)\n",
" draw_mesh_with_centroid(V1, F)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "29b3847a9adc46aab07c80e2d794a69c",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(FloatSlider(value=0.0, description='nu', max=1.0, min=-1.0), Output()), _dom_classes=('w…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"interact(draw_mesh_after_shear_transformation, V = fixed(V), F = fixed(F), nu = (-1, 1, 0.1));"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 5. Shear Equilibrium"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"from shear import shear_equilibrium\n",
"from geometry import compute_center_support_line\n",
"def compute_equilibrium_mesh(V, F):\n",
" x_csl = compute_center_support_line(V)\n",
" V1 = shear_equilibrium(V, F, x_csl)\n",
" draw_mesh_with_centroid(V1, F)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Copy the following codes and find equilibrium shapes for all other examples in ../data folder "
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1a828dcd3277486da42e79e5865c4917",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(0.5046897…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0.63531671 0.39031879 0. ]\n"
]
}
],
"source": [
"with open('../data/dinosaur.json', 'r') as infile:\n",
" [V, F] = json.load(infile)\n",
" V = np.array(V)\n",
" F = np.array(F)\n",
" compute_equilibrium_mesh(V, F)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "gc_course_env",
"language": "python",
"name": "gc_course_env"
},
"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": 4
}

View File

@@ -0,0 +1,374 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import meshplot as mp\n",
"import numpy as np\n",
"import sys\n",
"import json\n",
"from matplotlib import pyplot as plt\n",
"sys.path.append(\"../src/\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 1. Load OBJ model"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"with open('../data/gym.json', 'r') as infile:\n",
" [V, F] = json.load(infile)\n",
" V = np.array(V)\n",
" F = np.array(F)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 2. Mesh Plotting"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def draw_mesh(V, F):\n",
" shading = {\"flat\":True, # Flat or smooth shading of triangles\n",
" \"wireframe\":True, \"wire_width\": 0.03, \"wire_color\": \"black\", # Wireframe rendering\n",
" \"width\": 600, \"height\": 600, # Size of the viewer canvas\n",
" \"antialias\": True, # Antialising, might not work on all GPUs\n",
" \"scale\": 2.0, # Scaling of the model\n",
" \"side\": \"DoubleSide\", # FrontSide, BackSide or DoubleSide rendering of the triangles\n",
" \"colormap\": \"viridis\", \"normalize\": [None, None], # Colormap and normalization for colors\n",
" \"background\": \"#ffffff\", # Background color of the canvas\n",
" \"line_width\": 1.0, \"line_color\": \"black\", # Line properties of overlay lines\n",
" \"bbox\": False, # Enable plotting of bounding box\n",
" \"point_color\": \"red\", \"point_size\": 0.01 # Point properties of overlay points\n",
" }\n",
" #p = mp.plot(V, F, shading=shading, return_plot=True)\n",
" mp.plot(V, F)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/sora/.local/lib/python3.9/site-packages/jupyter_client/session.py:716: UserWarning: Message serialization failed with:\n",
"Out of range float values are not JSON compliant\n",
"Supporting this message is deprecated in jupyter-client 7, please make sure your message is JSON-compliant\n",
" content = self.pack(content)\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "10f6965f0b774229b05913c93cc79731",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(0.5660395…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"draw_mesh(V, F)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 3. Mesh Centroid Plotting"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"from geometry import compute_mesh_centroid\n",
"def draw_mesh_with_centroid(V, F):\n",
" shading = {\"flat\":True, # Flat or smooth shading of triangles\n",
" \"wireframe\":True, \"wire_width\": 0.03, \"wire_color\": \"black\", # Wireframe rendering\n",
" \"width\": 600, \"height\": 600, # Size of the viewer canvas\n",
" \"antialias\": True, # Antialising, might not work on all GPUs\n",
" \"scale\": 2.0, # Scaling of the model\n",
" \"side\": \"DoubleSide\", # FrontSide, BackSide or DoubleSide rendering of the triangles\n",
" \"colormap\": \"viridis\", \"normalize\": [None, None], # Colormap and normalization for colors\n",
" \"background\": \"#ffffff\", # Background color of the canvas\n",
" \"line_width\": 1.0, \"line_color\": \"black\", # Line properties of overlay lines\n",
" \"bbox\": False, # Enable plotting of bounding box\n",
" \"point_color\": \"red\", \"point_size\": 0.01 # Point properties of overlay points\n",
" }\n",
" mesh_plot = mp.plot(V, F, shading=shading, return_plot=True)\n",
" center0 = np.array(compute_mesh_centroid(V, F))\n",
" center1 = center0.copy()\n",
" center1[1] = 0\n",
" vertices = np.vstack([center0, center1])\n",
" mesh_plot.add_points(vertices, shading={\"point_color\": \"black\", \"point_size\": 0.1})\n",
" mesh_plot.add_edges(vertices, np.array([[0, 1]]), shading={\"line_color\": \"black\", \"line_width\" : 0.5});"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "183e46c464694a4faf5cd2c46de6f0b3",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(0.5660395…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"draw_mesh_with_centroid(V, F)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 4. Shearing Transformation"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"from ipywidgets import interact, interactive, fixed, interact_manual\n",
"import ipywidgets as widgets\n",
"from shear import shear_transformation\n",
"def draw_mesh_after_shear_transformation(V, F, nu):\n",
" V1 = shear_transformation(V, nu)\n",
" draw_mesh_with_centroid(V1, F)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "89d3fc02da0847b598183789c019b6da",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(FloatSlider(value=0.0, description='nu', max=1.0, min=-1.0), Output()), _dom_classes=('w…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"interact(draw_mesh_after_shear_transformation, V = fixed(V), F = fixed(F), nu = (-1, 1, 0.1));"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 5. Shear Equilibrium"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"from shear import shear_equilibrium\n",
"from geometry import compute_center_support_line\n",
"def compute_equilibrium_mesh(V, F):\n",
" x_csl = compute_center_support_line(V)\n",
" V1 = shear_equilibrium(V, F, x_csl)\n",
" draw_mesh_with_centroid(V1, F)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Copy the following codes and find equilibrium shapes for all other examples in ../data folder "
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9a4f8c51812b477ea4a39f964a209826",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(0.3502894…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"with open('../data/dance.json', 'r') as infile:\n",
" [V, F] = json.load(infile)\n",
" V = np.array(V)\n",
" F = np.array(F)\n",
" compute_equilibrium_mesh(V, F)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "37e4dae7a1c540a4899ae36f48424cc3",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(0.3594106…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"with open('../data/dinosaur.json', 'r') as infile:\n",
" [V, F] = json.load(infile)\n",
" V = np.array(V)\n",
" F = np.array(F)\n",
" compute_equilibrium_mesh(V, F)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ae4038d1f44949b08cf9bb12b2f55d22",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(0.0364573…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"with open('../data/fans.json', 'r') as infile:\n",
" [V, F] = json.load(infile)\n",
" V = np.array(V)\n",
" F = np.array(F)\n",
" compute_equilibrium_mesh(V, F)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ebee92986c1b47b683c696990b8bb13b",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Renderer(camera=PerspectiveCamera(children=(DirectionalLight(color='white', intensity=0.6, position=(0.4445750…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"with open('../data/gym.json', 'r') as infile:\n",
" [V, F] = json.load(infile)\n",
" V = np.array(V)\n",
" F = np.array(F)\n",
" compute_equilibrium_mesh(V, F)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "gc_course_env",
"language": "python",
"name": "gc_course_env"
},
"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": 4
}

Binary file not shown.

View File

@@ -0,0 +1,120 @@
import numpy as np
# -----------------------------------------------------------------------------
# Mesh geometry
# -----------------------------------------------------------------------------
def compute_faces_area(V, F):
"""
Computes the area of the faces of a given triangle mesh (V, F).
Input:
- V : np.array (|V|, 3)
The array of vertices positions.
Contains the coordinates of the i-th vertex in i-th row
- F : np.array (|F|, 3)
The array of triangle faces.
Output:
- area : np.array (|F|,)
The area of the faces. The i-th position contains the area of the i-th
face.
"""
# HW1 1.3.3
trig_area = lambda fi: ((V[fi[0]][1] - V[fi[1]][1]) * V[fi[2]][0]+ (V[fi[2]][1] - V[fi[0]][1]) * V[fi[1]][0] + (V[fi[1]][1] - V[fi[2]][1]) * V[fi[0]][0])/2.0
area = np.array([trig_area(fi) for fi in F])
return area
def compute_mesh_area(V, F):
"""
Computes the area of a given triangle mesh (V, F).
Input:
- V : np.array (|V|, 3)
The array of vertices positions.
Contains the coordinates of the i-th vertex in i-th row
- F : np.array (|F|, 3)
The array of triangle faces.
Output:
- area : float
The area of the mesh.
"""
# HW1 1.3.3
area = np.sum(compute_faces_area(V,F))
return area
def compute_faces_centroid(V, F):
"""
Computes the area centroid of each face of a given triangle mesh (V, F).
Input:
- V : np.array (|V|, 3)
The array of vertices positions.
Contains the coordinates of the i-th vertex in i-th row
- F : np.array (|F|, 3)
The array of triangle faces.
Output:
- cf : np.array (|F|, 3)
The area centroid of the faces.
"""
# HW1 1.3.4
cent_x = lambda fi: (V[fi[0]][0] + V[fi[1]][0] + V[fi[2]][0])/3.0
cent_y = lambda fi: (V[fi[0]][1] + V[fi[1]][1] + V[fi[2]][1])/3.0
cent_idx = lambda fi: [cent_x(fi), cent_y(fi), 0]
cf = np.array([cent_idx(fi) for fi in F])
return cf
def compute_mesh_centroid(V, F):
"""
Computes the area centroid of a given triangle mesh (V, F).
Input:
- V : np.array (|V|, 3)
The array of vertices positions.
Contains the coordinates of the i-th vertex in i-th row
- F : np.array (|F|, 3)
The array of triangle faces.
Output:
- centroid : np.array (3,)
The area centroid of the mesh.
"""
# HW1 1.3.4
face_centroid = compute_faces_centroid(V,F)
mesh_area= compute_mesh_area(V,F)
face_area = compute_faces_area(V,F)
face_centroid_x = face_centroid[:,0]
face_centroid_y = face_centroid[:,1]
face_centroid_z = face_centroid[:,2]
mc = np.array([np.sum(np.dot(face_centroid_x,face_area))/mesh_area, np.sum(np.dot(face_centroid_y,face_area))/mesh_area, 0])
return mc
def compute_center_support_line(V):
"""
Computes the x coordinate of the center of the support line
Input:
- V : np.array (|V|, 3)
The array of vertices positions.
Contains the coordinates of the i-th vertex in i-th row
Output:
- x_csl : float
the x coordinate of the center of the support line
"""
# HW1 1.3.5
support_v = np.fromiter((v[0] for v in V if v[1]<10**-5), dtype=V.dtype)
x_csl = np.amin(support_v)+(np.amax(support_v)-np.amin(support_v))/2
return x_csl

View File

@@ -0,0 +1,64 @@
import numpy as np
from geometry import compute_mesh_centroid
# -----------------------------------------------------------------------------
# Mesh geometry
# -----------------------------------------------------------------------------
def shear_transformation(V, nu):
"""
Computes vertices' postion after the shear transformation.
Input:
- V : np.array (|V|, 3)
The array of vertices positions.
Contains the coordinates of the i-th vertex in i-th row
- nu : the shear paramter
Output:
- V1 : np.array (|V|, 3)
The array of vertices positions after transformation.
"""
# HW1 1.3.6
nu_mat = np.array([[1,nu,0],[0,1,0],[0,0,1]])
V1 = np.matmul(nu_mat,V.T).T
return V1
def shear_equilibrium(V, F, x_csl):
"""
Shear the input mesh to make it equilibrium.
Input:
- V : np.array (|V|, 3)
The array of vertices positions.
Contains the coordinates of the i-th vertex in i-th row
- F : np.array (|F|, 3)
The array of triangle faces.
- x_csl: np.array (3, )
The x coordinate of the target centroid
Output:
- V1 : np.array (|V|, 3)
The array of vertices positions that are equilibrium.
"""
V1 = V.copy()
# HW1 1.3.7
nu = 0.0;
step = 0.5;
cent = compute_mesh_centroid(V1,F)
csl = cent[0]
while(abs(csl-x_csl) > 10**-5 and step > 10**-5):
if(csl > x_csl):
nu -= step;
else:
nu += step;
V1 = shear_transformation(V,nu)
cent = compute_mesh_centroid(V1,F)
csl = cent[0]
step = step/2.0;
return V1

View File

@@ -0,0 +1,79 @@
# import pytest
import pytest
import json
import sys
import numpy as np
sys.path.append('../')
sys.path.append('../src')
from src.geometry import *
from src.shear import *
eps = 1E-6
with open('test_data1.json', 'r') as infile:
homework_datas = json.load(infile)
@pytest.mark.timeout(1)
@pytest.mark.parametrize("data", homework_datas[0])
def test_faces_centroid(data):
V = np.array(data[0], dtype=float)
F = np.array(data[1], dtype=int)
centroid_ground_truth = np.array(data[2])
centroid_student = compute_faces_centroid(V, F)
assert np.linalg.norm(centroid_ground_truth - centroid_student) < eps
@pytest.mark.timeout(1)
@pytest.mark.parametrize("data", homework_datas[1])
def test_faces_area(data):
V = np.array(data[0], dtype=float)
F = np.array(data[1], dtype=int)
area_ground_truth = np.array(data[2])
area_student = compute_faces_area(V, F)
assert np.linalg.norm(area_ground_truth - area_student) < eps
@pytest.mark.timeout(1)
@pytest.mark.parametrize("data", homework_datas[2])
def test_mesh_centroid(data):
V = np.array(data[0], dtype=float)
F = np.array(data[1], dtype=int)
centroid_ground_truth = np.array(data[2])
centroid_student = compute_mesh_centroid(V, F)
assert np.linalg.norm(centroid_ground_truth - centroid_student) < eps
@pytest.mark.timeout(1)
@pytest.mark.parametrize("data", homework_datas[3])
def test_mesh_area(data):
V = np.array(data[0], dtype=float)
F = np.array(data[1], dtype=int)
area_ground_truth = np.array(data[2])
area_student = compute_mesh_area(V, F)
assert abs(area_ground_truth - area_student) < eps
@pytest.mark.timeout(1)
@pytest.mark.parametrize("data", homework_datas[4])
def test_center_support_line(data):
V = np.array(data[0], dtype=float)
F = np.array(data[1], dtype=int)
support_line_ground_truth = np.array(data[2])
support_line_student = compute_center_support_line(V)
assert abs(support_line_ground_truth - support_line_student) < eps
@pytest.mark.timeout(1)
@pytest.mark.parametrize("data", homework_datas[5])
def test_shear_tranformation(data):
V = np.array(data[0], dtype=float)
F = np.array(data[1], dtype=int)
nu = data[2]
V_shear_ground_truth = np.array(data[3], dtype=float)
V_shear_student = shear_transformation(V, nu)
assert np.linalg.norm(V_shear_student - V_shear_ground_truth) < eps
@pytest.mark.timeout(1)
@pytest.mark.parametrize("data", homework_datas[6])
def test_shear_equilibrium(data):
V = np.array(data[0], dtype=float)
F = np.array(data[1], dtype=int)
x_csl = data[2]
V_shear_ground_truth = np.array(data[3], dtype=float)
V_shear_student = shear_equilibrium(V, F, x_csl)
assert np.linalg.norm(V_shear_student - V_shear_ground_truth) < eps

View File

@@ -0,0 +1 @@
[[[[[0, 0, 0], [1, 0, 0], [0, 1, 0]], [[0, 1, 2]], [[0.3333333333333333, 0.3333333333333333, 0]]]], [[[[0, 0, 0], [1, 0, 0], [0, 1, 0]], [[0, 1, 2]], [0.5]]], [[[[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0]], [[0, 1, 2], [1, 3, 2]], [[0.5, 0.5, 0]]]], [[[[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0]], [[0, 1, 2], [1, 3, 2]], 1]], [[[[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0]], [[0, 1, 2], [1, 3, 2]], 0.5]], [[[[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0]], [[0, 1, 2], [1, 3, 2]], 0.5, [[0, 0, 0], [1, 0, 0], [0.5, 1, 0], [1.5, 1, 0]]]], [[[[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0]], [[0, 1, 2], [1, 3, 2]], 0.75, [[0, 0, 0], [1, 0, 0], [0.5, 1, 0], [1.5, 1, 0]]]]]