Switch to unified view

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