{ "cells": [ { "cell_type": "markdown", "id": "a1b2c3d4", "metadata": {}, "source": [ "# Clipping Planes\n", "\n", "Clipping planes cut through 3D meshes and fields, revealing interior structure. They work with mesh elements, coefficient functions, and vectors." ] }, { "cell_type": "markdown", "id": "b2c3d4e5", "metadata": {}, "source": [ "## Clipping a 3D Mesh\n", "\n", "`Clipping` controls the plane position and orientation. The GUI automatically provides interactive sliders for normal direction and position." ] }, { "cell_type": "code", "execution_count": null, "id": "c3d4e5f6", "metadata": {}, "outputs": [], "source": [ "from ngsolve import *\n", "from ngsolve_webgpu import *\n", "from webgpu.clipping import Clipping\n", "from webgpu.jupyter import Draw\n", "\n", "mesh = Mesh(unit_cube.GenerateMesh(maxh=0.2))\n", "meshdata = MeshData(mesh)\n", "clipping = Clipping()\n", "clipping.mode = clipping.Mode.PLANE\n", "clipping.center = [0.5, 0.5, 0.5]\n", "\n", "volume_elements = MeshElements3d(meshdata, clipping=clipping)\n", "volume_elements.shrink = 0.8\n", "scene = Draw(volume_elements)" ] }, { "cell_type": "markdown", "id": "d4e5f6a7", "metadata": {}, "source": [ "## Clipping a Function (ClippingCF)\n", "\n", "`ClippingCF` computes and renders function values on the clipping plane cross-section via a compute shader." ] }, { "cell_type": "code", "execution_count": null, "id": "e5f6a7b8", "metadata": {}, "outputs": [], "source": [ "from ngsolve import *\n", "from ngsolve_webgpu import *\n", "from webgpu.colormap import Colorbar\n", "from webgpu.clipping import Clipping\n", "from webgpu.jupyter import Draw\n", "\n", "mesh = Mesh(unit_cube.GenerateMesh(maxh=0.2))\n", "mesh_data = MeshData(mesh)\n", "cf = sin(10 * z) * cos(15 * x)\n", "function_data = FunctionData(mesh_data, cf, order=5)\n", "\n", "clipping = Clipping()\n", "clipping.center = [0.5, 0.5, 0.5]\n", "clipping.mode = clipping.Mode.PLANE\n", "clipping.normal = [1, 0, 0]\n", "\n", "clip_cf = ClippingCF(function_data, clipping=clipping)\n", "cfr = CFRenderer(function_data, clipping=clipping, colormap=clip_cf.colormap)\n", "\n", "scene = Draw([cfr, clip_cf, Colorbar(clip_cf.colormap)])" ] }, { "cell_type": "markdown", "id": "f6a7b8c9", "metadata": {}, "source": [ "## Clipping Properties\n", "\n", "| Property | Description |\n", "|---|---|\n", "| `clipping.center` | Point on the plane (list of 3 floats) |\n", "| `clipping.normal` | Plane normal direction (list of 3 floats) |\n", "| `clipping.mode` | `Clipping.Mode.DISABLED` or `Clipping.Mode.PLANE` |" ] } ], "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.14.5" } }, "nbformat": 4, "nbformat_minor": 5 }