Skip to content
Snippets Groups Projects
Commit b3ad53f4 authored by Matej Kovár's avatar Matej Kovár Committed by Radek Ošlejšek
Browse files

Resolve "Add basic JSON scheme for project"

parent 6d5a67c6
No related branches found
No related tags found
No related merge requests found
Showing
with 1145 additions and 383 deletions
package cz.fidentis.analyst;
import cz.fidentis.analyst.face.HumanFace;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
......@@ -14,8 +17,85 @@ import java.util.List;
*/
public class Project {
private boolean saved = true;
private List<HumanFace> faces = new ArrayList<>();
/* Project data (paths to faces, opened tabs..) */
private ProjectConfiguration cfg = new ProjectConfiguration();
/**
* Asks whether project is saved or some change was made
* @return true if project is saved, false otherwise
*/
public boolean isSaved() {
return saved;
}
public void setSaved(boolean saved) {
this.saved = saved;
}
public ProjectConfiguration getCfg() {
return cfg;
}
public void setCfg(ProjectConfiguration cfg) {
this.cfg = cfg;
}
/**
* Adds new path to project configuration
* @param path Path to be added
* @return true if path was successfully added
*/
public boolean addNewPath(Path path) {
return this.cfg.addPath(path);
}
/**
* Checks whether path is already loaded in project configuration
* @param path Path to be checked
* @return true if path was loaded, false otherwise
*/
public boolean pathLoaded(Path path) {
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);
}
/**
* Returns list of HumanFace secondary faces
*
......@@ -73,6 +153,29 @@ public class Project {
}
}
/**
* Removes face by providing its name
*
* @param name name of the face to be removed
*/
public void removeFaceByName(String name) {
HumanFace face = this.getFaceByName(name);
if (face != null) {
this.removeFace(face);
}
this.cfg.removePath(name);
//this.cfg.removeFaceTab(name);
}
/**
* Removes all faces from list of faces
*/
public void removeAll() {
faces.clear();
}
/**
* Removes faces which are sent to this function by list of HumanFace
* from faces
......@@ -101,5 +204,32 @@ public class Project {
}
return null;
}
/**
* Loads face from path
* @param name String name of face
* @return loaded HumanFace
*/
public HumanFace loadFace(String name) {
//File[] files = new File[getCfg().getPaths().size()];
//files = getCfg().openFiles().toArray(files);
HumanFace face = this.getFaceByName(name);
//File file = new File(path);
//for ()
//Path path = this.getCfg().pathToFaceByName(name);
if (face == null) {
try {
Logger out = Logger.measureTime();
Path path = this.getCfg().getPathToFaceByName(name);
File file = path.toFile();
face = new HumanFace(file, true); // loads also landmarks, if exist
out.printDuration("Loaded model " + face.getShortName() +" with " + face.getMeshModel().getNumVertices() + " vertices");
} catch (IOException ex) {
//ex.printStackTrace();
Logger.print(ex.toString());
}
}
return face;
}
}
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
* @author Matej Kovar
*/
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;
}
public void setPaths(List<Path> paths) {
this.paths = paths;
}
/**
* Adds path to paths
* @param path Path to be added
* @return true if path was successfully added
*/
public boolean addPath(Path path) {
return paths.add(path);
}
/**
* Removes specific path from paths
* @param name String of face
*/
public void removePath(String name) {
paths.removeIf(p -> p.toString().substring(p.toString().lastIndexOf(File.separatorChar) + 1, p.toString().lastIndexOf('.')).equals(name));
}
/**
* Returns path to face with specified name of file
* @param name String name of file
* @return Path to face
*/
public Path getPathToFaceByName(String name) {
for (Path p : paths) {
if (p.toString().substring(p.toString().lastIndexOf(File.separatorChar) + 1, p.toString().lastIndexOf('.')).equals(name)) {
return p;
}
}
return null;
}
/**
* Opens all files in paths
* @return List<File> list of files with faces
*/
public List<File> openFiles() {
List<File> f = new ArrayList<>();
paths.forEach(p -> {
f.add(p.toFile());
});
return f;
}
/**
* Removes all paths
*/
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);
}
}
}
......@@ -137,7 +137,18 @@
<artifactId>AbsoluteLayout</artifactId>
<version>RELEASE123</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.0</version>
<type>jar</type>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
......
......@@ -52,7 +52,7 @@ public class Canvas extends JPanel {
private final Scene scene = new Scene();
private final SceneRenderer sceneRenderer;
private final Camera camera = new Camera();
private final List<HumanFace> faces = new ArrayList();
private final List<HumanFace> faces = new ArrayList<>();
// Listeners:
private final CanvasListener listener;
......
package cz.fidentis.analyst.core;
import cz.fidentis.analyst.batch.BatchAction;
import cz.fidentis.analyst.canvas.Canvas;
import cz.fidentis.analyst.canvas.toolbar.SceneToolboxFaceToFace;
import cz.fidentis.analyst.canvas.toolbar.SceneToolboxSingleFace;
import cz.fidentis.analyst.curvature.CurvatureAction;
import cz.fidentis.analyst.distance.DistanceAction;
import cz.fidentis.analyst.face.HumanFace;
import cz.fidentis.analyst.registration.RegistrationAction;
import cz.fidentis.analyst.symmetry.ProfilesAction;
import cz.fidentis.analyst.symmetry.SymmetryAction;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.util.Objects;
import javax.swing.GroupLayout;
import javax.swing.JScrollPane;
import javax.swing.LayoutStyle;
import org.openide.windows.TopComponent;
/**
* A non-singleton window/tab for the analysis of two faces.
* The non-singleton window/tab for the analysis of one, two or many to many faces
*
* @author Radek Oslejsek
* @author Matej Kovar
*/
public class FaceToFaceTab extends TopComponent {
public class FaceTab extends TopComponent {
private final Canvas canvas ;
private final TopControlPanel controlPanel;
private final JScrollPane scrollPane;
private String nameOfFace1 = null;
private String nameOfFace2 = null;
private ActionListener listener = null;
/**
* Constructor.
* @param primary Primary face
* @param secondary Secondary face
* @param name Tab name
* @param listener action listener
*/
public FaceToFaceTab(HumanFace primary, HumanFace secondary, String name) {
public FaceTab(HumanFace primary, HumanFace secondary, String name, ActionListener listener) {
canvas = new Canvas();
canvas.addPrimaryFace(primary);
canvas.addSecondaryFace(secondary);
canvas.getScene().setDefaultColors();
canvas.addToolBox(new SceneToolboxFaceToFace(canvas));
controlPanel = new TopControlPanel();
this.listener = listener;
if (primary == null) { // N:N
canvas.addToolBox(new SceneToolboxSingleFace(canvas));
} else {
nameOfFace1 = primary.getShortName();
canvas.addPrimaryFace(primary);
if (secondary == null) { // single face analysis
canvas.getScene().setDefaultColors();
canvas.addToolBox(new SceneToolboxSingleFace(canvas));
nameOfFace2 = null;
} else { // 1:1
canvas.addSecondaryFace(secondary);
canvas.getScene().setDefaultColors();
canvas.addToolBox(new SceneToolboxFaceToFace(canvas));
nameOfFace2 = secondary.getShortName();
}
}
controlPanel = new TopControlPanel();
scrollPane = new JScrollPane(controlPanel);
setName(name);
......@@ -52,13 +80,24 @@ public class FaceToFaceTab extends TopComponent {
}
});
// (Re)render scene after all change listeners have been called
// (the first added listener is called last)
controlPanel.addChangeListener(e -> getCanvas().renderScene());
new RegistrationAction(canvas, controlPanel);
new DistanceAction(canvas, controlPanel);
new SymmetryAction(canvas, controlPanel);
new ProfilesAction(canvas, controlPanel);
if (primary == null) { // N:N
new BatchAction(canvas, controlPanel);
} else {
if (secondary == null) { // single face analysis
new CurvatureAction(getCanvas(), controlPanel);
new SymmetryAction(getCanvas(), controlPanel);
new ProfilesAction(getCanvas(), controlPanel);
} else { // 1:1
new RegistrationAction(canvas, controlPanel);
new DistanceAction(canvas, controlPanel);
new SymmetryAction(canvas, controlPanel);
new ProfilesAction(canvas, controlPanel);
}
}
}
@Override
......@@ -95,8 +134,64 @@ public class FaceToFaceTab extends TopComponent {
);
}
public String getNameOfFace1() {
return nameOfFace1;
}
public String getNameOfFace2() {
return nameOfFace2;
}
/**
* Checks whether this tab contains name of face
* @param name String name of face
* @return true if face with this name is in this tab
*/
public boolean hasFace(String name) {
return (name.equals(nameOfFace1) || name.equals(nameOfFace2));
}
public Canvas getCanvas() {
return canvas;
}
}
@Override
public boolean canClose() {
if (nameOfFace1 != null && nameOfFace2 == null) {
listener.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "FaceTab"));
} else if (nameOfFace1 != null && nameOfFace2 != null) {
listener.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "FaceToFaceTab"));
} else {
listener.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "ManyToManyTab"));
}
return super.canClose(); //To change body of generated methods, choose Tools | Templates.
}
@Override
public int hashCode() {
int hash = 5;
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final FaceTab other = (FaceTab) obj;
if (!Objects.equals(this.nameOfFace1, other.nameOfFace1)) {
return false;
}
return Objects.equals(this.nameOfFace2, other.nameOfFace2);
}
}
\ No newline at end of file
package cz.fidentis.analyst.core;
import cz.fidentis.analyst.canvas.Canvas;
import cz.fidentis.analyst.canvas.toolbar.SceneToolboxSingleFace;
import cz.fidentis.analyst.batch.BatchAction;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.GroupLayout;
import javax.swing.JScrollPane;
import javax.swing.LayoutStyle;
import org.openide.windows.TopComponent;
/**
* A non-singleton window/tab for the batch N:N analysis.
*
* @author Radek Oslejsek
*/
public class ManyToManyTab extends TopComponent {
private final Canvas canvas ;
private final TopControlPanel controlPanel;
private final JScrollPane scrollPane;
/**
* Constructor.
*
* @param name Tab name
*/
public ManyToManyTab(String name) {
canvas = new Canvas();
//canvas.initScene(faces.get(0)); // !!!
canvas.addToolBox(new SceneToolboxSingleFace(canvas)); // !!!
controlPanel = new TopControlPanel();
scrollPane = new JScrollPane(controlPanel);
setName(name);
initComponents();
// change the height so that it corresponds to the height of the OpenGL window
canvas.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
scrollPane.setSize(ControlPanel.CONTROL_PANEL_WIDTH, canvas.getHeight());
}
});
// (Re)render scene after all change listeners have been called
// (the first added listener is called last)
controlPanel.addChangeListener(e -> canvas.renderScene());
new BatchAction(canvas, controlPanel);
//new DistanceAction(canvas, controlPanel);
//new SymmetryAction(canvas, controlPanel);
//new ProfilesAction(canvas, controlPanel);
}
private void initComponents() {
GroupLayout layout = new GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(canvas, GroupLayout.DEFAULT_SIZE, 651, Short.MAX_VALUE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
// .addComponent(renderingToolBar, GroupLayout.PREFERRED_SIZE, RenderingToolBar.WIDTH, GroupLayout.PREFERRED_SIZE)
.addComponent(
scrollPane,
ControlPanel.CONTROL_PANEL_WIDTH,
ControlPanel.CONTROL_PANEL_WIDTH,
ControlPanel.CONTROL_PANEL_WIDTH
)
)
);
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createBaselineGroup(true, true)
.addComponent(canvas)
// .addComponent(renderingToolBar)
.addComponent(scrollPane)
))
);
}
}
package cz.fidentis.analyst.core;
import cz.fidentis.analyst.canvas.Canvas;
import cz.fidentis.analyst.canvas.toolbar.SceneToolboxSingleFace;
import cz.fidentis.analyst.curvature.CurvatureAction;
import cz.fidentis.analyst.face.HumanFace;
import cz.fidentis.analyst.symmetry.ProfilesAction;
import cz.fidentis.analyst.symmetry.SymmetryAction;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.GroupLayout;
import javax.swing.JScrollPane;
import javax.swing.LayoutStyle;
import org.openide.windows.TopComponent;
/**
* The non-singleton window/tab for detail inspection of a single face.
*
* @author Radek Oslejsek
*/
public final class SingleFaceTab extends TopComponent {
private final Canvas canvas;
private final TopControlPanel controlPanel;
private final JScrollPane scrollPane;
/**
* Constructor.
* @param face Face
* @param name Tab name
*/
public SingleFaceTab(HumanFace face, String name) {
canvas = new Canvas();
canvas.addPrimaryFace(face);
canvas.getScene().setDefaultColors();
canvas.addToolBox(new SceneToolboxSingleFace(canvas));
controlPanel = new TopControlPanel();
scrollPane = new JScrollPane(controlPanel);
setName(name);
initComponents();
// change the height so that it corresponds to the height of the OpenGL window
canvas.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
scrollPane.setSize(ControlPanel.CONTROL_PANEL_WIDTH, canvas.getHeight());
}
});
/*
* Add and open controll panels:
*/
// (Re)render scene after all change listeners have been called
// (the first added listener is called last)
controlPanel.addChangeListener(e -> getCanvas().renderScene());
new CurvatureAction(getCanvas(), controlPanel);
new SymmetryAction(getCanvas(), controlPanel);
new ProfilesAction(getCanvas(), controlPanel);
}
@Override
public int getPersistenceType() {
return TopComponent.PERSISTENCE_NEVER; // TO DO: change to .PERSISTENCE_ONLY_OPENED when we can re-create the ProjectTC
}
private void initComponents() {
GroupLayout layout = new GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(canvas, GroupLayout.DEFAULT_SIZE, 651, Short.MAX_VALUE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
// .addComponent(renderingToolBar, GroupLayout.PREFERRED_SIZE, RenderingToolBar.WIDTH, GroupLayout.PREFERRED_SIZE)
.addComponent(
scrollPane,
ControlPanel.CONTROL_PANEL_WIDTH,
ControlPanel.CONTROL_PANEL_WIDTH,
ControlPanel.CONTROL_PANEL_WIDTH
)
)
);
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createBaselineGroup(true, true)
.addComponent(canvas)
// .addComponent(renderingToolBar)
.addComponent(scrollPane)
))
);
}
public Canvas getCanvas() {
return canvas;
}
}
......@@ -44,7 +44,7 @@ public final class FaceStatePanel extends JPanel {
hasKDtree.setIcon(notCheck);
}
builder.addLine();
hasFeaturePoints = builder.addLabelLine("Has Feature points");
if (face.hasFeaturePoints()) {
hasFeaturePoints.setIcon(check);
......@@ -52,15 +52,15 @@ public final class FaceStatePanel extends JPanel {
hasFeaturePoints.setIcon(notCheck);
}
builder.addLine();
tmp1 = builder.addLabelLine("...");
tmp1.setIcon(notCheck);
builder.addLine();
tmp2 = builder.addLabelLine("...");
tmp2.setIcon(notCheck);
builder.addLine();
tmp3 = builder.addLabelLine("...");
tmp3.setIcon(notCheck);
builder.addLine();
......
......@@ -58,7 +58,7 @@ public class ModelsTableModel extends DefaultTableModel implements HumanFaceList
/**
* Adds new row to model
* @param name String name of the face
* @param hasKD boolean if face has KD tree calculated
* @param hasKD Boolean if face has KD tree calculated
*/
public void addRowWithName(String name, boolean hasKD) {
if (hasKD) {
......
......@@ -14,12 +14,6 @@ ProjectTopComp.jTable1.columnModel.title3=Title 4
ProjectTopComp.jTable1.columnModel.title1=Title 2
ProjectTopComp.jTable1.columnModel.title0_1=Models
ProjectTopComp.jTable1.columnModel.title1_1=
ProjectTopComp.analyseButton1.text=Analyse
ProjectTopComp.inflateButton1.text=Inflate
ProjectTopComp.deselectAllButton1.text=Deselect all
ProjectTopComp.selectAllButton1.text=Select all
ProjectTopComp.removeButton1.text=Remove
ProjectTopComp.addButton1.text=Add
ProjectTopComp.jTable2.columnModel.title3=Title 4
ProjectTopComp.jTable2.columnModel.title2=Title 3
ProjectTopComp.jTable2.columnModel.title1=Title 2
......@@ -29,5 +23,21 @@ MeasurementsPanel.jLabel3.text=Feature points distance:
MeasurementsPanel.jTextField1.text=
MeasurementsPanel.jTextField2.text=
MeasurementsPanel.jTextField3.text=
ProjectTopComp.oneOnOneButton1.text=Open 1:1
StartFrame.jButton1.text=jButton1
StartFrame.jButton2.text=jButton2
StartFrame.jButton3.text=jButton3
StartPanel.jButton1.text=
StartPanel.jButton2.text=
StartPanel.jButton3.text=Cancel
ProjectTopComp.saveProjectButton.AccessibleContext.accessibleName=SaveProject
ProjectTopComp.saveProjectButton.text=
ProjectTopComp.openProjectButton.text=
ProjectTopComp.newProjectButton.text=
ProjectTopComp.manyToManyButton.text=N:N
ProjectTopComp.analyseButton.text=Analyse
ProjectTopComp.addButton.text=Add
ProjectTopComp.removeButton.text=Remove
ProjectTopComp.selectAllButton.text=Select all
ProjectTopComp.deselectAllButton.text=Deselect all
ProjectTopComp.inflateButton.text=Inflate
ProjectTopComp.oneOnOneButton.text=Open 1:1
GUI/src/main/resources/new.png

3.08 KiB

GUI/src/main/resources/new100x24.png

1.31 KiB

GUI/src/main/resources/open.png

3.61 KiB

GUI/src/main/resources/open100x24.png

1.5 KiB

GUI/src/main/resources/save100x24.png

1.44 KiB

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