Create main.py
This commit is contained in:
268
3D_app/main.py
Normal file
268
3D_app/main.py
Normal file
@ -0,0 +1,268 @@
|
||||
import dash
|
||||
import dash_core_components as dcc
|
||||
import dash_html_components as html
|
||||
from dash.dependencies import Input, Output
|
||||
import plotly.graph_objects as go
|
||||
import numpy as np
|
||||
from util import *
|
||||
import dash_bootstrap_components as dbc
|
||||
import plotly.express as px
|
||||
|
||||
#initialisation de figure
|
||||
dossier = "Dataset/Shear_transform"
|
||||
fichiers_selectionnes = ['Shear_x001-x101_y{:03d}_Rot00_transform.csv'.format(i) for i in range(10, 62)]
|
||||
|
||||
#dossier = "Dataset/Shear_Wave_Rot00_CSV_Data"
|
||||
#fichiers_selectionnes = ['Shear_x001-x101_y{:03d}_Rot00.csv'.format(i) for i in range(10, 62)]
|
||||
|
||||
|
||||
print(fichiers_selectionnes)
|
||||
|
||||
pre_volume = np.array(lire_fichier_csv(dossier,fichiers_selectionnes))
|
||||
volume = pre_volume[:, ::32, :]
|
||||
dim_x, dim_y, dim_z = volume.shape
|
||||
|
||||
X, Y, Z = np.mgrid[0:dim_x, 0:dim_y, 0:dim_z]
|
||||
|
||||
fig = go.Figure(data=go.Volume(
|
||||
x=X.flatten(),
|
||||
y=Y.flatten(),
|
||||
z=Z.flatten(),
|
||||
value=volume.flatten(),
|
||||
#isomin=volume.min(),
|
||||
isomin=5000,
|
||||
isomax=volume.max(),
|
||||
opacity=0.1, # needs to be small to see through all surfaces
|
||||
surface_count=20, # needs to be a large number for good volume rendering
|
||||
colorscale='Jet'
|
||||
))
|
||||
|
||||
|
||||
# Initialize the Dash app
|
||||
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
|
||||
|
||||
# Define the app layout
|
||||
|
||||
#3D_card = dbc.Card(
|
||||
|
||||
|
||||
|
||||
#----------------definition layout----------------
|
||||
mesh_card = dbc.Card([
|
||||
dbc.CardBody([
|
||||
dcc.Graph(id='3dplot', figure=fig), # 'fig' is your 3D plotly figure
|
||||
dcc.Slider(
|
||||
id='iso-slider',
|
||||
min=volume.min(),
|
||||
max=volume.max() / 2,
|
||||
value=volume.min(),
|
||||
marks={str(i): str(i) for i in range(int(volume.min()), int(volume.max() / 2) + 1, int((volume.max() / 2 - volume.min()) / 10))},
|
||||
step=1
|
||||
),
|
||||
dcc.RangeSlider(
|
||||
id='y-slider',
|
||||
min=0,
|
||||
max=dim_y,
|
||||
value=[0, dim_y / 2],
|
||||
marks={str(i): str(i) for i in range(0, int(dim_y) + 1, max(1, int(dim_y / 20)))},
|
||||
step=1
|
||||
)
|
||||
])
|
||||
])
|
||||
|
||||
Ascan_card = dbc.Card([
|
||||
dbc.CardBody([
|
||||
dcc.Graph(id='heatmap-ascan'), # 'fig' is your 2D plotly figure
|
||||
dcc.Slider(
|
||||
id='layer-slider-ascan',
|
||||
min=0,
|
||||
max=dim_x - 1,
|
||||
value=0,
|
||||
step=1
|
||||
)
|
||||
])
|
||||
])
|
||||
|
||||
Bscan_card_xy = dbc.Card([
|
||||
dbc.CardBody([
|
||||
dcc.Graph(id='heatmap-bscan-xy'), # 'fig' is your 2D plotly figure
|
||||
dcc.Slider(
|
||||
id='layer-slider-bscan-xy',
|
||||
min=0,
|
||||
max=dim_x - 1,
|
||||
value=0,
|
||||
step=1,
|
||||
marks={}
|
||||
)
|
||||
])
|
||||
])
|
||||
|
||||
Bscan_card_zx = dbc.Card([
|
||||
dbc.CardBody([
|
||||
dcc.Graph(id='heatmap-bscan-zx'), # 'fig' is your 2D plotly figure
|
||||
dcc.Slider(
|
||||
id='layer-slider-bscan-zx',
|
||||
min=0,
|
||||
max=dim_z - 1,
|
||||
value=0,
|
||||
step=1
|
||||
)
|
||||
])
|
||||
])
|
||||
|
||||
with open("assets/modal.md", "r") as f:
|
||||
howto_md = f.read()
|
||||
|
||||
modal_overlay = dbc.Modal(
|
||||
[
|
||||
dbc.ModalBody(html.Div([dcc.Markdown(howto_md)], id="howto-md")),
|
||||
dbc.ModalFooter(dbc.Button("Close", id="howto-close", className="howto-bn")),
|
||||
],
|
||||
id="modal",
|
||||
size="lg",
|
||||
)
|
||||
|
||||
# Buttons
|
||||
button_gh = dbc.Button(
|
||||
"Learn more",
|
||||
id="howto-open",
|
||||
outline=True,
|
||||
color="secondary",
|
||||
# Turn off lowercase transformation for class .button in stylesheet
|
||||
style={"textTransform": "none"},
|
||||
)
|
||||
|
||||
button_howto = dbc.Button(
|
||||
"View Code on github",
|
||||
outline=True,
|
||||
color="primary",
|
||||
href="https://github.com/mathur04/stage_IJL/tree/main",
|
||||
id="gh-link",
|
||||
style={"text-transform": "none"},
|
||||
)
|
||||
|
||||
nav_bar = dbc.Navbar(
|
||||
dbc.Container(
|
||||
[
|
||||
dbc.Row(
|
||||
[
|
||||
dbc.Col(
|
||||
dbc.Row(
|
||||
[
|
||||
dbc.Col(
|
||||
html.A(
|
||||
html.Img(
|
||||
src=app.get_asset_url("logo_IJL couleur.png"),
|
||||
height="30px",
|
||||
),
|
||||
href="https://ijl.univ-lorraine.fr/",
|
||||
),
|
||||
style={"width": "min-content"},
|
||||
),
|
||||
dbc.Col(
|
||||
html.Div(
|
||||
[
|
||||
html.H3("3D app"),
|
||||
html.P(
|
||||
"IJL - Institut Jean Lamour / project stage M2 EEA 2023-2024",
|
||||
),
|
||||
],
|
||||
id="app_title",
|
||||
)
|
||||
),
|
||||
],
|
||||
align="center",
|
||||
style={"display": "inline-flex"},
|
||||
)
|
||||
),
|
||||
dbc.Col(
|
||||
[
|
||||
dbc.NavbarToggler(id="navbar-toggler"),
|
||||
dbc.Collapse(
|
||||
dbc.Nav(
|
||||
[dbc.NavItem(button_howto), dbc.NavItem(button_gh)],
|
||||
className="ml-auto",
|
||||
navbar=True,
|
||||
),
|
||||
id="navbar-collapse",
|
||||
navbar=True,
|
||||
),
|
||||
]
|
||||
),
|
||||
modal_overlay,
|
||||
],
|
||||
align="center",
|
||||
style={"width": "100%"},
|
||||
),
|
||||
],
|
||||
fluid=True,
|
||||
),
|
||||
color="white",
|
||||
dark=True,
|
||||
)
|
||||
|
||||
# main layout
|
||||
app.layout = dbc.Container([
|
||||
nav_bar,
|
||||
dbc.Row([dbc.Col(Ascan_card, width=6), dbc.Col(mesh_card, width=6)]),
|
||||
dbc.Row([dbc.Col(Bscan_card_xy, width=6), dbc.Col(Bscan_card_zx, width=6)])
|
||||
], fluid=True)
|
||||
|
||||
#----------------definition interaction----------------
|
||||
@app.callback(
|
||||
Output('3dplot', 'figure'),
|
||||
[Input('iso-slider', 'value'),Input('y-slider', 'value')]
|
||||
)
|
||||
def update_3dplot(iso_value, y_values):
|
||||
y_min, y_max = y_values
|
||||
selected_volume = volume[0:dim_x, int(y_min):int(y_max), 0:dim_z]
|
||||
X, Y, Z = np.mgrid[0:selected_volume.shape[0], 0:selected_volume.shape[1], 0:selected_volume.shape[2]]
|
||||
|
||||
fig = go.Figure(data=go.Volume(
|
||||
x=X.flatten(),
|
||||
y=Y.flatten(),
|
||||
z=Z.flatten(),
|
||||
value=selected_volume.flatten(),
|
||||
isomin=iso_value,
|
||||
isomax=selected_volume.max(),
|
||||
opacity=0.1,
|
||||
surface_count=20,
|
||||
colorscale='Jet'
|
||||
))
|
||||
|
||||
return fig
|
||||
|
||||
@app.callback(
|
||||
Output('heatmap-ascan', 'figure'),
|
||||
[Input('layer-slider-ascan', 'value')]
|
||||
)
|
||||
def update_heatmap_ascan(layer):
|
||||
fig = px.line(y=volume[layer, :, 5], title='A-scan')
|
||||
return fig
|
||||
|
||||
return update_heatmap_ascan(volume, layer)
|
||||
|
||||
@app.callback(
|
||||
Output('heatmap-bscan-xy', 'figure'),
|
||||
[Input('layer-slider-bscan-xy', 'value')]
|
||||
)
|
||||
def update_heatmap_bscan_xy(layer):
|
||||
fig = px.imshow(volume[layer, :, :], color_continuous_scale='Jet', aspect='auto')
|
||||
|
||||
return fig
|
||||
|
||||
@app.callback(
|
||||
Output('heatmap-bscan-zx', 'figure'),
|
||||
[Input('layer-slider-bscan-zx', 'value')]
|
||||
)
|
||||
def update_heatmap_bscan_zx(layer):
|
||||
fig = go.Figure(data=go.Heatmap(
|
||||
z=volume[:, :, layer],
|
||||
colorscale='Jet'
|
||||
))
|
||||
|
||||
return fig
|
||||
|
||||
# Run the app
|
||||
if __name__ == '__main__':
|
||||
app.run_server(debug=True, port=8051)
|
Reference in New Issue
Block a user