{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Decimation {#decimate_example}\n\nDecimate a mesh\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import pyvista as pv\nfrom pyvista import examples\n\nmesh = examples.download_face()\n\n# Define a camera position that shows this mesh properly\ncpos = [(0.4, -0.07, -0.31), (0.05, -0.13, -0.06), (-0.1, 1, 0.08)]\ndargs = dict(show_edges=True, color=True)\n\n# Preview the mesh\nmesh.plot(cpos=cpos, **dargs)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let\\'s define a target reduction and compare the\n`pyvista.PolyDataFilters.decimate`{.interpreted-text role=\"func\"} and\n`pyvista.PolyDataFilters.decimate_pro`{.interpreted-text role=\"func\"}\nfilters.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "target_reduction = 0.7\nprint(f\"Reducing {target_reduction * 100.0} percent out of the original mesh\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "decimated = mesh.decimate(target_reduction)\n\ndecimated.plot(cpos=cpos, **dargs)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "pro_decimated = mesh.decimate_pro(target_reduction, preserve_topology=True)\n\npro_decimated.plot(cpos=cpos, **dargs)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Side by side comparison:\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "pl = pv.Plotter(shape=(1, 3))\npl.add_mesh(mesh, **dargs)\npl.add_text(\"Input mesh\", font_size=24)\npl.camera_position = cpos\npl.reset_camera()\npl.subplot(0, 1)\npl.add_mesh(decimated, **dargs)\npl.add_text(\"Decimated mesh\", font_size=24)\npl.camera_position = cpos\npl.reset_camera()\npl.subplot(0, 2)\npl.add_mesh(pro_decimated, **dargs)\npl.add_text(\"Pro Decimated mesh\", font_size=24)\npl.camera_position = cpos\npl.reset_camera()\npl.link_views()\npl.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.12.2" } }, "nbformat": 4, "nbformat_minor": 0 }