diff --git a/src/Localiser/detectionGroupLocaliser/TMGroupLocInfo.java b/src/Localiser/detectionGroupLocaliser/TMGroupLocInfo.java index 3fe4a4e8..ace2b8aa 100644 --- a/src/Localiser/detectionGroupLocaliser/TMGroupLocInfo.java +++ b/src/Localiser/detectionGroupLocaliser/TMGroupLocInfo.java @@ -159,22 +159,21 @@ public class TMGroupLocInfo implements GroupLocInfo { private void copySubDetections(SuperDetection parentDataUnit, DetectionGroupOptions detectionGroupOptions) { - synchronized (parentDataUnit.getSubDetectionSyncronisation()) { - int totalUnits = parentDataUnit.getSubDetectionsCount(); - int keptUnits = totalUnits; - if (detectionGroupOptions != null) { - if (detectionGroupOptions.getMaxLocalisationPoints() == 0 || - detectionGroupOptions.getMaxLocalisationPoints() < parentDataUnit.getSubDetectionsCount()) { - keptUnits = detectionGroupOptions.getMaxLocalisationPoints(); - } - } - subDetectionList = new Vector<>(keptUnits); - float keepRat = (float) (totalUnits-1) / (float) (keptUnits-1); - for (int i = 0; i < keptUnits; i++) { - int unitIndex = Math.round(i*keepRat); - subDetectionList.add(parentDataUnit.getSubDetection(unitIndex)); + ArrayList subDets = parentDataUnit.getSubDetections(); + int totalUnits = subDets.size(); + int keptUnits = totalUnits; + if (detectionGroupOptions != null) { + if (detectionGroupOptions.getMaxLocalisationPoints() == 0 || + detectionGroupOptions.getMaxLocalisationPoints() < parentDataUnit.getSubDetectionsCount()) { + keptUnits = detectionGroupOptions.getMaxLocalisationPoints(); } } + subDetectionList = new Vector<>(keptUnits); + float keepRat = (float) (totalUnits-1) / (float) (keptUnits-1); + for (int i = 0; i < keptUnits; i++) { + int unitIndex = Math.round(i*keepRat); + subDetectionList.add(subDets.get(unitIndex)); + } } @@ -454,7 +453,7 @@ public class TMGroupLocInfo implements GroupLocInfo { * The real word vectors are relative to the earth surface. Thus they are the bearings vectors * from an array, rotated by the true heading, pitch and roll of the array. */ - protected void calculateWorldVectors() { + protected void calculateWorldVectors() { int nSubDetections=getDetectionCount(); rawRealWorldVectors = new PamVector[nSubDetections][]; PamVector[] v; diff --git a/src/PamguardMVC/superdet/SuperDetDataBlock.java b/src/PamguardMVC/superdet/SuperDetDataBlock.java index 581c0b92..014a8824 100644 --- a/src/PamguardMVC/superdet/SuperDetDataBlock.java +++ b/src/PamguardMVC/superdet/SuperDetDataBlock.java @@ -368,7 +368,7 @@ public class SuperDetDataBlock extends PamDataUnit> getSubDetections() { - if (subDetections == null) { - return null; - } - ArrayList> subDets = new ArrayList<>(getSubDetectionsCount()); - for (SubdetectionInfo subInfo:subDetections) { - T subDet = subInfo.getSubDetection(); - if (subDet == null) { - continue; + synchronized (getSubDetectionSyncronisation()) { + if (subDetections == null) { + return null; } - subDets.add(subDet); + ArrayList> subDets = new ArrayList<>(getSubDetectionsCount()); + for (SubdetectionInfo subInfo:subDetections) { + T subDet = subInfo.getSubDetection(); + if (subDet == null) { + continue; + } + subDets.add(subDet); + } + return subDets; } - return subDets; } public T getSubDetection(int ind) { synchronized (subDetectionSyncronisation) { if (subDetections == null) return null; + if (ind >= subDetections.size()) { + return null; + } return subDetections.get(ind).getSubDetection(); } } @@ -484,6 +489,24 @@ public class SuperDetection extends PamDataUnit> getPresentSubDetections() { + ArrayList> exList = new ArrayList<>(getSubDetectionsCount()); + synchronized (getSubDetectionSyncronisation()) { + for (SubdetectionInfo subInf : subDetections) { + if (subInf.getSubDetection() == null) { + continue; + } + exList.add(subInf); + } + exList.trimToSize(); + } + return exList; + } /** * Get the full list of subdetection info's (which may not all @@ -550,4 +573,21 @@ public class SuperDetection extends PamDataUnit> subInfIter = subDetections.listIterator(); +// while (subInfIter.hasNext()) { +// SubdetectionInfo subDetInfo = subInfIter.next(); +// if (subDetInfo.getSubDetection() == null) { +// subInfIter.remove(); +// } +// } +// } +// } + } diff --git a/src/clickDetector/offlineFuncs/OfflineEventDataBlock.java b/src/clickDetector/offlineFuncs/OfflineEventDataBlock.java index fe36734b..4af5872b 100644 --- a/src/clickDetector/offlineFuncs/OfflineEventDataBlock.java +++ b/src/clickDetector/offlineFuncs/OfflineEventDataBlock.java @@ -284,5 +284,17 @@ public class OfflineEventDataBlock extends SuperDetDataBlock> subDetections; /** * @param pamDetection */ public EventRotator(SuperDetection pamDetection) { super(); this.pamDetection = pamDetection; + this.subDetections = pamDetection.getPresentSubDetections(); rotatedWorldVectors = null; calculateMetrePoints(); } @@ -90,14 +100,14 @@ public class EventRotator { */ private void calculateMetrePoints() { lastUpdateTime = pamDetection.getLastUpdateTime(); - nSubDetections = pamDetection.getSubDetectionsCount(); + nSubDetections = subDetections.size(); subDetectionOrigins = new PamVector[nSubDetections]; subDetectionHeadings = new PamVector[nSubDetections]; pointTimes = new long[nSubDetections]; if (nSubDetections == 0) { return; } - PamDataUnit pd = pamDetection.getSubDetection(0); + PamDataUnit pd = subDetections.get(0).getSubDetection(); if (pd == null) { return; } @@ -110,7 +120,10 @@ public class EventRotator { LatLong detOrigin; for (int i = 0; i < nSubDetections; i++) { - pd = pamDetection.getSubDetection(i); + pd = subDetections.get(i).getSubDetection(); + if (pd == null) { + continue; + } localisation = pd.getLocalisation(); if (localisation == null) { continue; @@ -152,6 +165,9 @@ public class EventRotator { rotatedOrigins = new PamVector[nSubDetections]; rotatedHeadings = new PamVector[nSubDetections]; for (int i = 0; i < nSubDetections; i++) { + if (subDetectionOrigins[i] == null) { + continue; + } subDetectionHeadings[i] = new PamVector(Math.cos(Math.PI/2-rotatedArrayAngles[i]), Math.sin(Math.PI/2-rotatedArrayAngles[i]), 0); rotatedOrigins[i] = subDetectionOrigins[i].rotate(-referenceAngle); rotatedArrayAngles[i] = Math.PI/2. - rotatedArrayAngles[i]; @@ -170,7 +186,7 @@ public class EventRotator { PamDataUnit pd; AbstractLocalisation localisation; for (int i = 0; i < nSubDetections; i++) { - pd = pamDetection.getSubDetection(i); + pd = subDetections.get(i).getSubDetection(); localisation = pd.getLocalisation(); if (localisation == null) { continue; @@ -187,7 +203,7 @@ public class EventRotator { PamDataUnit pd; AbstractLocalisation localisation; for (int i = 0; i < nSubDetections; i++) { - pd = pamDetection.getSubDetection(i); + pd = subDetections.get(i).getSubDetection(); localisation = pd.getLocalisation(); if (localisation == null) { continue; diff --git a/src/targetMotionOld/dialog/DialogMap3DSwing.java b/src/targetMotionOld/dialog/DialogMap3DSwing.java index 6e82e14d..8d18cb9f 100644 --- a/src/targetMotionOld/dialog/DialogMap3DSwing.java +++ b/src/targetMotionOld/dialog/DialogMap3DSwing.java @@ -4,6 +4,7 @@ import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.util.ArrayList; +import java.util.List; import javax.swing.JPanel; @@ -18,6 +19,7 @@ import PamUtils.LatLong; import PamguardMVC.PamDataBlock; import PamguardMVC.PamDataUnit; import PamguardMVC.dataSelector.DataSelector; +import PamguardMVC.superdet.SubdetectionInfo; import clickDetector.ClickDataBlock; import targetMotionOld.TargetMotionLocaliser; @@ -66,9 +68,14 @@ public class DialogMap3DSwing extends DialogMap { mapDetData.allAvailable = true; mapDetData.select = true; - int nSub = currentEvent.getSubDetectionsCount(); + List> subDets = currentEvent.getPresentSubDetections(); + + int nSub = subDets.size(); for (int i = 0; i < nSub; i++) { - PamDataUnit subDet = currentEvent.getSubDetection(i); + PamDataUnit subDet = subDets.get(i).getSubDetection(); + if (subDet == null) { + continue; + } MapDetectionData subDetData = mapDetectionsManager.findDetectionData(subDet.getParentDataBlock()); if (subDetData != null && subDetData != mapDetData) { mapDetData = subDetData; @@ -81,8 +88,8 @@ public class DialogMap3DSwing extends DialogMap { */ LatLong eventCentre = currentEvent.getOriginLatLong(true); if (nSub >= 2) { - LatLong ll1 = currentEvent.getSubDetection(0).getOriginLatLong(true); - LatLong ll2 = currentEvent.getSubDetection(nSub-1).getOriginLatLong(true); + LatLong ll1 = subDets.get(0).getSubDetection().getOriginLatLong(true); + LatLong ll2 = subDets.get(nSub-1).getSubDetection().getOriginLatLong(true); if (ll1 != null & ll2 != null) { double lat = (ll1.getLatitude() + ll2.getLatitude())/2.; double lon = (ll1.getLongitude() + ll2.getLongitude())/2.;