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

Resolve "BUG: Saved task tabs do not reopen"

parent 898954d5
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
package cz.fidentis.analyst.gui.project;

import cz.fidentis.analyst.project.Project;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
@@ -14,6 +9,12 @@ import org.openide.filesystems.FileChooserBuilder;
import org.openide.util.NbBundle.Messages;
import org.openide.windows.WindowManager;

import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

/**
 * Opens an existing project.
 * 
@@ -74,7 +75,7 @@ public final class OpenProjectAction implements ActionListener {
        }
        
        win.getProjectPanel().openProject(dir);
        WindowManager.getDefault().getMainWindow().setTitle("FIDENTIS Analyst 2: " 
        WindowManager.getDefault().getMainWindow().setTitle("FIDENTIS Analyst II: "
                + win.getProjectPanel().getProject().getProjectName());
        win.requestActive();
    }
+10 −10
Original line number Diff line number Diff line
package cz.fidentis.analyst.gui.project;

import cz.fidentis.analyst.project.Project;
import cz.fidentis.analyst.project.FacesProxy;
import cz.fidentis.analyst.gui.elements.ProgressDialog;
import cz.fidentis.analyst.gui.project.table.ProjectTable;
import cz.fidentis.analyst.gui.task.TaskWindow;
import java.awt.Font;
import cz.fidentis.analyst.project.FacesProxy;
import cz.fidentis.analyst.project.Project;
import org.openide.filesystems.FileChooserBuilder;
import org.openide.windows.WindowManager;

import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.io.File;
@@ -14,13 +20,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.SwingWorker;
import javax.swing.event.ListSelectionEvent;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.openide.filesystems.FileChooserBuilder;
import org.openide.windows.WindowManager;

/**
 * The left-hand part of the project dashboard consisting of a project toolbar and 
@@ -129,6 +128,7 @@ public class ProjectPanel extends javax.swing.JPanel {
        try {
            this.project = new Project(dir);
        } catch (IOException ex) {
            ex.printStackTrace();
            return null;
        }
        
+11 −8
Original line number Diff line number Diff line
package cz.fidentis.analyst.gui.project;

import cz.fidentis.analyst.project.Project;
import cz.fidentis.analyst.project.FacesProxy;
import cz.fidentis.analyst.Logger;
import cz.fidentis.analyst.gui.elements.ProgressDialog;
import cz.fidentis.analyst.project.FacesProxy;
import cz.fidentis.analyst.project.Project;
import cz.fidentis.analyst.rendering.Camera;

import javax.swing.*;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.util.function.BiConsumer;
import javax.swing.SwingWorker;

/**
 * A worker for loading multiple task tabs (faces and cameras) of a project from dumped files.
@@ -19,7 +21,7 @@ import javax.swing.SwingWorker;
public class RecoverTasksWorker extends SwingWorker<Boolean, Integer> {
    
    private Project project;
    private ProgressDialog progressDialog;
    private ProgressDialog<Boolean, Integer> progressDialog;
    private final BiConsumer<Camera, FacesProxy> consumer;
    
    /**
@@ -30,7 +32,7 @@ public class RecoverTasksWorker extends SwingWorker<Boolean, Integer> {
     * @param consumer A method that creates an analytical tab from loaded camera and faces
     * @throws IllegalArgumentException if the project has not a folder assigned
     */
    public RecoverTasksWorker(Project project, ProgressDialog progressDialog, BiConsumer<Camera, FacesProxy> consumer) {
    public RecoverTasksWorker(Project project, ProgressDialog<Boolean, Integer> progressDialog, BiConsumer<Camera, FacesProxy> consumer) {
        if (!project.hasProjectDir()) {
            throw new IllegalArgumentException("project");
        }
@@ -43,9 +45,7 @@ public class RecoverTasksWorker extends SwingWorker<Boolean, Integer> {
    protected Boolean doInBackground() throws Exception {
        File projectDir = new File(project.getProjectDir().toString());
        
        File[] files = projectDir.listFiles((dir, name) -> { 
            return name.toLowerCase().endsWith(".bin"); 
        });
        File[] files = projectDir.listFiles((dir, name) -> name.toLowerCase().endsWith(".bin"));
        
        int counter = 0;
        for (File file: files) {
@@ -57,6 +57,9 @@ public class RecoverTasksWorker extends SwingWorker<Boolean, Integer> {
                Camera camera = (Camera) in.readObject();
                FacesProxy faces = new FacesProxy(in);
                this.consumer.accept(camera, faces);
            } catch (Exception ex) {
                Logger.print("[ERROR] Task recovery: " + ex);
                throw ex;
            }
            
            int progress = (int)Math.round(100.0 * ++counter / files.length);
+13 −17
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ import cz.fidentis.analyst.Logger;
import cz.fidentis.analyst.distance.kdtree.KdTreeApproxDistanceToTriangles;
import cz.fidentis.analyst.events.HumanFaceEvent;
import cz.fidentis.analyst.events.HumanFaceListener;
import cz.fidentis.analyst.shapes.Box;
import cz.fidentis.analyst.feature.FeaturePoint;
import cz.fidentis.analyst.feature.FeaturePointType.FeaturePointCategory;
import cz.fidentis.analyst.feature.RelationToMesh;
@@ -16,6 +15,7 @@ import cz.fidentis.analyst.mesh.CurvatureCalculator;
import cz.fidentis.analyst.mesh.core.MeshModel;
import cz.fidentis.analyst.mesh.io.MeshObjLoader;
import cz.fidentis.analyst.octree.Octree;
import cz.fidentis.analyst.shapes.Box;
import cz.fidentis.analyst.shapes.Plane;
import cz.fidentis.analyst.shapes.SurfaceMask;

@@ -26,7 +26,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * A human face instance.
@@ -45,6 +44,8 @@ import java.util.stream.Collectors;
 */
public class HumanFace implements Serializable {

    public static final String LANDMARK_FILE_SUFFIX = "_landmarks.csv";

    private MeshModel meshModel;

    /**
@@ -57,7 +58,6 @@ public class HumanFace implements Serializable {

    private Plane symmetryPlane;

    //private MeshFacet symmetryPlaneMesh;
    private Box bbox;

    private List<FeaturePoint> featurePoints;
@@ -68,7 +68,7 @@ public class HumanFace implements Serializable {
    
    private boolean hasCurvature = false;
    
    private final SurfaceMask surfaceMask = new SurfaceMask();
    private final transient SurfaceMask surfaceMask = new SurfaceMask();

    /**
     * Fast (de)serialization handler
@@ -170,7 +170,6 @@ public class HumanFace implements Serializable {
        }
        this.meshModel = meshModel;
        updateBoundingBox();
        //announceEvent(new MeshChangedEvent(this, getShortName(), this));
    }

    /**
@@ -276,6 +275,7 @@ public class HumanFace implements Serializable {
    /**
     *
     * @param points List of feature points
     * @deprecated
     */
    @Deprecated
    public void setFeaturePoints(List<FeaturePoint> points) {
@@ -302,7 +302,6 @@ public class HumanFace implements Serializable {
        if (featurePoints == null) {
            return Collections.emptyList();
        }
        //return Collections.unmodifiableList(featurePoints);
        return featurePoints;
    }
    
@@ -312,7 +311,7 @@ public class HumanFace implements Serializable {
    public List<FeaturePoint> getStandardFeaturePoints() {
        return getFeaturePoints().stream()
                .filter(fp -> fp.getFeaturePointType().getCategory() == FeaturePointCategory.STANDARD)
                .collect(Collectors.toList());
                .toList();
    }
    
    /**
@@ -321,7 +320,7 @@ public class HumanFace implements Serializable {
    public List<FeaturePoint> getCustomFeaturePoints() {
        return getFeaturePoints().stream()
                .filter(fp -> fp.getFeaturePointType().getCategory() == FeaturePointCategory.CUSTOM)
                .collect(Collectors.toList());
                .toList();
    }

    /**
@@ -453,17 +452,17 @@ public class HumanFace implements Serializable {
     * @return The file with landmarks or {@code null}
     */
    public final File findLandmarks() {
        String filename = getId().split(".obj")[0] + "_landmarks.csv";
        String filename = getId().split(".obj")[0] + LANDMARK_FILE_SUFFIX;
        if ((new File(filename)).exists()) {
            return new File(filename);
        }

        filename = getId().split("_ECA")[0] + "_landmarks.csv";
        filename = getId().split("_ECA")[0] + LANDMARK_FILE_SUFFIX;
        if ((new File(filename)).exists()) {
            return new File(filename);
        }

        filename = getId().split("_CA")[0] + "_landmarks.csv";
        filename = getId().split("_CA")[0] + LANDMARK_FILE_SUFFIX;
        if ((new File(filename)).exists()) {
            return new File(filename);
        }
@@ -497,9 +496,9 @@ public class HumanFace implements Serializable {
     * @return relation
     */
    protected RelationToMesh computeFeaturePointRelation(FeaturePoint featurePoint) {
        KdTree kdTree = computeKdTree(false);
        KdTree tmpKdTree = computeKdTree(false);
        KdTreeApproxDistanceToTriangles visitor = new KdTreeApproxDistanceToTriangles(featurePoint.getPosition(), true);
        kdTree.accept(visitor);
        tmpKdTree.accept(visitor);
        return new RelationToMesh(visitor.getDistance(), visitor.getNearestPoints());
    }

@@ -521,10 +520,7 @@ public class HumanFace implements Serializable {
            return false;
        }
        final HumanFace other = (HumanFace) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        return true;
        return Objects.equals(this.id, other.id);
    }