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

Adaptation to multiple mesh facets

parent cc26da10
No related branches found
No related tags found
No related merge requests found
...@@ -57,15 +57,15 @@ public class EfficiencyTests { ...@@ -57,15 +57,15 @@ public class EfficiencyTests {
System.out.println(); System.out.println();
System.out.println("Hausdorff distance sequentially:"); System.out.println("Hausdorff distance sequentially:");
testAndPrint(face1, new HausdorffDistance(face2.getMeshModel(), Strategy.POINT_TO_POINT_DISTANCE_ONLY, false, false), printDetails); //testAndPrint(face1, new HausdorffDistance(face2.getMeshModel(), Strategy.POINT_TO_POINT_DISTANCE_ONLY, false, false), printDetails);
testAndPrint(face1, new HausdorffDistance(face2.getMeshModel(), Strategy.POINT_TO_POINT, relativeDist, false), printDetails); //testAndPrint(face1, new HausdorffDistance(face2.getMeshModel(), Strategy.POINT_TO_POINT, relativeDist, false), printDetails);
testAndPrint(face1, new HausdorffDistance(face2.getMeshModel(), Strategy.POINT_TO_TRIANGLE_APPROXIMATE, relativeDist, false), printDetails); //testAndPrint(face1, new HausdorffDistance(face2.getMeshModel(), Strategy.POINT_TO_TRIANGLE_APPROXIMATE, relativeDist, false), printDetails);
System.out.println(); System.out.println();
System.out.println("Hausdorff distance concurrently:"); System.out.println("Hausdorff distance concurrently:");
testAndPrint(face1, new HausdorffDistance(face2.getMeshModel(), Strategy.POINT_TO_POINT_DISTANCE_ONLY, false, true), printDetails); //testAndPrint(face1, new HausdorffDistance(face2.getMeshModel(), Strategy.POINT_TO_POINT_DISTANCE_ONLY, false, true), printDetails);
testAndPrint(face1, new HausdorffDistance(face2.getMeshModel(), Strategy.POINT_TO_POINT, relativeDist, true), printDetails); //testAndPrint(face1, new HausdorffDistance(face2.getMeshModel(), Strategy.POINT_TO_POINT, relativeDist, true), printDetails);
testAndPrint(face1, new HausdorffDistance(face2.getMeshModel(), Strategy.POINT_TO_TRIANGLE_APPROXIMATE, relativeDist, true), printDetails); //testAndPrint(face1, new HausdorffDistance(face2.getMeshModel(), Strategy.POINT_TO_TRIANGLE_APPROXIMATE, relativeDist, true), printDetails);
} }
protected static void testAndPrint(HumanFace face, HausdorffDistance vis, boolean printDetails) { protected static void testAndPrint(HumanFace face, HausdorffDistance vis, boolean printDetails) {
......
...@@ -25,9 +25,8 @@ public class ApproxSymmetryPlane extends Plane implements Comparable<ApproxSymme ...@@ -25,9 +25,8 @@ public class ApproxSymmetryPlane extends Plane implements Comparable<ApproxSymme
* @param maxDistance Distance limit * @param maxDistance Distance limit
* @throws UnsupportedOperationException if the symmetry plane cannot be created * @throws UnsupportedOperationException if the symmetry plane cannot be created
*/ */
public ApproxSymmetryPlane( public ApproxSymmetryPlane(MeshFacet facet, SignificantPoints sigPoints,
MeshFacet facet, SignificantPoints sigPoints, Config config, int i, int j, double maxDistance Config config, int i, int j, double maxDistance) throws UnsupportedOperationException {
) throws UnsupportedOperationException {
if (i == j) { if (i == j) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
......
...@@ -4,18 +4,26 @@ import cz.fidentis.analyst.mesh.core.MeshFacet; ...@@ -4,18 +4,26 @@ import cz.fidentis.analyst.mesh.core.MeshFacet;
import cz.fidentis.analyst.mesh.core.MeshPoint; import cz.fidentis.analyst.mesh.core.MeshPoint;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.TreeSet;
import javax.vecmath.Vector3d; import javax.vecmath.Vector3d;
/** /**
* Finds and stores the top X points with the most significant curvarure. * Finds and stores the top X points with the most significant curvature.
* *
* @author Radek Oslejsek * @author Radek Oslejsek
* @author Natalia Bebjakova * @author Natalia Bebjakova
*/ */
public class SignificantPoints { public class SignificantPoints {
private final List<VertCurvature> significantPoints; private final int maxPoints;
private final PriorityQueue<VertCurvature> priorityQueue = new PriorityQueue<>();
private List<VertCurvature> significantPoints;
private List<List<Vector3d>> normCosVecCache; private List<List<Vector3d>> normCosVecCache;
...@@ -25,69 +33,57 @@ public class SignificantPoints { ...@@ -25,69 +33,57 @@ public class SignificantPoints {
/** /**
* Constructor. * Constructor.
* @param curvatures List of points' curvatures *
* @param max Maximal number of points * @param max Maximal number of significant points
*/ */
public SignificantPoints(List<Double> curvatures, int max) { public SignificantPoints(int max) {
List<VertCurvature> sp = new ArrayList<>(curvatures.size()); this.maxPoints = max;
for (int i = 0; i < curvatures.size(); i++) { }
sp.add(new VertCurvature(i, curvatures.get(i)));
} /**
* Adds vertices of the mesh facet into candidate to significant points.
Collections.sort(sp); *
if (max < sp.size()) { * @param facet Mesh facet.
significantPoints = new ArrayList<>(sp.subList(0, max)); * @param curvatures Curvatures of the mesh facet.
} else { * @throws NullPointerException of some input parameter is missing.
significantPoints = sp; * @throws UnsupportedOperationException if the {@link #selectSignigicantPoints()}
* was already called.
*/
public void processMeshFacet(MeshFacet facet, List<Double> curvatures) {
if (significantPoints != null) {
throw new UnsupportedOperationException("The processing stage already finished by calling the selectSignigicantPoints() method.");
} }
SortedSet<VertCurvature> sp = new TreeSet<>();
for (int i = 0; i < curvatures.size(); i++) {
priorityQueue.add(new VertCurvature(facet, i, curvatures.get(i)));
}
} }
/** /**
* Precomputes and caches some values related to the computation of * Selects significant points. The {@link #processMeshFacet} method
* asymmetric plane from curvature. * can be used anymore.
* *
* @param facet Mesh facet * @param cacheData If {@code true}, then pre-computes and caches some values
* related to the computation of asymmetric plane from curvature.
*/ */
public void cacheData(MeshFacet facet) { public void selectSignigicantPoints(boolean cacheData) {
if (normCosVecCache != null) { if (significantPoints != null) {
return; return;
} }
significantPoints = new ArrayList<>(maxPoints);
normCosVecCache = new ArrayList<>(significantPoints.size()); for (int i = 0; i < maxPoints; i++) {
avgPosCache = new ArrayList<>(significantPoints.size()); VertCurvature vc = priorityQueue.poll();
curRatioCache = new ArrayList<>(significantPoints.size()); if (vc == null) {
break;
for (int i = 0; i < significantPoints.size(); i++) { } else {
List<Vector3d> cosArray = new ArrayList<>(significantPoints.size()); significantPoints.add(vc);
normCosVecCache.add(cosArray);
List<Vector3d> posArray = new ArrayList<>(significantPoints.size());
avgPosCache.add(posArray);
List<Double> curArray = new ArrayList<>(significantPoints.size());
curRatioCache.add(curArray);
for (int j = 0; j < significantPoints.size(); j++) {
MeshPoint meshPointI = facet.getVertex(significantPoints.get(i).vertIndex);
MeshPoint meshPointJ = facet.getVertex(significantPoints.get(j).vertIndex);
Vector3d ni = new Vector3d(meshPointI.getNormal());
Vector3d nj = new Vector3d(meshPointJ.getNormal());
ni.normalize();
nj.normalize();
ni.sub(nj);
ni.normalize();
cosArray.add(ni);
Vector3d avrg = new Vector3d(meshPointI.getPosition());
Vector3d aux = new Vector3d(meshPointJ.getPosition());
avrg.add(aux);
avrg.scale(0.5);
posArray.add(avrg);
curArray.add(significantPoints.get(i).curvature / significantPoints.get(j).curvature);
} }
} }
priorityQueue.clear();
if (cacheData) {
cacheData();
}
} }
/** /**
...@@ -134,14 +130,18 @@ public class SignificantPoints { ...@@ -134,14 +130,18 @@ public class SignificantPoints {
* *
* @param i The "i" (index of the ordering) * @param i The "i" (index of the ordering)
* @return index of the i-th most significant mesh vertex. * @return index of the i-th most significant mesh vertex.
* @throws IllegalArgumentException if the {@code i} paramter is out of rage * @throws IllegalArgumentException if the {@code i} parameter is out of rage
* @throws UnsupportedOperationException if the method {@link #selectSignigicantPoints(boolean)}
* was not called yet.
*/ */
public int getVertexIndex(int i) { public int getVertexIndex(int i) {
if (i >= 0 && i < significantPoints.size()) { if (significantPoints == null) {
return significantPoints.get(i).vertIndex; throw new UnsupportedOperationException("Call selectSignigicantPoints() method firt");
} else { }
if (i < 0 || i >= significantPoints.size()) {
throw new IllegalArgumentException("i"); throw new IllegalArgumentException("i");
} }
return significantPoints.get(i).vertIndex;
} }
/** /**
...@@ -149,24 +149,97 @@ public class SignificantPoints { ...@@ -149,24 +149,97 @@ public class SignificantPoints {
* *
* @param i The "i" (index of the ordering) * @param i The "i" (index of the ordering)
* @return curvature of the i-th most significant mesh vertex. * @return curvature of the i-th most significant mesh vertex.
* @throws IllegalArgumentException if the {@code i} paramter is out of rage * @throws IllegalArgumentException if the {@code i} parameter is out of rage
* @throws UnsupportedOperationException if the method {@link #selectSignigicantPoints(boolean)}
* was not called yet.
*/ */
public double getCurvature(int i) { public double getCurvature(int i) {
if (i >= 0 && i < significantPoints.size()) { if (significantPoints == null) {
return significantPoints.get(i).curvature; throw new UnsupportedOperationException("Call selectSignigicantPoints() method firt");
} else { }
if (i < 0 || i >= significantPoints.size()) {
throw new IllegalArgumentException("i");
}
return significantPoints.get(i).curvature;
}
/**
* Returns mesh facet of the i-th most significant mesh vertex.
*
* @param i The "i" (index of the ordering)
* @return mesh facet of the i-th most significant mesh vertex.
* @throws IllegalArgumentException if the {@code i} parameter is out of rage
* @throws UnsupportedOperationException if the method {@link #selectSignigicantPoints(boolean)}
* was not called yet.
*/
public MeshFacet getMeshFacet(int i) {
if (significantPoints == null) {
throw new UnsupportedOperationException("Call selectSignigicantPoints() method firt");
}
if (i < 0 || i >= significantPoints.size()) {
throw new IllegalArgumentException("i"); throw new IllegalArgumentException("i");
} }
return significantPoints.get(i).facet;
} }
/** /**
* Returns numnber of the most significant points. * Returns number of the most significant points.
* @return numnber of the most significant points. * @return number of the most significant points.
*/ */
public int size() { public int size() {
return significantPoints.size(); return significantPoints.size();
} }
/**
* Pre-computes and caches some values related to the computation of
* asymmetric plane from curvature.
*
* @param facet Mesh facet
*/
protected void cacheData() {
if (normCosVecCache != null) { // ?????? !!!!!!
return;
}
normCosVecCache = new ArrayList<>(significantPoints.size());
avgPosCache = new ArrayList<>(significantPoints.size());
curRatioCache = new ArrayList<>(significantPoints.size());
for (int i = 0; i < significantPoints.size(); i++) {
List<Vector3d> cosArray = new ArrayList<>(significantPoints.size());
normCosVecCache.add(cosArray);
List<Vector3d> posArray = new ArrayList<>(significantPoints.size());
avgPosCache.add(posArray);
List<Double> curArray = new ArrayList<>(significantPoints.size());
curRatioCache.add(curArray);
for (int j = 0; j < significantPoints.size(); j++) {
VertCurvature vcI = significantPoints.get(i);
VertCurvature vcJ = significantPoints.get(j);
MeshPoint meshPointI = vcI.facet.getVertex(vcI.vertIndex);
MeshPoint meshPointJ = vcJ.facet.getVertex(vcJ.vertIndex);
Vector3d ni = new Vector3d(meshPointI.getNormal());
Vector3d nj = new Vector3d(meshPointJ.getNormal());
ni.normalize();
nj.normalize();
ni.sub(nj);
ni.normalize();
cosArray.add(ni);
Vector3d avrg = new Vector3d(meshPointI.getPosition());
Vector3d aux = new Vector3d(meshPointJ.getPosition());
avrg.add(aux);
avrg.scale(0.5);
posArray.add(avrg);
curArray.add(vcI.curvature / vcJ.curvature);
}
}
}
/** /**
* Helper class for sorting points with respect to their curvature. * Helper class for sorting points with respect to their curvature.
* @author Radek Oslejsek * @author Radek Oslejsek
...@@ -175,15 +248,28 @@ public class SignificantPoints { ...@@ -175,15 +248,28 @@ public class SignificantPoints {
private final int vertIndex; private final int vertIndex;
private final double curvature; private final double curvature;
private final MeshFacet facet;
VertCurvature(int vertIndex, double curvature) { VertCurvature(MeshFacet facet, int vertIndex, double curvature) {
this.vertIndex = vertIndex; this.vertIndex = vertIndex;
this.curvature = curvature; this.curvature = curvature;
this.facet = facet;
} }
/**
* Compares this object with the specified object for order.
* Curvature is taken into consideration as the primary value (descendant ordering).
* If the curvature equals, then the objects are sorted randomly (1 is always returned).
* This approach preserves all points in sorted collections.
*
* @param arg the object to be compared.
* @return a negative integer, zero, or a positive integer as this object
* is less than, equal to, or greater than the specified object.
*/
@Override @Override
public int compareTo(VertCurvature arg) { public int compareTo(VertCurvature arg) {
return -Double.compare(this.curvature, arg.curvature); int comp = Double.compare(arg.curvature, this.curvature);
return (comp == 0) ? 1 : comp;
} }
public String toString() { public String toString() {
......
...@@ -96,8 +96,12 @@ public class SymmetryEstimator { ...@@ -96,8 +96,12 @@ public class SymmetryEstimator {
public void calculateSymmetryPlane(boolean concurrently) { public void calculateSymmetryPlane(boolean concurrently) {
List<Plane> planes = new ArrayList<>(); List<Plane> planes = new ArrayList<>();
final SignificantPoints sigPoints = new SignificantPoints(curvatures, config.getSignificantPointCount()); final SignificantPoints sigPoints = new SignificantPoints(config.getSignificantPointCount());
sigPoints.cacheData(facet); sigPoints.processMeshFacet(facet, curvatures);
sigPoints.selectSignigicantPoints(true);
//final SignificantPoints sigPoints = new SignificantPoints(curvatures, config.getSignificantPointCount());
//sigPoints.cacheData(facet);
final double maxDistance = calculateMaxRelativeDistance(facet, config); final double maxDistance = calculateMaxRelativeDistance(facet, config);
/* /*
......
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