Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #476 improving visualization #477

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions 3d box labelling.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "3b024f4b-1fed-4252-aede-bd8b19428a7a",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1215958ecc154b398d3843b0b2b8c75e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Widget(value='<iframe src=\"http://localhost:54199/index.html?ui=P_0x1e41171c080_1&reconnect=auto\" class=\"pyvis…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import pyvista as pv\n",
"from pyvista import examples\n",
"import numpy as np\n",
"\n",
"# Download a sample mesh (bunny model)\n",
"mesh = examples.download_bunny_coarse()\n",
"\n",
"# Create a Plotter object\n",
"pl = pv.Plotter()\n",
"\n",
"# Add the bunny mesh to the plotter\n",
"pl.add_mesh(mesh, show_edges=True, color='white')\n",
"\n",
"# Define the coordinate ranges for the left ear\n",
"xmin, xmax = -0.11, -0.05\n",
"ymin, ymax = 0.10, 0.18\n",
"zmin, zmax = -0.08, -0.02\n",
"\n",
"# Extract points within the specified ranges\n",
"points = mesh.points\n",
"mask = (\n",
" (points[:, 0] >= xmin) & (points[:, 0] <= xmax) &\n",
" (points[:, 1] >= ymin) & (points[:, 1] <= ymax) &\n",
" (points[:, 2] >= zmin) & (points[:, 2] <= zmax)\n",
")\n",
"left_ear_points = points[mask]\n",
"#print(\"Extracted Points (Left Ear):\")\n",
"#print(left_ear_points)\n",
"# Ensure there are points in the left ear region\n",
"if left_ear_points.size > 0:\n",
" # Calculate the centroid of the extracted points\n",
" left_ear_centroid = left_ear_points.mean(axis=0)\n",
" #print(\"Left Ear Centroid:\", left_ear_centroid)\n",
" # Add a label to the central point of the left ear\n",
" pl.add_point_labels([left_ear_centroid], [\"Left Ear\"], point_color='blue', point_size=10, font_size=50, text_color='black')\n",
"else:\n",
" print(\"No points found in the specified range for the left ear.\")\n",
"# Set the camera position for a better view\n",
"# Adjusting the camera position to move closer to the model\n",
"pl.camera_position = [(0.1, 0.1, 0.5), # Position (closer to the model)\n",
" (0.02, 0.03, -0.02), # Focal point (focus on specific area)\n",
" (0, 1, 0)]\n",
"\n",
"'''pl.camera_position = 'xy'\n",
"\n",
"# Ensure the plotter window is sized appropriately\n",
"pl.window_size = [800, 600]'''\n",
"# Show the plot\n",
"pl.show()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "706b8fdc-9c8e-4b56-a782-1b1b32423e31",
"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.12.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading