From 79fbc6dd60ba14a982dabe8787b7d039c0249207 Mon Sep 17 00:00:00 2001
From: Lewin Probst <info@emirror.de>
Date: Sun, 26 Apr 2020 15:28:22 +0200
Subject: [PATCH] The tracking method can now be selected in the soundsource
 combination table.

---
 VERSION                                       |  2 +-
 lib/+artoa/+controller/+main/open.m           |  1 -
 .../+parameter/comboboxTrackingMethod.m       | 16 ----------
 .../+parameter/createCombinationsTable.m      |  3 +-
 .../+parameter/getDefaultCombinationCell.m    |  3 +-
 .../+parameter/validateCombinationsInput.m    |  6 ++++
 .../updateTableGeneratedTracks.m              |  2 +-
 lib/+artoa/+gui/main.m                        | 29 +++++++------------
 lib/+artoa/+trajectory/calculate.m            |  3 +-
 .../+trajectory/calculateCombinationSegment.m | 16 +++-------
 .../+versioning/+migrations/versions/v4183.m  | 10 +++++++
 11 files changed, 38 insertions(+), 53 deletions(-)
 delete mode 100644 lib/+artoa/+controller/+track/+parameter/comboboxTrackingMethod.m
 create mode 100644 lib/+artoa/+versioning/+migrations/versions/v4183.m

diff --git a/VERSION b/VERSION
index cd00472..80945bc 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-182
\ No newline at end of file
+183
\ No newline at end of file
diff --git a/lib/+artoa/+controller/+main/open.m b/lib/+artoa/+controller/+main/open.m
index a68584f..3410aa5 100644
--- a/lib/+artoa/+controller/+main/open.m
+++ b/lib/+artoa/+controller/+main/open.m
@@ -32,7 +32,6 @@ callbacks.openTrackTrajectoryOutput = @artoa.controller.track.trajectoryOutput.o
 callbacks.switchHideDeletedDataPoints = @artoa.controller.switchHideDeletedPoints;
 
 %% Prepare callbacks for track parameter
-callbacks.comboboxTrackingMethod = @artoa.controller.track.parameter.comboboxTrackingMethod;
 callbacks.checkboxDopplerCorrection = @artoa.controller.track.parameter.checkboxDopplerCorrection;
 callbacks.comboboxInterpolationMethod = @artoa.controller.track.parameter.comboboxInterpolationMethod;
 callbacks.comboboxSoundspeedMethod = @artoa.controller.track.parameter.comboboxSoundspeedMethod;
diff --git a/lib/+artoa/+controller/+track/+parameter/comboboxTrackingMethod.m b/lib/+artoa/+controller/+track/+parameter/comboboxTrackingMethod.m
deleted file mode 100644
index bbbd9e6..0000000
--- a/lib/+artoa/+controller/+track/+parameter/comboboxTrackingMethod.m
+++ /dev/null
@@ -1,16 +0,0 @@
-function [newValue] = comboboxTrackingMethod(~, ~)
-%COMBOBOXTRACKINGMETHOD Summary of this function goes here
-%   Detailed explanation goes here
-
-global artoaGui artoaWorkspace;
-
-selectedIndex = artoaGui.trackParameter.comboboxTrackingMethod.Value;
-
-newValue = artoaGui.trackParameter.comboboxTrackingMethod.String{selectedIndex};
-
-artoaWorkspace.trackParameter.trackingMethodValue = selectedIndex;
-artoaWorkspace.trackParameter.trackingMethodString = newValue;
-
-
-end
-
diff --git a/lib/+artoa/+controller/+track/+parameter/createCombinationsTable.m b/lib/+artoa/+controller/+track/+parameter/createCombinationsTable.m
index 14f1d8b..3b86f9a 100644
--- a/lib/+artoa/+controller/+track/+parameter/createCombinationsTable.m
+++ b/lib/+artoa/+controller/+track/+parameter/createCombinationsTable.m
@@ -10,7 +10,8 @@ variableNames = { ...
     'referencePosition', ...
     'soundspeed1', ...
     'soundspeed2', ...
-    'soundspeed3' ...
+    'soundspeed3', ...
+    'trackingMethod' ...
 };
 
 %% Create struct for workspace
diff --git a/lib/+artoa/+controller/+track/+parameter/getDefaultCombinationCell.m b/lib/+artoa/+controller/+track/+parameter/getDefaultCombinationCell.m
index 4032dce..a271b55 100644
--- a/lib/+artoa/+controller/+track/+parameter/getDefaultCombinationCell.m
+++ b/lib/+artoa/+controller/+track/+parameter/getDefaultCombinationCell.m
@@ -11,7 +11,8 @@ emptyCell = { ...
     '', ...
     1464, ...
     1464, ...
-    1464 ...
+    1464, ...
+    '' ...
 };
 
 end
