diff --git a/Comparison/pom.xml b/Comparison/pom.xml index b49b10b4ca291ff8a0bc39d768f3e493d9de03ae..506ead0b0bef9fea1f3fabbac2fcb270df16375b 100644 --- a/Comparison/pom.xml +++ b/Comparison/pom.xml @@ -59,6 +59,14 @@ <target>8</target> </configuration> </plugin> + <!-- <plugin> + <groupId>org.openjfx</groupId> + <artifactId>javafx-maven-plugin</artifactId> + <version>0.0.4</version> + <configuration> + <mainClass>org.openjfx.App</mainClass> + </configuration> + </plugin> --> </plugins> </build> <dependencies> @@ -77,6 +85,17 @@ <artifactId>vecmath</artifactId> <version>${version.javax.vecmath}</version> </dependency> + <!-- <dependency> + <groupId>org.openjfx</groupId> + <artifactId>javafx-controls</artifactId> + <version>11.0.2</version> + </dependency> --> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> + <version>5.6.0</version> + <scope>test</scope> + </dependency> </dependencies> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> diff --git a/Comparison/src/main/java/cz/fidentis/analyst/comparison/ClosestVertices.java b/Comparison/src/main/java/cz/fidentis/analyst/comparison/ClosestVertices.java index 811cc3712b7794772201bdbc434d150cda253bc5..b088e9925639117b13862f5ff1c7a8b2494f54e6 100644 --- a/Comparison/src/main/java/cz/fidentis/analyst/comparison/ClosestVertices.java +++ b/Comparison/src/main/java/cz/fidentis/analyst/comparison/ClosestVertices.java @@ -2,13 +2,23 @@ package cz.fidentis.analyst.comparison; import cz.fidentis.analyst.mesh.core.MeshPoint; -import javax.vecmath.Vector3d; - +/** + * + * @author Matej Lukes + */ public class ClosestVertices { + private MeshPoint firstVertex; private MeshPoint secondVertex; private double distance; + /** + * Constructor. + * + * @param firstVertex Firt vertex of the pair + * @param secondVertex Second vertex of the pair + * @param distance Distance + */ public ClosestVertices(MeshPoint firstVertex, MeshPoint secondVertex, double distance) { this.firstVertex = firstVertex; this.secondVertex = secondVertex; diff --git a/Comparison/src/main/java/cz/fidentis/analyst/comparison/Comparison.java b/Comparison/src/main/java/cz/fidentis/analyst/comparison/Comparison.java index f639b1a21c77ea8ed9ce33ba55a81227d342a4c2..22a7673bb10a94de9c30b0111f0d2903673996b9 100644 --- a/Comparison/src/main/java/cz/fidentis/analyst/comparison/Comparison.java +++ b/Comparison/src/main/java/cz/fidentis/analyst/comparison/Comparison.java @@ -23,7 +23,7 @@ public class Comparison { * @param path path to meshModel file * @return CompletableFuture */ - public CompletableFuture LoadMainModel(String path) { + public CompletableFuture loadMainModel(String path) { return CompletableFuture.runAsync(() -> { try { @@ -40,7 +40,7 @@ public class Comparison { * @param path path to meshModel file * @return CompletableFuture */ - public CompletableFuture LoadComparedModel(String path) { + public CompletableFuture loadComparedModel(String path) { return CompletableFuture.runAsync(() -> { try { comparedFacet = MeshObjLoader.read(new File(path)).getFacets().get(1); @@ -56,9 +56,9 @@ public class Comparison { * @param method registration method * @return CompletableFuture */ - public CompletableFuture Register(RegistrationMethod method) { + public CompletableFuture register(RegistrationMethod method) { return CompletableFuture.runAsync(() -> comparedFacet = Registration - .Register(mainFacet, comparedFacet, method)); + .register(mainFacet, comparedFacet, method)); } /** @@ -66,7 +66,7 @@ public class Comparison { * * @return list containing vertex from first facet, closest vertex to it from second facet, distance */ - public CompletableFuture<List<ClosestVertices>> CompareHausdorffDistanceToVertices() { + public CompletableFuture<List<ClosestVertices>> compareHausdorffDistanceToVertices() { hausdorffDistance = new HausdorffDistance(mainFacet, comparedFacet); return CompletableFuture.supplyAsync(() -> hausdorffDistance.calculateHausdorffDistanceToVertices()); } @@ -76,7 +76,7 @@ public class Comparison { * * @return list containing vertex from first facet, closest point to it from second facet, distance */ - public CompletableFuture<List<ClosestVertices>> CompareHausdorffDistanceToMesh() { + public CompletableFuture<List<ClosestVertices>> compareHausdorffDistanceToMesh() { hausdorffDistance = new HausdorffDistance(mainFacet, comparedFacet); return CompletableFuture.supplyAsync(() -> hausdorffDistance.calculateHausdorffDistanceToMesh()); } diff --git a/Comparison/src/main/java/cz/fidentis/analyst/comparison/HausdorffDistance.java b/Comparison/src/main/java/cz/fidentis/analyst/comparison/HausdorffDistance.java index 2483bafb2aeea7689813daaea559519184ac3a43..79f62b67f8dba2e4ac5a7c809fefce8dac0b8f00 100644 --- a/Comparison/src/main/java/cz/fidentis/analyst/comparison/HausdorffDistance.java +++ b/Comparison/src/main/java/cz/fidentis/analyst/comparison/HausdorffDistance.java @@ -2,14 +2,18 @@ package cz.fidentis.analyst.comparison; import cz.fidentis.analyst.mesh.core.MeshFacet; import cz.fidentis.analyst.mesh.core.MeshPoint; -import javafx.util.Pair; +import cz.fidentis.analyst.mesh.core.MeshPointImpl; +import cz.fidentis.analyst.mesh.core.MeshTriangle; import javax.vecmath.Vector3d; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Optional; -import java.util.concurrent.*; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @@ -17,6 +21,7 @@ import java.util.stream.Collectors; * @author Matej Lukes */ public class HausdorffDistance { + private MeshFacet mainFacet; private MeshFacet comparedFacet; @@ -43,7 +48,7 @@ public class HausdorffDistance { } /** - * finds the nearest vertex on the second facet + * Finds the nearest vertex on the second facet. * * @param vertex vertex from * @return vertex, nearest vertex from second facet, distance @@ -140,7 +145,7 @@ public class HausdorffDistance { for (final MeshPoint vertex : mainFacet.getVertices()) { closestPointsFutures.add(executor.submit(() -> { - ClosestVertices result = CalculateNearestPointOnMesh(vertex, + ClosestVertices result = calculateNearestPointOnMesh(vertex, comparedFacet.getCornerTable() .getTriangleIndexesByVertexIndex(comparedFacet.getVertices() .indexOf(getNearestVertex(vertex) @@ -178,7 +183,7 @@ public class HausdorffDistance { progress.set(0); return mainFacet.getVertices().parallelStream() .map((meshPoint) -> { - ClosestVertices result = CalculateNearestPointOnMesh(meshPoint, + ClosestVertices result = calculateNearestPointOnMesh(meshPoint, comparedFacet.getCornerTable() .getTriangleIndexesByVertexIndex(comparedFacet.getVertices() .indexOf(getNearestVertex(meshPoint) @@ -195,16 +200,20 @@ public class HausdorffDistance { * @param indicesOfTrianglesOfVertex indices of triangles that contain the nearest vertex on second mesh * @return vertex from first facet, closest point to it from second facet, distance */ - private ClosestVertices CalculateNearestPointOnMesh( - MeshPoint vertex, List<Integer> indicesOfTrianglesOfVertex) { + private ClosestVertices calculateNearestPointOnMesh(MeshPoint vertex, List<Integer> indicesOfTrianglesOfVertex) { Vector3d vertexPosition = vertex.getPosition(); List<Pair<Vector3d, Double>> projections = new ArrayList<>(indicesOfTrianglesOfVertex.size()); Vector3d helperVector = new Vector3d(); + List<MeshTriangle> trList = comparedFacet.asTriangles(); for (int index : indicesOfTrianglesOfVertex) { - List<Vector3d> triangle = comparedFacet.getVerticesOfTriangle(index).stream() - .map(MeshPoint::getPosition) - .collect(Collectors.toList()); + List<Vector3d> triangle = new ArrayList<>(); + triangle.add(trList.get(index).vertex1.getPosition()); + triangle.add(trList.get(index).vertex2.getPosition()); + triangle.add(trList.get(index).vertex3.getPosition()); + //List<Vector3d> triangle = comparedFacet.asTriangles()..getVerticesOfTriangle(index).stream() + // .map(MeshPoint::getPosition) + // .collect(Collectors.toList()); Vector3d projection = getProjectionToTrianglePlane(vertexPosition, triangle); if (isPointInTriangle(projection, triangle)) { helperVector.sub(vertexPosition, projection); @@ -219,7 +228,7 @@ public class HausdorffDistance { Pair<Vector3d, Double> closestPosition = projections.stream() .min(Comparator.comparingDouble(Pair::getValue)).orElseGet(() -> new Pair<>(null, Double.MAX_VALUE)); return new ClosestVertices(vertex, - new MeshPoint(closestPosition.getKey(), null, null), + new MeshPointImpl(closestPosition.getKey(), null, null), closestPosition.getValue()); } @@ -313,4 +322,34 @@ public class HausdorffDistance { double t = ab.dot(ap) / ab.lengthSquared(); return new Vector3d(edgeVertex1.x + t * ab.x, edgeVertex1.y + t * ab.y, edgeVertex1.z + t * ab.z); } + + + /** + * Helper class for pairs. + * + * @param <K> key + * @param <V> value + */ + private class Pair<K,V> { + private K key; + private V value; + + /** + * Constructor. + * @param key key + * @param value value + */ + public Pair(K key, V value) { + this.key = key; + this.value = value; + } + + public K getKey() { + return key; + } + + public V getValue() { + return value; + } + } } diff --git a/Comparison/src/main/java/cz/fidentis/analyst/comparison/Registration.java b/Comparison/src/main/java/cz/fidentis/analyst/comparison/Registration.java index a42d3191e4a36dd919bf4a7fba4d1c410d3daa1e..29385305a7f19ae18df527c0fb8ed1a077560e11 100644 --- a/Comparison/src/main/java/cz/fidentis/analyst/comparison/Registration.java +++ b/Comparison/src/main/java/cz/fidentis/analyst/comparison/Registration.java @@ -2,9 +2,21 @@ package cz.fidentis.analyst.comparison; import cz.fidentis.analyst.mesh.core.MeshFacet; +/** + * + * @author Matej Lukes + */ public class Registration { - public static MeshFacet Register(MeshFacet facet, MeshFacet registeredFacet, RegistrationMethod method) { + /** + * Heler method - TO DO + * + * @param facet main facet + * @param registeredFacet refistered facet + * @param method registration method + * @return TO DO + */ + public static MeshFacet register(MeshFacet facet, MeshFacet registeredFacet, RegistrationMethod method) { switch (method) { case NO_REGISTRATION: return registeredFacet; diff --git a/Comparison/src/main/java/cz/fidentis/analyst/comparison/RegistrationMethod.java b/Comparison/src/main/java/cz/fidentis/analyst/comparison/RegistrationMethod.java index f707c12454c70962b8ee7bc9fe3630f5c4dfa0a2..3aefbf00eb4cf73dbf13fb08d0c40d597fa526d5 100644 --- a/Comparison/src/main/java/cz/fidentis/analyst/comparison/RegistrationMethod.java +++ b/Comparison/src/main/java/cz/fidentis/analyst/comparison/RegistrationMethod.java @@ -1,5 +1,8 @@ package cz.fidentis.analyst.comparison; +/** + * @author Matej Lukes + */ public enum RegistrationMethod { NO_REGISTRATION } diff --git a/Comparison/src/main/java/cz/fidentis/analyst/symmetry/SymmetryEstimator.java b/Comparison/src/main/java/cz/fidentis/analyst/symmetry/SymmetryEstimator.java index 50e9f043b3d572ea22ce7d7ac486c295fcabd574..385f0d4578dd833b351e8fbbdc8c603a642ad1da 100644 --- a/Comparison/src/main/java/cz/fidentis/analyst/symmetry/SymmetryEstimator.java +++ b/Comparison/src/main/java/cz/fidentis/analyst/symmetry/SymmetryEstimator.java @@ -3,15 +3,11 @@ package cz.fidentis.analyst.symmetry; import cz.fidentis.analyst.mesh.core.CornerTableRow; import cz.fidentis.analyst.mesh.core.MeshFacet; import cz.fidentis.analyst.mesh.core.MeshPoint; -import cz.fidentis.analyst.mesh.core.MeshPointImpl; import cz.fidentis.analyst.mesh.core.BoundingBox; import cz.fidentis.analyst.mesh.core.MeshTriangle; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; import javax.swing.ImageIcon; import javax.swing.JOptionPane; import javax.swing.JPanel; diff --git a/Comparison/src/test/java/cz/fidentis/analyst/comparison/ComparisonTest.java b/Comparison/src/test/java/cz/fidentis/analyst/comparison/ComparisonTest.java index f593127d05fbf6f8137fad89590e49982df8bc78..101d95a9c435994467c41afeea3b040127644dc4 100644 --- a/Comparison/src/test/java/cz/fidentis/analyst/comparison/ComparisonTest.java +++ b/Comparison/src/test/java/cz/fidentis/analyst/comparison/ComparisonTest.java @@ -1,9 +1,8 @@ package cz.fidentis.analyst.comparison; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; -import java.io.IOException; - -public class ComparisonTest extends TestCase { +public class ComparisonTest { } \ No newline at end of file diff --git a/MeshModel/src/main/java/cz/fidentis/analyst/mesh/io/MeshObjExporter.java b/MeshModel/src/main/java/cz/fidentis/analyst/mesh/io/MeshObjExporter.java index e518c9adee25c1e061d031795743492c7e5dcf10..3e5a9da9eb3ca7d63b1db313daf5f73e028bfbb0 100644 --- a/MeshModel/src/main/java/cz/fidentis/analyst/mesh/io/MeshObjExporter.java +++ b/MeshModel/src/main/java/cz/fidentis/analyst/mesh/io/MeshObjExporter.java @@ -49,7 +49,7 @@ public class MeshObjExporter { * @param exportFile file for exporting. * @throws java.io.IOException */ - public void exportFacetToObj(MeshFacet facet, File exportFile) throws IOException { + protected void exportFacetToObj(MeshFacet facet, File exportFile) throws IOException { int formatIndex = exportFile.getName().lastIndexOf("."); String fileName; //name that is writen to file