diff --git a/examples/ipynb/notebook_showcase_k3d.ipynb b/examples/ipynb/notebook_showcase_k3d.ipynb index 05ee674a..39fdda88 100644 --- a/examples/ipynb/notebook_showcase_k3d.ipynb +++ b/examples/ipynb/notebook_showcase_k3d.ipynb @@ -1,208 +1,250 @@ { - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import gustaf as gus\n", - "import vedo\n", - "\n", - "vedo.settings.default_backend = \"k3d\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mesh_faces_box = gus.create.faces.box(\n", - " bounds=[[0, 0], [2, 2]], resolutions=[2, 3]\n", - ")\n", - "mesh_faces_box.show_options[\"c\"] = 6\n", - "a = mesh_faces_box.show(axes=1)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Volumes does not create an error anymore. Currently is exchanged to volumes.to_faces() might be able to be exchanged back to true volume plotting if vedo fixes UGrid." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mesh_volumes_box = gus.create.volumes.box(\n", - " bounds=[[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]], resolutions=[2, 3, 4]\n", - ")\n", - "mesh_volumes_box.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mesh_faces_triangle = gus.create.faces.box(\n", - " bounds=[[0, 0], [2, 2]],\n", - " resolutions=[3, 3],\n", - " simplex=True,\n", - ")\n", - "mesh_faces_triangle.show()\n", - "print(mesh_faces_triangle.bounds())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mesh_faces_triangle_bs = gus.create.faces.box(\n", - " bounds=[[0, 0], [2, 2]],\n", - " resolutions=[3, 3],\n", - " simplex=True,\n", - " backslash=True,\n", - ")\n", - "mesh_faces_triangle_bs.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gus.show(\n", - " [\"faces-box\", mesh_faces_box],\n", - " [\"volumes-box\", mesh_volumes_box],\n", - " [\"faces-triangle\", mesh_faces_triangle],\n", - " [\"faces-triangle-backslash\", mesh_faces_triangle_bs],\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import splinepy" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def CubeLinear(origin, length):\n", - " origin_length = origin + length\n", - " return splinepy.Bezier(\n", - " degrees=[1] * 3,\n", - " control_points=[\n", - " [origin, origin, origin],\n", - " [origin_length, origin, origin],\n", - " [origin, origin_length, origin],\n", - " [origin_length, origin_length, origin],\n", - " [origin, origin, origin_length],\n", - " [origin_length, origin, origin_length],\n", - " [origin, origin_length, origin_length],\n", - " [origin_length, origin_length, origin_length],\n", - " ],\n", - " )\n", - "\n", - "\n", - "length_center, length_corner = 0.2, 0.1\n", - "cube_center, cube_corner = (\n", - " CubeLinear(origin=0.5, length=length_center),\n", - " CubeLinear(origin=1.0, length=-length_corner),\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The following works but looks very stupidly since the knot vector points and control points are shown much bigger than they should." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "cube_center.show_options[\"knots\"] = False\n", - "# cube_center.show_options[\"control_points\"] = True\n", - "# cube_center.show_options[\"control_point_ids\"] = False\n", - "# cube_center.show_options[\"control_mesh\"] = True\n", - "# cube_center.show_options[\"control_mesh_lw\"] = 1\n", - "# cube_center.show_options[\"knot_lw\"] = 1\n", - "# cube_center.show_options[\"control_point_r\"] = 1\n", - "gus.show([\"cube-center\", cube_center])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Plot microstructures in ipy notebook. This is currently working somewhat." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from splinepy import microstructure\n", - "from splinepy.io import iges\n", - "\n", - "turbine_blade_cross_section = iges.load(\n", - " \"turbineBladeCrossSectionSurrogate.iges\"\n", - ")[0]\n", - "turbine_blade_tiled = microstructure.Microstructure(\n", - " deformation_function=turbine_blade_cross_section,\n", - " tiling=[1, 4],\n", - " microtile=microstructure.tiles.Cross2D(),\n", - ")\n", - "turbine_blade_tiled.show(\n", - " resolutions=10,\n", - " control_points=False,\n", - " knots=False,\n", - " scalarbar=False,\n", - " lightning=\"off\",\n", - ")" - ] - } - ], - "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.13" - } - }, - "nbformat": 4, - "nbformat_minor": 4 + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Gustaf in Notebook -> It is magic\n", + "\n", + "Well actually we just ripped off vedo plotting again. But we had to adapt it a little bit to suite it to our needs. For example multiple plots in a cell were to possible, the horror. So we fixed this and now you can bask in the glory of this work. Or well develop your Sicenecy stuff with it, what ever floats your float/boat/toast?\n", + "\n", + "*Attention, please make sure to change the vedo backend to **k3d** to make this work.* " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import gustaf as gus\n", + "import vedo\n", + "\n", + "vedo.settings.default_backend = \"k3d\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Show boxes\n", + "\n", + "This example is nearly verbatim from equally named standard example. In the first cell it is also shown how to activate axes to see the value ranges of the structure shown. The number does not matter as long as it converts to True as a bool." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "mesh_faces_box = gus.create.faces.box(\n", + " bounds=[[0, 0], [2, 2]], resolutions=[2, 3]\n", + ")\n", + "mesh_faces_box.show_options[\"c\"] = 6\n", + "a = mesh_faces_box.show(axes=1)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If you do not want to show a grid that is also fine. But here is not only a 2D structure but a 3D structure." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "mesh_volumes_box = gus.create.volumes.box(\n", + " bounds=[[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]], resolutions=[2, 3, 4]\n", + ")\n", + "mesh_volumes_box.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Ok, now lets speed up. We can plot 2 things in a single cell next to each other, YAY. Should always be in a single show call." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "mesh_faces_triangle = gus.create.faces.box(\n", + " bounds=[[0, 0], [2, 2]],\n", + " resolutions=[3, 3],\n", + " simplex=True,\n", + ")\n", + "mesh_faces_triangle_bs = gus.create.faces.box(\n", + " bounds=[[0, 0], [2, 2]],\n", + " resolutions=[3, 3],\n", + " simplex=True,\n", + " backslash=True,\n", + ")\n", + "gus.show(\n", + " [\"faces-triangle\", mesh_faces_triangle],\n", + " [\"faces-triangle-backslash\", mesh_faces_triangle_bs],\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Alright that works very nicely (hopefully). Now do 4 things!" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "gus.show(\n", + " [\"faces-box\", mesh_faces_box],\n", + " [\"volumes-box\", mesh_volumes_box],\n", + " [\"faces-triangle\", mesh_faces_triangle],\n", + " [\"faces-triangle-backslash\", mesh_faces_triangle_bs],\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Splinepy plotting examples\n", + "\n", + "Now really turn up the heat with splines.\n", + "\n", + "You will need to install splinepy into the environment that you are using as kernel for this notebook." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import splinepy" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Yes, this is a convoluted way to define a cubed spline. This was something some one send to me to try out if it worked in a notebook. Sue me that I did not exchange it with the better and easier way to create a cubed spline with the build in splinepy functionality. (Hint see the example provided with splinepy to check out all they can do. It is amazing!)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def CubeLinear(origin, length):\n", + " origin_length = origin + length\n", + " return splinepy.Bezier(\n", + " degrees=[1] * 3,\n", + " control_points=[\n", + " [origin, origin, origin],\n", + " [origin_length, origin, origin],\n", + " [origin, origin_length, origin],\n", + " [origin_length, origin_length, origin],\n", + " [origin, origin, origin_length],\n", + " [origin_length, origin, origin_length],\n", + " [origin, origin_length, origin_length],\n", + " [origin_length, origin_length, origin_length],\n", + " ],\n", + " )\n", + "\n", + "\n", + "length_center, length_corner = 0.2, 0.1\n", + "cube_center, cube_corner = (\n", + " CubeLinear(origin=0.5, length=length_center),\n", + " CubeLinear(origin=1.0, length=-length_corner),\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now show me what you prepared for me!\n", + "\n", + "You might want to limit certain stuff that is normally shown since rendering in a notebook is apparently more compute intensive than otherwise. So I have turned of plotting the splines knots for you. If you want you can turn them on again. I will not be mad, I promise." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "cube_center.show_options[\"knots\"] = False\n", + "cube_corner.show_options[\"knots\"] = False\n", + "gus.show([cube_center, cube_corner])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Have you heard of microstructures? I heard they were cool. Here they are!" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from splinepy import microstructure\n", + "from splinepy.io import iges\n", + "\n", + "turbine_blade_cross_section = iges.load(\n", + " \"turbineBladeCrossSectionSurrogate.iges\"\n", + ")[0]\n", + "turbine_blade_tiled = microstructure.Microstructure(\n", + " deformation_function=turbine_blade_cross_section,\n", + " tiling=[1, 4],\n", + " microtile=microstructure.tiles.Cross2D(),\n", + ")\n", + "turbine_blade_tiled.show(\n", + " resolutions=10,\n", + " control_points=False,\n", + " knots=False,\n", + " scalarbar=False,\n", + " lightning=\"off\",\n", + ")" + ] + } + ], + "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.13" + } + }, + "nbformat": 4, + "nbformat_minor": 4 } diff --git a/pyproject.toml b/pyproject.toml index baf961d1..e9513211 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,7 +36,7 @@ content-type = "text/markdown" [project.optional-dependencies] all = [ - "vedo>=2023.4.3,<2023.5.0", + "vedo==2023.5.0", "scipy", "meshio", "napf>=0.0.5",