Skip to content
Snippets Groups Projects
Commit 37f1bd32 authored by Radek Ošlejšek's avatar Radek Ošlejšek
Browse files

Added serialization

parent 97a084d0
No related branches found
No related tags found
No related merge requests found
Showing
with 116 additions and 27 deletions
...@@ -10,8 +10,12 @@ import cz.fidentis.analyst.symmetry.Plane; ...@@ -10,8 +10,12 @@ import cz.fidentis.analyst.symmetry.Plane;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
/** /**
* This class encapsulates data for a 3D scan of a single human face. * This class encapsulates data for a 3D scan of a single human face.
...@@ -34,7 +38,7 @@ import java.io.InputStream; ...@@ -34,7 +38,7 @@ import java.io.InputStream;
* *
* @author Radek Oslejsek * @author Radek Oslejsek
*/ */
public class HumanFace implements MeshListener { public class HumanFace implements MeshListener, Serializable {
private MeshModel meshModel; private MeshModel meshModel;
...@@ -42,10 +46,11 @@ public class HumanFace implements MeshListener { ...@@ -42,10 +46,11 @@ public class HumanFace implements MeshListener {
private MeshFacet cuttingPlane; private MeshFacet cuttingPlane;
private EventBus eventBus = new EventBus(); private transient EventBus eventBus = new EventBus();
/** /**
* Reads a 3D human phase from file. * 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 file OBJ file
* @throws IOException on I/O failure * @throws IOException on I/O failure
...@@ -55,7 +60,8 @@ public class HumanFace implements MeshListener { ...@@ -55,7 +60,8 @@ public class HumanFace implements MeshListener {
} }
/** /**
* Reads a 3D human phase from file. * Reads a 3D human face from the given OBJ stream.
* Use {@link restoreFromFile} to restore the human face from a dump file.
* *
* @param is input stream with OBJ data * @param is input stream with OBJ data
* @throws IOException on I/O failure * @throws IOException on I/O failure
...@@ -136,4 +142,34 @@ public class HumanFace implements MeshListener { ...@@ -136,4 +142,34 @@ public class HumanFace implements MeshListener {
public MeshFacet getCuttingPlane() { public MeshFacet getCuttingPlane() {
return cuttingPlane; return cuttingPlane;
} }
/**
* Creates serialized dump of the human face. Event buses are not stored.
* Therefore, listeners have to re-register again after recovery.
*
* @return Dump file
* @throws IOException on error in creating the dump file
*/
public File dumpToFile() throws IOException {
File tempFile = File.createTempFile(this.getClass().getSimpleName(), ".ser");
tempFile.deleteOnExit();
try (ObjectOutputStream fos = new ObjectOutputStream(new FileOutputStream(tempFile))) {
fos.writeObject(this);
}
return tempFile;
}
/**
* Restores human face from a dump file.
*
* @param dumpFile The file
* @return Human face
* @throws IOException on error in reading the dump file
* @throws java.lang.ClassNotFoundException on error when instantiating the human face
*/
public static HumanFace restoreFromFile(File dumpFile) throws IOException, ClassNotFoundException {
try (ObjectInputStream fos = new ObjectInputStream(new FileInputStream(dumpFile))) {
return (HumanFace) fos.readObject();
}
}
} }
package cz.fidentis.analyst.symmetry; package cz.fidentis.analyst.symmetry;
import java.io.Serializable;
import java.util.List; import java.util.List;
import javax.vecmath.Vector3d; import javax.vecmath.Vector3d;
...@@ -8,7 +9,7 @@ import javax.vecmath.Vector3d; ...@@ -8,7 +9,7 @@ import javax.vecmath.Vector3d;
* *
* @author Natalia Bebjakova * @author Natalia Bebjakova
*/ */
public class Plane { public class Plane implements Serializable {
private Vector3d normal; private Vector3d normal;
private double distance; private double distance;
......
...@@ -12,6 +12,7 @@ import cz.fidentis.analyst.visitors.mesh.HausdorffDistance; ...@@ -12,6 +12,7 @@ import cz.fidentis.analyst.visitors.mesh.HausdorffDistance;
import cz.fidentis.analyst.visitors.mesh.HausdorffDistance.Strategy; import cz.fidentis.analyst.visitors.mesh.HausdorffDistance.Strategy;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -25,7 +26,7 @@ public class EfficiencyTests { ...@@ -25,7 +26,7 @@ public class EfficiencyTests {
private static File girlFile = new File("src/test/resources/cz/fidentis/analyst/average_girl_17-20.obj"); private static File girlFile = new File("src/test/resources/cz/fidentis/analyst/average_girl_17-20.obj");
private static File boyFile = new File("src/test/resources/cz/fidentis/analyst/average_boy_17-20.obj"); private static File boyFile = new File("src/test/resources/cz/fidentis/analyst/average_boy_17-20.obj");
private static File faceFile2 = new File("src/test/resources/cz/fidentis/analyst/00002_01_ECA.obj"); private static File faceFile2 = new File("src/test/resources/cz/fidentis/analyst/00002_01_ECA.obj");
private static File faceFile4 = new File("src/test/resources/cz/fidentis/analyst/00004_01_ECA.obj"); private static File faceFile4 = new File("/home/oslejsek/GIT/HCI/analyst2/GUI/src/test/resources/cz/fidentis/analyst/00004_01_ECA.obj");
private static File basicFaceFile = new File("src/test/resources/cz/fidentis/analyst/basic-model-04.obj"); private static File basicFaceFile = new File("src/test/resources/cz/fidentis/analyst/basic-model-04.obj");
private static HumanFace face1; private static HumanFace face1;
...@@ -36,16 +37,27 @@ public class EfficiencyTests { ...@@ -36,16 +37,27 @@ public class EfficiencyTests {
* @param args Input arguments * @param args Input arguments
* @throws IOException on IO error * @throws IOException on IO error
*/ */
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException, ClassNotFoundException {
face1 = new HumanFace(boyFile); face1 = printFaceLoad(faceFile4);
face2 = new HumanFace(faceFile4); face2 = printFaceLoad(faceFile4);
face1.getMeshModel().simplifyModel(); face1.getMeshModel().simplifyModel();
face2.getMeshModel().simplifyModel(); face2.getMeshModel().simplifyModel();
List<HumanFace> list = new ArrayList<>();
for (int i = 0; i < 500; i++) {
System.out.print(i+". " + formatSize(Runtime.getRuntime().freeMemory()) + "/" + formatSize(Runtime.getRuntime().maxMemory()) + " ");
HumanFace face = printFaceLoad(faceFile4);
face.getMeshModel().simplifyModel();
list.add(face);
}
list.clear();
boolean relativeDist = false; boolean relativeDist = false;
boolean printDetails = false; boolean printDetails = false;
printFaceDump(face1);
//face1.getMeshModel().compute(new GaussianCurvature()); // initialize everything, then measure //face1.getMeshModel().compute(new GaussianCurvature()); // initialize everything, then measure
System.out.println("ICP:"); System.out.println("ICP:");
...@@ -118,5 +130,30 @@ public class EfficiencyTests { ...@@ -118,5 +130,30 @@ public class EfficiencyTests {
"\t" + plane.getNormal() + ", " + plane.getDistance() "\t" + plane.getNormal() + ", " + plane.getDistance()
); );
} }
private static void printFaceDump(HumanFace face) throws IOException, ClassNotFoundException {
long startTime = System.currentTimeMillis();
File file = face.dumpToFile();
long endTime = System.currentTimeMillis();
System.out.println("Human face dumping:\t " +(endTime-startTime) + " msec");
startTime = System.currentTimeMillis();
HumanFace f = HumanFace.restoreFromFile(file);
endTime = System.currentTimeMillis();
System.out.println("Human face restore:\t " +(endTime-startTime) + " msec");
}
private static HumanFace printFaceLoad(File file) throws IOException {
long startTime = System.currentTimeMillis();
HumanFace face = new HumanFace(file);
long endTime = System.currentTimeMillis();
System.out.println("Human face loading:\t " +(endTime-startTime) + " msec");
return face;
}
public static String formatSize(long v) {
if (v < 1024) return v + " B";
int z = (63 - Long.numberOfLeadingZeros(v)) / 10;
return String.format("%.1f %sB", (double)v / (1L << (z*10)), " KMGTPE".charAt(z));
}
} }
package cz.fidentis.analyst.kdtree; package cz.fidentis.analyst.kdtree;
import cz.fidentis.analyst.mesh.core.MeshFacet; import cz.fidentis.analyst.mesh.core.MeshFacet;
import java.io.Serializable;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
...@@ -14,7 +15,7 @@ import javax.vecmath.Vector3d; ...@@ -14,7 +15,7 @@ import javax.vecmath.Vector3d;
* *
* @author Maria Kocurekova * @author Maria Kocurekova
*/ */
public class KdNode { public class KdNode implements Serializable {
/** /**
* Current depth in the kd-tree * Current depth in the kd-tree
......
...@@ -4,6 +4,7 @@ import com.google.common.eventbus.EventBus; ...@@ -4,6 +4,7 @@ import com.google.common.eventbus.EventBus;
import cz.fidentis.analyst.mesh.core.MeshFacet; import cz.fidentis.analyst.mesh.core.MeshFacet;
import cz.fidentis.analyst.mesh.core.MeshFacetImpl; import cz.fidentis.analyst.mesh.core.MeshFacetImpl;
import cz.fidentis.analyst.mesh.core.MeshPoint; import cz.fidentis.analyst.mesh.core.MeshPoint;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
...@@ -34,11 +35,11 @@ import javax.vecmath.Vector3d; ...@@ -34,11 +35,11 @@ import javax.vecmath.Vector3d;
* @author Maria Kocurekova * @author Maria Kocurekova
* @author Radek Oslejsek * @author Radek Oslejsek
*/ */
public class KdTree { public class KdTree implements Serializable {
private KdNode root; private KdNode root;
private EventBus eventBus = new EventBus(); private final transient EventBus eventBus = new EventBus();
/** /**
* Constructor. * Constructor.
...@@ -140,8 +141,8 @@ public class KdTree { ...@@ -140,8 +141,8 @@ public class KdTree {
public void accept(KdTreeVisitor visitor) { public void accept(KdTreeVisitor visitor) {
visitor.visitKdTree(this); visitor.visitKdTree(this);
} }
/*********************************************************** /***********************************************************
* PRIVATE METHODS * PRIVATE METHODS
***********************************************************/ ***********************************************************/
......
package cz.fidentis.analyst.mesh.core; package cz.fidentis.analyst.mesh.core;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
...@@ -13,7 +14,7 @@ import java.util.stream.Collectors; ...@@ -13,7 +14,7 @@ import java.util.stream.Collectors;
* *
* @author Matej Lukes * @author Matej Lukes
*/ */
public class CornerTable { public class CornerTable implements Serializable {
private final List<CornerTableRow> rows = new ArrayList<>(); private final List<CornerTableRow> rows = new ArrayList<>();
......
package cz.fidentis.analyst.mesh.core; package cz.fidentis.analyst.mesh.core;
import java.io.Serializable;
/** /**
* single row in corner table * Single row in corner table.
* *
* @author Matej Lukes * @author Matej Lukes
*/ */
public class CornerTableRow { public class CornerTableRow implements Serializable {
/** /**
* Index to the corner (corner table row) with a vertex on the opposite triangle * Index to the corner (corner table row) with a vertex on the opposite triangle
......
...@@ -2,6 +2,7 @@ package cz.fidentis.analyst.mesh.core; ...@@ -2,6 +2,7 @@ package cz.fidentis.analyst.mesh.core;
import java.util.List; import java.util.List;
import cz.fidentis.analyst.mesh.MeshVisitor; import cz.fidentis.analyst.mesh.MeshVisitor;
import java.io.Serializable;
import javax.vecmath.Vector3d; import javax.vecmath.Vector3d;
/** /**
...@@ -11,7 +12,7 @@ import javax.vecmath.Vector3d; ...@@ -11,7 +12,7 @@ import javax.vecmath.Vector3d;
* *
* @author Matej Lukes * @author Matej Lukes
*/ */
public interface MeshFacet extends Iterable<MeshTriangle> { public interface MeshFacet extends Iterable<MeshTriangle>, Serializable {
/** /**
* returns vertex of specified index * returns vertex of specified index
......
...@@ -7,6 +7,7 @@ import cz.fidentis.analyst.mesh.MeshVisitor; ...@@ -7,6 +7,7 @@ import cz.fidentis.analyst.mesh.MeshVisitor;
import cz.fidentis.analyst.mesh.events.FacetAddedEvent; import cz.fidentis.analyst.mesh.events.FacetAddedEvent;
import java.util.Collections; import java.util.Collections;
import cz.fidentis.analyst.mesh.events.MeshListener; import cz.fidentis.analyst.mesh.events.MeshListener;
import java.io.Serializable;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
...@@ -28,11 +29,11 @@ import java.util.concurrent.Executors; ...@@ -28,11 +29,11 @@ import java.util.concurrent.Executors;
* @author Matej Lukes * @author Matej Lukes
* @author Radek Oslejsek * @author Radek Oslejsek
*/ */
public class MeshModel { public class MeshModel implements Serializable {
private final List<MeshFacet> facets = new ArrayList<>(); private final List<MeshFacet> facets = new ArrayList<>();
private EventBus eventBus = new EventBus(); private final transient EventBus eventBus = new EventBus();
/** /**
* Constructor of MeshModel * Constructor of MeshModel
......
package cz.fidentis.analyst.mesh.core; package cz.fidentis.analyst.mesh.core;
import java.io.Serializable;
import javax.vecmath.Vector3d; import javax.vecmath.Vector3d;
/** /**
...@@ -7,7 +8,7 @@ import javax.vecmath.Vector3d; ...@@ -7,7 +8,7 @@ import javax.vecmath.Vector3d;
* *
* @author Matej Lukes * @author Matej Lukes
*/ */
public interface MeshPoint { public interface MeshPoint extends Serializable {
/** /**
* Helper method that calculates distance of two 3D points. * Helper method that calculates distance of two 3D points.
......
...@@ -3,18 +3,25 @@ import javax.media.j3d.Texture; ...@@ -3,18 +3,25 @@ import javax.media.j3d.Texture;
import javax.vecmath.Vector3d; import javax.vecmath.Vector3d;
/** /**
* Material.
*
* @author Matej Lukes * @author Matej Lukes
*/ */
public class Material { public class Material {
private String name;
private final String name;
// colour info // colour info
private Vector3d ambient, diffuse, specularColors; private final Vector3d ambient;
private double shininess, alpha, illumination; private final Vector3d diffuse;
private final Vector3d specularColors;
private final double shininess;
private final double alpha;
private final double illumination;
// texture info // texture info
private String textureFileName; private final String textureFileName;
private Texture texture; private final Texture texture;
/** /**
* *
......
...@@ -4,7 +4,7 @@ default_mac_userdir="${HOME}/Library/Application Support/${APPNAME}/dev" ...@@ -4,7 +4,7 @@ default_mac_userdir="${HOME}/Library/Application Support/${APPNAME}/dev"
# options used by the launcher by default, can be overridden by explicit # options used by the launcher by default, can be overridden by explicit
# command line switches # command line switches
default_options="--branding fidentisanalyst -J-Xms24m -J-Xmx1G" default_options="--branding fidentisanalyst -J-Xms4G -J-Xmx4G"
# for development purposes you may wish to append: -J-Dnetbeans.logger.console=true -J-ea # for development purposes you may wish to append: -J-Dnetbeans.logger.console=true -J-ea
# default location of JDK/JRE, can be overridden by using --jdkhome <dir> switch # default location of JDK/JRE, can be overridden by using --jdkhome <dir> switch
......
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