Skip to content

Commit

Permalink
examples, comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Leuthold committed Sep 14, 2023
1 parent df9b09b commit 46ac5df
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 21 deletions.
28 changes: 28 additions & 0 deletions examples/example_callbacks.m
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions examples/example_new_axes_creation.m
Original file line number Diff line number Diff line change
@@ -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");
16 changes: 10 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
19 changes: 10 additions & 9 deletions src/+gfx/+internal/Orbit3d.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/+gfx/orbit3d.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 46ac5df

Please sign in to comment.