diff --git a/Comparison/src/main/java/cz/fidentis/analyst/symmetry/ApproxSymmetryPlane.java b/Comparison/src/main/java/cz/fidentis/analyst/symmetry/ApproxSymmetryPlane.java index 74c7fe3cc87d2d493b3355517ab50d67f569aad0..7bc26d6373d4baacb35baf097c34653f687663f3 100644 --- a/Comparison/src/main/java/cz/fidentis/analyst/symmetry/ApproxSymmetryPlane.java +++ b/Comparison/src/main/java/cz/fidentis/analyst/symmetry/ApproxSymmetryPlane.java @@ -8,7 +8,8 @@ package cz.fidentis.analyst.symmetry; * */ public class ApproxSymmetryPlane extends Plane implements Comparable<ApproxSymmetryPlane> { - public int votes; + + private int votes; /** * returns number of votes that were given to plane while computing the symmetry diff --git a/Comparison/src/main/java/cz/fidentis/analyst/symmetry/Plane.java b/Comparison/src/main/java/cz/fidentis/analyst/symmetry/Plane.java index c1f5484a390542d1834524340e8a5e336d1ea72a..b2827693c2e1aaa9472ce16737afbc290fafb4b1 100644 --- a/Comparison/src/main/java/cz/fidentis/analyst/symmetry/Plane.java +++ b/Comparison/src/main/java/cz/fidentis/analyst/symmetry/Plane.java @@ -1,5 +1,7 @@ package cz.fidentis.analyst.symmetry; +import javax.vecmath.Vector3d; + /** * Symmetry plane. * @@ -7,13 +9,11 @@ package cz.fidentis.analyst.symmetry; */ public class Plane { - public double a; - public double b; - public double c; - public double d; + private Vector3d normal; + private double distance; /** - * Creates new plane + * Creates new plane. * * @param a a coordinate * @param b b coordinate @@ -21,10 +21,18 @@ public class Plane { * @param d d coordinate */ public Plane(double a, double b, double c, double d) { - this.a = a; - this.b = b; - this.c = c; - this.d = d; + normal = new Vector3d(a,b,c); + distance = d; + } + + /** + * Constructor. + * @param normal Normal vector of the plane + * @param dist distance + * @throws IllegalArgumentExpcption if the @code{plane} argument is null + */ + public Plane(Vector3d normal, double dist) { + this(normal.x, normal.y, normal.z, dist); } /** @@ -33,25 +41,16 @@ public class Plane { * @throws IllegalArgumentExpcption if the @code{plane} argument is null */ public Plane(Plane plane) { - if (plane == null) { - throw new IllegalArgumentException(); - } - a = plane.a; - b = plane.b; - c = plane.c; - d = plane.d; + this(plane.getNormal(), plane.getDistance()); } /** * Normalize the plane */ public void normalize() { - double normalLength = Math.sqrt(a * a + b * b + c * c); - - a /= normalLength; - b /= normalLength; - c /= normalLength; - d /= normalLength; + double normalLength = normal.length(); + normal.normalize(); + distance /= normalLength; // Do we really want this? --ro } /** @@ -61,6 +60,18 @@ public class Plane { */ @Override public String toString(){ - return "APPROXIMATE PLANE:\n" + a + "\n" + b + "\n" + c + "\n" + d + "\n"; + return "APPROXIMATE PLANE:" + System.lineSeparator() + + normal.x + System.lineSeparator() + + normal.y + System.lineSeparator() + + normal.z + System.lineSeparator() + + distance + System.lineSeparator(); + } + + public Vector3d getNormal() { + return normal; + } + + public double getDistance() { + return distance; } } 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 36d2faf796691e7bdb8e06ccfe28c4e57c03215f..98bd7a3b898dc516a7af45d149e16e60fbb1b029 100644 --- a/Comparison/src/main/java/cz/fidentis/analyst/symmetry/SymmetryEstimator.java +++ b/Comparison/src/main/java/cz/fidentis/analyst/symmetry/SymmetryEstimator.java @@ -227,26 +227,28 @@ public class SymmetryEstimator { Collections.sort(planes); ArrayList<ApproxSymmetryPlane> finalPlanes = new ArrayList<>(); for (int i = 0; i < planes.size(); i++) { - if (planes.get(i).votes == lastVotes){ + if (planes.get(i).getVotes() == lastVotes){ finalPlanes.add(planes.get(i)); } } - Plane finalPlane = new Plane(0, 0, 0, 0); - Vector3d refDir = new Vector3d(finalPlanes.get(0).a, finalPlanes.get(0).b, finalPlanes.get(0).c); + //Plane finalPlane = new Plane(0, 0, 0, 0); + double newA = 0, newB = 0, newC = 0, newD = 0; + Vector3d refDir = finalPlanes.get(0).getNormal(); for (int i = 0; i < finalPlanes.size(); i++) { - Vector3d normDir = new Vector3d(finalPlanes.get(i).a, finalPlanes.get(i).b, finalPlanes.get(i).c); + Vector3d normDir = finalPlanes.get(i).getNormal(); if (normDir.dot(refDir) < 0) { - finalPlane.a -= finalPlanes.get(i).a; - finalPlane.b -= finalPlanes.get(i).b; - finalPlane.c -= finalPlanes.get(i).c; - finalPlane.d -= finalPlanes.get(i).d; + newA -= normDir.x; + newB -= normDir.y; + newC -= normDir.z; + newD -= finalPlanes.get(i).getDistance(); } else { - finalPlane.a += finalPlanes.get(i).a; - finalPlane.b += finalPlanes.get(i).b; - finalPlane.c += finalPlanes.get(i).c; - finalPlane.d += finalPlanes.get(i).d; + newA += normDir.x; + newB += normDir.y; + newC += normDir.z; + newD += finalPlanes.get(i).getDistance(); } } + Plane finalPlane = new Plane(newA, newB, newC, newD); finalPlane.normalize(); if (config.isAveraging()){ plane = finalPlane; @@ -264,21 +266,21 @@ public class SymmetryEstimator { * @return mesh that represents facet with computed plane of approximate symmetry */ public SymmetryEstimator mergeWithPlane(Plane plane) { - Vector3d normal = new Vector3d(plane.a, plane.b, plane.c); + Vector3d normal = plane.getNormal(); Vector3d midPoint = boundingBox.getMidPoint().getPosition(); - double alpha = -((plane.a * midPoint.x) + - (plane.b * midPoint.y) + (plane.c * midPoint.z) + - plane.d) / (normal.dot(normal)); + double alpha = -((normal.x * midPoint.x) + + (normal.y * midPoint.y) + (normal.z * midPoint.z) + + plane.getDistance()) / (normal.dot(normal)); Vector3d midPointOnPlane = new Vector3d(midPoint); Vector3d nn = new Vector3d(normal); nn.scale(alpha); midPointOnPlane.add(nn); - double val = plane.a * midPointOnPlane.x + plane.b * - midPointOnPlane.y + plane.c * - midPointOnPlane.z + plane.d; + double val = normal.x * midPointOnPlane.x + normal.y * + midPointOnPlane.y + normal.z * + midPointOnPlane.z + plane.getDistance(); Vector3d a = new Vector3d(); if (Math.abs(normal.dot(new Vector3d(0.0, 1.0, 0.0))) > Math.abs(normal.dot(new Vector3d (1.0, 0.0, 0.0)))) { @@ -363,10 +365,16 @@ public class SymmetryEstimator { * * @author Natália Bebjaková */ - private class TriangleVertexAreas { - public double v1Area; - public double v2Area; - public double v3Area; + private final class TriangleVertexAreas { + public final double v1Area; + public final double v2Area; + public final double v3Area; + + private TriangleVertexAreas(double v1, double v2, double v3) { + v1Area = v1; + v2Area = v2; + v3Area = v3; + } } /** @@ -403,41 +411,41 @@ public class SymmetryEstimator { MeshPoint v3Half = (t.vertex2.addPosition(t.vertex1)).dividePosition(2); - TriangleVertexAreas area = new TriangleVertexAreas(); + //TriangleVertexAreas area = new TriangleVertexAreas(); if (d1 < 0) { - area.v3Area = ((v2Half.subtractPosition(t.vertex3)).crossProduct(v1Half.subtractPosition(t.vertex3))).abs() / 2.0; - area.v2Area = ((v3Half.subtractPosition(t.vertex2)).crossProduct(v1Half.subtractPosition(t.vertex2))).abs() / 2.0; - area.v1Area = (((v1Half.subtractPosition(t.vertex1)).crossProduct(v3Half.subtractPosition(t.vertex1))).abs() / 2.0) + + double v3Area = ((v2Half.subtractPosition(t.vertex3)).crossProduct(v1Half.subtractPosition(t.vertex3))).abs() / 2.0; + double v2Area = ((v3Half.subtractPosition(t.vertex2)).crossProduct(v1Half.subtractPosition(t.vertex2))).abs() / 2.0; + double v1Area = (((v1Half.subtractPosition(t.vertex1)).crossProduct(v3Half.subtractPosition(t.vertex1))).abs() / 2.0) + (((v1Half.subtractPosition(t.vertex1)).crossProduct(v2Half.subtractPosition(t.vertex1))).abs() / 2.0); - return area; + return new TriangleVertexAreas(v1Area, v2Area, v3Area); } if (d2 < 0) { - area.v1Area = ((v3Half.subtractPosition(t.vertex1)).crossProduct(v2Half.subtractPosition(t.vertex1))).abs() / 2.0; - area.v3Area = ((v1Half.subtractPosition(t.vertex3)).crossProduct(v2Half.subtractPosition(t.vertex3))).abs() / 2.0; - area.v2Area = (((v2Half.subtractPosition(t.vertex2)).crossProduct(v1Half.subtractPosition(t.vertex2))).abs() / 2.0) + + double v1Area = ((v3Half.subtractPosition(t.vertex1)).crossProduct(v2Half.subtractPosition(t.vertex1))).abs() / 2.0; + double v3Area = ((v1Half.subtractPosition(t.vertex3)).crossProduct(v2Half.subtractPosition(t.vertex3))).abs() / 2.0; + double v2Area = (((v2Half.subtractPosition(t.vertex2)).crossProduct(v1Half.subtractPosition(t.vertex2))).abs() / 2.0) + (((v2Half.subtractPosition(t.vertex2)).crossProduct(v3Half.subtractPosition(t.vertex2))).abs() / 2.0); - return area; + return new TriangleVertexAreas(v1Area, v2Area, v3Area); } if (d3 < 0) { - area.v2Area = ((v1Half.subtractPosition(t.vertex2)).crossProduct(v3Half.subtractPosition(t.vertex2))).abs() / 2.0; - area.v1Area = ((v2Half.subtractPosition(t.vertex1)).crossProduct(v3Half.subtractPosition(t.vertex1))).abs() / 2.0; - area.v3Area = (((v3Half.subtractPosition(t.vertex3)).crossProduct(v2Half.subtractPosition(t.vertex3))).abs() / 2.0) + + double v2Area = ((v1Half.subtractPosition(t.vertex2)).crossProduct(v3Half.subtractPosition(t.vertex2))).abs() / 2.0; + double v1Area = ((v2Half.subtractPosition(t.vertex1)).crossProduct(v3Half.subtractPosition(t.vertex1))).abs() / 2.0; + double v3Area = (((v3Half.subtractPosition(t.vertex3)).crossProduct(v2Half.subtractPosition(t.vertex3))).abs() / 2.0) + (((v3Half.subtractPosition(t.vertex3)).crossProduct(v1Half.subtractPosition(t.vertex3))).abs() / 2.0); - return area; + return new TriangleVertexAreas(v1Area, v2Area, v3Area); } MeshPoint circumcenter = t.vertex1.multiplyPosition(d1).addPosition(t.vertex2.multiplyPosition(d2).addPosition(t.vertex3.multiplyPosition(d3))); - area.v1Area = (((v2Half.subtractPosition(t.vertex1)).crossProduct(circumcenter.subtractPosition(t.vertex1))).abs() / 2.0) + + double v1Area = (((v2Half.subtractPosition(t.vertex1)).crossProduct(circumcenter.subtractPosition(t.vertex1))).abs() / 2.0) + (((v3Half.subtractPosition(t.vertex1)).crossProduct(circumcenter.subtractPosition(t.vertex1))).abs() / 2.0); - area.v2Area = (((v3Half.subtractPosition(t.vertex2)).crossProduct(circumcenter.subtractPosition(t.vertex2))).abs() / 2.0) + + double v2Area = (((v3Half.subtractPosition(t.vertex2)).crossProduct(circumcenter.subtractPosition(t.vertex2))).abs() / 2.0) + (((v1Half.subtractPosition(t.vertex2)).crossProduct(circumcenter.subtractPosition(t.vertex2))).abs() / 2.0); - area.v3Area = (((v1Half.subtractPosition(t.vertex3)).crossProduct(circumcenter.subtractPosition(t.vertex3))).abs() / 2.0) + + double v3Area = (((v1Half.subtractPosition(t.vertex3)).crossProduct(circumcenter.subtractPosition(t.vertex3))).abs() / 2.0) + (((v2Half.subtractPosition(t.vertex3)).crossProduct(circumcenter.subtractPosition(t.vertex3))).abs() / 2.0); - return area; + return new TriangleVertexAreas(v1Area, v2Area, v3Area); } /** @@ -668,8 +676,8 @@ public class SymmetryEstimator { double maxDist) { plane.normalize(); - Vector3d normal = new Vector3d(plane.a, plane.b, plane.c); - double d = plane.d; + Vector3d normal = plane.getNormal(); + double d = plane.getDistance(); double maxCurvRatio = 1.0 / minCurvRatio; int votes = 0; //List<Vector3d> normals = calculateNormals(); diff --git a/GUI/src/main/java/cz/fidentis/analyst/gui/SymmetryPanel.form b/GUI/src/main/java/cz/fidentis/analyst/gui/SymmetryPanel.form index 65d045392839a2d7c63dd98b9731e7518c2821a6..3af48b80f709f79399b8138ff9d0553279069aea 100644 --- a/GUI/src/main/java/cz/fidentis/analyst/gui/SymmetryPanel.form +++ b/GUI/src/main/java/cz/fidentis/analyst/gui/SymmetryPanel.form @@ -77,7 +77,7 @@ </Group> <EmptySpace max="-2" attributes="0"/> <Group type="103" groupAlignment="0" attributes="0"> - <Component id="minCurvatio4" pref="157" max="32767" attributes="0"/> + <Component id="minCurvatio4" pref="0" max="32767" attributes="0"/> <Group type="102" alignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0"> <Component id="minCurvatio" min="-2" max="-2" attributes="0"/> @@ -208,7 +208,6 @@ <Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor"> <Color id="Hand Cursor"/> </Property> - <Property name="opaque" type="boolean" value="false"/> </Properties> </Component> <Component class="javax.swing.JSlider" name="angleCosineSlider"> @@ -218,7 +217,6 @@ <Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor"> <Color id="Hand Cursor"/> </Property> - <Property name="opaque" type="boolean" value="false"/> </Properties> </Component> <Component class="javax.swing.JLabel" name="minCurvatio"> @@ -250,7 +248,6 @@ <Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor"> <Color id="Hand Cursor"/> </Property> - <Property name="opaque" type="boolean" value="false"/> </Properties> </Component> <Component class="javax.swing.JLabel" name="minCurvatio3"> @@ -272,7 +269,6 @@ <Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor"> <Color id="Hand Cursor"/> </Property> - <Property name="opaque" type="boolean" value="false"/> </Properties> </Component> <Component class="javax.swing.JLabel" name="minCurvatio4"> @@ -293,7 +289,6 @@ <Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor"> <Color id="Hand Cursor"/> </Property> - <Property name="opaque" type="boolean" value="false"/> </Properties> </Component> <Component class="javax.swing.JLabel" name="significantPointLabel"> @@ -325,7 +320,6 @@ <Component class="javax.swing.JCheckBox" name="averagingCheckBox"> <Properties> <Property name="selected" type="boolean" value="true"/> - <Property name="opaque" type="boolean" value="false"/> </Properties> <Events> <EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="averagingCheckBoxMouseClicked"/> diff --git a/GUI/src/main/java/cz/fidentis/analyst/gui/SymmetryPanel.java b/GUI/src/main/java/cz/fidentis/analyst/gui/SymmetryPanel.java index 5335736e00c2ec99746ca8f3aeb337147e93acc9..4e85f9e3810289cc45ef10cdf062238e3855eede 100644 --- a/GUI/src/main/java/cz/fidentis/analyst/gui/SymmetryPanel.java +++ b/GUI/src/main/java/cz/fidentis/analyst/gui/SymmetryPanel.java @@ -525,8 +525,8 @@ public final class SymmetryPanel extends javax.swing.JPanel { * @param evt Final computed plane is shown to user */ private void showPlaneLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_showPlaneLabelMouseClicked - JOptionPane.showMessageDialog(frameMain, "Approximate plane of symmetry: \n" + finalPlane.a + "\n" + finalPlane.b + "\n" + finalPlane.c + "\n" + - finalPlane.d + "\n", "Final plane.", 0, new ImageIcon(getClass().getResource("/cz/fidentis/analyst/gui/resources/showPlanePane.png"))); + JOptionPane.showMessageDialog(frameMain, "Approximate plane of symmetry: \n" + finalPlane.getNormal().x + "\n" + finalPlane.getNormal().y + "\n" + finalPlane.getNormal().z + "\n" + + finalPlane.getDistance() + "\n", "Final plane.", 0, new ImageIcon(getClass().getResource("/cz/fidentis/analyst/gui/resources/showPlanePane.png"))); }//GEN-LAST:event_showPlaneLabelMouseClicked /**