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

Resolve "Indicate faces analyzed in multiple tasks"

parent 988dfb20
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -110,7 +110,18 @@
            <artifactId>ejml-all</artifactId>
            <version>0.41</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.13.0</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.13.0</version>
            <type>jar</type>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+89 −35
Original line number Diff line number Diff line
@@ -4,6 +4,9 @@ import cz.fidentis.analyst.face.HumanFace;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.prefs.Preferences;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.nio.file.Paths;


/**
@@ -15,8 +18,13 @@ import java.nio.file.Path;
public class Project {
    
    private boolean saved = true;
    private String projectName = "";
    
    /* Project data (paths to faces, opened tabs..) */
    private ObjectMapper mapper = new ObjectMapper();
    
    private Preferences userPreferences = Preferences.userNodeForPackage(Project.class); 
    
    /* Project data (paths to faces) */
    private ProjectConfiguration cfg = new ProjectConfiguration();
    
    /**
@@ -39,6 +47,10 @@ public class Project {
        this.cfg = cfg;
    }
    
    public String getProjectName() {
        return projectName;
    }
    
    /**
     * Adds new path to project configuration
     * @param path Path to be added
@@ -57,40 +69,6 @@ public class Project {
        return this.cfg.getPaths().contains(path);
    }
    
    /**
     * Adds new FaceToFace tab to project configuration
     * @param name1 String name of first face
     * @param name2 String name of second face
     */
    public void addNewFaceToFaceTabFace(String name1, String name2) {
        this.cfg.addFaceToFaceTabFace(name1, name2);
    }
    
    /**
     * Adds new face to FaceTab
     * @param name String name of face
     */
    public void addNewSingleFaceTabFace(String name) {
        this.cfg.addSingleFaceTabFace(name);
    }
    
    /**
     * Removes FaceTab
     * @param name String name of face
     */
    public void removeFaceTab(String name) {
        this.cfg.removeFaceTab(name);
    }
    
    /**
     * Removes FaceToFace tab
     * @param name1 String name of first face
     * @param name2 String name of second face
     */
    public void removeFaceToFaceTab(String name1, String name2) {
        this.cfg.removeFaceToFaceTab(name1, name2);
    }
       
    /**
     * Loads face from path
     * @param name String name of face
@@ -141,4 +119,80 @@ public class Project {
        return false;
    }
    
    /**
     * Close currently loaded project
     */
    public void closeProject() {
        userPreferences.remove("pathToMostRecentProject");
    }
    
    /**
     * Save currently loaded project
     * @param file file where to store project
     * @return true if project was successfully saved
     */
    public boolean saveProject(File file) {
        
        try {
            mapper.writeValue(file, cfg);
            userPreferences.put("pathToMostRecentProject", file.getAbsolutePath());
            setSaved(true);
            projectName = file.getName().split(".json")[0];
            return true;
        } catch (IOException ex) {
            //Exceptions.printStackTrace(ex);
        }
        return false;
    }
    
    /**
     * Create new project
     */
    public void newProject() {
        setCfg(new ProjectConfiguration());
        projectName = "";
        setSaved(true);
    }
    
    /**
     * Gets path to project file
     * @return String path to project file
     */
    public String getPathToProjectFile() {
        return userPreferences.get("pathToMostRecentProject", "");
    }
    
    /**
     * Loads most recent project from user preferences
     * @return File where project is saved, null if no project was found
     */
    public File getRecentProject() {
        
        String path = getPathToProjectFile();
        if (path.equals("")) {
            return null;
        }
        Path p = Paths.get(path);
        return p.toFile();
    }
   
    /**
     * Loads project from file
     * @param projectFile file with project
     * @return true if project was successfully loaded, false otherwise
     */
    public boolean openProjectFromFile(File projectFile) {
        if (projectFile != null) {
            try {
                closeProject();
                cfg = mapper.readValue(projectFile, ProjectConfiguration.class);
                userPreferences.put("pathToMostRecentProject", projectFile.getAbsolutePath());
                setSaved(true);
                projectName = projectFile.getName().split(".json")[0];
            } catch (IOException ex) {
                return false;
            }
        } 
        return true;
    }
}
+1 −71
Original line number Diff line number Diff line
@@ -3,13 +3,11 @@ package cz.fidentis.analyst;
import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * This class encapsulates data important for project (re)storing such as paths
 * to faces or which tabs were opened
 * to faces
 * 
 * @author Matej Kovar
 */
