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

Resolve "Fix error in the registration GUI"

parent 00b599e2
No related branches found
No related tags found
No related merge requests found
Showing with 56 additions and 92 deletions
......@@ -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();
}
......@@ -111,6 +111,7 @@ public class SymmetryEstimatorMesh extends SymmetryEstimator {
*
* @return Symmetry plane
*/
@Override
public Plane getSymmetryPlane() {
return getSymmetryPlane(true);
}
......
......@@ -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;
......
......@@ -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();
});
}
......
......@@ -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();
......
......@@ -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(
......
......@@ -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;
}
}
}
......@@ -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);
}
......
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);
}
}
}
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