Clear Filters
Clear Filters

Extract information while drawing using polyline

37 views (last 30 days)
EL MOUSLIH
EL MOUSLIH on 25 Jul 2024
Answered: Shubham on 6 Aug 2024 at 8:43
Hello,
I want to draw a polyline in a figure, while drawing the polyline i want to extract the the previous position and the current position but while drawing not when the draw is finished, i tried to use event listener as shown in the code bellow
figure;
ax = axes;
% Draw a polyline interactively
roi = drawpolyline(ax);
addlistener(roi,'MovingROI',@allevents);
addlistener(roi,'ROIMoved',@allevents);
function allevents(~,evt)
evname = evt.EventName;
disp(selectionType)
switch(evname)
case{'MovingROI'}
disp(['ROI moving previous position: ' mat2str(evt.PreviousPosition)]);
disp(['ROI moving current position: ' mat2str(evt.CurrentPosition)]);
case{'ROIMoved'}
disp(['ROI moved previous position: ' mat2str(evt.PreviousPosition)]);
disp(['ROI moved current position: ' mat2str(evt.CurrentPosition)]);
end
end
This code works only after the polyline is finished drawing, I want to be while drawing,
Could you please resolve my Isuue ?
  1 Comment
dpb
dpb on 25 Jul 2024
I don't have the TB to play with, but the <Polyline> doc says need to call the <draw> method to start interactive drawing. I would suspect that will then trigger the callback functions. But, those will have to be registered prior to entering interactive mode.

Sign in to comment.

Answers (1)

Shubham
Shubham on 6 Aug 2024 at 8:43
Hi El,
As per my understanding, you want to know the current and previous position of the points while you are using the "drawpolyline" function.
As @dpb mentioned, the "Polyline" ROI object only triggers the event listeners and their callbacks once the drawing is finished. This means there is no way to use "Polyline" ROI event listeners to capture the points' positions before you complete the "Polyline" ROI drawing.
However, you can set the "WindowButtonDownFcn" callback on the parent figure and define your custom logic to extract the coordinates of the points wherever the user clicks. This approach allows you to capture the points' positions in real-time as the user clicks to add points to the "Polyline" ROI.
For more information about "drawpolyline", refer to the documentation link:
Hope it helps!
Regards,
Shubham

Community Treasure Hunt

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

Start Hunting!