Skip to content
Snippets Groups Projects
Commit 1d31c245 authored by leprob001's avatar leprob001
Browse files

Improvements to the selection modes in edit time of arrival window. The ginput...

Improvements to the selection modes in edit time of arrival window. The ginput method is not used anymore.
parent 1bf5c0ba
No related branches found
No related tags found
No related merge requests found
197
\ No newline at end of file
198
\ No newline at end of file
function [] = pickPoint()
function [] = pickPoint(src, ~)
%PICKPOINT Lets the user pick a point in the plot.
% Selection can be aborted by using the right mouse button.
global artoaGui artoaWorkspace artoaConfig;
%% Check if polygon is already selected
modeName = 'pickPoint';
%% Check for any active mode
if strcmp(artoaGui.editTimeOfArrival.currentInteractionMode, modeName)
% pickPoint mode is active, so finish the mode
closePickPointMode();
return;
end
if ~islogical(artoaGui.editTimeOfArrival.currentInteractionMode)
errordlg('Another interaction mode is currently active. Please finish it first!', 'Interaction mode error!');
return;
end
%% Set mode to pickPoint
openPickPointMode();
%% Check if polygon is already selected
artoa.controller.edit.timeOfArrival.dropSelection();
%% Initialize variable
artoaGui.editTimeOfArrival.userSelection = {};
artoaWorkspace.editTimeOfArrival.userSelection = [];
artoaWorkspace.editTimeOfArrival.userSelection = false(length(artoaWorkspace.toaData.toa), 1);
%% Select point by mouse
button = src;
[dx, dy, button] = ginput(1);
return
while button == 1
[x_closest, y_closest, index] = findClosestMatch(dx, dy);
%% Helper functions
hold on;
artoaGui.editTimeOfArrival.userSelection{end + 1} = scatter(x_closest, y_closest, artoaConfig.defaults.pickPointMarkerSize, [0 0 0]);
hold off;
artoaWorkspace.editTimeOfArrival.userSelection = [ ...
artoaWorkspace.editTimeOfArrival.userSelection, ...
index
];
[dx, dy, button] = ginput(1);
end
function openPickPointMode()
pan('off');
zoom('off');
brush('off');
artoaGui.editTimeOfArrival.axesScatterTimeOfArrival.ButtonDownFcn = @onPick;
artoaGui.editTimeOfArrival.scatterTimeOfArrival.ButtonDownFcn = @onDirectPick;
artoaGui.editTimeOfArrival.currentInteractionMode = modeName;
artoaGui.figures.editTimeOfArrival.Color = [.6 .6 .6];
artoaGui.figures.editTimeOfArrival.Pointer = 'cross';
src.String = 'Finish';
drawnow;
end
function closePickPointMode()
artoaGui.editTimeOfArrival.axesScatterTimeOfArrival.ButtonDownFcn = '';
artoaGui.editTimeOfArrival.scatterTimeOfArrival.ButtonDownFcn = '';
artoaGui.editTimeOfArrival.currentInteractionMode = false;
artoaGui.figures.editTimeOfArrival.Color = [.94 .94 .94];
artoaGui.figures.editTimeOfArrival.Pointer = 'arrow';
src.String = 'Point(s)';
drawnow;
end
function onDirectPick(~, event)
[x_closest, y_closest, index] = findClosestMatch(event.IntersectionPoint(1), event.IntersectionPoint(2));
if islogical(index)
return;
end
hold on;
artoaGui.editTimeOfArrival.userSelection{end + 1} = scatter( ...
x_closest, y_closest, ...
artoaConfig.defaults.pickPointMarkerSize, [0 0 0] ...
);
hold off;
artoaWorkspace.editTimeOfArrival.userSelection(index) = true;
button.String = ['Finish ' num2str(sum(artoaWorkspace.editTimeOfArrival.userSelection)) ' selected'];
end
function onPick(~, event)
[x_closest, y_closest, index] = findClosestMatch( ...
event.IntersectionPoint(1), event.IntersectionPoint(2) ...
);
if islogical(index)
return;
end
hold on;
artoaGui.editTimeOfArrival.userSelection{end + 1} = scatter(x_closest, y_closest, artoaConfig.defaults.pickPointMarkerSize, [0 0 0]);
hold off;
artoaWorkspace.editTimeOfArrival.userSelection(index) = true;
button.String = ['Finish ' num2str(sum(artoaWorkspace.editTimeOfArrival.userSelection)) ' selected'];
end
function [x_closest, y_closest, index] = findClosestMatch(dx, dy)
function [x_closest, y_closest, index] = findClosestMatch(dx, dy, ignoreDeleted)
if nargin == 2
ignoreDeleted = false;
end
% 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 ~ignoreDeleted & (artoaWorkspace.toaData.status(index) ~= 2)
return;
end
% reset output because the point is deleted
x_closest = false;
y_closest = false;
index = false;
end
end
......
function [] = pickPolygon()
function [] = pickPolygon(src, ~)
%PICKPOLYGON Lets the user pick a polygon in the plot.
% During selection, a line is being plotted that shows the selected
% points by the user.
......@@ -8,57 +8,139 @@ function [] = pickPolygon()
global artoaGui artoaWorkspace;
%% Check if polygon is already selected
modeName = 'pickPolygon';
%% Check for any active mode
if strcmp(artoaGui.editTimeOfArrival.currentInteractionMode, modeName)
% pickPoint mode is active, so finish the mode
closePickPolygonMode();
return;
end
if ~islogical(artoaGui.editTimeOfArrival.currentInteractionMode)
errordlg('Another interaction mode is currently active. Please finish it first!', 'Interaction mode error!');
return;
end
%% Set mode to pickPoint
openPickPolygonMode();
%% Check if polygon is already selected
artoa.controller.edit.timeOfArrival.dropSelection();
%% Select polygon by mouse
x = [];
y = [];
%% Initialize variable
artoaGui.editTimeOfArrival.userSelection = {};
artoaWorkspace.editTimeOfArrival.userSelection = false(length(artoaWorkspace.toaData.toa), 1);
%% Initialize polygon
artoaGui.editTimeOfArrival.tmpPolygon = struct();
artoaGui.editTimeOfArrival.tmpPolygon.x = [];
artoaGui.editTimeOfArrival.tmpPolygon.y = [];
% draw the line that will be extended on every click
artoaGui.editTimeOfArrival.userSelection = line( ...
NaN, NaN, 'Color', [0 0 0], 'LineStyle', '-' ...
);
[dx, dy, button] = ginput(1);
while button == 1
% get boundaries
bound = artoaGui.editTimeOfArrival.axesScatterTimeOfArrival.XLim;
dx = artoa.data.adjustToBoundaries(dx, bound(1), bound(2));
bound = artoaGui.editTimeOfArrival.axesScatterTimeOfArrival.YLim;
dy = artoa.data.adjustToBoundaries(dy, bound(1), bound(2));
% add values to array
x = [x; dx];
y = [y; dy];
if length(x) == 1
continue;
button = src;
return
%% Helper functions
function openPickPolygonMode()
pan('off');
zoom('off');
brush('off');
artoa.controller.edit.timeOfArrival.userCallbackFix();
set(artoaGui.figures.editTimeOfArrival, 'WindowButtonMotionFcn', @onMouseMove);
set(artoaGui.figures.editTimeOfArrival, 'WindowButtonDownFcn', @onMouseAxesDown);
artoaGui.editTimeOfArrival.currentInteractionMode = modeName;
artoaGui.figures.editTimeOfArrival.Color = [.6 .6 .6];
artoaGui.figures.editTimeOfArrival.Pointer = 'cross';
src.String = 'Finish';
drawnow;
end
% update the line
set(artoaGui.editTimeOfArrival.userSelection, 'XData', x, 'YData', y);
[dx, dy, button] = ginput(1);
end
% close the poligon by adding the first value as the last one
if length(x) > 3 % a polygon can only be closed if there are more than three values
x = [x; x(1)];
y = [y; y(1)];
else
[artoaGui.editTimeOfArrival, artoaWorkspace.editTimeOfArrival] = artoa.controller.edit.clearSelection(artoaGui.editTimeOfArrival, artoaWorkspace.editTimeOfArrival);
return;
end
% update the line
set(artoaGui.editTimeOfArrival.userSelection, 'XData', x, 'YData', y);
% store the selected points in the workspace for editing
artoaWorkspace.editTimeOfArrival.userSelection = inpolygon( ...
artoaWorkspace.toaData.toaDate, ...
artoaWorkspace.toaData.toa, ...
x, ...
y ...
);
function closePickPolygonMode()
finishPolygon();
set(artoaGui.figures.editTimeOfArrival, 'WindowButtonMotionFcn', '');
set(artoaGui.figures.editTimeOfArrival, 'WindowButtonDownFcn', '');
artoaGui.editTimeOfArrival.currentInteractionMode = false;
artoaGui.figures.editTimeOfArrival.Color = [.94 .94 .94];
artoaGui.figures.editTimeOfArrival.Pointer = 'arrow';
src.String = 'Polygon';
drawnow;
end
function onMouseAxesDown(src, ~)
currentPoint = artoaGui.editTimeOfArrival.axesScatterTimeOfArrival.CurrentPoint;
if strcmp(src.SelectionType, 'alt')
finishPolygon();
closePickPolygonMode();
return;
end
% get boundaries
bound = artoaGui.editTimeOfArrival.axesScatterTimeOfArrival.XLim;
dx = artoa.data.adjustToBoundaries(currentPoint(1, 1), bound(1), bound(2));
bound = artoaGui.editTimeOfArrival.axesScatterTimeOfArrival.YLim;
dy = artoa.data.adjustToBoundaries(currentPoint(1, 2), bound(1), bound(2));
% add values to array
artoaGui.editTimeOfArrival.tmpPolygon.x = [artoaGui.editTimeOfArrival.tmpPolygon.x; dx];
artoaGui.editTimeOfArrival.tmpPolygon.y = [artoaGui.editTimeOfArrival.tmpPolygon.y; dy];
button.String = ['Finish ' num2str(length(artoaGui.editTimeOfArrival.tmpPolygon.x)) ' selected'];
if length(artoaGui.editTimeOfArrival.tmpPolygon.x) == 1
return;
end
% update the line
set( ...
artoaGui.editTimeOfArrival.userSelection, ...
'XData', artoaGui.editTimeOfArrival.tmpPolygon.x, ...
'YData', artoaGui.editTimeOfArrival.tmpPolygon.y ...
);
end
function onMouseMove(~, ~)
if ~artoa.data.hasMember(artoaGui, 'editTimeOfArrival', 'tmpPolygon', 'x') ...
|| isempty(artoaGui.editTimeOfArrival.tmpPolygon.x)
return;
end
mousepoint = get(artoaGui.editTimeOfArrival.axesScatterTimeOfArrival, 'CurrentPoint');
set(artoaGui.editTimeOfArrival.userSelection, ...
'XData', [artoaGui.editTimeOfArrival.tmpPolygon.x; mousepoint(1, 1) - .1], ...
'YData', [artoaGui.editTimeOfArrival.tmpPolygon.y; mousepoint(1, 2) - .1] ...
);
drawnow;
end
function finishPolygon()
% close the poligon by adding the first value as the last one
if length(artoaGui.editTimeOfArrival.tmpPolygon.x) > 3 % a polygon can only be closed if there are more than three values
x = [artoaGui.editTimeOfArrival.tmpPolygon.x; artoaGui.editTimeOfArrival.tmpPolygon.x(1)];
y = [artoaGui.editTimeOfArrival.tmpPolygon.y; artoaGui.editTimeOfArrival.tmpPolygon.y(1)];
else
[artoaGui.editTimeOfArrival, artoaWorkspace.editTimeOfArrival] = artoa.controller.edit.clearSelection(artoaGui.editTimeOfArrival, artoaWorkspace.editTimeOfArrival);
return;
end
% update the line
set(artoaGui.editTimeOfArrival.userSelection, 'XData', x, 'YData', y);
% store the selected points in the workspace for editing
artoaWorkspace.editTimeOfArrival.userSelection = inpolygon( ...
artoaWorkspace.toaData.toaDate, ...
artoaWorkspace.toaData.toa, ...
x, ...
y ...
);
end
end
......@@ -15,6 +15,11 @@ if isfield(guiHandle, 'userSelection')
guiHandle = rmfield(guiHandle, 'userSelection');
end
if (isfield(guiHandle, 'tmpPolygon'))
guiHandle = rmfield(guiHandle, 'tmpPolygon');
end
%% Remove the selection field from workspace
if (isfield(workspaceStruct, 'userSelection'))
workspaceStruct = rmfield(workspaceStruct, 'userSelection');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment