Skip to content
Snippets Groups Projects
Commit fa57f8e8 authored by Jakub Kolman's avatar Jakub Kolman
Browse files

[#38] feat: procrustes visualisation

parent 8bd53bfa
No related branches found
No related tags found
No related merge requests found
Showing
with 44289 additions and 66 deletions
...@@ -73,27 +73,21 @@ public class ProcrustesAnalysis { ...@@ -73,27 +73,21 @@ public class ProcrustesAnalysis {
return faceModel2; return faceModel2;
} }
public List<SimpleMatrix> analyze() { public void analyze() {
List<SimpleMatrix> transformation = new ArrayList<>(); List<SimpleMatrix> transformation = new ArrayList<>();
this.superImpose(); this.superImpose();
SimpleMatrix rotation = this.rotate(); this.rotate();
if (rotation != null) {
transformation.add(rotation);
return transformation;
} else {
return null;
}
} }
// private Point3d computeCentroidsDistance(Point3d centroid1, Point3d centroid2) { private Point3d computeCentroidsDistance(Point3d centroid1, Point3d centroid2) {
// double x = (centroid1.x - centroid2.x); double x = (centroid1.x - centroid2.x);
// double y = (centroid1.y - centroid2.y); double y = (centroid1.y - centroid2.y);
// double z = (centroid1.z - centroid2.z); double z = (centroid1.z - centroid2.z);
//
// Point3d computedCentroid = new Point3d(x, y, z); Point3d computedCentroid = new Point3d(x, y, z);
// return computedCentroid; return computedCentroid;
// } }
/** /**
* Imposes two face models (lists of feature points and vertices) over each other * Imposes two face models (lists of feature points and vertices) over each other
...@@ -132,28 +126,28 @@ public class ProcrustesAnalysis { ...@@ -132,28 +126,28 @@ public class ProcrustesAnalysis {
faceModel.setVerticesMatrix(centeredVertices); faceModel.setVerticesMatrix(centeredVertices);
} }
// private void moveModelToSameOrigin(List<MeshPoint> vertices, HashMap<Integer, FeaturePoint> featurePointsMap) { private void moveModelToSameOrigin(List<MeshPoint> vertices, HashMap<Integer, FeaturePoint> featurePointsMap) {
// Point3d diff = computeCentroidsDistance(this.modelCentroid1, this.modelCentroid2); Point3d diff = computeCentroidsDistance(this.modelCentroid1, this.modelCentroid2);
// moveModelToPoint(diff, vertices, featurePointsMap); moveModelToPoint(diff, vertices, featurePointsMap);
// } }
// private void moveModelToPoint(Point3d centroid, List<MeshPoint> vertices, HashMap<Integer, FeaturePoint> featurePointsMap) { private void moveModelToPoint(Point3d centroid, List<MeshPoint> vertices, HashMap<Integer, FeaturePoint> featurePointsMap) {
// moveVertices(centroid, vertices); moveVertices(centroid, vertices);
//// moveFeaturePointsToVertices(centroid, featurePointsMap); moveFeaturePointsToVertices(centroid, featurePointsMap);
// } }
// private void moveFeaturePointsToVertices(Point3d centroid, HashMap<Integer, FeaturePoint> featurePointsMap) { private void moveFeaturePointsToVertices(Point3d centroid, HashMap<Integer, FeaturePoint> featurePointsMap) {
// for (FeaturePoint fp : featurePointsMap.values()) { for (FeaturePoint fp : featurePointsMap.values()) {
// fp.getPosition().x = fp.getPosition().x + centroid.x; fp.getPosition().x = fp.getPosition().x + centroid.x;
// fp.getPosition().y = fp.getPosition().y + centroid.y; fp.getPosition().y = fp.getPosition().y + centroid.y;
// fp.getPosition().z = fp.getPosition().z + centroid.z; fp.getPosition().z = fp.getPosition().z + centroid.z;
// } }
// } }
/** /**
* By rotation of matrices solves orthogonal procrustes problem * By rotation of matrices solves orthogonal procrustes problem
*/ */
private SimpleMatrix rotate() { private void rotate() {
// There is no reason trying to rotate less than 3 elements // There is no reason trying to rotate less than 3 elements
if (this.getFaceModel1().getFeaturePointsMap().size() < 3) { if (this.getFaceModel1().getFeaturePointsMap().size() < 3) {
...@@ -188,8 +182,6 @@ public class ProcrustesAnalysis { ...@@ -188,8 +182,6 @@ public class ProcrustesAnalysis {
SimpleMatrix rotatedVertices = this.faceModel2.getVerticesMatrix().mult(r); SimpleMatrix rotatedVertices = this.faceModel2.getVerticesMatrix().mult(r);
createListFromMatrix(rotatedVertices, this.faceModel2); createListFromMatrix(rotatedVertices, this.faceModel2);
return r;
} }
private void createListFromMatrix(SimpleMatrix rotatedVertices, ProcrustesAnalysisFaceModel faceModel) { private void createListFromMatrix(SimpleMatrix rotatedVertices, ProcrustesAnalysisFaceModel faceModel) {
...@@ -226,18 +218,18 @@ public class ProcrustesAnalysis { ...@@ -226,18 +218,18 @@ public class ProcrustesAnalysis {
* @param vertices * @param vertices
* @return * @return
*/ */
// private void moveVertices(Point3d centroid, List<MeshPoint> vertices) { private void moveVertices(Point3d centroid, List<MeshPoint> vertices) {
// if (vertices != null && centroid != null) { if (vertices != null && centroid != null) {
//// List<MeshPoint> movedVertices = null; // List<MeshPoint> movedVertices = null;
// for (MeshPoint v : vertices) { for (MeshPoint v : vertices) {
// v.getPosition().x = (v.getPosition().x + centroid.x); v.getPosition().x = (v.getPosition().x + centroid.x);
// v.getPosition().y = (v.getPosition().y + centroid.y); v.getPosition().y = (v.getPosition().y + centroid.y);
// v.getPosition().z = (v.getPosition().z + centroid.z); v.getPosition().z = (v.getPosition().z + centroid.z);
// } }
// } else { } else {
// throw new ProcrustesAnalysisException("Could not compute vertices locations after moving the centroid from model to feature points"); throw new ProcrustesAnalysisException("Could not compute vertices locations after moving the centroid from model to feature points");
// } }
// } }
/** /**
* Creates sorted feature point lists and compares them whether they have * Creates sorted feature point lists and compares them whether they have
......
...@@ -44,12 +44,12 @@ public class ProcrustesAnalysisComparison { ...@@ -44,12 +44,12 @@ public class ProcrustesAnalysisComparison {
private static final String HEAD_01 = "0002_01_ECA.obj"; private static final String HEAD_01 = "0002_01_ECA.obj";
private static final String HEAD_02 = "0002_01_ECA.obj"; private static final String HEAD_02 = "0002_01_ECA.obj";
private static final String OLD_FP_HEAD_01 = "head01_landmarks.csv"; private static final String OLD_FP_HEAD_01 = "3points_head01_landmarks.csv";
private static final String OLD_FP_HEAD_02 = "head02_landmarks.csv"; private static final String OLD_FP_HEAD_02 = "3points_head02_landmarks.csv";
private static final Path OLD_HEAD_01_PATH = Paths.get( private static final Path OLD_HEAD_01_PATH = Paths.get(
"cz", "fidentis", "comparison", "procrustesAnalysis", "faces", "head01_ECA.obj"); "cz", "fidentis", "comparison", "procrustesAnalysis", "faces", "3points_head01_ECA.obj");
private static final Path OLD_HEAD_02_PATH = Paths.get( private static final Path OLD_HEAD_02_PATH = Paths.get(
"cz", "fidentis", "comparison", "procrustesAnalysis", "faces", "head02_ECA.obj"); "cz", "fidentis", "comparison", "procrustesAnalysis", "faces", "3points_head02_ECA.obj");
...@@ -71,26 +71,27 @@ public class ProcrustesAnalysisComparison { ...@@ -71,26 +71,27 @@ public class ProcrustesAnalysisComparison {
// HumanFace face2 = factory.getFace(factory.loadFace(fru.getFileFromResource(FACE_2_PATH.toString()))); // HumanFace face2 = factory.getFace(factory.loadFace(fru.getFileFromResource(FACE_2_PATH.toString())));
// HEADS from the old models // HEADS from the old models
// List<FeaturePoint> fpList01 = featurePointImportService.importFeaturePoints( List<FeaturePoint> fpList01 = featurePointImportService.importFeaturePoints(
// FP_FILE_DIRECTORY.toString(), OLD_FP_HEAD_01); FP_FILE_DIRECTORY.toString(), OLD_FP_HEAD_01);
// List<FeaturePoint> fpList02 = featurePointImportService.importFeaturePoints( List<FeaturePoint> fpList02 = featurePointImportService.importFeaturePoints(
// FP_FILE_DIRECTORY.toString(), OLD_FP_HEAD_02); FP_FILE_DIRECTORY.toString(), OLD_FP_HEAD_02);
// HumanFace face1 = factory.getFace(factory.loadFace(fru.getFileFromResource(OLD_HEAD_01_PATH.toString()))); HumanFace face1 = factory.getFace(factory.loadFace(fru.getFileFromResource(OLD_HEAD_01_PATH.toString())));
// HumanFace face2 = factory.getFace(factory.loadFace(fru.getFileFromResource(OLD_HEAD_02_PATH.toString()))); HumanFace face2 = factory.getFace(factory.loadFace(fru.getFileFromResource(OLD_HEAD_02_PATH.toString())));
//
// face1.setFeaturePoints(fpList01); face1.setFeaturePoints(fpList01);
// face2.setFeaturePoints(fpList02); face2.setFeaturePoints(fpList02);
//
// ProcrustesAnalysis pa = new ProcrustesAnalysis(face1, face2); ProcrustesAnalysis pa = new ProcrustesAnalysis(face1, face2);
pa.analyze();
// import fp export csv // import fp export csv
// List<FeaturePoint> fpList01 = featurePointImportService.importFeaturePoints( // List<FeaturePoint> fpList01 = featurePointImportService.importFeaturePoints(
// FP_FILE_DIRECTORY.toString(), "3points_head02head01.fp"); // FP_FILE_DIRECTORY.toString(), "3points_head02head01.fp");
List<FeaturePoint> fpList02 = featurePointImportService.importFeaturePoints( // List<FeaturePoint> fpList02 = featurePointImportService.importFeaturePoints(
FP_FILE_DIRECTORY.toString(), "3points_top_head02.fp"); // FP_FILE_DIRECTORY.toString(), "3points_top_head02.fp");
FeaturePointExportService featurePointExportService = new FeaturePointExportService(); // FeaturePointExportService featurePointExportService = new FeaturePointExportService();
// featurePointExportService.exportFeaturePoints(fpList01, "head01", "CSV"); // featurePointExportService.exportFeaturePoints(fpList01, "head01", "CSV");
featurePointExportService.exportFeaturePoints(fpList02, "3points_top_head02", "CSV"); // featurePointExportService.exportFeaturePoints(fpList02, "3points_top_head02", "CSV");
System.out.println("finished"); System.out.println("finished");
......
newmtl default
Ns 10.0000
Ni 1.5000
d 1.0000
Tr 0.0000
Tf 1.0000 1.0000 1.0000
illum 2
Ka 0.79f 0.6f 0.54f
Kd 0.79f 0.6f 0.54f
Ks 0.0000 0.0000 0.0000
Ke 0.0000 0.0000 0.0000
Scan name,EX_R x,EX_R y,EX_R z,EX_L x,EX_L y,EX_L z,EN_R x,EN_R y,EN_R z
head01,-35.208347,44.349754,38.47641,29.282866,44.72036,40.04837,0.0055007935,-1.238967,44.85251
\ No newline at end of file
# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
# File Created: 13.05.2013 23:45:50
newmtl default
Ns 10.0000
Ni 1.5000
d 1.0000
Tr 0.0000
Tf 1.0000 1.0000 1.0000
illum 2
Ka 0.79f 0.6f 0.54f
Kd 0.79f 0.6f 0.54f
Ks 0.0000 0.0000 0.0000
Ke 0.0000 0.0000 0.0000
Scan name,EX_R x,EX_R y,EX_R z,EX_L x,EX_L y,EX_L z,EN_R x,EN_R y,EN_R z
head02,64.33597,49.641045,-0.630764,77.867096,72.18757,-66.65968,83.431335,12.202349,-64.44226
\ No newline at end of file
...@@ -272,7 +272,9 @@ public class RegistrationAction extends ControlPanelAction { ...@@ -272,7 +272,9 @@ public class RegistrationAction extends ControlPanelAction {
HumanFace secondaryFace = getScene().getHumanFace(1); HumanFace secondaryFace = getScene().getHumanFace(1);
ProcrustesAnalysis procrustesAnalysisInit = new ProcrustesAnalysis(primaryFace, secondaryFace); ProcrustesAnalysis procrustesAnalysisInit = new ProcrustesAnalysis(primaryFace, secondaryFace);
List<SimpleMatrix> transformation = procrustesAnalysisInit.analyze(); procrustesAnalysisInit.analyze();
calculateFeaturePoints();
calculateHausdorffDistance();
} }
protected void applyICP() { protected void applyICP() {
......
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