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

Minor changes

parent 5ad6b817
No related branches found
No related tags found
No related merge requests found
...@@ -87,14 +87,39 @@ public class DistanceToTrianglesVisitor extends MeshVisitor { ...@@ -87,14 +87,39 @@ public class DistanceToTrianglesVisitor extends MeshVisitor {
DistanceToVerticesVisitor vis = new DistanceToVerticesVisitor(myPoint, relativeDist, false); DistanceToVerticesVisitor vis = new DistanceToVerticesVisitor(myPoint, relativeDist, false);
facet.accept(vis); facet.accept(vis);
List<MeshFacet> closestFacets = vis.getClosestFacets(); List<MeshFacet> clFacets = vis.getClosestFacets();
List<Integer> closestVertices = vis.getClosestVertices(); List<Integer> clVertices = vis.getClosestVertices();
for (int i = 0; i < closestVertices.size(); i++) { // for all found closest vertices for (int i = 0; i < clVertices.size(); i++) { // for all found closest vertices
MeshFacet closestF = closestFacets.get(i); MeshFacet closestF = clFacets.get(i);
int closestI = closestVertices.get(i); int closestI = clVertices.get(i);
MeshPoint closestP = closestF.getVertex(closestI);
Vector3d projection = closestF.getClosestAdjacentPoint(my, closestI);
Vector3d aux = new Vector3d(projection);
aux.sub(myPoint.getPosition());
double dist = aux.length();
synchronized (this) {
if (dist > distance) {
continue;
}
if (dist < distance) { // new closest point
sign = relativeDist ? (int) Math.signum(aux.dot(myPoint.getNormal())): 1;
distance = dist;
closestFacets.clear();
closestTriangles.clear();
closestFacets.add(closestF);
closestTriangles.add(closestI);
} else { // the same distance
if (!closestFacets.contains(closestF)) {
closestFacets.add(closestF);
closestTriangles.add(closestI);
}
}
}
/*
CornerTable ct = closestF.getCornerTable(); CornerTable ct = closestF.getCornerTable();
List<Integer> adjacentTrianglesI = ct.getTriangleIndexesByVertexIndex(closestI); List<Integer> adjacentTrianglesI = ct.getTriangleIndexesByVertexIndex(closestI);
...@@ -111,6 +136,7 @@ public class DistanceToTrianglesVisitor extends MeshVisitor { ...@@ -111,6 +136,7 @@ public class DistanceToTrianglesVisitor extends MeshVisitor {
Vector3d projection = tri.getClosestPoint(my); Vector3d projection = tri.getClosestPoint(my);
checkAndUpdateDistance(projection, facet, i); checkAndUpdateDistance(projection, facet, i);
} }
*/
} }
} }
......
...@@ -84,7 +84,30 @@ public class DistanceToVerticesVisitor extends MeshVisitor { ...@@ -84,7 +84,30 @@ public class DistanceToVerticesVisitor extends MeshVisitor {
protected void visitMeshFacet(MeshFacet facet) { protected void visitMeshFacet(MeshFacet facet) {
List<MeshPoint> vertices = facet.getVertices(); List<MeshPoint> vertices = facet.getVertices();
for (int i = 0; i < vertices.size(); i++) { for (int i = 0; i < vertices.size(); i++) {
checkAndUpdateDistance(vertices.get(i).getPosition(), facet, i); //checkAndUpdateDistance(vertices.get(i).getPosition(), facet, i);
Vector3d pointOnSurface = vertices.get(i).getPosition();
Vector3d aux = new Vector3d(pointOnSurface);
aux.sub(myPoint.getPosition());
double dist = aux.length();
synchronized (this) {
if (dist > distance) {
continue;
}
if (dist < distance) { // new closest point
distance = dist;
sign = relativeDist ? (int) Math.signum(aux.dot(myPoint.getNormal())): 1;
closestFacets.clear();
closestVertices.clear();
closestFacets.add(facet);
closestVertices.add(i);
} else { // the same distance
if (!closestFacets.contains(facet)) {
closestFacets.add(facet);
closestVertices.add(i);
}
}
}
} }
} }
...@@ -142,7 +165,6 @@ public class DistanceToVerticesVisitor extends MeshVisitor { ...@@ -142,7 +165,6 @@ public class DistanceToVerticesVisitor extends MeshVisitor {
protected void checkAndUpdateDistance(Vector3d pointOnSurface, MeshFacet facet, int index) { protected void checkAndUpdateDistance(Vector3d pointOnSurface, MeshFacet facet, int index) {
Vector3d aux = new Vector3d(pointOnSurface); Vector3d aux = new Vector3d(pointOnSurface);
aux.sub(myPoint.getPosition()); aux.sub(myPoint.getPosition());
sign = relativeDist ? (int) Math.signum(aux.dot(myPoint.getNormal())): 1;
double dist = aux.length(); double dist = aux.length();
synchronized (this) { synchronized (this) {
...@@ -152,6 +174,7 @@ public class DistanceToVerticesVisitor extends MeshVisitor { ...@@ -152,6 +174,7 @@ public class DistanceToVerticesVisitor extends MeshVisitor {
if (dist < distance) { // new closest point if (dist < distance) { // new closest point
distance = dist; distance = dist;
sign = relativeDist ? (int) Math.signum(aux.dot(myPoint.getNormal())): 1;
closestFacets.clear(); closestFacets.clear();
closestVertices.clear(); closestVertices.clear();
closestFacets.add(facet); closestFacets.add(facet);
......
...@@ -18,6 +18,7 @@ import java.util.concurrent.Executors; ...@@ -18,6 +18,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.vecmath.Vector3d;
/** /**
* Visitor for Hausdorff distance. * Visitor for Hausdorff distance.
...@@ -62,6 +63,7 @@ public class HausdorffDistanceVisitor extends MeshVisitor { ...@@ -62,6 +63,7 @@ public class HausdorffDistanceVisitor extends MeshVisitor {
throw new IllegalArgumentException("mainFacets"); throw new IllegalArgumentException("mainFacets");
} }
for (MeshFacet f: mainFacets) { for (MeshFacet f: mainFacets) {
// create the list of distances initiate it with infinity
distances.put(f, new ArrayList<>()); distances.put(f, new ArrayList<>());
} }
this.relativeDistance = relativeDistance; this.relativeDistance = relativeDistance;
...@@ -107,12 +109,13 @@ public class HausdorffDistanceVisitor extends MeshVisitor { ...@@ -107,12 +109,13 @@ public class HausdorffDistanceVisitor extends MeshVisitor {
ExecutorService executor = Executors.newFixedThreadPool(threads); ExecutorService executor = Executors.newFixedThreadPool(threads);
List<Future<MeshVisitor>> results = new LinkedList<>(); List<Future<MeshVisitor>> results = new LinkedList<>();
// fo all my facets
for (Map.Entry<MeshFacet, List<Double>> entry: distances.entrySet()) { for (Map.Entry<MeshFacet, List<Double>> entry: distances.entrySet()) {
List<MeshPoint> vertices = entry.getKey().getVertices(); List<MeshPoint> vertices = entry.getKey().getVertices();
List<Double> distList = entry.getValue(); List<Double> distList = entry.getValue();
if (concurrently()) { if (concurrently()) {
for (int i = 0; i < vertices.size(); i++) { for (int i = 0; i < vertices.size(); i++) { // for all my vertices
if (strategy == Strategy.POINT_TO_POINT) { if (strategy == Strategy.POINT_TO_POINT) {
DistanceToVerticesVisitor visitor = new DistanceToVerticesVisitor(vertices.get(i), relativeDistance, true); DistanceToVerticesVisitor visitor = new DistanceToVerticesVisitor(vertices.get(i), relativeDistance, true);
comparedFacet.accept(visitor); comparedFacet.accept(visitor);
...@@ -125,40 +128,36 @@ public class HausdorffDistanceVisitor extends MeshVisitor { ...@@ -125,40 +128,36 @@ public class HausdorffDistanceVisitor extends MeshVisitor {
results.add(result); results.add(result);
} }
} }
//updateFacetDistancesConcurrently(distList, results);
boolean firstComparison = distList.isEmpty();
try { try {
boolean firstApplication = distList.isEmpty(); // first application of the visitor
for (int i = 0; i < results.size(); i++) { // wait ntil all computations are finished for (int i = 0; i < results.size(); i++) { // wait ntil all computations are finished
if (strategy == Strategy.POINT_TO_POINT) { if (strategy == Strategy.POINT_TO_POINT) {
DistanceToVerticesVisitor visitor = (DistanceToVerticesVisitor) results.get(i).get(); DistanceToVerticesVisitor visitor = (DistanceToVerticesVisitor) results.get(i).get();
double dist = visitor.getDistance(); double dist = visitor.getDistance();
updateDistances(distList, firstComparison, dist, i); updateDistances(distList, firstApplication, dist, i);
} else if (strategy == Strategy.POINT_TO_TRIANGLE) { } else if (strategy == Strategy.POINT_TO_TRIANGLE) {
DistanceToTrianglesVisitor visitor = (DistanceToTrianglesVisitor) results.get(i).get(); DistanceToTrianglesVisitor visitor = (DistanceToTrianglesVisitor) results.get(i).get();
double dist = visitor.getDistance(); double dist = visitor.getDistance();
updateDistances(distList, firstComparison, dist, i); updateDistances(distList, firstApplication, dist, i);
} }
} }
} catch (InterruptedException | ExecutionException ex) { } catch (InterruptedException | ExecutionException ex) {
Logger.getLogger(HausdorffDistanceVisitor.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(HausdorffDistanceVisitor.class.getName()).log(Level.SEVERE, null, ex);
} }
} else { // sequentially } else { // sequentially
//updateFacetDistancesSequentially(vertices, distList, comparedFacet); boolean firstApplication = distList.isEmpty(); // first application of the visitor
boolean firstComparison = distList.isEmpty(); for (int i = 0; i < vertices.size(); i++) { // for all my vertices
for (int i = 0; i < vertices.size(); i++) {
if (strategy == Strategy.POINT_TO_POINT) { if (strategy == Strategy.POINT_TO_POINT) {
DistanceToVerticesVisitor visitor = new DistanceToVerticesVisitor(vertices.get(i), relativeDistance, false); DistanceToVerticesVisitor visitor = new DistanceToVerticesVisitor(vertices.get(i), relativeDistance, false);
comparedFacet.accept(visitor); comparedFacet.accept(visitor);
double dist = visitor.getDistance(); double dist = visitor.getDistance();
updateDistances(distList, firstComparison, dist, i); updateDistances(distList, firstApplication, dist, i);
} else if (strategy == Strategy.POINT_TO_TRIANGLE) { } else if (strategy == Strategy.POINT_TO_TRIANGLE) {
DistanceToTrianglesVisitor visitor = new DistanceToTrianglesVisitor(vertices.get(i), relativeDistance, false); DistanceToTrianglesVisitor visitor = new DistanceToTrianglesVisitor(vertices.get(i), relativeDistance, false);
comparedFacet.accept(visitor); comparedFacet.accept(visitor);
double dist = visitor.getDistance(); double dist = visitor.getDistance();
updateDistances(distList, firstComparison, dist, i); updateDistances(distList, firstApplication, dist, i);
} }
} }
} }
...@@ -186,19 +185,13 @@ public class HausdorffDistanceVisitor extends MeshVisitor { ...@@ -186,19 +185,13 @@ public class HausdorffDistanceVisitor extends MeshVisitor {
return distances; return distances;
} }
protected void updateDistances(List<Double> distList, boolean firstComparison, double dist, int index) { protected synchronized void updateDistances(List<Double> distList, boolean firstApplication, double dist, int index) {
if (firstComparison) { if (firstApplication) {
distList.add(dist); distList.add(dist);
return; } else if (dist >= 0 && dist < distList.get(index)) {
}
if (dist >= 0 && dist < distList.get(index)) {
distList.set(index, dist); distList.set(index, dist);
return; } else if (dist < 0 && dist > distList.get(index)) { // for relative dist only
}
if (dist < 0 && dist > distList.get(index)) { // for relative dist only
distList.set(index, dist); distList.set(index, dist);
} }
} }
} }
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