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 ff1e56b889fbb359e0a7ad0e265574e8e6a4cecb..192d585741e74fdc759076fe676272069eb0c70d 100644 --- a/GUI/src/main/java/cz/fidentis/analyst/distance/DistanceAction.java +++ b/GUI/src/main/java/cz/fidentis/analyst/distance/DistanceAction.java @@ -42,7 +42,6 @@ public class DistanceAction extends ControlPanelAction { private String heatmapDisplayed = DistancePanel.HEATMAP_HAUSDORFF_DISTANCE; private boolean weightedFPsShow = true; - private Map<MeshFacet, List<Double>> weightedHausdorffDistance = null; private FeaturePointType hoveredFeaturePoint = null; private final DistancePanel controlPanel; @@ -221,8 +220,6 @@ public class DistanceAction extends ControlPanelAction { if (visitor == null) { calculateHausdorffDistance(featurePointTypes); - weightedHausdorffDistance = getWeightedDistance(); - // Update GUI elements that display the calculated Hausdorff distance metrics setFeaturePointWeigths(); setHausdorffDistanceStatistics(); @@ -276,31 +273,6 @@ public class DistanceAction extends ControlPanelAction { getSecondaryDrawableFace().getHumanFace().accept(visitor); } - /** - * Calculates weighted Hausdorff distance of the face. - * - * @return weighted Hausdorff distance - */ - private Map<MeshFacet, List<Double>> getWeightedDistance() { - final Map<MeshFacet, List<Double>> weightedDistances = new HashMap<>(visitor.getDistances()); - final Map<MeshFacet, List<Double>> mergedPriorities = visitor.getMergedPriorities() - .get(getSecondaryDrawableFace().getHumanFace()); - - // Merge the map of distances with the map of priorities - for (final Map.Entry<MeshFacet, List<Double>> facetPriorities: mergedPriorities.entrySet()) { - weightedDistances.merge( - facetPriorities.getKey(), - facetPriorities.getValue(), - (distancesList, prioritiesList) -> - IntStream.range(0, distancesList.size()) - .mapToDouble(i -> distancesList.get(i) * prioritiesList.get(i)) - .boxed() - .collect(Collectors.toList())); - } - - return weightedDistances; - } - /** * Updates the GUI elements of {@link DistancePanel} that display * the weights of feature points used to calculate the weighted Hausdorff distance. @@ -334,7 +306,7 @@ public class DistanceAction extends ControlPanelAction { .flatMap(List::stream) .mapToDouble(Double::doubleValue) .summaryStatistics(), - weightedHausdorffDistance + getWeightedDistance() .values() .stream() .flatMap(List::stream) @@ -343,6 +315,31 @@ public class DistanceAction extends ControlPanelAction { ); } + /** + * Calculates weighted Hausdorff distance of the face. + * + * @return weighted Hausdorff distance + */ + private Map<MeshFacet, List<Double>> getWeightedDistance() { + final Map<MeshFacet, List<Double>> weightedDistances = new HashMap<>(visitor.getDistances()); + final Map<MeshFacet, List<Double>> mergedPriorities = visitor.getMergedPriorities() + .get(getSecondaryDrawableFace().getHumanFace()); + + // Merge the map of distances with the map of priorities + for (final Map.Entry<MeshFacet, List<Double>> facetPriorities: mergedPriorities.entrySet()) { + weightedDistances.merge( + facetPriorities.getKey(), + facetPriorities.getValue(), + (distancesList, prioritiesList) -> + IntStream.range(0, distancesList.size()) + .mapToDouble(i -> distancesList.get(i) * prioritiesList.get(i)) + .boxed() + .collect(Collectors.toList())); + } + + return weightedDistances; + } + /** * Returns {@code true} if the heatmap is displayed and {@code false} otherwise. *