Mouse click callback trigger while drawroifreehand active

13 views (last 30 days)
I am trying to trigger the mouse click callback on my axes/figure while the drawfreehand function is active. This is for a masking tool I have made in app designer and was hoping to have the software differentiate between a left click (add to mask) and a right click (remove region from mask). The ROI object that results from the drawfreehand is converted to a mask and via logical indexing of the alpha map data in the axes, I either assign the transparency value or a zero so that the region shows up as not masked.
Currently developing this tool in 2022a.
Below is a snippet showing the DrawROI function that I have working recursively so the user can continue to draw regions in the axes to update the masked region(s). The roi handle object is deleted at the start so that the axes dont get overloaded with roi objects.
My buttonDownFcn for the image object in axes is AdjustOn
function DrawROI(app)
% DRAWROI will create the masked region encapsulated by the
% drawn ROI. Values are set according to set mode
try
uiresume(app.UIFigure)
if ~isempty(app.SetMode) && isvalid(app.ax2) && app.EditMode == 3
app.ClearROI
% Only allows the user to draw a freehand while in the
% axes to prevent out of bounds drawing
app.roiH = drawfreehand(app.ax2, 'DrawingArea', [1 1 app.N, app.M]);
app.UpdateUndoStack
app.Points2Mask
app.DrawROI
end
catch ME
id = ME.identifier;
if ~strcmp(id, 'MATLAB:class:InvalidHandle')
throw(ME)
end
end
end
function AdjustOn(app, ~, event)
% ADJUSTON will enable the mask editing and make the initial
% mask edit when the click is first made
switch event.Button
% A left click will add to the mask and a right click will
% subtract from the click - allows for fast edits in place of needing extra buttons in GUI
case 1
app.SetMode = 1;
case 3
app.SetMode = -1;
end
uiresume(app.UIFigure)
% Gets the mask before an edit is done to allow user to undo
% changes
app.UpdateUndoStack
if app.EditMode == 1
% Touches up by changing a single region
app.ClickHeld = true;
app.TouchUpMask
elseif app.EditMode == 2
% Masks a single point
app.ClickHeld = true;
app.PaintPoint
elseif app.EditMode == 4
% Masks the region selected by the animated line
app.ClickHeld = true;
if ~isempty(app.CursorROI)
set(app.CursorROI, 'FaceAlpha', 1)
set(app.CursorROI, 'Color', app.cmask(2,:))
end
app.TurboPaint
elseif app.EditMode == 5
app.ClickHeld = true;
app.SeedGrow
end
end

Answers (1)

Sugandhi
Sugandhi on 24 Aug 2023
Hi,
I understand that you are trying to trigger the mouse click callback on my axes/figure while the 'drawfreehand' function is active.
To trigger the mouse, click callback on your axes/figure while the 'drawfreehand' function is active, use the 'WindowButtonDownFcn' property of the figure or axes. This property allows you to define a callback function that will be executed when a mouse button is pressed.
By setting the 'WindowButtonDownFcn' or 'ButtonDownFcn' property and defining the corresponding callback function, you can differentiate between left and right clicks while the 'drawfreehand' function is active and perform the desired actions accordingly.
For more understanding, kindly go through following links:

Community Treasure Hunt

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

Start Hunting!