-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #376 from scipp/new-mesh-3d
Add mesh 3d
- Loading branch information
Showing
23 changed files
with
660 additions
and
73 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "0", | ||
"metadata": {}, | ||
"source": [ | ||
"# 3D mesh plot\n", | ||
"\n", | ||
"This notebook illustrates how to render 3D meshes\n", | ||
"by supplying a list of vertex positions and vertex indices to construct the mesh faces." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "1", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import scipp as sc\n", | ||
"import plopp as pp\n", | ||
"from plopp.data import examples" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "2", | ||
"metadata": {}, | ||
"source": [ | ||
"## Loading mesh data\n", | ||
"\n", | ||
"We load a file containing the data to construct the [Utah teapot](https://en.wikipedia.org/wiki/Utah_teapot)\n", | ||
"(see below for a description of the data format)." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "3", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"dg = sc.io.load_hdf5(examples.teapot())\n", | ||
"dg" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "4", | ||
"metadata": {}, | ||
"source": [ | ||
"## Creating a mesh plot\n", | ||
"\n", | ||
"We can now send the data to the [`mesh3d`](../../generated/plopp.mesh3d.html) function for rendering (we color the mesh according to z position):" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "5", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"pp.mesh3d(\n", | ||
" vertices=dg[\"vertices\"],\n", | ||
" faces=dg[\"faces\"],\n", | ||
" vertexcolors=dg[\"vertices\"].fields.z,\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "6", | ||
"metadata": {}, | ||
"source": [ | ||
"## Adding mesh edges\n", | ||
"\n", | ||
"It is also possible to show the edges of the mesh using the `edgecolor` argument:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "7", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"pp.mesh3d(\n", | ||
" vertices=dg[\"vertices\"],\n", | ||
" faces=dg[\"faces\"],\n", | ||
" vertexcolors=dg[\"vertices\"].fields.z,\n", | ||
" edgecolor=\"black\",\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "8", | ||
"metadata": {}, | ||
"source": [ | ||
"## The data format\n", | ||
"\n", | ||
"The data used above contains a list of `vertices` (position vectors in 3d space),\n", | ||
"and a list of `faces` which define how the vertices are connected to each other.\n", | ||
"\n", | ||
"The faces is a flat list of sequences of 3 indices that code for vertices which make up mesh triangles.\n", | ||
"\n", | ||
"As an example, we will construct a simple tetrahedric mesh." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "9", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"vertices = sc.vectors(\n", | ||
" dims=[\"vertices\"],\n", | ||
" values=[[-1, 0, 0], [0.7, 0, 1], [0.7, 0, -1], [0, 1.3, 0]],\n", | ||
" unit=\"m\",\n", | ||
")\n", | ||
"faces = sc.array(\n", | ||
" dims=[\"faces\"],\n", | ||
" values=[\n", | ||
" # First triangle\n", | ||
" 0, 1, 3,\n", | ||
" # Second triangle\n", | ||
" 1, 2, 3,\n", | ||
" # Third triangle\n", | ||
" 2, 0, 3,\n", | ||
" # Fourth triangle\n", | ||
" 0, 2, 1,\n", | ||
" ],\n", | ||
")\n", | ||
"\n", | ||
"pp.mesh3d(\n", | ||
" vertices=vertices,\n", | ||
" faces=faces,\n", | ||
" edgecolor=\"black\",\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "10", | ||
"metadata": {}, | ||
"source": [ | ||
"You can then also add colors on the vertices:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "11", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"pp.mesh3d(\n", | ||
" vertices=vertices,\n", | ||
" faces=faces,\n", | ||
" vertexcolors=vertices.fields.x,\n", | ||
" edgecolor=\"black\",\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" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.