From 46ac5dfe84e10f120260ffeed6633607d116dc4f Mon Sep 17 00:00:00 2001 From: Markus Leuthold Date: Thu, 14 Sep 2023 11:31:09 +0200 Subject: [PATCH] examples, comments --- examples/example_callbacks.m | 28 ++++++++++++++++++++++++++++ examples/example_new_axes_creation.m | 6 +++--- readme.md | 16 ++++++++++------ src/+gfx/+internal/Orbit3d.m | 19 ++++++++++--------- src/+gfx/orbit3d.m | 6 +++--- 5 files changed, 54 insertions(+), 21 deletions(-) create mode 100644 examples/example_callbacks.m diff --git a/examples/example_callbacks.m b/examples/example_callbacks.m new file mode 100644 index 0000000..bdbd502 --- /dev/null +++ b/examples/example_callbacks.m @@ -0,0 +1,28 @@ +hGrid = uigridlayout([1 2]); +hGrid.Parent.Name = "Orbit3d for multiple axes (Press h for help)"; + +hAxes1 = uiaxes("Parent", hGrid); +hAxes2 = uiaxes("Parent", hGrid); + +gfx.orbit3d(hAxes1); +gfx.orbit3d(hAxes2); + +mesh = load('trimesh3d'); + +hPatch1 = patch("parent", hAxes1, "Vertices", [mesh.x mesh.y mesh.z], "Faces", mesh.tri, "FaceColor", "y"); +hPatch2 = patch("parent", hAxes2, "Vertices", [mesh.x mesh.y mesh.z], "Faces", mesh.tri, "FaceColor", "r"); + +% right click on first axes changes mesh color +gfx.FigureEventDispatcher.addAxesEvent(... + "WindowMousePress", @(~,~)set(hPatch1, 'FaceColor', rand(1, 3)), ... + hAxes1, @(f,~)f.SelectionType == "alt"); + +% pressing v toggles hAxes1 visibility, no matter what is the current object +gfx.FigureEventDispatcher.addFigureEvent(... + "KeyPress", @(~,ev)toggleAxesVisibility(hAxes1, ev.Key), hGrid.Parent); + +function toggleAxesVisibility(hAxes, key) +if isequal(key, 'v') + hAxes.Visible = ~ hAxes.Visible; +end +end \ No newline at end of file diff --git a/examples/example_new_axes_creation.m b/examples/example_new_axes_creation.m index c6fdd3a..1b722e4 100644 --- a/examples/example_new_axes_creation.m +++ b/examples/example_new_axes_creation.m @@ -1,13 +1,13 @@ mesh = load('trimesh3d'); %% equivalent to cla(): create a new figure with a new axes if no figure exists yet -gfx.clearOrNewUiAxes3d +gfx.clearUiAxes3d; patch("Vertices", [mesh.x mesh.y mesh.z], "Faces", mesh.tri, "FaceColor", "y"); %% equivalent to figure(): always create a new figure -gfx.newUiAxes3d; +gfx.newUiFigure3d; patch("Vertices", [mesh.x mesh.y mesh.z], "Faces", mesh.tri, "FaceColor", "r"); %% equivalent to cla(): clear the red mesh of the current figure and plot a new blue one -gfx.clearOrNewUiAxes3d; +gfx.clearUiAxes3d; patch("Vertices", [mesh.x mesh.y mesh.z], "Faces", mesh.tri, "FaceColor", "b"); diff --git a/readme.md b/readme.md index 0f00c7d..71f1e57 100644 --- a/readme.md +++ b/readme.md @@ -3,19 +3,19 @@ User-friendly, feature rich replacement of Matlab's `cameratoolbar` Matlab lacks a powerful and user friendly interactive tool to handle 3d objects in a plot. Matlab's own `cameratoolbar` doesn't allow to zoom in/out with the scroll wheel, does not set the light properly and has a quite esoteric orbit function. Furthermore, as of Matlab 2022a, `cameratoolbar` does not support the new web-based `uiaxes` -This toolbox implements a quaternion based 3d orbit. Multiple axes are supported, thanks to a newly implemented per-axes (rather than Matlab's own per-figure) event handler. +This toolbox implements a quaternion based 3d orbit. Multiple axes are supported, thanks to a newly implemented per-axes (rather than Matlab's own per-figure) event handler. Both the old java based and the new web based figures/axes are supported. ## Features |Event|Action | |--|--| -|Right click & move | Rotate objects | -|Right double-click| Set rotation center| -|Left click |User defined callback | +|Left-click & move | Rotate objects | +|Double-click | Set rotation center| +|Right-click |User defined callback | |Scroll wheel |Zoom towards to/away from mouse pointer | |Key r |Reset view | |Key t |Toggle transparency of selected obj | |Key w |Toggle wireframe of selected patch | -|Key c|Toggle color of selected obj | +|Key c |Toggle color of selected obj | |Key h |Show help | ## Example code @@ -33,7 +33,11 @@ This toolbox implements a quaternion based 3d orbit. Multiple axes are supported "Faces", mesh.tri, ... "FaceColor", "y"); -Please find more examples in the folder `examples` +Please find more examples in the folder `examples` about the following topics +* Simple 3d orbit +* Multiple uiaxes +* Per-figure and per-axes callbacks +* gca/gcf/clf/cla replacements for uiaxes/uifigure containing a 3d orbit ## Installation diff --git a/src/+gfx/+internal/Orbit3d.m b/src/+gfx/+internal/Orbit3d.m index 406d6ab..7f553bf 100644 --- a/src/+gfx/+internal/Orbit3d.m +++ b/src/+gfx/+internal/Orbit3d.m @@ -3,9 +3,9 @@ % o3d = gfx.internal.Orbit3d; % % USER INTERACTIONS - % Right mouse click & move: Rotate objects - % Right double-click: Set rotation center - % Left click: User defined callback + % Left mouse click & move: Rotate objects + % Double click: Set rotation center + % Right click: User defined callback % Scroll wheel: Zoom towards to/away from mouse pointer % Key r: Reset view % Key t: Toggle transparency of selected obj @@ -286,12 +286,13 @@ function toggleColor(~, hObj) function toggleHelp(~, hFig) hHelp = findobj(hFig, "Tag", "help"); if isempty(hHelp) - uilabel("Parent",hFig,"Text","right click: rotate obj", "Position", [10 10 200 20], "Tag","help"); - uilabel("Parent",hFig,"Text","double right click: set new rotation center", "Position", [10 30 300 20], "Tag","help"); - uilabel("Parent",hFig,"Text","r: reset view", "Position", [10 50 200 20], "Tag","help"); - uilabel("Parent",hFig,"Text","w: wireframe", "Position", [10 70 200 20], "Tag","help"); - uilabel("Parent",hFig,"Text","c: next color", "Position", [10 90 200 20], "Tag","help"); - uilabel("Parent",hFig,"Text","t: transparency", "Position", [10 110 200 20], "Tag","help"); + uilabel("Parent",hFig,"Text","left click & move: rotate obj", "Position", [10 10 200 20], "Tag","help"); + uilabel("Parent",hFig,"Text","double click: set new rotation center", "Position", [10 30 300 20], "Tag","help"); + uilabel("Parent",hFig,"Text","scroll wheel: zoom", "Position", [10 50 300 20], "Tag","help"); + uilabel("Parent",hFig,"Text","r: reset view", "Position", [10 70 200 20], "Tag","help"); + uilabel("Parent",hFig,"Text","w: wireframe", "Position", [10 90 200 20], "Tag","help"); + uilabel("Parent",hFig,"Text","c: next color", "Position", [10 110 200 20], "Tag","help"); + uilabel("Parent",hFig,"Text","t: transparency", "Position", [10 130 200 20], "Tag","help"); else delete(hHelp) end diff --git a/src/+gfx/orbit3d.m b/src/+gfx/orbit3d.m index e8ade69..56fb950 100644 --- a/src/+gfx/orbit3d.m +++ b/src/+gfx/orbit3d.m @@ -3,9 +3,9 @@ function orbit3d(hAxes) % gfx.orbit3d(hAxes); % % USER INTERACTIONS -% Right mouse click & move: Rotate objects -% Right double-click: Set rotation center -% Left click: User defined callback +% Left mouse click & move: Rotate objects +% Double click: Set rotation center +% Right click: User defined callback % Scroll wheel: Zoom towards to/away from mouse pointer % Key r: Reset view % Key t: Toggle transparency of selected obj