Skip to content
Snippets Groups Projects
Commit 6e73b843 authored by Radek Ošlejšek's avatar Radek Ošlejšek
Browse files

Minor refactoring

parent 0097802f
No related branches found
No related tags found
No related merge requests found
...@@ -107,23 +107,15 @@ public class SymmetryEstimator { ...@@ -107,23 +107,15 @@ public class SymmetryEstimator {
*/ */
public Plane getApproxSymmetryPlane(JPanel panel) { public Plane getApproxSymmetryPlane(JPanel panel) {
ArrayList<ApproxSymmetryPlane> planes = new ArrayList<>(); List<ApproxSymmetryPlane> planes = new ArrayList<>();
//List<Vector3d> normals = calculateNormals(); //List<Vector3d> normals = calculateNormals();
if (!facet.hasVertexNormals()) { if (!facet.hasVertexNormals()) {
facet.calculateVertexNormals(); facet.calculateVertexNormals();
} }
double[] curvatures = new double[facet.getNumberOfVertices()];
for (int i = 0; i < facet.getNumberOfVertices(); i++) { double[] curvatures = initCurvatures();
if (facet.getNumberOfVertices() == 2500) { List<Double> sortedCurvatures = new ArrayList<>();
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<>();
for (int i = 0; i < curvatures.length; i++) { for (int i = 0; i < curvatures.length; i++) {
sortedCurvatures.add(curvatures[i]); sortedCurvatures.add(curvatures[i]);
} }
...@@ -134,8 +126,8 @@ public class SymmetryEstimator { ...@@ -134,8 +126,8 @@ public class SymmetryEstimator {
} }
double bottomCurvature = sortedCurvatures.get(sortedCurvatures.size() - 1 - config.getSignificantPointCount()); double bottomCurvature = sortedCurvatures.get(sortedCurvatures.size() - 1 - config.getSignificantPointCount());
ArrayList<Integer> significantPoints = new ArrayList<>(); List<Integer> significantPoints = new ArrayList<>();
ArrayList<Double> significantCurvatures = new ArrayList<>(); List<Double> significantCurvatures = new ArrayList<>();
for (int i = 0; i < facet.getNumberOfVertices(); i++) { for (int i = 0; i < facet.getNumberOfVertices(); i++) {
if (curvatures[i] >= bottomCurvature) { if (curvatures[i] >= bottomCurvature) {
...@@ -160,8 +152,8 @@ public class SymmetryEstimator { ...@@ -160,8 +152,8 @@ public class SymmetryEstimator {
if (i != j) { if (i != j) {
double minRatio = config.getMinCurvRatio(); double minRatio = config.getMinCurvRatio();
double maxRatio = 1.0 / minRatio; double maxRatio = 1.0 / minRatio;
if (significantCurvatures.get(i) / significantCurvatures.get(j) >= minRatio && significantCurvatures.get(i) / if (significantCurvatures.get(i) / significantCurvatures.get(j) >= minRatio &&
significantCurvatures.get(j) <= maxRatio) { significantCurvatures.get(i) / significantCurvatures.get(j) <= maxRatio) {
Vector3d p1 = new Vector3d(facet.getVertex(significantPoints.get(i)).getPosition()); Vector3d p1 = new Vector3d(facet.getVertex(significantPoints.get(i)).getPosition());
Vector3d p2 = new Vector3d(facet.getVertex(significantPoints.get(j)).getPosition()); Vector3d p2 = new Vector3d(facet.getVertex(significantPoints.get(j)).getPosition());
...@@ -220,6 +212,34 @@ public class SymmetryEstimator { ...@@ -220,6 +212,34 @@ public class SymmetryEstimator {
finalPlanes.add(planes.get(i)); 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; double newA = 0, newB = 0, newC = 0, newD = 0;
Vector3d refDir = finalPlanes.get(0).getNormal(); Vector3d refDir = finalPlanes.get(0).getNormal();
for (int i = 0; i < finalPlanes.size(); i++) { for (int i = 0; i < finalPlanes.size(); i++) {
...@@ -238,16 +258,7 @@ public class SymmetryEstimator { ...@@ -238,16 +258,7 @@ public class SymmetryEstimator {
} }
Plane finalPlane = new Plane(newA, newB, newC, newD); Plane finalPlane = new Plane(newA, newB, newC, newD);
finalPlane.normalize(); finalPlane.normalize();
if (config.isAveraging()){ return finalPlane;
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;
} }
/** /**
...@@ -658,8 +669,8 @@ public class SymmetryEstimator { ...@@ -658,8 +669,8 @@ public class SymmetryEstimator {
* @return total votes given to plane while computing the symmetry * @return total votes given to plane while computing the symmetry
*/ */
private int getVotes(Plane plane, private int getVotes(Plane plane,
ArrayList<Double> curvatures, List<Double> curvatures,
ArrayList<Integer> points, List<Integer> points,
double minCurvRatio, double minCurvRatio,
double minAngleCos, double minAngleCos,
double minNormAngleCos, double minNormAngleCos,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment