diff --git a/GUI/src/main/java/cz/fidentis/analyst/distance/DistanceAction.java b/GUI/src/main/java/cz/fidentis/analyst/distance/DistanceAction.java index 908e9a41d4973fe562bcba51489c5e92e7294cb1..4ad83890b23f99ddf67027c3b5f761ab73e09b0e 100644 --- a/GUI/src/main/java/cz/fidentis/analyst/distance/DistanceAction.java +++ b/GUI/src/main/java/cz/fidentis/analyst/distance/DistanceAction.java @@ -10,6 +10,7 @@ import cz.fidentis.analyst.visitors.face.HausdorffDistancePrioritized; import cz.fidentis.analyst.visitors.mesh.HausdorffDistance.Strategy; import java.awt.Color; import java.awt.event.ActionEvent; +import java.util.Collection; import java.util.DoubleSummaryStatistics; import java.util.HashMap; import java.util.List; @@ -142,15 +143,20 @@ public class DistanceAction extends ControlPanelAction { final Map<FeaturePointType, Double> featurePointWeights = new HashMap<>(faceWeights.size()); for (final Map.Entry<FeaturePointType, Map<MeshFacet, Double>> fpWeights: faceWeights.entrySet()) { - featurePointWeights.put( - fpWeights.getKey(), - fpWeights.getValue() - .values() - .stream() - .mapToDouble(weight -> weight) - .average() - .orElse(Double.NaN) - ); + final Collection<Double> weightsList = fpWeights.getValue().values(); + + final double average; + if (weightsList.isEmpty()) { + average = Double.NaN; + } else { + double sum = 0; + for (final double weight: weightsList) { + sum += weight; + } + average = sum / weightsList.size(); + } + + featurePointWeights.put(fpWeights.getKey(), average); } controlPanel.updateFeaturePointWeights(featurePointWeights);