Skip to content

v0.2.55..v0.2.56 changeset MaximalSubline.h

Garret Voltz edited this page Aug 14, 2020 · 3 revisions
diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/subline-matching/MaximalSubline.h b/hoot-core/src/main/cpp/hoot/core/algorithms/subline-matching/MaximalSubline.h
index 6a3be24..4148acb 100644
--- a/hoot-core/src/main/cpp/hoot/core/algorithms/subline-matching/MaximalSubline.h
+++ b/hoot-core/src/main/cpp/hoot/core/algorithms/subline-matching/MaximalSubline.h
@@ -22,7 +22,7 @@
  * This will properly maintain the copyright information. DigitalGlobe
  * copyrights will be updated automatically.
  *
- * @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019 DigitalGlobe (http://www.digitalglobe.com/)
+ * @copyright Copyright (C) 2015, 2016, 2017, 2018, 2019, 2020 DigitalGlobe (http://www.digitalglobe.com/)
  */
 #ifndef MAXIMALSUBLINE_H
 #define MAXIMALSUBLINE_H
@@ -46,7 +46,7 @@ class WaySublineMatch;
  * Given a set of limitations on defining whether or not two points "match", calculate an
  * approximation of the maximal line within those constraints.
  *
- * @note It may be worth investaging a probabilistic approach to this problem. Although we'll either
+ * @todo It may be worth investaging a probabilistic approach to this problem. Although we'll either
  * need a clever way to do it unsupervised, or some point matching training data to establish
  * distributions. It'll also likely increase the computational complexity.
  */
@@ -56,13 +56,12 @@ public:
 
   static std::string className() { return "hoot::MaximalSubline"; }
 
-  static int logWarnCount;
-
   class MatchCriteria
   {
   public:
 
-    virtual ~MatchCriteria() {}
+    MatchCriteria() = default;
+    virtual ~MatchCriteria() = default;
 
     /**
      * Returns a match score for @a index1 way segment matches @a index2. The indexes refer to a
@@ -107,7 +106,7 @@ public:
 
     ThresholdMatchCriteria(Meters maxDistance, Radians maxAngleDiff);
 
-    virtual ~ThresholdMatchCriteria() {}
+    virtual ~ThresholdMatchCriteria() = default;
 
     virtual double match(int index1, int index2) const;
 
@@ -117,7 +116,6 @@ public:
 
     Meters _maxDistance;
     Radians _maxAngleDiff;
-
   };
 
   /**
@@ -129,6 +127,8 @@ public:
    */
   MaximalSubline(MatchCriteria* criteria, Meters minSplitSize);
 
+  virtual ~MaximalSubline() = default;
+
   /**
    * This code is still experimental at best.
    *
@@ -161,15 +161,24 @@ public:
    *  vector will be resized as needed.
    * @return 0.0 if there are no common sublines, otherwise the score of the best subline.
    */
-  double findMaximalSubline(const ConstOsmMapPtr &map, const ConstWayPtr& w1, const ConstWayPtr &w2,
-    std::vector<WayLocation>& wl1, std::vector<WayLocation> &wl2);
+  double findMaximalSubline(const ConstOsmMapPtr &map, const ConstWayPtr& w1, const ConstWayPtr& w2,
+    std::vector<WayLocation>& wl1, std::vector<WayLocation>& wl2);
+
+  void setMaxRecursionComplexity(int maxRecursions) { _maxRecursionComplexity = maxRecursions; }
 
 private:
 
+  static int logWarnCount;
+
   std::shared_ptr<MatchCriteria> _criteria;
   Meters _spacing;
   Meters _minSplitSize;
 
+  // places a limit on the number of recursive matching calls that can be made and throws an
+  // exception once that limit has been reached; only used in select places in the code
+  int _maxRecursionComplexity;
+  int _findBestMatchesRecursionCount;
+
   struct SublineScore
   {
     int start1, stop1;
@@ -183,30 +192,30 @@ private:
    * @param index The index of the first node in the line segment to look at.
    */
   WayLocation _calculateEndWayLocation(const ConstOsmMapPtr &map, const ConstWayPtr& a,
-    const ConstWayPtr &b, int indexA, int indexB);
+    const ConstWayPtr& b, int indexA, int indexB);
 
   /**
    * Determines the start of the way location in way a. The way location will start in the line
    * segment specified by index.
    * @param index The index of the first node in the line segment to look at.
    */
-  WayLocation _calculateStartWayLocation(const ConstOsmMapPtr &map, const ConstWayPtr& a,
-    const ConstWayPtr &b, int indexA, int indexB);
+  WayLocation _calculateStartWayLocation(const ConstOsmMapPtr& map, const ConstWayPtr& a,
+    const ConstWayPtr& b, int indexA, int indexB);
 
-  void _calculateSublineScores(const ConstOsmMapPtr &map, const ConstWayPtr& w1,
-    const ConstWayPtr &w2, Sparse2dMatrix &scores);
+  void _calculateSublineScores(const ConstOsmMapPtr& map, const ConstWayPtr& w1,
+    const ConstWayPtr& w2, Sparse2dMatrix &scores);
 
   std::vector<std::pair<WayLocation, WayLocation>> _discretizePointPairs(const ConstOsmMapPtr &map,
     const ConstWayPtr& w1, const ConstWayPtr& w2, std::vector<WaySublineMatch> &rawSublineMatches);
 
-  std::vector<WaySublineMatch> _extractAllMatches(const ConstOsmMapPtr &map, const ConstWayPtr& w1,
-    const ConstWayPtr &w2, Sparse2dMatrix &sublineMatrix);
+  std::vector<WaySublineMatch> _extractAllMatches(const ConstOsmMapPtr& map, const ConstWayPtr& w1,
+    const ConstWayPtr& w2, Sparse2dMatrix& sublineMatrix);
 
-  std::vector<WaySublineMatch> _findBestMatches(const ConstOsmMapPtr &map, const ConstWayPtr& w1,
-    const ConstWayPtr &w2, Sparse2dMatrix &sublineMatrix, double &bestScore);
+  std::vector<WaySublineMatch> _findBestMatches(const ConstOsmMapPtr& map, const ConstWayPtr& w1,
+    const ConstWayPtr& w2, Sparse2dMatrix& sublineMatrix, double& bestScore);
 
-  double _findBestMatchesRecursive(std::vector<WaySublineMatch>& candidates, std::vector<bool>& keepers,
-    size_t offset);
+  double _findBestMatchesRecursive(std::vector<WaySublineMatch>& candidates,
+                                   std::vector<bool>& keepers, size_t offset);
 
   /**
    * Find the ends of all the subline matches.
@@ -251,7 +260,6 @@ private:
                                   const std::vector<WaySublineMatch>& rawSublineMatches,
                                   const std::vector<std::pair<WayLocation, WayLocation>>& pairs,
                                   cv::Mat& m, std::vector<int>& starts, std::vector<int>& ends);
-
 };
 
 }
Clone this wiki locally