diff --git a/gui/roi/ieROIDraw.m b/gui/roi/ieROIDraw.m index 65a632e8..872cf9b7 100644 --- a/gui/roi/ieROIDraw.m +++ b/gui/roi/ieROIDraw.m @@ -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] @@ -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); @@ -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' diff --git a/main/ieAxisGet.m b/main/ieAxisGet.m new file mode 100644 index 00000000..2c44ae14 --- /dev/null +++ b/main/ieAxisGet.m @@ -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 diff --git a/tutorials/gui/t_ROIDraw.m b/tutorials/gui/t_ROIDraw.m index 06f60fa2..c5d4f37c 100644 --- a/tutorials/gui/t_ROIDraw.m +++ b/tutorials/gui/t_ROIDraw.m @@ -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 @@ -40,14 +35,16 @@ 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 @@ -55,12 +52,14 @@ 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