diff --git a/lib/+artoa/+controller/+track/+parameter/validateCombinationsInput.m b/lib/+artoa/+controller/+track/+parameter/validateCombinationsInput.m
index 738434b..5d0ddf2 100644
--- a/lib/+artoa/+controller/+track/+parameter/validateCombinationsInput.m
+++ b/lib/+artoa/+controller/+track/+parameter/validateCombinationsInput.m
@@ -28,6 +28,12 @@ if any(isnan(pCombinationsTable.soundspeed1)) ...
     return;
 end
 
+if any(isempty(pCombinationsTable.trackingMethod)) ...
+        || any(strcmp(pCombinationsTable.trackingMethod, ''))
+    message = 'You must select a tracking method for all combinations!';
+    return;
+end
+
 success = true;
 
 end
diff --git a/lib/+artoa/+controller/+track/+trajectoryOutput/updateTableGeneratedTracks.m b/lib/+artoa/+controller/+track/+trajectoryOutput/updateTableGeneratedTracks.m
index 984a2b5..7564388 100644
--- a/lib/+artoa/+controller/+track/+trajectoryOutput/updateTableGeneratedTracks.m
+++ b/lib/+artoa/+controller/+track/+trajectoryOutput/updateTableGeneratedTracks.m
@@ -28,7 +28,7 @@ for i = 1:length(trajectories)
         generatedTracks{i, 1} = '';
     end
     generatedTracks{i, 2} = trajectories{i}.id;
-    generatedTracks{i, 3} = trajectories{i}.trackParameter.trackingMethodString;
+    generatedTracks{i, 3} = strjoin(trajectories{i}.trackParameter.soundsourceCombinations.trackingMethod, ', ');
 end
 
 tableHandle.Data = generatedTracks;
