Commit 26de4916 authored by Radek Ošlejšek's avatar Radek Ošlejšek
Browse files

Resolve "Make the speed of the movement of 3D models adaptive; add undo of the movement"

parent 541310f1
Loading
Loading
Loading
Loading
+27 −1
Original line number Diff line number Diff line
@@ -2,9 +2,11 @@ package cz.fidentis.analyst.gui.task.registration;

import cz.fidentis.analyst.Logger;
import cz.fidentis.analyst.canvas.Canvas;
import cz.fidentis.analyst.drawables.DrawableFace;
import cz.fidentis.analyst.drawables.DrawablePointCloud;
import cz.fidentis.analyst.events.*;
import cz.fidentis.analyst.face.HumanFace;
import cz.fidentis.analyst.face.HumanFaceState;
import cz.fidentis.analyst.procrustes.PrTrans;
import cz.fidentis.analyst.registration.RegistrationUtils;
import cz.fidentis.analyst.gui.elements.SpinSlider;
@@ -50,6 +52,11 @@ public class RegistrationAction extends ControlPanelAction<RegistrationPanel> im
     */
    private double fpThreshold = 5.0;

    /**
     * The old state of transformed secondary face for possible fall back
     */
    private HumanFaceState secFaceState = null;

    /**
     * Constructor.
     * A new {@code RegistrationPanel} is instantiated and added to the {@code topControlPane}
@@ -71,6 +78,7 @@ public class RegistrationAction extends ControlPanelAction<RegistrationPanel> im
                            getControlPanel().getIcpUndersamplingStrength());
                },
                () -> { // HIDE
                    secFaceState = null; // clear cached state
                    getScene().setOtherDrawable(pointCloudSlot, null);
                    pointCloudSlot = -1;
                }
@@ -100,6 +108,7 @@ public class RegistrationAction extends ControlPanelAction<RegistrationPanel> im
        switch (action) {
            case RegistrationPanel.ACTION_COMMAND_REGISTER:
                String alg = getControlPanel().getRegistrationAlgorihm();
                this.secFaceState = getSecondaryFace().getState(); // cache original state for possible undo
                if (RegistrationPanel.AUTO_ALIGNMENT_ALGORITHM[0].equals(alg)) { // ICP
                    applyICP();
                } else if (RegistrationPanel.AUTO_ALIGNMENT_ALGORITHM[1].equals(alg)) { // Procrustes
@@ -114,9 +123,12 @@ public class RegistrationAction extends ControlPanelAction<RegistrationPanel> im
                getSecondaryFace().announceEvent(new HumanFaceTransformedEvent(getSecondaryFace(), "", this));
                pointCloudSlot = drawPointSamples(getCanvas().getScene().getSecondaryFaceSlot(),
                        pointCloudSlot, getControlPanel().getIcpUndersamplingStrength());

                break;
            case RegistrationPanel.ACTION_COMMAND_MANUAL_TRANSFORMATION_IN_PROGRESS:
                getControlPanel().setTranslationFactor(getScene()); // adapt movement speed to the size of the scene
                if (this.secFaceState == null) {
                    this.secFaceState = getSecondaryFace().getState(); // cache original state for possible undo
                }
                RegistrationUtils.transformFace(
                        getSecondaryDrawableFace().getHumanFace(),
                        getControlPanel().getAndClearManualRotation(),
@@ -139,6 +151,20 @@ public class RegistrationAction extends ControlPanelAction<RegistrationPanel> im
                        getControlPanel().getIcpUndersamplingStrength()
                );
                break;
            case RegistrationPanel.ACTION_COMMAND_UNDO_TRANSFORMATION:
                if (this.secFaceState != null) {
                    getSecondaryFace().setState(this.secFaceState);
                    getScene().setHumanFace(getScene().getSecondaryFaceSlot(), getSecondaryFace()); // update drawable
                    getSecondaryDrawableFace().setColor(DrawableFace.SKIN_COLOR_SECONDARY);
                    highlightCloseFeaturePoints();
                    pointCloudSlot = drawPointSamples(getCanvas().getScene().getSecondaryFaceSlot(),
                        pointCloudSlot, getControlPanel().getIcpUndersamplingStrength());
                    getSecondaryFace().announceEvent(
                            new HumanFaceTransformedEvent(getSecondaryFace(), "", this, true)
                    );
                    this.secFaceState = null;
                }
                break;
            case RegistrationPanel.ACTION_COMMAND_FP_CLOSENESS_THRESHOLD:
                fpThreshold = ((Number) (((JFormattedTextField) ae.getSource()).getValue())).doubleValue();
                highlightCloseFeaturePoints();
+60 −44
Original line number Diff line number Diff line
@@ -38,27 +38,35 @@
          </Group>
          <Group type="102" alignment="0" attributes="0">
              <EmptySpace min="-2" pref="791" max="-2" attributes="0"/>
              <Component id="jSeparator2" max="32767" attributes="0"/>
              <Component id="jSeparator2" pref="1" max="32767" attributes="0"/>
              <EmptySpace min="-2" pref="450" max="-2" attributes="0"/>
          </Group>
          <Group type="102" alignment="0" attributes="0">
              <EmptySpace max="-2" attributes="0"/>
              <Group type="103" groupAlignment="1" max="-2" attributes="0">
                  <Group type="102" alignment="0" attributes="0">
              <Group type="103" groupAlignment="0" attributes="0">
                  <Group type="102" attributes="0">
                      <Component id="jPanel6" min="-2" max="-2" attributes="0"/>
                      <EmptySpace max="-2" attributes="0"/>
                      <Component id="jPanel1" max="32767" attributes="0"/>
                      <Component id="jPanel1" min="-2" max="-2" attributes="0"/>
                      <EmptySpace min="0" pref="0" max="32767" attributes="0"/>
                      <Component id="jSeparator7" min="-2" pref="50" max="-2" attributes="0"/>
                  </Group>
                  <Component id="transformationPanel" alignment="0" pref="0" max="32767" attributes="0"/>
                  <Component id="jPanel3" alignment="0" max="32767" attributes="0"/>
                  <Group type="102" attributes="0">
                      <Group type="103" groupAlignment="1" max="-2" attributes="0">
                          <Component id="jPanel2" alignment="0" max="32767" attributes="0"/>
                          <Component id="transformationPanel" pref="0" max="32767" attributes="0"/>
                          <Component id="jPanel3" max="32767" attributes="0"/>
                          <Component id="jButton2" alignment="0" min="-2" pref="209" max="-2" attributes="0"/>
                      </Group>
                      <EmptySpace min="0" pref="0" max="32767" attributes="0"/>
                  </Group>
              </Group>
              <EmptySpace max="32767" attributes="0"/>
              <Component id="jSeparator7" min="-2" pref="50" max="-2" attributes="0"/>
          </Group>
      </Group>
    </DimensionLayout>
    <DimensionLayout dim="1">
      <Group type="103" groupAlignment="0" attributes="0">
          <Group type="102" alignment="0" attributes="0">
              <Group type="103" groupAlignment="0" attributes="0">
                  <Group type="102" alignment="0" attributes="0">
                      <Group type="103" groupAlignment="0" attributes="0">
@@ -68,23 +76,22 @@
                          </Group>
                          <Group type="102" alignment="0" attributes="0">
                              <EmptySpace max="-2" attributes="0"/>
                      <Group type="103" groupAlignment="1" attributes="0">
                              <Component id="jPanel6" min="-2" max="-2" attributes="0"/>
                          <Component id="jPanel1" min="-2" max="-2" attributes="0"/>
                          </Group>
                      </Group>
                      <EmptySpace pref="6" max="32767" attributes="0"/>
                  </Group>
                  <Component id="jPanel1" alignment="1" min="-2" max="-2" attributes="0"/>
              </Group>
              <EmptySpace max="-2" attributes="0"/>
              <Group type="103" groupAlignment="1" attributes="0">
                  <Group type="102" attributes="0">
              <Component id="jPanel3" min="-2" max="-2" attributes="0"/>
                      <EmptySpace min="-2" pref="142" max="-2" attributes="0"/>
                  </Group>
              <EmptySpace max="-2" attributes="0"/>
              <Component id="transformationPanel" min="-2" pref="134" max="-2" attributes="0"/>
              </Group>
              <EmptySpace max="-2" attributes="0"/>
              <Component id="jPanel2" min="-2" max="-2" attributes="0"/>
              <EmptySpace min="-2" pref="669" max="-2" attributes="0"/>
              <EmptySpace max="-2" attributes="0"/>
              <Component id="jButton2" min="-2" max="-2" attributes="0"/>
              <EmptySpace min="-2" pref="661" max="-2" attributes="0"/>
              <Component id="jSeparator11" min="-2" pref="10" max="-2" attributes="0"/>
              <EmptySpace min="-2" pref="221" max="-2" attributes="0"/>
              <Component id="jSeparator2" min="-2" pref="10" max="-2" attributes="0"/>
@@ -909,19 +916,19 @@
                  <Component id="selectableComboBox1" min="-2" max="-2" attributes="0"/>
                  <EmptySpace max="-2" attributes="0"/>
                  <Component id="jButton1" min="-2" max="-2" attributes="0"/>
                  <EmptySpace min="0" pref="0" max="32767" attributes="0"/>
                  <EmptySpace min="0" pref="269" max="32767" attributes="0"/>
              </Group>
          </Group>
        </DimensionLayout>
        <DimensionLayout dim="1">
          <Group type="103" groupAlignment="0" attributes="0">
              <Group type="102" alignment="0" attributes="0">
              <Group type="102" attributes="0">
                  <EmptySpace max="-2" attributes="0"/>
                  <Group type="103" groupAlignment="3" attributes="0">
                      <Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/>
                      <Component id="selectableComboBox1" alignment="3" min="-2" max="-2" attributes="0"/>
                      <Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/>
                  </Group>
                  <EmptySpace max="32767" attributes="0"/>
                  <EmptySpace min="0" pref="6" max="32767" attributes="0"/>
              </Group>
          </Group>
        </DimensionLayout>
@@ -995,18 +1002,18 @@
              <Group type="102" alignment="0" attributes="0">
                  <EmptySpace max="-2" attributes="0"/>
                  <Group type="103" groupAlignment="1" attributes="0">
                      <Component id="jTextField1" alignment="1" min="-2" pref="24" max="-2" attributes="0"/>
                      <Component id="jTextField1" alignment="1" min="-2" pref="28" max="-2" attributes="0"/>
                      <Group type="103" alignment="1" groupAlignment="3" attributes="0">
                          <Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
                          <Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
                          <Component id="jTextField2" alignment="3" min="-2" pref="24" max="-2" attributes="0"/>
                          <Component id="jTextField2" alignment="3" min="-2" pref="28" max="-2" attributes="0"/>
                      </Group>
                  </Group>
                  <EmptySpace type="unrelated" max="-2" attributes="0"/>
                  <Group type="103" groupAlignment="1" attributes="0">
                      <Group type="103" alignment="1" groupAlignment="3" attributes="0">
                          <Component id="featurePointsLabel" alignment="3" min="-2" max="-2" attributes="0"/>
                          <Component id="thersholdFTF" alignment="3" min="-2" pref="27" max="-2" attributes="0"/>
                          <Component id="thersholdFTF" alignment="3" min="-2" pref="28" max="-2" attributes="0"/>
                      </Group>
                      <Group type="102" alignment="0" attributes="0">
                          <Group type="103" groupAlignment="1" max="-2" attributes="0">
@@ -1235,7 +1242,7 @@
                              </Group>
                          </Group>
                      </Group>
                      <EmptySpace max="32767" attributes="0"/>
                      <EmptySpace pref="40" max="32767" attributes="0"/>
                  </Group>
              </Group>
            </DimensionLayout>
@@ -1249,15 +1256,20 @@
                      </Group>
                      <EmptySpace min="-2" pref="8" max="-2" attributes="0"/>
                      <Group type="103" groupAlignment="0" attributes="0">
                          <Component id="jFormattedTextField1" min="-2" pref="22" max="-2" attributes="0"/>
                          <Component id="jLabel5" alignment="0" min="-2" max="-2" attributes="0"/>
                          <Component id="jLabel5" min="-2" max="-2" attributes="0"/>
                          <Component id="jFormattedTextField1" min="-2" pref="28" max="-2" attributes="0"/>
                      </Group>
                      <EmptySpace type="unrelated" max="-2" attributes="0"/>
                      <Group type="103" groupAlignment="1" attributes="0">
                      <Group type="103" groupAlignment="0" attributes="0">
                          <Group type="102" attributes="0">
                              <EmptySpace min="-2" pref="10" max="-2" attributes="0"/>
                              <Component id="jLabel6" min="-2" pref="16" max="-2" attributes="0"/>
                          <Component id="jFormattedTextField2" min="-2" pref="20" max="-2" attributes="0"/>
                          </Group>
                      <EmptySpace min="-2" pref="22" max="-2" attributes="0"/>
                          <Group type="102" attributes="0">
                              <EmptySpace max="-2" attributes="0"/>
                              <Component id="jFormattedTextField2" min="-2" pref="28" max="-2" attributes="0"/>
                          </Group>
                      </Group>
                      <EmptySpace type="unrelated" max="-2" attributes="0"/>
                      <Group type="103" groupAlignment="0" attributes="0">
                          <Component id="spinSlider1" min="-2" max="-2" attributes="0"/>
                          <Component id="jLabel8" alignment="0" min="-2" max="-2" attributes="0"/>
@@ -1375,10 +1387,7 @@
        </DimensionLayout>
        <DimensionLayout dim="1">
          <Group type="103" groupAlignment="0" attributes="0">
              <Group type="102" alignment="0" attributes="0">
                  <Component id="infoLinkButton1" pref="49" max="32767" attributes="0"/>
                  <EmptySpace max="-2" attributes="0"/>
              </Group>
              <Component id="infoLinkButton1" max="32767" attributes="0"/>
          </Group>
        </DimensionLayout>
      </Layout>
@@ -1392,5 +1401,12 @@
        </Component>
      </SubComponents>
    </Container>
    <Component class="javax.swing.JButton" name="jButton2">
      <Properties>
        <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
          <ResourceString bundle="cz/fidentis/analyst/gui/task/registration/Bundle.properties" key="RegistrationPanel.jButton2.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
        </Property>
      </Properties>
    </Component>
  </SubComponents>
</Form>
+85 −53

File changed.

Preview size limit exceeded, changes collapsed.

+1 −0
Original line number Diff line number Diff line
@@ -54,3 +54,4 @@ RegistrationPanel.jPanel3.border.title=Registration parameters
RegistrationPanel.jPanel5.border.title=ICP parameters
RegistrationPanel.jPanel6.border.title=Help
RegistrationPanel.infoLinkButton1.text=
RegistrationPanel.jButton2.text=Undo last transformations
+0 −45
Original line number Diff line number Diff line
package cz.fidentis.analyst.face;

import java.util.Comparator;

/**
 * Comparator for HumanFace faces
 * 
 * @author Matej Kovar
 */
public class FaceStateComparator implements Comparator<HumanFace> {
    /*
    private boolean kdTreeFilter = false;
    private boolean featurePointsFilter = false;
    private boolean alphabeticalFilter = false;

    public FaceStateComparator(boolean kdTreeFilter, boolean featurePointsFilter, boolean alphabeticalFilter) {
        this.kdTreeFilter = kdTreeFilter;
        this.featurePointsFilter = featurePointsFilter;
        this.alphabeticalFilter = alphabeticalFilter;
    }*/
    
    @Override
    public int compare(HumanFace face1, HumanFace face2) {
        int comparison;
        
        comparison = Boolean.compare(face1.hasFeaturePoints(), face2.hasFeaturePoints());
        
        // Both have feature points
        if (comparison == 0) {
            
            comparison = Boolean.compare(face1.hasKdTree(), face2.hasKdTree());
            
            // Both have KD Tree
            if (comparison == 0) {
                
                // Alphabeticaly
                comparison = face1.getShortName().compareTo(face2.getShortName());
            }
        }
        
        return comparison; 
    }

    
}
Loading