-
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.
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.
- 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 | ||
% 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 |