{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Visible Vertices\n\nDisplay vertices on a mesh in the same fashion as edge visibility.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import pyvista as pv\nfrom pyvista import examples\n\nmesh = examples.download_bunny_coarse()\n\ncpos = [(0.036, 0.367, 0.884), (0.024, 0.033, -0.022), (-0.303, 0.895, -0.325)]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can easily display all vertices of a mesh with a `points` style\nrepresentation when plotting:\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "pl = pv.Plotter()\npl.add_mesh(mesh, style='points', color='magenta', render_points_as_spheres=True, point_size=10)\npl.show(cpos=cpos)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "However, we often want to see the vertices of a mesh rendered atop the\nsurface geometry. Much like how we can render the edges of a mesh:\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "pl = pv.Plotter()\npl.add_mesh(mesh, show_edges=True)\npl.show(cpos=cpos)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In order to display the vertices atop a mesh\\'s surface geometry, simply\npass `show_vertices=True` to render them along side the original\ngeometry.\n\n::: note\n::: title\nNote\n:::\n\nVertex styling can be changed using `vertex_color`, `vertex_opacity`,\nand `vertex_style`.\n:::\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "pl = pv.Plotter()\npl.add_mesh(\n mesh,\n show_edges=True,\n vertex_color='magenta',\n render_points_as_spheres=True,\n point_size=10,\n show_vertices=True,\n)\npl.show(cpos=cpos)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you wish to have further control over the way surface points are\nplotted alongside the surface geometry, extract the surface points and\nplot them separately.\n\nThe first step is to extract the outer surface geometry of the mesh then\ngrab all the points of that extraction.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "surf_points = mesh.extract_surface().points" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now that we have the vertices extracted, we can use `add_points()\n<pyvista.Plotter.add_points>`{.interpreted-text role=\"func\"} to render\nthem along side the original geometry.\n\nColor the points by their Y position.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "pl = pv.Plotter()\npl.add_mesh(mesh, show_edges=True)\npl.add_points(\n surf_points,\n color='magenta',\n render_points_as_spheres=True,\n point_size=10,\n scalars=surf_points[:, 1],\n lighting=False,\n show_scalar_bar=False,\n)\npl.show(cpos=cpos)" ] } ], "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 }