From 6874436f516f7de043dfb31b1c8be4b0f5af12e7 Mon Sep 17 00:00:00 2001 From: Hugo Oliveira Date: Mon, 31 Aug 2020 15:34:51 +1000 Subject: [PATCH] fix(graph): fallback for missing the image toolbox 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. --- Graph/checkMooringPlannedDepths.m | 4 +-- Util/select_points.m | 52 +++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 Util/select_points.m diff --git a/Graph/checkMooringPlannedDepths.m b/Graph/checkMooringPlannedDepths.m index 4ece21b45..71e32c2bc 100644 --- a/Graph/checkMooringPlannedDepths.m +++ b/Graph/checkMooringPlannedDepths.m @@ -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 diff --git a/Util/select_points.m b/Util/select_points.m new file mode 100644 index 000000000..1577529cc --- /dev/null +++ b/Util/select_points.m @@ -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