From 4fc5f31299b67c0dd9023534bcfde7b326f85fb6 Mon Sep 17 00:00:00 2001
From: Lewin Probst <info@emirror.de>
Date: Fri, 22 Nov 2019 11:19:45 +0100
Subject: [PATCH] Added function to get involved soundsources. Trimmed
 soundsource names in combination.

---
 .../+track/getInvolvedSoundsources.m          | 21 +++++++++++++++++++
 .../+float/calculateCombinationSegment.m      |  2 +-
 lib/+artoa/+float/calculateTrajectory.m       | 12 ++---------
 3 files changed, 24 insertions(+), 11 deletions(-)
 create mode 100644 lib/+artoa/+controller/+track/getInvolvedSoundsources.m

diff --git a/lib/+artoa/+controller/+track/getInvolvedSoundsources.m b/lib/+artoa/+controller/+track/getInvolvedSoundsources.m
new file mode 100644
index 0000000..60eabc0
--- /dev/null
+++ b/lib/+artoa/+controller/+track/getInvolvedSoundsources.m
@@ -0,0 +1,21 @@
+function [involvedSoundsources, involvedSoundsourceNames] = getInvolvedSoundsources()
+%GETINVOLVEDSOUNDSOURCES Summary of this function goes here
+%   Detailed explanation goes here
+
+global artoaWorkspace;
+
+involvedSoundsourceNames = fieldnames(artoaWorkspace.filteredSoundsources);
+involvedSoundsources = struct();
+for i = 1:length(involvedSoundsourceNames)
+    if artoa.soundsources.hasAppliedToa(involvedSoundsourceNames{i}, artoaWorkspace.toaData.soundSource)
+        extracted = artoa.data.extractSoundsourcesFromStruct( ...
+            involvedSoundsourceNames{i}, ...
+            artoaWorkspace.filteredSoundsources ...
+        );
+        involvedSoundsources.(involvedSoundsourceNames{i}) = extracted;
+        clear extracted;
+    end
+end
+
+end
+
diff --git a/lib/+artoa/+float/calculateCombinationSegment.m b/lib/+artoa/+float/calculateCombinationSegment.m
index 545d13a..15c1ee6 100644
--- a/lib/+artoa/+float/calculateCombinationSegment.m
+++ b/lib/+artoa/+float/calculateCombinationSegment.m
@@ -47,7 +47,7 @@ segmentClockError = [];
 segmentVelocities = struct();
 
 %% Get sound sources
-soundsourceNames = unique(strsplit(pCombinationDetails.soundsources{1}, ' '));
+soundsourceNames = unique(strsplit(strtrim(pCombinationDetails.soundsources{1}), ' '));
 
 %% Get tracking method
 trackingMethod = lower(pTrackingMethod);
diff --git a/lib/+artoa/+float/calculateTrajectory.m b/lib/+artoa/+float/calculateTrajectory.m
index fda4e6f..328228b 100644
--- a/lib/+artoa/+float/calculateTrajectory.m
+++ b/lib/+artoa/+float/calculateTrajectory.m
@@ -34,16 +34,8 @@ soundsourceCombinations = pTrackingParameter.soundsourceCombinations;
 uniqueToaDates = unique(pToaData.toaDate);
 
 %% Get all sound sources that are involved
-involvedSoundsourceNames = ...
-    unique(flatten( ...
-        cellfun( ...
-            @strsplit, soundsourceCombinations.soundsources, 'UniformOutput', false ...
-        ) ...
-    ));
-involvedSoundsources = artoa.data.extractSoundsourcesFromStruct( ...
-    involvedSoundsourceNames, ...
-    pSoundsources ...
-);
+[involvedSoundsources, involvedSoundsourceNames] = ...
+    artoa.controller.track.getInvolvedSoundsources();
 
 %% Add float drift to TOA
 pToaData = artoa.data.addFloatDrift( ...
-- 
GitLab