-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #684 from aodn/handle_missing_drawrectangle
fix(graph): fallback for missing the image toolbox
- Loading branch information
Showing
2 changed files
with
53 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |