Skip to content

Commit

Permalink
Merge pull request #684 from aodn/handle_missing_drawrectangle
Browse files Browse the repository at this point in the history
fix(graph): fallback for missing the image toolbox
  • Loading branch information
lbesnard authored Nov 27, 2020
2 parents 44e043b + 6874436 commit c6e3db8
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
% [email protected]
%
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 c6e3db8

Please sign in to comment.