diff --git a/Comparison/pom.xml b/Comparison/pom.xml index 19c5050978c68c0cd18ef365d7ebd16b3fcb6a31..4b7c8a9170e5f782444821bd5378084adb113e22 100644 --- a/Comparison/pom.xml +++ b/Comparison/pom.xml @@ -93,6 +93,11 @@ <artifactId>guava</artifactId> <version>30.1-jre</version> </dependency> + <dependency> + <groupId>de.ruedigermoeller</groupId> + <artifactId>fst</artifactId> + <version>2.57</version> + </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> diff --git a/Comparison/src/main/java/cz/fidentis/analyst/face/HumanFace.java b/Comparison/src/main/java/cz/fidentis/analyst/face/HumanFace.java index b5bad8373fe49b6308b3e2aaa1a83b323706ac7f..93b3abecafda2fb50fbbf8631029dabcd2f67da4 100644 --- a/Comparison/src/main/java/cz/fidentis/analyst/face/HumanFace.java +++ b/Comparison/src/main/java/cz/fidentis/analyst/face/HumanFace.java @@ -14,10 +14,11 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Objects; +import org.nustaq.serialization.FSTConfiguration; +import org.nustaq.serialization.FSTObjectInput; +import org.nustaq.serialization.FSTObjectOutput; /** * This class encapsulates data for a 3D scan of a single human face. @@ -52,6 +53,11 @@ public class HumanFace implements MeshListener, Serializable { private final String id; + /** + * Fast (de)serialization handler + */ + private static final FSTConfiguration FST_CONF = FSTConfiguration.createDefaultConfiguration(); + /** * Reads a 3D human face from the given OBJ file. * Use {@link restoreFromFile} to restore the human face from a dump file. @@ -156,10 +162,14 @@ public class HumanFace implements MeshListener, Serializable { public File dumpToFile() throws IOException { File tempFile = File.createTempFile(this.getClass().getSimpleName(), ".ser"); tempFile.deleteOnExit(); - try (ObjectOutputStream fos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(tempFile)))) { - fos.writeObject(this); - fos.flush(); + + //try (ObjectOutputStream fos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(tempFile)))) { + try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tempFile))) { + FSTObjectOutput out = FST_CONF.getObjectOutput(bos); + out.writeObject(this, HumanFace.class); + out.flush(); } + return tempFile; } @@ -171,9 +181,12 @@ public class HumanFace implements MeshListener, Serializable { * @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 BufferedInputStream(new FileInputStream(dumpFile)))) { - return (HumanFace) fos.readObject(); + public static HumanFace restoreFromFile(File dumpFile) throws IOException, ClassNotFoundException, Exception { + //try (ObjectInputStream fos = new ObjectInputStream(new BufferedInputStream(new FileInputStream(dumpFile)))) { + try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(dumpFile))) { + FSTObjectInput in = FST_CONF.getObjectInput(bis); + HumanFace face = (HumanFace) in.readObject(HumanFace.class); + return face; } } diff --git a/Comparison/src/main/java/cz/fidentis/analyst/face/HumanFaceCache.java b/Comparison/src/main/java/cz/fidentis/analyst/face/HumanFaceCache.java index 99a42718049cd6b434a2aaa3caeb6fa2b3a9d657..6aadb085fe838f3eeef8e39884e2f733dc80a162 100644 --- a/Comparison/src/main/java/cz/fidentis/analyst/face/HumanFaceCache.java +++ b/Comparison/src/main/java/cz/fidentis/analyst/face/HumanFaceCache.java @@ -33,7 +33,7 @@ public abstract class HumanFaceCache { /** * Keep at least this portion of the Java heap memory free */ - public static final double MIN_FREE_MEMORY = 0.05; // 5% + public static final double MIN_FREE_MEMORY = 0.2; // 20% private final Map<String, HumanFace> inMemoryFaces = new HashMap<>(); private final Map<String, File> dumpedFaces = new HashMap<>(); diff --git a/GUI/src/main/java/cz/fidentis/analyst/tests/EfficiencyTests.java b/GUI/src/main/java/cz/fidentis/analyst/tests/EfficiencyTests.java index 4164dd148e57f7aebec6e01c0cdab08d8f13f346..59a693005f81601459f3cdf22b41b52a873edc64 100644 --- a/GUI/src/main/java/cz/fidentis/analyst/tests/EfficiencyTests.java +++ b/GUI/src/main/java/cz/fidentis/analyst/tests/EfficiencyTests.java @@ -38,25 +38,23 @@ public class EfficiencyTests { * @param args Input arguments * @throws IOException on IO error */ - public static void main(String[] args) throws IOException, ClassNotFoundException { + public static void main(String[] args) throws IOException, ClassNotFoundException, Exception { face1 = printFaceLoad(faceFile4); face2 = printFaceLoad(faceFile4); face1.getMeshModel().simplifyModel(); face2.getMeshModel().simplifyModel(); - /* for (int i = 0; i < 10; i++) { - HumanFace face = HumanFacePrivilegedCache.instance().loadFace(faceFile4); - face.getMeshModel().simplifyModel(); - System.out.println(i+".\t" + HumanFacePrivilegedCache.instance()); + //HumanFace face = HumanFacePrivilegedCache.instance().loadFace(faceFile4); + //face.getMeshModel().simplifyModel(); + //System.out.println(i+".\t" + HumanFacePrivilegedCache.instance()); + printFaceDump(face1); } - */ boolean relativeDist = false; boolean printDetails = false; - printFaceDump(face1); //face1.getMeshModel().compute(new GaussianCurvature()); // initialize everything, then measure @@ -131,7 +129,7 @@ public class EfficiencyTests { ); } - private static void printFaceDump(HumanFace face) throws IOException, ClassNotFoundException { + private static void printFaceDump(HumanFace face) throws IOException, ClassNotFoundException, Exception { long startTime = System.currentTimeMillis(); File file = face.dumpToFile(); long endTime = System.currentTimeMillis();