forked from maximedieudonne/MeshVisualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallbacks.py
More file actions
45 lines (39 loc) · 1.9 KB
/
Copy pathcallbacks.py
File metadata and controls
45 lines (39 loc) · 1.9 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
from dash.dependencies import Input, Output, State
import fonctions as fct
import numpy as np
def register_callbacks(app, mesh_path, texture_path):
# Charger le mesh
mesh = fct.load_mesh(mesh_path)
vertices = mesh.vertices
faces = mesh.faces
# Charger la texture (si fournie)
scalars = fct.read_gii_file(texture_path) if texture_path else None
color_min_default, color_max_default = (np.min(scalars), np.max(scalars)) if scalars is not None else (0, 1)
@app.callback(
Output('3d-mesh', 'figure'),
[Input('range-slider', 'value'),
Input('toggle-contours', 'value'),
Input('toggle-black-intervals', 'value'),
Input('colormap-dropdown', 'value'),
Input('toggle-center-colormap', 'value')],
[State('3d-mesh', 'relayoutData')]
)
def update_figure(value_range, toggle_contours, toggle_black_intervals, selected_colormap, center_colormap, relayout_data):
min_value, max_value = value_range
camera = relayout_data['scene.camera'] if relayout_data and 'scene.camera' in relayout_data else None
show_contours = 'on' in toggle_contours
use_black_intervals = 'on' in toggle_black_intervals
center_on_zero = 'on' in center_colormap
fig = fct.plot_mesh_with_colorbar(
vertices, faces, scalars, color_min=min_value, color_max=max_value,
camera=camera, show_contours=show_contours, colormap=selected_colormap,
use_black_intervals=use_black_intervals, center_colormap_on_zero=center_on_zero
)
return fig
# Callback pour mettre à jour la liste des colormaps en fonction du type choisi
@app.callback(
Output('colormap-dropdown', 'options'),
[Input('colormap-type-dropdown', 'value')]
)
def update_colormap_options(selected_type):
return [{'label': cmap, 'value': cmap} for cmap in fct.get_colorscale_names(selected_type)]