Using viscircles in App Designer

9 visualizaciones (últimos 30 días)
Karen Eich Hammer
Karen Eich Hammer el 2 de Abr. de 2019
Comentada: Walter Roberson el 25 de Feb. de 2022
I am trying to use viscircles in App Designer. Is that possible?
I have a image (imshow) shown on my App, and I would like to draw the the circles on the image..
  4 comentarios
Karolin Guldevall
Karolin Guldevall el 25 de Feb. de 2022
I also have this problem. I just get this error message when trying to change my app made in GUIDE into App Designer.
"Error using uistack (line 72)
Functionality not supported with figures created with the uifigure function.
Error in viscircles (line 165)
uistack(thinCircHdl,'up');"
Are there any plans to update uistack to also work with figures in the new app designing environment?
Walter Roberson
Walter Roberson el 25 de Feb. de 2022
Unfortunately, the people who know about future plans are (mostly) not permitted to talk about those future plans.
(The people like the CEO, who is of course authorized to talk about nearly anything about plans... they rarely visit here.)

Iniciar sesión para comentar.

Respuestas (2)

N/A
N/A el 18 de Abr. de 2019
Editada: N/A el 19 de Abr. de 2019
I looked into it and changed the viscircles.m function a bit. Create a sepparate file named appviscircles.m and paste in the code below. Then, instead of calling viscircles, call appviscircles. It's the exact same thing as viscircles, but I got rid of the call to uistack and changed the hold to hold(ax, ...) so that there are no additional windows opening.
Tested on version 2018b Update 3.
function h = appviscircles(varargin)
varargin = matlab.images.internal.stringToChar(varargin);
[ax, centers, radii, options] = parseInputs(varargin{:});
if isempty(centers)
h = [];
return;
end
isHoldOn = ishold(ax);
hold(ax, 'on');
cObj = onCleanup(@()preserveHold(ax,isHoldOn)); % Preserve original hold state
thetaResolution = 2;
theta=(0:thetaResolution:360)'*pi/180;
x = bsxfun(@times,radii',cos(theta));
x = bsxfun(@plus,x,(centers(:,1))');
x = cat(1,x,nan(1,length(radii)));
x = x(:);
y = bsxfun(@times,radii',sin(theta));
y = bsxfun(@plus,y,(centers(:,2))');
y = cat(1,y,nan(1,length(radii)));
y = y(:);
% Create hggroup object that will contain the two circles as children
h = hggroup('Parent', ax);
if options.EnhanceVisibility
% Draw the thicker background white circle
thickEdgeColor = 'w';
thickLineWidth = options.LineWidth + 1;
if (strcmpi(options.LineStyle,'none'))
thickLineStyle = 'none';
else
thickLineStyle = '-';
end
line(x,y,'Parent',h, ...
'Color',thickEdgeColor, ...
'LineWidth',thickLineWidth, ...
'LineStyle',thickLineStyle);
% Bring the thin foreground circle on top
% uistack(thinCircHdl,'up');
end
% Draw the thinner foreground colored circle
line(ax,x,y,'Parent',h, ...
'Color',options.Color, ...
'LineWidth',options.LineWidth, ...
'LineStyle',options.LineStyle);
end
% -------------------------------------------------------------------------
function [ax, centers, radii, options] = parseInputs(varargin)
narginchk(2, 11);
needNewAxes = 0;
first_string = min(find(cellfun(@ischar, varargin), 1, 'first'));
if isempty(first_string)
first_string = length(varargin) + 1;
end
if first_string == 3
% viscircles(centers, radii)
needNewAxes = 1;
centers = varargin{1};
radii = varargin{2};
elseif first_string == 4
% viscircles(ax, centers, radii)
ax = varargin{1};
% ax = validateAxes(ax);
centers = varargin{2};
radii = varargin{3};
else
error(message('images:validate:invalidSyntax'))
end
% Handle remaining name-value pair parsing
name_value_pairs = varargin(first_string:end);
num_pairs = numel(name_value_pairs);
if (rem(num_pairs, 2) ~= 0)
error(message('images:validate:missingParameterValue'));
end
% Do not change the order of argument names listed below
args_names = {'Color','LineWidth','LineStyle','EnhanceVisibility'};
arg_default_values = {'red', 2, '-', true};
% Set default parameter values
for i = 1: numel(args_names)
options.(args_names{i}) = arg_default_values{i};
end
% Support for older arguments - do not change the order of argument names listed below
args_names = cat(2,args_names, {'EdgeColor', 'DrawBackgroundCircle'});
for i = 1:2:num_pairs
arg = name_value_pairs{i};
if ischar(arg)
idx = find(strncmpi(arg, args_names, numel(arg)));
if isempty(idx)
error(message('images:validate:unknownInputString', arg))
elseif numel(idx) > 1
error(message('images:validate:ambiguousInputString', arg))
elseif numel(idx) == 1
if(idx == 5) % If 'EdgeColor' is specified
idx = 1; % Map to 'Color'
elseif(idx == 6) % If 'DrawBackgroundCircle' is specified
idx = 4; % Map to 'EnhanceVisibility'
end
options.(args_names{idx}) = name_value_pairs{i+1};
end
else
error(message('images:validate:mustBeString'));
end
end
% Validate parameter values. Let LINE do the validation for EdgeColor,
% LineStyle and LineWidth.
[centers, radii] = validateCentersAndRadii(centers, radii, first_string);
options.EnhanceVisibility = validateEnhanceVisibility( ...
options.EnhanceVisibility);
% If required, create new axes after parsing
if(needNewAxes)
ax = gca;
end
end
% -------------------------------------------------------------------------
function preserveHold(ax, wasHoldOn)
% Function for preserving hold behavior on exit
if ~wasHoldOn
hold(ax, 'off')
end
end
function ax = validateAxes(ax)
if ~ishghandle(ax)
error(message('images:validate:invalidAxes','AX'))
end
objType = get(ax,'type');
if ~strcmp(objType,'axes')
error(message('images:validate:invalidAxes','AX'))
end
end
function [centers, radii] = validateCentersAndRadii(centers, radii, ...
first_string)
if(~isempty(centers))
validateattributes(centers,{'numeric'},{'nonsparse','real', ...
'ncols',2}, mfilename,'centers',first_string-2);
validateattributes(radii,{'numeric'},{'nonsparse','real','nonnegative', ...
'vector'}, mfilename,'radii',first_string-1);
if(size(centers,1) ~= length(radii))
error(message('images:validate:unequalNumberOfRows','CENTERS','RADII'))
end
centers = double(centers);
radii = double(radii(:)); % Convert to a column vector
end
end
function doEnhanceVisibility = validateEnhanceVisibility(doEnhanceVisibility)
if ~(islogical(doEnhanceVisibility) || isnumeric(doEnhanceVisibility)) ...
|| ~isscalar(doEnhanceVisibility)
error(message('images:validate:invalidLogicalParam', ...
'EnhanceVisibility', 'VISCIRCLES', 'EnhanceVisibility'))
end
doEnhanceVisibility = logical(doEnhanceVisibility);
end

Ali Mostaed
Ali Mostaed el 26 de Sept. de 2020
Yes. But you should make the 'EnhanceVisibility' option off:
e.g.:
viscircles(Center,Rad,'Color','r','EnhanceVisibility',false);

Categorías

Más información sobre Printing and Saving en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by