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

Initial implementation of Haisdorf Distance (has to be refactored)

parent ffe1f62a
No related branches found
No related tags found
No related merge requests found
Showing with 107 additions and 29 deletions
......@@ -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>
......
......@@ -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;
......
......@@ -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());
}
......
......@@ -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;
}
}
}
......@@ -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;
......
package cz.fidentis.analyst.comparison;
/**
* @author Matej Lukes
*/
public enum RegistrationMethod {
NO_REGISTRATION
}
......@@ -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;
......
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
......@@ -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
......
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