From 6e73b843acdf2b88afd38c59e2bf40fc7af330f7 Mon Sep 17 00:00:00 2001
From: Radek Oslejsek <oslejsek@fi.muni.cz>
Date: Fri, 23 Oct 2020 11:30:03 +0200
Subject: [PATCH] Minor refactoring

---
 .../analyst/symmetry/SymmetryEstimator.java   | 69 +++++++++++--------
 1 file changed, 40 insertions(+), 29 deletions(-)

diff --git a/Comparison/src/main/java/cz/fidentis/analyst/symmetry/SymmetryEstimator.java b/Comparison/src/main/java/cz/fidentis/analyst/symmetry/SymmetryEstimator.java
index b0e19f0e..918c5088 100644
--- a/Comparison/src/main/java/cz/fidentis/analyst/symmetry/SymmetryEstimator.java
+++ b/Comparison/src/main/java/cz/fidentis/analyst/symmetry/SymmetryEstimator.java
@@ -107,23 +107,15 @@ public class SymmetryEstimator {
      */
     public Plane getApproxSymmetryPlane(JPanel panel) {
         
-        ArrayList<ApproxSymmetryPlane> planes = new ArrayList<>();
+        List<ApproxSymmetryPlane> planes = new ArrayList<>();
         //List<Vector3d> normals = calculateNormals();
+        
         if (!facet.hasVertexNormals()) {
             facet.calculateVertexNormals();
         }
-        double[] curvatures = new double[facet.getNumberOfVertices()];
-        for (int i = 0; i < facet.getNumberOfVertices(); i++) {
-            if (facet.getNumberOfVertices() == 2500) {
-                curvatures[i] = this.getMaxCurvature(i);
-            } else {
-                curvatures[i] = this.getGaussianCurvature(i);
-            }
-            if (Double.isNaN(curvatures[i])){
-                curvatures[i] = Double.MIN_VALUE;
-            }
-        }
-        ArrayList<Double> sortedCurvatures = new ArrayList<>();
+        
+        double[] curvatures = initCurvatures();
+        List<Double> sortedCurvatures = new ArrayList<>();
         for (int i = 0; i < curvatures.length; i++) {
             sortedCurvatures.add(curvatures[i]);
         }
@@ -134,8 +126,8 @@ public class SymmetryEstimator {
         }
         double bottomCurvature = sortedCurvatures.get(sortedCurvatures.size() - 1 - config.getSignificantPointCount());   
         
-        ArrayList<Integer> significantPoints = new ArrayList<>();
-        ArrayList<Double> significantCurvatures = new ArrayList<>();
+        List<Integer> significantPoints = new ArrayList<>();
+        List<Double> significantCurvatures = new ArrayList<>();
         
         for (int i = 0; i < facet.getNumberOfVertices(); i++) {
             if (curvatures[i] >= bottomCurvature) {
@@ -160,8 +152,8 @@ public class SymmetryEstimator {
                 if (i != j) {
                     double minRatio = config.getMinCurvRatio();
                     double maxRatio = 1.0 / minRatio;
-                    if (significantCurvatures.get(i) / significantCurvatures.get(j) >= minRatio && significantCurvatures.get(i) /
-                            significantCurvatures.get(j) <= maxRatio) {
+                    if (significantCurvatures.get(i) / significantCurvatures.get(j) >= minRatio && 
+                            significantCurvatures.get(i) / significantCurvatures.get(j) <= maxRatio) {
                         
                         Vector3d p1 = new Vector3d(facet.getVertex(significantPoints.get(i)).getPosition());
                         Vector3d p2 = new Vector3d(facet.getVertex(significantPoints.get(j)).getPosition());
@@ -220,6 +212,34 @@ public class SymmetryEstimator {
                 finalPlanes.add(planes.get(i));
             }
         }
+        Plane finalPlane = computeNewPlane(finalPlanes);
+        if (config.isAveraging()){
+            plane = finalPlane;
+        }
+        if (panel != null) {
+            JOptionPane.showMessageDialog(panel, "Symmetry estimate done.", "Done", 0,
+                   new ImageIcon(getClass().getResource("/cz/fidentis/analyst/gui/resources/exportedModel.png")));
+            progressMonitor.close();
+        }
+        return plane;
+    }
+    
+    private double[] initCurvatures() {
+        double[] curvatures = new double[facet.getNumberOfVertices()];
+        for (int i = 0; i < facet.getNumberOfVertices(); i++) {
+            if (facet.getNumberOfVertices() == 2500) {
+                curvatures[i] = this.getMaxCurvature(i);
+            } else {
+                curvatures[i] = this.getGaussianCurvature(i);
+            }
+            if (Double.isNaN(curvatures[i])){
+                curvatures[i] = Double.MIN_VALUE;
+            }
+        }
+        return curvatures;
+    }
+    
+    private Plane computeNewPlane(List<ApproxSymmetryPlane> finalPlanes) {
         double newA = 0, newB = 0, newC = 0, newD = 0;
         Vector3d refDir = finalPlanes.get(0).getNormal();
         for (int i = 0; i < finalPlanes.size(); i++) {
@@ -238,16 +258,7 @@ public class SymmetryEstimator {
         }
         Plane finalPlane = new Plane(newA, newB, newC, newD);
         finalPlane.normalize();
-        if (config.isAveraging()){
-            plane = finalPlane;
-        }
-        if (panel != null) {
-            JOptionPane.showMessageDialog(panel, "Symmetry estimate done.", "Done", 0,
-                   new ImageIcon(getClass().getResource("/cz/fidentis/analyst/gui/resources/exportedModel.png")));
-
-            progressMonitor.close();
-        }
-        return plane;
+        return finalPlane;
     }
     
     /**
@@ -658,8 +669,8 @@ public class SymmetryEstimator {
      * @return total votes given to plane while computing the symmetry
      */
     private int getVotes(Plane plane,
-            ArrayList<Double> curvatures,
-            ArrayList<Integer> points,
+            List<Double> curvatures,
+            List<Integer> points,
             double minCurvRatio,
             double minAngleCos,
             double minNormAngleCos,
-- 
GitLab