Trying to add callback function in class
Mostrar comentarios más antiguos
I am attempting to create a class the will have two line ROI objects. This class should have a callback function for when the lines are moved by the user. I am able to add a listener to the lines but only if the callback function is static.
Is it possible to do this without using a static method? Ultimatly I would like to use the callback method to compare the positions of the two lines as one of them is moved.
classdef imageRange < handle
properties
region double
line1
line2
rect
X double
end
methods
function obj = imageRange(axes, dataAxes)
x = dataAxes{1,4};
y = dataAxes{2,4};
midpoint = mean([x(1),x(3)]);
obj.X = floor(midpoint);
obj.rect = rectangle(axes,'Position',[obj.X,y(1),...
ceil(midpoint)-floor(midpoint), y(3) - y(1)]);
obj.rect.EdgeColor = [0,0,0,0];
obj.rect.FaceColor = [.5,.5,.5];
obj.rect.FaceAlpha = .1;
obj.line1 = drawline(axes,'Position',[floor(midpoint), y(1); ...
floor(midpoint), y(3)],'Color',[0.6350 0.0780 0.1840], ...
'InteractionsAllowed','translate', ...
'MarkerSize',.1, ...
'LineWidth',1);
addlistener(obj.line1, 'MovingROI', @(src,event)obj.allevents(src,event));
obj.line2 = drawline(axes,'Position',[ceil(midpoint), y(1); ...
ceil(midpoint), y(3)],'Color',[0 0.4470 0.7410], ...
'InteractionsAllowed','translate', ...
'MarkerSize',.1, ...
'LineWidth',1);
obj.region = dataAxes{1,5};
end
end
methods (Static)
function allevents(src,event)
event.PreviousPosition(1,1)
end
end
end
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Object Containers en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!