From 049d9b15304c5985c9b2b5c4191c21c5c27a48c3 Mon Sep 17 00:00:00 2001 From: Lewin Probst <info@emirror.de> Date: Wed, 27 Nov 2019 11:38:06 +0100 Subject: [PATCH] Added support for multiple point selection. --- .../+edit/+timeOfArrival/pickPoint.m | 36 ++++++++++++------- lib/+artoa/+controller/+edit/clearSelection.m | 6 +++- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/lib/+artoa/+controller/+edit/+timeOfArrival/pickPoint.m b/lib/+artoa/+controller/+edit/+timeOfArrival/pickPoint.m index d5a5596..932ebea 100644 --- a/lib/+artoa/+controller/+edit/+timeOfArrival/pickPoint.m +++ b/lib/+artoa/+controller/+edit/+timeOfArrival/pickPoint.m @@ -8,25 +8,35 @@ global artoaGui artoaWorkspace; artoa.controller.edit.timeOfArrival.dropSelection(); +%% Initialize variable +artoaGui.editTimeOfArrival.userSelection = {}; +artoaWorkspace.editTimeOfArrival.userSelection = []; + %% Select point by mouse [dx, dy, button] = ginput(1); -% find closest match -% calculate distance -distance = sqrt((artoaWorkspace.toaData.toaDate - dx).^2 + (artoaWorkspace.toaData.toa - dy).^2); -[~, index] = min(distance); -x_closest = artoaWorkspace.toaData.toaDate(index); -y_closest = artoaWorkspace.toaData.toa(index); - -if button ~= 1 - return; +while button == 1 + [x_closest, y_closest, index] = findClosestMatch(dx, dy); + + hold on; + artoaGui.editTimeOfArrival.userSelection{end + 1} = scatter(x_closest, y_closest, artoaWorkspace.defaults.pickPointMarkerSize, [0 0 0]); + hold off; + artoaWorkspace.editTimeOfArrival.userSelection = [ ... + artoaWorkspace.editTimeOfArrival.userSelection, ... + index + ]; + [dx, dy, button] = ginput(1); end -hold on; -artoaGui.editTimeOfArrival.userSelection = scatter(x_closest, y_closest, artoaWorkspace.defaults.pickPointMarkerSize, [0 0 0]); -hold off; -artoaWorkspace.editTimeOfArrival.userSelection = index; + function [x_closest, y_closest, index] = findClosestMatch(dx, dy) + % find closest match + % calculate distance + distance = sqrt((artoaWorkspace.toaData.toaDate - dx).^2 + (artoaWorkspace.toaData.toa - dy).^2); + [~, index] = min(distance); + x_closest = artoaWorkspace.toaData.toaDate(index); + y_closest = artoaWorkspace.toaData.toa(index); + end end diff --git a/lib/+artoa/+controller/+edit/clearSelection.m b/lib/+artoa/+controller/+edit/clearSelection.m index 4b8e802..24cce4b 100644 --- a/lib/+artoa/+controller/+edit/clearSelection.m +++ b/lib/+artoa/+controller/+edit/clearSelection.m @@ -7,7 +7,11 @@ workspaceStruct = pWorkspaceStruct; %% Remove selection from gui if isfield(guiHandle, 'userSelection') - delete(guiHandle.userSelection); + if iscell(guiHandle.userSelection) + cellfun(@delete, guiHandle.userSelection); + else + delete(guiHandle.userSelection); + end guiHandle = rmfield(guiHandle, 'userSelection'); end -- GitLab