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 78a2be5f6c786995cec4d3440dcc416159a50f77..b4dc38cf8db03b35cd5b119261c94f4d02b2fdd8 100644 --- a/Comparison/src/main/java/cz/fidentis/analyst/symmetry/SymmetryEstimator.java +++ b/Comparison/src/main/java/cz/fidentis/analyst/symmetry/SymmetryEstimator.java @@ -11,7 +11,7 @@ public abstract class SymmetryEstimator extends MeshVisitor { /** * Returns a symmetry plane. - * @return a symmetry plane or {@code null{ + * @return a symmetry plane or {@code null} */ public abstract Plane getSymmetryPlane(); } diff --git a/Comparison/src/main/java/cz/fidentis/analyst/symmetry/SymmetryEstimatorMesh.java b/Comparison/src/main/java/cz/fidentis/analyst/symmetry/SymmetryEstimatorMesh.java index c859bbcaf48a8e19c6dc487104ff701394d38e67..8374a544cd4948a99861e3b098d8e8ddec4e2ea4 100644 --- a/Comparison/src/main/java/cz/fidentis/analyst/symmetry/SymmetryEstimatorMesh.java +++ b/Comparison/src/main/java/cz/fidentis/analyst/symmetry/SymmetryEstimatorMesh.java @@ -111,6 +111,7 @@ public class SymmetryEstimatorMesh extends SymmetryEstimator { * * @return Symmetry plane */ + @Override public Plane getSymmetryPlane() { return getSymmetryPlane(true); } diff --git a/Comparison/src/main/java/cz/fidentis/analyst/visitors/mesh/sampling/PointSampling.java b/Comparison/src/main/java/cz/fidentis/analyst/visitors/mesh/sampling/PointSampling.java index 8fc3cc17b9e29938a2fbb8a9df5c190615ad343e..8199fc634fb87023a56047fbe878299ede1a84ec 100644 --- a/Comparison/src/main/java/cz/fidentis/analyst/visitors/mesh/sampling/PointSampling.java +++ b/Comparison/src/main/java/cz/fidentis/analyst/visitors/mesh/sampling/PointSampling.java @@ -98,7 +98,7 @@ public abstract class PointSampling extends MeshVisitor { */ public final void setRequiredSamples(double perc) { if (perc <= 0.0 || perc > 1) { - throw new IllegalArgumentException("perc"); + throw new IllegalArgumentException("perc = " + perc); } this.samplingType = PointSamplingType.PERCENTAGE; this.samplingLimit = perc; diff --git a/GUI/src/main/java/cz/fidentis/analyst/core/ProgressDialog.java b/GUI/src/main/java/cz/fidentis/analyst/core/ProgressDialog.java index 3ffcc1a6dfafebbada78eeb3a39afcaeacb47351..746b897162797c0172aab63afaea1afbabe42c77 100644 --- a/GUI/src/main/java/cz/fidentis/analyst/core/ProgressDialog.java +++ b/GUI/src/main/java/cz/fidentis/analyst/core/ProgressDialog.java @@ -107,7 +107,7 @@ public class ProgressDialog<T,V> extends JDialog { setSize(450, 100); cancelButton.addActionListener((ActionEvent e) -> { - task.cancel(true); + System.out.println("ZZZ " + task.cancel(true)); dispose(); }); } diff --git a/GUI/src/main/java/cz/fidentis/analyst/core/SpinSlider.java b/GUI/src/main/java/cz/fidentis/analyst/core/SpinSlider.java index b8af0323baec7f431f9d9d5ce2aad6c70cac551e..bbffbe9aabaf590d65a38afff4fd50da85ff556e 100644 --- a/GUI/src/main/java/cz/fidentis/analyst/core/SpinSlider.java +++ b/GUI/src/main/java/cz/fidentis/analyst/core/SpinSlider.java @@ -191,6 +191,21 @@ public class SpinSlider extends JPanel { * @param value Initial value between 0 and 100. */ public void initPercentage(int value) { + initPercentage(value, 0, 100); + } + + /** + * Initializes this spin-slider to percents in given range. + * + * @param value Initial value between 0 and 100. + * @param min min value in the range 0..100 + * @param max max value in the range 0..100 + */ + public void initPercentage(int value, int min, int max) { + if (min > max || min < 0 || max > 100) { + throw new IllegalArgumentException("min/max: " + min + "/" + max); + } + remove(slider); if (spinner != null) { remove(spinner); @@ -200,8 +215,8 @@ public class SpinSlider extends JPanel { spinner = new JSpinner(); spinner.setModel(new SpinnerNumberModel(value, 0, 100, 1)); spinner.setEditor(new JSpinner.NumberEditor(spinner, "0'%'")); - slider.setMinimum(0); - slider.setMaximum(100); + slider.setMinimum(min); + slider.setMaximum(max); slider.setValue(value); initComponents(); diff --git a/GUI/src/main/java/cz/fidentis/analyst/registration/RegistrationPanel.java b/GUI/src/main/java/cz/fidentis/analyst/registration/RegistrationPanel.java index f23211d92d082f5a90bd392eca4f7e0f533a64ac..e40d77b13ddddfb4eea3452b2be224de7a6d24bd 100644 --- a/GUI/src/main/java/cz/fidentis/analyst/registration/RegistrationPanel.java +++ b/GUI/src/main/java/cz/fidentis/analyst/registration/RegistrationPanel.java @@ -94,7 +94,7 @@ public class RegistrationPanel extends ControlPanel { thersholdFTF.setValue(5.0); thersholdFTF.addActionListener(createListener(action, ACTION_COMMAND_FP_CLOSENESS_THRESHOLD)); - spinSlider1.initPercentage(this.undersamplingStrength); + spinSlider1.initPercentage(this.undersamplingStrength, 1, 100); spinSlider1.addSpinnerListener((ActionEvent e) -> { // update slider when the input field changed this.undersamplingStrength = (Integer) spinSlider1.getValue(); action.actionPerformed(new ActionEvent( diff --git a/GUI/src/main/java/cz/fidentis/analyst/symmetry/SymmetryAction.java b/GUI/src/main/java/cz/fidentis/analyst/symmetry/SymmetryAction.java index c15cdeaa9b359bdcf664dd902954d2a8c1c96f82..680748a1315558a92581dcebd2286d7e30d13808 100644 --- a/GUI/src/main/java/cz/fidentis/analyst/symmetry/SymmetryAction.java +++ b/GUI/src/main/java/cz/fidentis/analyst/symmetry/SymmetryAction.java @@ -3,7 +3,6 @@ package cz.fidentis.analyst.symmetry; import cz.fidentis.analyst.Logger; import cz.fidentis.analyst.canvas.Canvas; import cz.fidentis.analyst.core.ControlPanelAction; -import cz.fidentis.analyst.core.ProgressDialog; import cz.fidentis.analyst.core.SpinSlider; import cz.fidentis.analyst.face.HumanFace; import cz.fidentis.analyst.face.events.HumanFaceEvent; @@ -21,15 +20,14 @@ import cz.fidentis.analyst.visitors.mesh.sampling.NoSampling; import cz.fidentis.analyst.visitors.mesh.sampling.PointSampling; import cz.fidentis.analyst.visitors.mesh.sampling.RandomSampling; import cz.fidentis.analyst.visitors.mesh.sampling.UniformSpaceSampling; +import java.awt.Cursor; import java.awt.event.ActionEvent; -import java.beans.PropertyChangeEvent; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.swing.JTabbedPane; -import javax.swing.SwingWorker; import javax.vecmath.Point3d; import javax.vecmath.Vector3d; @@ -160,48 +158,23 @@ public class SymmetryAction extends ControlPanelAction implements HumanFaceListe protected void recomputeFromMesh(int faceSlot) { HumanFace face = getCanvas().getHumanFace(faceSlot); - SymmetryEstimator estimator = null; if (face == null) { return; } - String alg = controlPanel.getAlgorithm(); - if (alg.equals(SymmetryPanel.ALGORITHM[1])) { - estimator = new SymmetryEstimatorRobust( - getSamplingStrategy(), - controlPanel.getPointSamplingStrength1(), - controlPanel.getPointSamplingStrength2()); - } else if (alg.equals(SymmetryPanel.ALGORITHM[2])) { - estimator = new SymmetryEstimatorRobustMesh( - getSamplingStrategy(), - controlPanel.getPointSamplingStrength1(), - controlPanel.getPointSamplingStrength2()); - } else if (alg.equals(SymmetryPanel.ALGORITHM[0])) { - estimator = new SymmetryEstimatorMesh( - getSamplingStrategy(), - controlPanel.getPointSamplingStrength1()); - //face.getMeshModel().compute(estimator); - //face.setSymmetryPlane(estimator.getSymmetryPlane()); - } else { - return; - } + SymmetryEstimator estimator = getSymmetryEstimator(); + face.computeCurvature(false); Logger log = Logger.measureTime(); - ProgressDialog progressBar = new ProgressDialog(controlPanel, "Symmetry plane estimation"); - SymmetryTask task = new SymmetryTask(face, estimator, progressBar); - - // The following code will be executed when the task is done: - task.addPropertyChangeListener((PropertyChangeEvent evt) -> { - if ("state".equals(evt.getPropertyName()) && (SwingWorker.StateValue.DONE.equals(evt.getNewValue()))) { - setDrawablePlane(face, faceSlot); - face.announceEvent(new SymmetryPlaneChangedEvent(face, "", this)); - log.printDuration("Symmetry plane estimation from mesh for " + face.getShortName()); - } - }); + controlPanel.getParent().setCursor(new Cursor(Cursor.WAIT_CURSOR)); + face.getMeshModel().compute(estimator); + face.setSymmetryPlane(estimator.getSymmetryPlane()); + controlPanel.getParent().setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + log.printDuration("Symmetry plane estimation from mesh for " + face.getShortName()); - // run the task - progressBar.runTask(task); + setDrawablePlane(face, faceSlot); + face.announceEvent(new SymmetryPlaneChangedEvent(face, "", this)); } protected void recomputeFromFeaturePoints(int index) { @@ -257,7 +230,7 @@ public class SymmetryAction extends ControlPanelAction implements HumanFaceListe } protected void updatePrecision(HumanFace face) { - if (face == null) { + if (face == null || !face.hasSymmetryPlane()) { return; } @@ -325,4 +298,24 @@ public class SymmetryAction extends ControlPanelAction implements HumanFaceListe } } + private SymmetryEstimator getSymmetryEstimator() { + String alg = controlPanel.getAlgorithm(); + if (alg.equals(SymmetryPanel.ALGORITHM[1])) { + return new SymmetryEstimatorRobust( + getSamplingStrategy(), + controlPanel.getPointSamplingStrength1(), + controlPanel.getPointSamplingStrength2()); + } else if (alg.equals(SymmetryPanel.ALGORITHM[2])) { + return new SymmetryEstimatorRobustMesh( + getSamplingStrategy(), + controlPanel.getPointSamplingStrength1(), + controlPanel.getPointSamplingStrength2()); + } else if (alg.equals(SymmetryPanel.ALGORITHM[0])) { + return new SymmetryEstimatorMesh( + getSamplingStrategy(), + controlPanel.getPointSamplingStrength1()); + } else { + return null; + } + } } diff --git a/GUI/src/main/java/cz/fidentis/analyst/symmetry/SymmetryPanel.java b/GUI/src/main/java/cz/fidentis/analyst/symmetry/SymmetryPanel.java index 57b8fb8baa37651adf88de6efd755f9657ad69aa..33d9732550950b0501c11b7133fd7b3cae16cfcb 100644 --- a/GUI/src/main/java/cz/fidentis/analyst/symmetry/SymmetryPanel.java +++ b/GUI/src/main/java/cz/fidentis/analyst/symmetry/SymmetryPanel.java @@ -168,15 +168,16 @@ public class SymmetryPanel extends ControlPanel { private void setDefaultValues(ActionListener action) { if (getAlgorithm().equals(ALGORITHM[1])) { // new robust - spinSlider1.initInteger(100, 10, 500, 1); + spinSlider1.initInteger(100, 10, 1000, 1); spinSlider2.initInteger(1000, 10, 5000, 1); spinSlider2.setEnabled(true); } else if (getAlgorithm().equals(ALGORITHM[2])) { // new robust with curvature spinSlider1.initInteger(200, 10, 500, 1); - spinSlider2.initInteger(200, 10, 5000, 1); + spinSlider2.initInteger(200, 10, 500, 1); spinSlider2.setEnabled(true); } else if (getAlgorithm().equals(ALGORITHM[0])) { // old fast spinSlider1.initInteger(200, 10, 500, 1); + spinSlider2.initInteger(0, 0, 100, 1); spinSlider2.setEnabled(false); } diff --git a/GUI/src/main/java/cz/fidentis/analyst/symmetry/SymmetryTask.java b/GUI/src/main/java/cz/fidentis/analyst/symmetry/SymmetryTask.java deleted file mode 100644 index 2018810e61ca56f57dd4c69db989304815530f93..0000000000000000000000000000000000000000 --- a/GUI/src/main/java/cz/fidentis/analyst/symmetry/SymmetryTask.java +++ /dev/null @@ -1,46 +0,0 @@ -package cz.fidentis.analyst.symmetry; - -import cz.fidentis.analyst.core.ProgressDialog; -import cz.fidentis.analyst.face.HumanFace; -import javax.swing.SwingWorker; - -/** - * A task that computes symmetry plane from mesh. - * - * @author Radek Oslejsek - */ -public class SymmetryTask extends SwingWorker<Void, Void> { - - private SymmetryEstimator symmetryEstimator; - private HumanFace face; - private final ProgressDialog progressDialog; - - /** - * Constructor. - * - * @param face Human face - * @param symmetryEstimator Symmetry estimation algorithm - * @param progressDialog progress dialogue - */ - public SymmetryTask(HumanFace face, SymmetryEstimator symmetryEstimator, ProgressDialog progressDialog) { - this.symmetryEstimator = symmetryEstimator; - this.face = face; - this.progressDialog = progressDialog; - } - - @Override - protected Void doInBackground() throws Exception { - face.computeCurvature(false); - face.getMeshModel().compute(symmetryEstimator); - face.setSymmetryPlane(symmetryEstimator.getSymmetryPlane()); - return null; - } - - @Override - protected void done() { - progressDialog.dispose(); // close progess bar - if (isCancelled()) { - face.setSymmetryPlane(null); - } - } -}