@@ -18,15 +16,6 @@ public class ProjectConfiguration {
    /* Paths to loaded models */
    private List<Path> paths = new ArrayList<>();

    private List<String> singleTabFaces = new ArrayList<>();
    
    // f.e. [face1 : [face2, face3], face2 : [face4, face5, face6], face3 : [face4]...]
    private Map<String, List<String>> faceToFaceTabFaces = new HashMap<>();
    
    //private Map<HumanFace, SingleFaceTab> singleFaceTabs = new HashMap<>();
    //private Map<HumanFace, FaceToFaceTab> faceToFaceTabs = new HashMap<>();
    

    public List<Path> getPaths() {
        return paths;
    }
@@ -95,63 +84,4 @@ public class ProjectConfiguration {
    public void clearPaths() {
        paths.clear();
    }

    public List<String> getSingleTabFaces() {
        return singleTabFaces;
    }

    public void setSingleTabFaces(List<String> singleTabFaces) {
        this.singleTabFaces = singleTabFaces;
    }

    public Map<String, List<String>> getFaceToFaceTabFaces() {
        return faceToFaceTabFaces;
    }

    public void setFaceToFaceTabFaces(Map<String, List<String>> faceToFaceTabFaces) {
        this.faceToFaceTabFaces = faceToFaceTabFaces;
    }

    /**
     * Adds SingleFace tab
     * @param name String name of face
     */
    public void addSingleFaceTabFace(String name) {
        singleTabFaces.add(name);
    }
    
    /**
     * Adds FaceToFace tab
     * @param name1 String name of first face
     * @param name2 String name of second face
     */
    public void addFaceToFaceTabFace(String name1, String name2) {
        if (faceToFaceTabFaces.containsKey(name1)) {
            faceToFaceTabFaces.get(name1).add(name2);
        } else {
            List<String> faces = new ArrayList<>();
            faces.add(name2);
            faceToFaceTabFaces.put(name1, faces);
        }
    }
    
    /**
     * Removes SingleFace tab
     * @param name String name of face
     */
    public void removeFaceTab(String name) {
        singleTabFaces.remove(name);
    }
    
    /**
     * Removes FaceToFace tab
     * @param name1 String name of first face
     * @param name2 String name of second face
     */
    public void removeFaceToFaceTab(String name1, String name2) {
        faceToFaceTabFaces.get(name1).remove(name2);
        if (faceToFaceTabFaces.get(name1).isEmpty()) {
            faceToFaceTabFaces.remove(name1);
        }
    }
}
+1 −6
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@ import cz.fidentis.analyst.visitors.face.HumanFaceVisitor;
import cz.fidentis.analyst.visitors.mesh.BoundingBox;
import cz.fidentis.analyst.visitors.mesh.BoundingBox.BBox;
import cz.fidentis.analyst.visitors.mesh.CurvatureCalculator;
import java.awt.image.BufferedImage;

import java.io.File;
import java.io.IOException;
@@ -62,8 +61,6 @@ public class HumanFace implements Serializable {

    private final String id;
    
    private transient BufferedImage preview;

    private boolean hasCurvature = false;

    /**
@@ -73,7 +70,6 @@ public class HumanFace implements Serializable {

    /**
     * Reads a 3D human face from the given OBJ file.
     * Use {@link restoreFromFile} to restore the human face from a dump file.
     *
     * @param file OBJ file
     * @param loadLandmarks If {@code true}, then the constructor aims to load
@@ -108,7 +104,6 @@ public class HumanFace implements Serializable {
    /**
     * Reads a 3D human face from the given OBJ file.
     * Also loads landmarks (feature points) if appropriate file is found.
     * Use {@link restoreFromFile} to restore the human face from a dump file.
     *
     * @param file OBJ file
     * @throws IOException on I/O failure
+4 −4
Original line number Diff line number Diff line
@@ -118,7 +118,7 @@ public class IcpTransformer extends MeshVisitor {
     * Mean distance of vertices is computed for each ICP iteration.
     * If the difference between the previous and current mean distances is less than the error,
     * then the ICP computation stops. Reasonable number seems to be 0.05.
     * @param strategy One of the reduction strategies. If {@code null}, then {@link NoUndersampling} is used.
     * @param strategy One of the reduction strategies. If {@code null}, then {@code NoUndersampling} is used.
     * @throws IllegalArgumentException if some parameter is wrong
     */
    public IcpTransformer(MeshFacet mainFacet, int maxIteration, boolean scale, double error, PointSampling strategy) {
@@ -141,7 +141,7 @@ public class IcpTransformer extends MeshVisitor {
     * Mean distance of vertices is computed for each ICP iteration.
     * If the difference between the previous and current mean distances is less than the error,
     * then the ICP computation stops. Reasonable number seems to be 0.05.
     * @param strategy One of the reduction strategies. If {@code null}, then {@link NoUndersampling} is used.
     * @param strategy One of the reduction strategies. If {@code null}, then {@code NoUndersampling} is used.
     * @throws IllegalArgumentException if some parameter is wrong
     */
    public IcpTransformer(Set<MeshFacet> mainFacets, int maxIteration, boolean scale, double error, PointSampling strategy) {
@@ -174,7 +174,7 @@ public class IcpTransformer extends MeshVisitor {
     * Mean distance of vertices is computed for each ICP iteration.
     * If the difference between the previous and current mean distances is less than the error,
     * then the ICP computation stops. Reasonable number seems to be 0.05.
     * @param strategy One of the reduction strategies. If {@code null}, then {@link NoUndersampling} is used.
     * @param strategy One of the reduction strategies. If {@code null}, then {@code NoUndersampling} is used.
     * @throws IllegalArgumentException if some parameter is wrong
     */
    public IcpTransformer(MeshModel mainModel, int maxIteration, boolean scale, double error, PointSampling strategy) {
@@ -197,7 +197,7 @@ public class IcpTransformer extends MeshVisitor {
     * Mean distance of vertices is computed for each ICP iteration.
     * If the difference between the previous and current mean distances is less than the error,
     * then the ICP computation stops. Reasonable number seems to be 0.05.
     * @param strategy One of the reduction strategies. If {@code null}, then {@link NoUndersampling} is used.
     * @param strategy One of the reduction strategies. If {@code null}, then {@code NoUndersampling} is used.
     * @throws IllegalArgumentException if some parameter is wrong
     */
    public IcpTransformer(KdTree primaryKdTree, int maxIteration, boolean scale, double error, PointSampling strategy) {
Loading