Mentions légales du service

Skip to content
Snippets Groups Projects
Commit cfd554d5 authored by DEBREUVE Eric's avatar DEBREUVE Eric
Browse files

added slider to select isovalue for 3d gfp view

parent 27c54263
No related branches found
No related tags found
No related merge requests found
...@@ -61,6 +61,7 @@ class soma_validation_window_t: ...@@ -61,6 +61,7 @@ class soma_validation_window_t:
"main_window", "main_window",
"three_d_selector", "three_d_selector",
"mip_axis_wgt", "mip_axis_wgt",
"isovalue_wgt",
"gfp_wgt", "gfp_wgt",
"gfp_3d_wgt", "gfp_3d_wgt",
"lmap_wgt", "lmap_wgt",
...@@ -71,6 +72,7 @@ class soma_validation_window_t: ...@@ -71,6 +72,7 @@ class soma_validation_window_t:
main_window: tknt.Tk main_window: tknt.Tk
three_d_selector: tknt.Checkbutton three_d_selector: tknt.Checkbutton
mip_axis_wgt: tknt.Menubutton mip_axis_wgt: tknt.Menubutton
isovalue_wgt: tknt.Scale
gfp_wgt: mip_widget_t gfp_wgt: mip_widget_t
gfp_3d_wgt: Optional[three_d_widget_t] gfp_3d_wgt: Optional[three_d_widget_t]
lmap_wgt: mip_widget_t lmap_wgt: mip_widget_t
...@@ -114,6 +116,7 @@ class soma_validation_window_t: ...@@ -114,6 +116,7 @@ class soma_validation_window_t:
resizeable=True, resizeable=True,
parent=main_window, parent=main_window,
) )
isovalue_wgt = None
gfp_3d_wgt = None gfp_3d_wgt = None
lmap_3d_wgt = None lmap_3d_wgt = None
state_variable = tknt.IntVar() state_variable = tknt.IntVar()
...@@ -149,7 +152,7 @@ class soma_validation_window_t: ...@@ -149,7 +152,7 @@ class soma_validation_window_t:
lmap_wgt.grid( lmap_wgt.grid(
row=next_available_row, column=1, sticky=tknt.W + tknt.E + tknt.N + tknt.S row=next_available_row, column=1, sticky=tknt.W + tknt.E + tknt.N + tknt.S
) )
next_available_row += 1 next_available_row += 2 # Leave one row free for isovalue slider
cursor_nfo.grid(row=next_available_row, column=0) cursor_nfo.grid(row=next_available_row, column=0)
done_button.grid(row=next_available_row, column=1) done_button.grid(row=next_available_row, column=1)
...@@ -217,19 +220,47 @@ class soma_validation_window_t: ...@@ -217,19 +220,47 @@ class soma_validation_window_t:
else: else:
gfp = self.gfp_wgt.image gfp = self.gfp_wgt.image
lmap = self.lmap_wgt.image lmap = self.lmap_wgt.image
self.gfp_3d_wgt = three_d_widget_t( gfp_min = nmpy.amin(gfp)
gfp, INITIAL_RELATIVE_ISOVALUE * nmpy.amax(gfp), self.main_window gfp_max = nmpy.amax(gfp)
) gfp_extent = gfp_max - gfp_min
self.lmap_3d_wgt = three_d_widget_t(lmap, 0.5, self.main_window)
isovalue_variable = tknt.DoubleVar()
isovalue_variable.set(INITIAL_RELATIVE_ISOVALUE * gfp_max)
self.gfp_3d_wgt = three_d_widget_t(gfp, self.main_window)
self.lmap_3d_wgt = three_d_widget_t(lmap, self.main_window)
self.gfp_3d_wgt.ComputeAndPlotIsosurface(isovalue_variable)
self.lmap_3d_wgt.ComputeAndPlotIsosurface(0.5)
self.gfp_3d_wgt.AddCompanionAxes(self.lmap_3d_wgt.axes) self.gfp_3d_wgt.AddCompanionAxes(self.lmap_3d_wgt.axes)
self.lmap_3d_wgt.AddCompanionAxes(self.gfp_3d_wgt.axes) self.lmap_3d_wgt.AddCompanionAxes(self.gfp_3d_wgt.axes)
self.isovalue_wgt = tknt.Scale(
self.main_window,
orient="horizontal",
from_=gfp_min + 0.1 * gfp_extent,
to=gfp_max - 0.1 * gfp_extent,
resolution=0.8 * gfp_extent / 100.0,
tickinterval=0.8 * gfp_extent / 10.0,
variable=isovalue_variable,
label="Isovalue",
)
self.isovalue_wgt.set(isovalue_variable.get())
ChangeIsovalue = (
lambda *args, **kwargs: self.gfp_3d_wgt.ComputeAndPlotIsosurface(
isovalue_variable
)
)
isovalue_variable.trace_add("write", ChangeIsovalue)
self.gfp_3d_wgt.grid( self.gfp_3d_wgt.grid(
row=1, column=0, sticky=tknt.W + tknt.E + tknt.N + tknt.S row=1, column=0, sticky=tknt.W + tknt.E + tknt.N + tknt.S
) )
self.lmap_3d_wgt.grid( self.lmap_3d_wgt.grid(
row=1, column=1, sticky=tknt.W + tknt.E + tknt.N + tknt.S row=1, column=1, sticky=tknt.W + tknt.E + tknt.N + tknt.S
) )
self.isovalue_wgt.grid(
row=2, column=0, sticky=tknt.W + tknt.E + tknt.N + tknt.S
)
self.invisible_widgets = soon_invisible_widgets self.invisible_widgets = soon_invisible_widgets
if three_d_state == 0: if three_d_state == 0:
...@@ -396,7 +427,6 @@ class three_d_widget_t(tknt.Frame): ...@@ -396,7 +427,6 @@ class three_d_widget_t(tknt.Frame):
def __init__( def __init__(
self, self,
image: array_t, image: array_t,
value: float,
parent: Union[tknt.Widget, tknt.Tk], parent: Union[tknt.Widget, tknt.Tk],
/, /,
*args, *args,
...@@ -413,17 +443,11 @@ class three_d_widget_t(tknt.Frame): ...@@ -413,17 +443,11 @@ class three_d_widget_t(tknt.Frame):
class_=self.__class__.__name__, class_=self.__class__.__name__,
) )
vertices, triangles, *_ = sims.marching_cubes(image, level=value, step_size=2)
figure = figure_t() figure = figure_t()
axes = figure.add_subplot(111, projection=axes_3d_t.name) axes = figure.add_subplot(111, projection=axes_3d_t.name)
axes.plot_trisurf( axes.set_xlabel("First")
vertices[:, 0], axes.set_ylabel("Second")
vertices[:, 1], axes.set_zlabel("Third")
triangles,
vertices[:, 2],
cmap="Spectral",
lw=1,
)
plot_wgt = matplotlib_widget_t(figure, master=self) plot_wgt = matplotlib_widget_t(figure, master=self)
plot_wgt.draw() plot_wgt.draw()
...@@ -431,21 +455,51 @@ class three_d_widget_t(tknt.Frame): ...@@ -431,21 +455,51 @@ class three_d_widget_t(tknt.Frame):
toolbar = toolbar_widget_t(plot_wgt, self, pack_toolbar=False) toolbar = toolbar_widget_t(plot_wgt, self, pack_toolbar=False)
toolbar.update() toolbar.update()
toolbar.pack(side=tknt.BOTTOM, fill=tknt.X)
plot_wgt.get_tk_widget().pack(fill=tknt.BOTH, expand=True) plot_wgt.get_tk_widget().pack(fill=tknt.BOTH, expand=True)
toolbar.pack(side=tknt.BOTTOM, fill=tknt.X)
self.image = image
self.vertices = vertices
self.triangles = triangles
self.figure = figure self.figure = figure
self.axes = axes self.axes = axes
self.vertices = None
self.triangles = None
self.isosurface = None
self.companion_axes = None self.companion_axes = None
self.live_synchronization = False self.live_synchronization = False
self.synchronization_context = None self.synchronization_context = None
self.motion_event_id = None self.motion_event_id = None
self.button_release_id = None self.button_release_id = None
self.plot_wgt = plot_wgt self.plot_wgt = plot_wgt
self.toolbar = toolbar self.toolbar = toolbar
def ComputeAndPlotIsosurface(self, isovalue: Union[float, tknt.DoubleVar]) -> None:
""""""
if self.isosurface is not None:
self.isosurface.remove()
if isinstance(isovalue, tknt.DoubleVar):
isovalue = isovalue.get()
vertices, triangles, *_ = sims.marching_cubes(
self.image, level=isovalue, step_size=2
)
isosurface = self.axes.plot_trisurf(
vertices[:, 0],
vertices[:, 1],
triangles,
vertices[:, 2],
cmap="Spectral",
lw=1,
)
self.vertices = vertices
self.triangles = triangles
self.isosurface = isosurface
self.figure.canvas.draw_idle()
def AddCompanionAxes( def AddCompanionAxes(
self, axes: pypl.Axes, /, *, live_synchronization: bool = False self, axes: pypl.Axes, /, *, live_synchronization: bool = False
) -> None: ) -> None:
...@@ -609,7 +663,7 @@ def _Synchronize3DViews(context, source: pypl.Axes, target: pypl.Axes) -> None: ...@@ -609,7 +663,7 @@ def _Synchronize3DViews(context, source: pypl.Axes, target: pypl.Axes) -> None:
"""""" """"""
if context in source._rotate_btn: if context in source._rotate_btn:
target.view_init(elev=source.elev, azim=source.azim) target.view_init(elev=source.elev, azim=source.azim)
elif scontext in source._zoom_btn: elif context in source._zoom_btn:
target.set_xlim3d(source.get_xlim3d()) target.set_xlim3d(source.get_xlim3d())
target.set_ylim3d(source.get_ylim3d()) target.set_ylim3d(source.get_ylim3d())
target.set_zlim3d(source.get_zlim3d()) target.set_zlim3d(source.get_zlim3d())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment