[8406bc]: / PYTHON / plotBoneModels_example.py

Download this file

51 lines (46 with data), 1.7 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#PLOTBONEMODELS_EXAMPLE provides an example how to plot the VSD subjects.
#
# AUTHOR: Maximilian C. M. Fischer
# COPYRIGHT (C) 2022-2023 Maximilian C. M. Fischer
# LICENSE: EUPL v1.2
#
from pathlib import Path
import scipy.io
import plotly.graph_objects as go
import plotly.io
mod_path = Path(__file__).parent
relativePath = '../Bones/002.mat'
subjectPath = (mod_path / relativePath).resolve()
MAT = scipy.io.loadmat(subjectPath)
plotly.io.renderers.default='browser'
meshColor = 'white'
lightingEffects = dict(ambient=0.6, diffuse=1, roughness=0.5, specular=0.6, fresnel=2)
for b in range(0, MAT['B'].size):
# Extract vertices and faces of one bone
vertices = MAT['B'][0, b][2][0][0][0]
# Subtract 1 from the faces for proper indexing
faces = MAT['B'][0, b][2][0][0][1] - 1
if b == 0:
fig = go.Figure(go.Mesh3d(
x=vertices[:, 0], y=vertices[:, 1], z=vertices[:, 2],
i=faces[:, 0], j=faces[:, 1], k=faces[:, 2],
opacity=1, color=meshColor, lighting=lightingEffects))
else:
fig.add_trace(go.Mesh3d(
x=vertices[:, 0], y=vertices[:, 1], z=vertices[:, 2],
i=faces[:, 0], j=faces[:, 1], k=faces[:, 2],
opacity=1, color=meshColor, lighting=lightingEffects))
fig.update_scenes(camera_projection_type='orthographic')
fig['layout']['scene']['aspectmode'] = "data"
camera = dict(eye=dict(x=-2.5, y=-5, z=1))
fig.update_layout(scene_camera=camera)
axesSettings = dict(
backgroundcolor="grey",
gridcolor="white",
showbackground=True,
zerolinecolor="white")
fig.update_layout(scene=dict(
xaxis=axesSettings,
yaxis=axesSettings,
zaxis=axesSettings))
fig.show()