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