You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
341 lines
9.2 KiB
341 lines
9.2 KiB
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "cb7708b5",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Jupyter viewer example\n",
|
|
"This notebook is an example of using the occwl JupyterViewer to view solids and select faces and edges."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "701cae48",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Automatically reload libraries when the code changes\n",
|
|
"%load_ext autoreload\n",
|
|
"%autoreload 2\n",
|
|
"\n",
|
|
"# Depending on how you have occwl installed you may need to switch into the src directory for jupyter to see the code\n",
|
|
"import os\n",
|
|
"os.chdir(\"../src\")\n",
|
|
"\n",
|
|
"# Imports from occwl\n",
|
|
"from occwl.compound import Compound\n",
|
|
"from occwl.entity_mapper import EntityMapper\n",
|
|
"from occwl.uvgrid import uvgrid\n",
|
|
"from occwl.jupyter_viewer import JupyterViewer\n",
|
|
"\n",
|
|
"os.chdir(\"../\")\n",
|
|
"\n",
|
|
"import numpy as np\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "e8a359e2",
|
|
"metadata": {},
|
|
"source": [
|
|
"We start by loading a step file."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"id": "a6ec9b63",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Loaded 1 solids\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"solids = list(Compound.load_from_step(\"examples/example.stp\").solids())\n",
|
|
"print(f\"Loaded {len(solids)} solids\")\n",
|
|
"solid = solids[0]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "5ec829be",
|
|
"metadata": {},
|
|
"source": [
|
|
"We can now create the JupyterViewer and display the solid. This is a minimal example."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"id": "f5d9fa3b",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
"model_id": "704db9d17e37467781eb7669dd3b5e8d",
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
},
|
|
"text/plain": [
|
|
"HBox(children=(VBox(children=(HBox(children=(Checkbox(value=True, description='Axes', layout=Layout(height='au…"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"viewer = JupyterViewer()\n",
|
|
"viewer.display(solid)\n",
|
|
"viewer.show()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "65f36b19",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Adding color to faces and edges\n",
|
|
"Here is an example using a few more advanced options. Control over the color of faces and edges."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"id": "94ee67d9",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
"model_id": "0c65c6d8d6ab4477b571eb8e52f7a2c9",
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
},
|
|
"text/plain": [
|
|
"HBox(children=(VBox(children=(HBox(children=(Checkbox(value=True, description='Axes', layout=Layout(height='au…"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"viewer2 = JupyterViewer()\n",
|
|
"viewer2.display(solid, shape_color=\"green\", edge_color=\"black\", render_edges=True)\n",
|
|
"viewer2.show()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "b78c529f",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Selecting individual faces and edges\n",
|
|
"To allow individual faces and edges to be selected you need to display them individually as shown below."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"id": "4d680663",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
"model_id": "307e703fa4a44a0fb0e3227116b75278",
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
},
|
|
"text/plain": [
|
|
"HBox(children=(VBox(children=(HBox(children=(Checkbox(value=True, description='Axes', layout=Layout(height='au…"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"viewer3 = JupyterViewer()\n",
|
|
"for face in solid.faces():\n",
|
|
" viewer3.display(face, render_edges=True)\n",
|
|
"viewer3.show()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "ec9aa9dd",
|
|
"metadata": {},
|
|
"source": [
|
|
"Double click on the faces to select them, then rerun the cell below"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"id": "ff65e1cf",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"The faces you selected were [10 12 13]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"if len(viewer3.selected_faces()) <= 0:\n",
|
|
" print(\"Please select some faces to view this demo\")\n",
|
|
"else:\n",
|
|
" entity_mapper = EntityMapper(solid)\n",
|
|
" selected_face_indices = viewer3.selected_face_indices(entity_mapper)\n",
|
|
" print(f\"The faces you selected were {selected_face_indices}\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "54eac6df",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Viewing faces colored by some scalar function\n",
|
|
"Here we show how to color the faces based on their area"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"id": "f1a6a002",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAV0AAAAfCAYAAABEbx5kAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8rg+JYAAAACXBIWXMAAAsTAAALEwEAmpwYAAACSUlEQVR4nO3cu27cQAyF4TOyVr5ULpI6fro8bfIQqZM6tnUbFwayHO7MQHYMpsj/VZIORVFegIWx2JRzFgAgxvCvBwCA/wlLFwACsXQBIBBLFwACsXQBIBBLFwACjb3wLn3K93qQJOVUZtmsa5tlt8Zb2eG6VH6l7X09fF2uZr7fbs9N3e5mKrLO7LYuFcdlXfrLOl/b7XHgnl7doPY7XmTG4P82jXuK55rMjeeygz0uRq/36Nblzkz5WN1gv7Zpjgf/dU5zOjR6+3kvs8Z9/uOw2V6f7+LcRrura/XovGP3uXtrPrXrPrqHf0dz+l36lXP+rIru0r3Xg77qmyRpPZUPmG/Px+tkrt+VPYrsNr+5bp3az7V1fsayR/ms+WY399Svv56bHrb3jX/u+b752tRdl/228ZydTDaOZb9pstlevS5Jk3nueOV6nLZqZq9L0mT6j4N51ljWjYPpcbVVjyVpTKbHsFWv97Ipuflk6syxvf6amR5ayx7Z9Mimbi/rWtmY3UybmWMzdburW222V69L0rSYOtt7cfM1sml2det2LHte/hyntfx8ZDI9mx5L+Y56WurZ0/q+utlkj417fPZoesydOp/9Xt5eV8zXnj1JP9TAvxcAIBBLFwACsXQBIBBLFwACsXQBIBBLFwACsXQBIBBLFwACsXQBIBBLFwACsXQBIBBLFwACsXQBIBBLFwACsXQBIFDK/od9bZjST3V+FxIAUPWl9SPm3aULAPhY/HsBAAKxdAEgEEsXAAKxdAEgEEsXAAK9AFeNKQkvQhLUAAAAAElFTkSuQmCC",
|
|
"text/plain": [
|
|
"<Figure size 432x288 with 1 Axes>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
"model_id": "7789b749978447cabe5d3bdc771ca8a2",
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
},
|
|
"text/plain": [
|
|
"HBox(children=(VBox(children=(HBox(children=(Checkbox(value=True, description='Axes', layout=Layout(height='au…"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"face_areas = []\n",
|
|
"for face in solid.faces():\n",
|
|
" face_areas.append(face.area())\n",
|
|
"face_areas = np.array(face_areas)\n",
|
|
"viewer4 = JupyterViewer()\n",
|
|
"viewer4.display_face_colormap(solid, face_areas)\n",
|
|
"viewer4.show()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "94211f6b",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Visualizing point grids\n",
|
|
"This example shows how point grids can be visualized"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 12,
|
|
"id": "5c393325",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
"model_id": "3159b6a2b389464d89566ab30bfe8f8d",
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
},
|
|
"text/plain": [
|
|
"HBox(children=(VBox(children=(HBox(children=(Checkbox(value=True, description='Axes', layout=Layout(height='au…"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"viewer5 = JupyterViewer()\n",
|
|
"for face in solid.faces():\n",
|
|
" viewer5.display(face, render_edges=True)\n",
|
|
"viewer5.show()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 14,
|
|
"id": "b23d1ba0",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"if len(viewer5.selected_faces()) <= 0:\n",
|
|
" print(\"Please select some faces to view this demo\")\n",
|
|
"else:\n",
|
|
" for face in viewer5.selected_faces():\n",
|
|
" num_u = 5\n",
|
|
" num_v = 5\n",
|
|
" points = np.reshape(uvgrid(face, num_u, num_v, method=\"point\"),(-1, 3))\n",
|
|
" viewer5.display_points(points)\n",
|
|
" normals = uvgrid(face, num_u, num_v, method=\"normal\").reshape((-1, 3))\n",
|
|
" viewer5.display_unit_vectors(points, normals)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "a3d82c30",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"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.4"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|
|
|