Skip to content

Commit

Permalink
Improving the ROI drawing code
Browse files Browse the repository at this point in the history
  • Loading branch information
wandell committed Jan 26, 2020
1 parent e55868b commit eb05768
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 34 deletions.
28 changes: 9 additions & 19 deletions gui/roi/ieROIDraw.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
% window.
%
% Inputs:
% isetobj: Type of object ('scene','oi','sensor','ip', or 'display')
% isetobj: An ISETCam object type ('scene','oi','sensor','ip', or
% 'display') or just the string. If just the string, (e.g., 'ip')
% then the routine gets the currently selected object from the
% database environment.
%
% Key/val pairs
% Key/val pairs:
% shape: Type of shape ('rect')
% shape data: Values needed to draw the shape
% rect = [row col width height]
Expand Down Expand Up @@ -50,10 +53,12 @@
delete(shapeHandle);
%}

%%
varargin = ieParamFormat(varargin);

p = inputParser;
p.addRequired('isetobj',@ischar);
vFunc = @(x)(ischar(x) || (isstruct(x) && isfield(x,'type')));
p.addRequired('isetobj',vFunc);
p.addParameter('shape','rect',@ischar);
p.addParameter('shapedata',[1 1 5 5],@isnumeric);
p.addParameter('color','w',@ischar);
Expand All @@ -63,24 +68,9 @@
p.parse(isetobj,varargin{:});
shape = p.Results.shape;

%% Get the current axis for that iset object type

switch isetobj
case 'scene'
ax = get(sceneWindow,'CurrentAxes');
case 'oi'
ax = get(oiWindow,'CurrentAxes');
case 'sensor'
ax = get(sensorImageWindow,'CurrentAxes');
case 'ip'
ax = get(ipWindow,'CurrentAxes');
case 'display'
ax = get(displayWindow,'CurrentAxes');
otherwise
error('Unknown iset object type %s\n',isetobj);
end

%% Draw the shape
ax = ieAxisGet(isetobj);

switch shape
case 'rect'
Expand Down
52 changes: 52 additions & 0 deletions main/ieAxisGet.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
function ax = ieAxisGet(obj,varargin)
% Return the image axis in a window of one of the major ISETCam types
%
% Syntax
% ax = ieAxisGet(obj,varargin)
%
% Inputs
% obj - Either a string or an ISETCam object with a .type slot
%
% Optional key/value pair
% N/A
%
% Returns
% ax - Handle to the axis in the window
%
% Wandell, January 24 2020
%
% See also
%

%%
% varargin = ieParamFormat(varargin);

p = inputParser;
vFunc = @(x)(ischar(x) || (isstruct(x) && isfield(x,'type')));
p.addRequired('isetobj',vFunc);

%% Get the type string if it is a struct

if isstruct(obj)
tmp = obj; clear obj;
obj = vcEquivalentObjtype(tmp.type);
end

%% Switch through the cases

switch lower(vcEquivalentObjtype(obj))
case 'scene'
ax = get(sceneWindow,'CurrentAxes');
case 'opticalimage'
ax = get(oiWindow,'CurrentAxes');
case 'isa'
ax = get(sensorImageWindow,'CurrentAxes');
case 'vcimage'
ax = get(ipWindow,'CurrentAxes');
case 'display'
ax = get(displayWindow,'CurrentAxes');
otherwise
error('Unknown iset object type %s\n',isetobj);
end

end
29 changes: 14 additions & 15 deletions tutorials/gui/t_ROIDraw.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,20 @@

%% Create the baseline windows

scene = sceneCreate;
sceneWindow(scene);

oi = oiCreate;
oi = oiCompute(oi,scene);
oiWindow(oi);
sensor = sensorCreate;
sensor = sensorCompute(sensor,oi);
sensorWindow(sensor);
ip = ipCreate;
ip = ipCompute(ip,sensor);
ipWindow(ip);
scene = sceneCreate; ieAddObject(scene);

oi = oiCreate; oi = oiCompute(oi,scene); ieAddObject(oi);

sensor = sensorCreate; sensor = sensorCompute(sensor,oi); ieAddObject(sensor);

ip = ipCreate; ip = ipCompute(ip,sensor); ieAddObject(ip);

%% Rect on a scene

scene = sceneCreate;
rect = [20 50 10 5]; % row, col, width, height
shapeHandle = ieROIDraw('scene','shape','rect','shape data',rect,'line width',5);
shapeHandle.LineStyle = ':';
pause(1);
delete(shapeHandle);

%% Rect on an oi
Expand All @@ -40,27 +35,31 @@
shapeHandle = ieROIDraw('oi','shape','rect','shape data',rect);
shapeHandle.LineStyle = ':';
shapeHandle.EdgeColor = 'w';
pause(1)
delete(shapeHandle);

%% Circle on an oi

c = [10 20 20];
c = [15 30 20]; % Radius, row, col
shapeHandle = ieROIDraw('oi','shape','circle','shape data',c);
shapeHandle.LineStyle = ':';
shapeHandle.EdgeColor = 'w';
shapeHandle.Color = 'w';
pause(1)
delete(shapeHandle);

%% Circle on a sensor

c = [10 20 20];
shapeHandle = ieROIDraw('sensor','shape','circle','shape data',c);
shapeHandle.Color = 'w';
pause(1)
delete(shapeHandle);

%% Rect on an IP
rect = [50 50 20 20];
[shapeHandle,ax] = ieROIDraw('ip','shape','rect','shape data',rect);
shapeHandle.EdgeColor = 'g';
pause(1)
delete(shapeHandle);

%% End
Expand Down

0 comments on commit eb05768

Please sign in to comment.