Commit 0b418e8c authored by Matej Kovár's avatar Matej Kovár Committed by Radek Ošlejšek
Browse files

Resolve "Show changes from HumanFace in list of models (via EventBus)"

parent f51302ba
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
package cz.fidentis.analyst;

import cz.fidentis.analyst.face.HumanFace;
import cz.fidentis.analyst.mesh.events.MeshEvent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -15,7 +14,6 @@ import java.util.List;
 */
public class Project {
    
    //private HumanFace primaryFace;
    private List<HumanFace> faces = new ArrayList<>();
    
    /**
+45 −0
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; 
    }

    
}
+39 −17
Original line number Diff line number Diff line
@@ -4,10 +4,14 @@ import com.google.common.eventbus.EventBus;
import cz.fidentis.analyst.feature.FeaturePoint;
import cz.fidentis.analyst.feature.services.FeaturePointImportService;
import cz.fidentis.analyst.kdtree.KdTree;
import cz.fidentis.analyst.kdtree.events.KdTreeCreated;
import cz.fidentis.analyst.kdtree.events.KdTreeDestroyed;
import cz.fidentis.analyst.kdtree.events.KdTreeEvent;
import cz.fidentis.analyst.mesh.core.MeshFacet;
import cz.fidentis.analyst.mesh.core.MeshModel;
import cz.fidentis.analyst.mesh.events.MeshEvent;
import cz.fidentis.analyst.mesh.events.MeshListener;
import cz.fidentis.analyst.kdtree.events.KdTreeListener;
import cz.fidentis.analyst.mesh.io.MeshObjLoader;
import cz.fidentis.analyst.symmetry.Plane;
import cz.fidentis.analyst.visitors.face.HumanFaceVisitor;
@@ -25,7 +29,6 @@ import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import java.util.Objects;
import java.util.Observable;
//import org.nustaq.serialization.FSTConfiguration;
//import org.nustaq.serialization.FSTObjectInput;
//import org.nustaq.serialization.FSTObjectOutput;
@@ -51,7 +54,7 @@ import java.util.Observable;
 * 
 * @author Radek Oslejsek
 */
public class HumanFace extends Observable implements MeshListener, Serializable {
public class HumanFace implements MeshListener, KdTreeListener, Serializable {
    
    private MeshModel meshModel;
    
@@ -107,6 +110,7 @@ public class HumanFace extends Observable implements MeshListener, Serializable
            throw new IllegalArgumentException("meshModel");
        }
        this.meshModel = meshModel;
        //eventBus.post(new MeshChangedEvent());
    }

    /**
@@ -115,10 +119,8 @@ public class HumanFace extends Observable implements MeshListener, Serializable
     * 
     * @param listener Listener concerned in the human face changes.
     */
    public void registerListener(MeshListener listener) {
    public void registerListener(HumanFaceListener listener) {
        eventBus.register(listener);
        setChanged();
        notifyObservers(this);
    }
    
    /**
@@ -126,10 +128,8 @@ public class HumanFace extends Observable implements MeshListener, Serializable
     * 
     * @param listener Registered listener
     */
    public void unregisterListener(MeshListener listener) {
    public void unregisterListener(HumanFaceListener listener) {
        eventBus.unregister(listener);  
        setChanged();
        notifyObservers(this);        
    }

    /**
@@ -187,8 +187,6 @@ public class HumanFace extends Observable implements MeshListener, Serializable
     */
    public void setFeaturePoints(List<FeaturePoint> points) {
        featurePoints = points;
        setChanged();
        notifyObservers(this);
    }
    
    /**
@@ -200,8 +198,6 @@ public class HumanFace extends Observable implements MeshListener, Serializable
     */
    public void loadFeaturePoints(String path, String fileName) throws IOException {
        featurePoints = FeaturePointImportService.importFeaturePoints(path, fileName);
        setChanged();
        notifyObservers(this);
    }
    
    /**
@@ -215,6 +211,14 @@ public class HumanFace extends Observable implements MeshListener, Serializable
        return Collections.unmodifiableList(featurePoints);
    }
    
    /**
     * Checks if HumanFace has feature points
     * @return true if yes and false if not
     */
    public boolean hasFeaturePoints() {
        return featurePoints != null;
    }
    
    /**
     * Returns unique ID of the face.
     * 
@@ -252,6 +256,14 @@ public class HumanFace extends Observable implements MeshListener, Serializable
        return this.kdTree;
    }
    
    /**
     * Checks if HumanFace has KdTree calculated
     * @return true if yes and false if not
     */
    public boolean hasKdTree() {
        return kdTree != null;
    }
    
    /**
     * Computes new k-d tree or returns the existing one.
     * 
@@ -262,8 +274,8 @@ public class HumanFace extends Observable implements MeshListener, Serializable
    public KdTree computeKdTree(boolean recompute) {
        if (kdTree == null || recompute) {
            kdTree = new KdTree(new ArrayList<>(meshModel.getFacets()));
            setChanged();
            notifyObservers(this);
            kdTree.registerListener(this);
            eventBus.post(new KdTreeCreated(this.getShortName()));
        }
        return kdTree;
    }
@@ -275,11 +287,21 @@ public class HumanFace extends Observable implements MeshListener, Serializable
    public KdTree removeKdTree() {
        KdTree ret = this.kdTree;
        this.kdTree = null;
        setChanged();
        notifyObservers(this);
        eventBus.post(new KdTreeDestroyed(this.getShortName()));
        return ret;
    }
    
    /**
     * Captures events fired by {@link cz.fidentis.analyst.kdtree.KdTree} and
     * redirects them to our listeners.
     * 
     * @param event A fired event.
     */
    @Override
    public void kdTreeEvent(KdTreeEvent event) {
        eventBus.post(event);
    }

    /**
     * Creates serialized dump of the human face. Event buses are not stored.
     * Therefore, listeners have to re-register again after recovery.
+3 −2
Original line number Diff line number Diff line
package cz.fidentis.analyst.face;

import cz.fidentis.analyst.kdtree.events.KdTreeListener;
import cz.fidentis.analyst.mesh.events.MeshListener;

/**
@@ -9,6 +10,6 @@ import cz.fidentis.analyst.mesh.events.MeshListener;
 * 
 * @author Radek Oslejsek
 */
public interface HumanFaceListener extends MeshListener {
public interface HumanFaceListener extends KdTreeListener, MeshListener {

}
+280 −522

File changed.

Preview size limit exceeded, changes collapsed.

Loading