Skip to content

Commit

Permalink
fix(graph): fallback for missing the image toolbox
Browse files Browse the repository at this point in the history
The problem:

The `drawrectangle` function, which
extract user interactive click/drag
positions, is a proprietary function
of the image processing toolbox.
Hence, usage is limited to users that
are licensed to it.

The fix:

Include a fallback function for users
without the toolbox.

How is fixed:

The select_points function is restored
on the repository, modified as
a closure to handle the positional
extraction. It will call
`drawrectangle` if available, otherwise
it will extract the positions with
the previous/old code.
  • Loading branch information
ocehugo committed Nov 9, 2020
1 parent 64d4289 commit 6874436
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
4 changes: 1 addition & 3 deletions Graph/checkMooringPlannedDepths.m
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,7 @@ function checkMooringPlannedDepths(sample_data, isQC, saveToFile, exportDir)
uiwait(hMsgbox);

%select the area to use for comparison
rec = drawrectangle(hAxPress);
x = [rec.Position(1) rec.Position(1)+rec.Position(3)];
delete(rec);
[x, ~] = select_points(hAxPress);
iGood = timeVar >= x(1) & timeVar <= x(2);
end

Expand Down
52 changes: 52 additions & 0 deletions Util/select_points.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
function [x,y] = select_points(hAx)
% function [x,y] = select_points(hAx)
%
% Interactively draw a rectangle in
% the current axis and extract its own coordinates.
%
% Inputs:
%
% hAx [graphics.axis.Axes] - a Matlab Axis class
%
% Outputs:
%
% x [double] - a row vector of the start/end horizontal
% rectangle positions
% y [double] - a row vector of the start/end vertical
% rectangle positions.
%
% Example:
%
% %manual evaluation
% % [x,y] = drawrectangle(gca());
% % % draw or click with mose
% % assert(isnumerical(x));
% % assert(isnumerical(y));
%
%
% author: Rebecca Cowley
% hugo.oliveira@utas.edu.au
%
if isdeployed || license('test', 'Image_Toolbox')
rec = drawrectangle(hAx);
x = [rec.Position(1) rec.Position(1) + rec.Position(3)];
y = [rec.Position(2) rec.Position(2) + rec.Position(4)];
delete(rec);
else
axes(hAx);
k = waitforbuttonpress;
point1 = get(gca, 'CurrentPoint'); % button down detected
finalRect = rbbox; % return figure units
point2 = get(gca, 'CurrentPoint'); % button up detected
point1 = point1(1, 1:2); % extract x and y
point2 = point2(1, 1:2);
p1 = min(point1, point2); % calculate locations
offset = abs(point1 - point2); % and dimensions
x = [p1(1) p1(1) + offset(1) p1(1) + offset(1) p1(1) p1(1)];
y = [p1(2) p1(2) p1(2) + offset(2) p1(2) + offset(2) p1(2)];
hold on
axis manual
plot(x, y); % redraw in dataspace units
end

end

0 comments on commit 6874436

Please sign in to comment.