diff --git a/lib/+artoa/+gui/main.m b/lib/+artoa/+gui/main.m
index 248b10a..2a3c4d9 100644
--- a/lib/+artoa/+gui/main.m
+++ b/lib/+artoa/+gui/main.m
@@ -23,8 +23,7 @@ availableCallbacks = { ...
     'openTrackParameter', ...
     'openTrackTrajectoryOutput', ...
     'switchHideDeletedDataPoints', ...
-    'comboboxTrackingMethod', ...  % FIRST ITEM TRACK PARAMETER CALLBACKS
-    'checkboxDopplerCorrection', ...
+    'checkboxDopplerCorrection', ... % FIRST ITEM TRACK PARAMETER CALLBACKS
     'comboboxInterpolationMethod', ...
     'comboboxSoundspeedMethod', ...
     'checkboxPlotResiduals', ...
@@ -268,31 +267,21 @@ buttonHeight = .3;
 
 % Tracking method frame
 
-artoaGui.trackParameter.frameTrackingMethod = uipanel( ...
+artoaGui.trackParameter.frameCorrections = uipanel( ...
     'Parent', artoaGui.trackParameter.frameTrackingParameter, ...
-    'Title', 'Tracking Method', ...
+    'Title', 'Corrections', ...
     'Units', 'normalized', ...
     'BackgroundColor', 'white', ...
     'Position', [left .75 width .20] ...
 );
 
-artoaGui.trackParameter.comboboxTrackingMethod = uicontrol( ...
-    'Parent', artoaGui.trackParameter.frameTrackingMethod, ...
-    'String', pTrackingMethods, ...
-    'Style', 'popupmenu', ...
-    'FontSize', 8, ...
-    'Units', 'normalized', ...
-    'Position', [left .5 .9 .4], ...
-    'CallBack', pCallbacks.comboboxTrackingMethod ...
-);
-
 artoaGui.trackParameter.checkboxDopplerCorrection = uicontrol( ...
-    'Parent', artoaGui.trackParameter.frameTrackingMethod, ...
+    'Parent', artoaGui.trackParameter.frameCorrections, ...
     'String', 'Apply Doppler Correction', ...
     'Style', 'checkbox', ...
     'FontSize', 8, ...
     'Units', 'normalized', ...
-    'Position', [left .1 .9 .3], ...
+    'Position', [left .5 .9 .3], ...
     'Value', 1, ...
     'CallBack', pCallbacks.checkboxDopplerCorrection ...
 );
@@ -396,8 +385,11 @@ columns = { ...
     'End', ...
     'Sound Sources', ...
     'Reference Position', ...
-    'Sound Speed', 'Sound Speed', 'Sound Speed' ...
+    'Sound Speed', 'Sound Speed', 'Sound Speed', ...
+    'Tracking Method' ...
 };
+columnFormat = cell(1, length(columns));
+columnFormat{end} = pTrackingMethods;
 artoaGui.trackParameter.tableSoundSourceCombinations = uitable( ...
     artoaGui.trackParameter.frameTrackingParameter, ...
     'Units', 'normalized', ...
@@ -405,10 +397,11 @@ artoaGui.trackParameter.tableSoundSourceCombinations = uitable( ...
     'Data', cell(1, length(columns)), ...
     'ColumnName', columns, ...
     'ColumnEditable', true, ...
+    'ColumnFormat', (columnFormat), ...
     'CellSelectionCallback', pCallbacks.tableSoundSourceCombinationsSelection,... %@(app,event) disp(num2str(event.Indices)) ...
     'CellEditCallback', pCallbacks.tableSoundSourceCombinationsEdit ...
 );
-clear columns;
+clear columns columnFormat;
 
 % Track buttons frame
 
diff --git a/lib/+artoa/+trajectory/calculate.m b/lib/+artoa/+trajectory/calculate.m
index bc7d921..7f0ec78 100644
--- a/lib/+artoa/+trajectory/calculate.m
+++ b/lib/+artoa/+trajectory/calculate.m
@@ -236,8 +236,7 @@ for oCombination = 1:size(soundsourceCombinations, 1)
         preparedData, ...
         currentCombination, ...%trajectory(end, :), ...
         floatReferenceTime, ...
-        pSoundVelocity(oCombination, :), ...
-        pTrackingParameter.trackingMethodString ...
+        pSoundVelocity(oCombination, :) ...
     );
     
     % remove NaNs from segment
diff --git a/lib/+artoa/+trajectory/calculateCombinationSegment.m b/lib/+artoa/+trajectory/calculateCombinationSegment.m
index 105bd21..ec0413b 100644
--- a/lib/+artoa/+trajectory/calculateCombinationSegment.m
+++ b/lib/+artoa/+trajectory/calculateCombinationSegment.m
@@ -1,4 +1,4 @@
-function [segmentPositions, segmentDates, segmentClockError, segmentResiduals] = calculateCombinationSegment(pCorrectedData, pCombinationDetails, pFloatReferenceTime, pSoundVelocity, pTrackingMethod)
+function [segmentPositions, segmentDates, segmentClockError, segmentResiduals] = calculateCombinationSegment(pCorrectedData, pCombinationDetails, pFloatReferenceTime, pSoundVelocity)
 %CALCULATECOMBINATIONSEGMENT Combination segment calculation.
 %   Using the input data, the function calculates the segment positions,
 %   its corresponding dates as well as the clock error (in case of hyperbolic calculation)
@@ -20,14 +20,6 @@ function [segmentPositions, segmentDates, segmentClockError, segmentResiduals] =
 %           used.
 %           For all other methods, only one value needs to be set.
 %           Unit: [m/s]
-%       pTrackingMethod (string/char):
-%           Contains the tracking algorithm that should be used.
-%           Available methods:
-%               least square
-%               exclusive least square
-%               circular
-%               hyperbolic
-%
 %
 %   Returns:
 %       segmentPositions (double):
@@ -50,7 +42,7 @@ segmentVelocities = struct();
 soundsourceNames = unique(strsplit(strtrim(pCombinationDetails.soundsources{1}), ' '));
 
 %% Get tracking method
-trackingMethod = lower(pTrackingMethod);
+trackingMethod = lower(pCombinationDetails.trackingMethod{:});
 
 %% Get start and end point
 segmentStart = pCombinationDetails{1, 1};
@@ -151,7 +143,7 @@ end
 switch trackingMethod
     case {'least square', 'exclusive least square'}
         for oDates = 1:length(intersectedToaDates)
-            if strcmp(pTrackingMethod, 'exclusive least square') ...
+            if strcmp(trackingMethod, 'exclusive least square') ...
                 && (sum(~isnan(distanceToSoundsources{oDates})) ~= length(soundsourcePositions))
                 segmentPositions = [segmentPositions; [NaN, NaN]];
                 segmentClockError = [segmentClockError; NaN(1, 3)];
@@ -194,7 +186,7 @@ switch trackingMethod
     otherwise
         % prepare soundsource infos
         [segmentPositions, segmentClockError] = artoa.plugins.tracking.callTrackingMethod( ...
-            pTrackingMethod, ...
+            trackingMethod, ...
             pluginTables, ...
             pluginSoundsourcePositions, ...
             pCombinationDetails ...
diff --git a/lib/+artoa/+versioning/+migrations/versions/v4183.m b/lib/+artoa/+versioning/+migrations/versions/v4183.m
new file mode 100644
index 0000000..8d2c4e8
--- /dev/null
+++ b/lib/+artoa/+versioning/+migrations/versions/v4183.m
@@ -0,0 +1,10 @@
+if ~artoa.data.hasMember(artoaWorkspace, 'trackParameter', 'soundsourceCombinations', 'trackingMethod')
+    artoaWorkspace.trackParameter.soundsourceCombinations.trackingMethod(:) = {''};
+end
+
+if artoa.data.hasMember(artoaWorkspace, 'trackParameter', 'trackingMethodString')
+    rmfield(artoaWorkspace.trackParameter, 'trackingMethodString');
+end
+if artoa.data.hasMember(artoaWorkspace, 'trackParameter', 'trackingMethodValue')
+    rmfield(artoaWorkspace.trackParameter, 'trackingMethodValue');
+end
\ No newline at end of file
-- 
GitLab