From fe0fb334c655d9c8c3d562665c1b4765227dac79 Mon Sep 17 00:00:00 2001 From: Daniel Schramm <xschramm@fi.muni.cz> Date: Wed, 22 Sep 2021 23:26:40 +0200 Subject: [PATCH] Display statistics of ordinary and weighted Hausdorff distance side by side --- .../analyst/distance/DistanceAction.java | 65 +++++++++---------- .../analyst/distance/DistancePanel.java | 52 +++++++++------ 2 files changed, 63 insertions(+), 54 deletions(-) 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 b94b2702..9ed0f49e 100644 --- a/GUI/src/main/java/cz/fidentis/analyst/distance/DistanceAction.java +++ b/GUI/src/main/java/cz/fidentis/analyst/distance/DistanceAction.java @@ -11,7 +11,6 @@ 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.DoubleSummaryStatistics; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -39,7 +38,7 @@ public class DistanceAction extends ControlPanelAction { private boolean relativeDist = false; private boolean weightedDist = false; - private Map<MeshFacet, List<Double>> hausdorffDistance = null; + private Map<MeshFacet, List<Double>> weightedHausdorffDistance = null; private final DistancePanel controlPanel; @@ -88,7 +87,6 @@ public class DistanceAction extends ControlPanelAction { break; case DistancePanel.ACTION_COMMAND_WEIGHTED_DISTANCE: this.weightedDist = ((JToggleButton) ae.getSource()).isSelected(); - this.hausdorffDistance = null; // recompute only priorities calculateHausdorffDistance(); break; case DistancePanel.ACTION_COMMAND_DISTANCE_RECOMPUTE: @@ -126,33 +124,27 @@ public class DistanceAction extends ControlPanelAction { true); getSecondaryDrawableFace().getHumanFace().accept(visitor); + weightedHausdorffDistance = getWeightedDistance(); + + // Update GUI elements that display the calculated Hausdorff distance metrics setFeaturePointWeigths(); - hausdorffDistance = null; - } - - // Update GUI elements that display the calculated Hausdorff distance - if (hausdorffDistance == null) { - hausdorffDistance = getWeightedDistance(); setHausdorffDistanceStatistics(); } - getSecondaryDrawableFace().setHeatMap(hausdorffDistance); + + getSecondaryDrawableFace().setHeatMap(weightedDist ? weightedHausdorffDistance : visitor.getDistances()); } /** - * Calculates weighted (or regular) Hausdorff distance of the face. + * Calculates weighted Hausdorff distance of the face. * * @return weighted Hausdorff distance */ private Map<MeshFacet, List<Double>> getWeightedDistance() { - if (!weightedDist) { - return visitor.getDistances(); - } - - // Merge the map of distances with the map of priorities 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(), @@ -166,24 +158,6 @@ public class DistanceAction extends ControlPanelAction { return weightedDistances; } - - /** - * Updates the GUI elements of {@link DistancePanel} elements that display - * statistical data about the calculated Hausdorff distance. - */ - private void setHausdorffDistanceStatistics() { - final DoubleSummaryStatistics distanceStats = hausdorffDistance.values() - .stream() - .flatMap(List::stream) - .mapToDouble(distance -> distance) - .summaryStatistics(); - - controlPanel.updateHausdorffDistanceStats( - distanceStats.getAverage(), - distanceStats.getMax(), - distanceStats.getMin() - ); - } /** * Updates the GUI elements of {@link DistancePanel} that display @@ -205,6 +179,27 @@ public class DistanceAction extends ControlPanelAction { .average() .orElse(Double.NaN)))); } + + /** + * Updates the GUI elements of {@link DistancePanel} elements that display + * statistical data about the calculated Hausdorff distance. + */ + private void setHausdorffDistanceStatistics() { + controlPanel.updateHausdorffDistanceStats( + visitor.getDistances() + .values() + .stream() + .flatMap(List::stream) + .mapToDouble(distance -> distance) + .summaryStatistics(), + weightedHausdorffDistance + .values() + .stream() + .flatMap(List::stream) + .mapToDouble(distance -> distance) + .summaryStatistics() + ); + } /** * Changes the colour of the secondary face's feature point at the given index. diff --git a/GUI/src/main/java/cz/fidentis/analyst/distance/DistancePanel.java b/GUI/src/main/java/cz/fidentis/analyst/distance/DistancePanel.java index a82351c7..07009dcc 100644 --- a/GUI/src/main/java/cz/fidentis/analyst/distance/DistancePanel.java +++ b/GUI/src/main/java/cz/fidentis/analyst/distance/DistancePanel.java @@ -8,6 +8,7 @@ import cz.fidentis.analyst.scene.DrawableFeaturePoints; import cz.fidentis.analyst.symmetry.SymmetryPanel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.DoubleSummaryStatistics; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -51,7 +52,7 @@ public class DistancePanel extends ControlPanel { public static final String STRATEGY_POINT_TO_TRIANGLE = "Point to triangle"; private final Map<FeaturePointType, JLabel> featurePointStats; - private final JLabel avgHD, maxHD, minHD; + private final JLabel avgHD, avgHDWeight, maxHD, maxHDWeight, minHD, minHDWeight; /** * Constructor. @@ -81,14 +82,6 @@ public class DistancePanel extends ControlPanel { builder.addGap(); builder.addLine(); - builder.addCheckBoxOptionLine( - null, - "Weighted Hausdorff distance", - false, - createListener(action, ACTION_COMMAND_WEIGHTED_DISTANCE) - ); - builder.addLine(); - final JPanel featurePointsPanel = new JPanel(); final ControlPanelBuilder fpBuilder = new ControlPanelBuilder(featurePointsPanel); featurePointStats = new HashMap<>(featurePoints.size()); @@ -138,23 +131,39 @@ public class DistancePanel extends ControlPanel { ); builder.addLine(); + builder.addCheckBoxOptionLine( + null, + "Weighted Hausdorff distance", + false, + createListener(action, ACTION_COMMAND_WEIGHTED_DISTANCE) + ); + builder.addLine(); + builder.addCaptionLine("Hausdorff distance:"); builder.addLine(); + builder.addOptionText(""); + builder.addOptionText("Hausdorff distance"); + builder.addOptionText("Weighted Hasudorff distance"); + builder.addLine(); + builder.addOptionText("Average"); - builder.addGap(); avgHD = builder.addLabelLine(""); builder.addGap(); + builder.addGap(); + avgHDWeight = builder.addLabelLine(""); builder.addLine(); builder.addOptionText("Maximum"); - builder.addGap(); maxHD = builder.addLabelLine(""); builder.addGap(); + builder.addGap(); + maxHDWeight = builder.addLabelLine(""); builder.addLine(); builder.addOptionText("Minimum"); - builder.addGap(); minHD = builder.addLabelLine(""); builder.addGap(); + builder.addGap(); + minHDWeight = builder.addLabelLine(""); builder.addLine(); builder.addVerticalStrut(); @@ -177,14 +186,19 @@ public class DistancePanel extends ControlPanel { /** * Updates GUI elements that display statistical data about the calculated Hausdorff distance. * - * @param averageDist Average distance - * @param maxDist Maximum distance - * @param minDist Minimum distance + * @param hausdorffDistance Statistical data of the ordinary Hausdorff distance + * @param weightedHausdorffDistance Statistical data of the weighted Hausdorff distance */ - public void updateHausdorffDistanceStats(double averageDist, double maxDist, double minDist) { - avgHD.setText(Double.toString(averageDist)); - maxHD.setText(Double.toString(maxDist)); - minHD.setText(Double.toString(minDist)); + public void updateHausdorffDistanceStats(DoubleSummaryStatistics hausdorffDistance, + DoubleSummaryStatistics weightedHausdorffDistance) { + avgHD.setText(Double.toString(hausdorffDistance.getAverage())); + avgHDWeight.setText(Double.toString(weightedHausdorffDistance.getAverage())); + + maxHD.setText(Double.toString(hausdorffDistance.getMax())); + maxHDWeight.setText(Double.toString(weightedHausdorffDistance.getMax())); + + minHD.setText(Double.toString(hausdorffDistance.getMin())); + minHDWeight.setText(Double.toString(weightedHausdorffDistance.getMin())); } /** -- GitLab