{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Mesh manipulation" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from vedo import dataurl, Mesh, Arrows, show, settings\n", "settings.default_backend = \"vtk\"" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "\n", "
\n", "vedo.mesh.Mesh
(....embl.es/examples/data/man.vtk)\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
bounds
(x/y/z)
-0.9169 ... 0.9169
-0.3300 ... 0.2617
-1.570 ... 1.685
center of mass (1.01e-10, 4.06e-11, 2.20e-11)
average size 0.911
nr. points / faces 24461 / 24459
cell data array MaterialIds
\n", "
" ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Load a mesh\n", "mesh = Mesh(dataurl+\"man.vtk\").color(\"white\")\n", "mesh" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "\n", "
\n", "vedo.mesh.Mesh
(....embl.es/examples/data/man.vtk)\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
bounds
(x/y/z)
-0.9070 ... 0.9041
-0.3287 ... 0.2765
-1.566 ... 1.691
center of mass (-3.62e-3, 0.0158, 0.0810)
average size 0.945
nr. points / faces 205 / 399
\n", "
" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Create a heavily decimated copy with about 200 points\n", "# (to speed up the computation)\n", "mesh_dec = mesh.clone().triangulate().decimate(n=200)\n", "mesh_dec" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "sources = [[0.9, 0.0, 0.2]] # this point moves\n", "targets = [[1.2, 0.0, 0.4]] # ...to this.\n", "for pt in mesh_dec.points():\n", " if pt[0] < 0.3: # while these pts don't move\n", " sources.append(pt) # (e.i. source = target)\n", " targets.append(pt)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "
\n", "\n", "
\n", "vedo.mesh.Mesh
(....embl.es/examples/data/man.vtk)\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
bounds
(x/y/z)
-0.9177 ... 1.173
-0.3300 ... 0.2617
-1.570 ... 1.684
center of mass (0.0237, 4.06e-11, 0.0158)
average size 0.935
nr. points / faces 24461 / 24459
cell data array MaterialIds
\n", "
" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Warp the mesh\n", "mesh_warped = mesh.clone().warp(sources, targets)\n", "mesh_warped.c(\"blue\").wireframe()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "# Create the arrows representing the displacement\n", "arrow = Arrows(sources, targets)\n", "\n", "# Show the meshes and the arrow\n", "show(mesh, mesh_warped, arrow, axes=1).close()" ] } ], "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.10.10" } }, "nbformat": 4, "nbformat_minor": 2 }