From b87d11dd3e197245da2e8dbe33da9d65e6c21772 Mon Sep 17 00:00:00 2001
From: Daniel Schramm <xschramm@fi.muni.cz>
Date: Tue, 14 Sep 2021 15:06:08 +0200
Subject: [PATCH] Selection of feature points by their type corrected

---
 .../face/HausdorffDistancePrioritized.java    | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/Comparison/src/main/java/cz/fidentis/analyst/visitors/face/HausdorffDistancePrioritized.java b/Comparison/src/main/java/cz/fidentis/analyst/visitors/face/HausdorffDistancePrioritized.java
index 52f2949e..14507cc6 100644
--- a/Comparison/src/main/java/cz/fidentis/analyst/visitors/face/HausdorffDistancePrioritized.java
+++ b/Comparison/src/main/java/cz/fidentis/analyst/visitors/face/HausdorffDistancePrioritized.java
@@ -322,15 +322,18 @@ public class HausdorffDistancePrioritized extends HumanFaceVisitor  {
     public void visitHumanFace(HumanFace humanFace) {
         // Compute the Hasudorff distance using the 'distanceVisitor'
         humanFace.getMeshModel().compute(distanceVisitor, inParallel());
-        
+
         final Map<MeshFacet, List<Double>> hausdorffDistances = distanceVisitor.getDistances();
-                
+
         // Compute priorities of humanFace's vertices for each of the given feature point types
         for (final Map.Entry<FeaturePointType, Double> fpType: featurePointTypes.entrySet()) {
             final FeaturePointType featurePointType = fpType.getKey();
             final double featurePointRadius = fpType.getValue();
             
-            final FeaturePoint featurePoint = humanFace.getFeaturePoints().get(featurePointType.getType()); // Get feature point of desired type
+            final FeaturePoint featurePoint = getFeaturePointByType(humanFace, featurePointType);
+            if (featurePoint == null) {
+                continue;
+            }
             
             final PrioritySphere priorityVisitor = new PrioritySphere(featurePoint.getPosition(), featurePointRadius);
             humanFace.getMeshModel().compute(priorityVisitor, inParallel());
@@ -377,4 +380,14 @@ public class HausdorffDistancePrioritized extends HumanFaceVisitor  {
             }
         }
     }
+    
+    protected FeaturePoint getFeaturePointByType(HumanFace face, FeaturePointType type) {
+        for (final FeaturePoint featurePoint: face.getFeaturePoints()) {
+            if (type.getType() == featurePoint.getFeaturePointType().getType()) {
+                return featurePoint;
+            }
+        }
+        
+        return null;
+    }
 }
-- 
GitLab