Skip to content

v0.2.49..v0.2.50 changeset RdpWayGeneralizer.h

Garret Voltz edited this page Nov 6, 2019 · 1 revision
diff --git a/hoot-core/src/main/cpp/hoot/core/algorithms/RdpWayGeneralizer.h b/hoot-core/src/main/cpp/hoot/core/algorithms/RdpWayGeneralizer.h
index 7ad2be8..99e403c 100644
--- a/hoot-core/src/main/cpp/hoot/core/algorithms/RdpWayGeneralizer.h
+++ b/hoot-core/src/main/cpp/hoot/core/algorithms/RdpWayGeneralizer.h
@@ -29,7 +29,7 @@
 #define RDP_WAY_GENERALIZER_H
 
 // Hoot
-#include <hoot/core/elements/ConstOsmMapConsumer.h>
+#include <hoot/core/elements/OsmMapConsumer.h>
 #include <hoot/core/elements/OsmMap.h>
 
 // Qt
@@ -69,7 +69,7 @@ class Way;
  * would have to have been generated for the points kept in the reduction, while deleting the old
  * ones.  That isn't desirable from a runtime performance standpoint.
  */
-class RdpWayGeneralizer : public ConstOsmMapConsumer
+class RdpWayGeneralizer : public OsmMapConsumer
 {
 
 public:
@@ -80,8 +80,9 @@ public:
     Generalizes a way to a set of reduced points.  The map the way belongs to is modified.
 
     @param way the way whose points are to be reduced
+    @return the number of nodes removed
     */
-  void generalize(const std::shared_ptr<Way>& way);
+  int generalize(const std::shared_ptr<Way>& way);
 
   /**
     Sets the distance parameter that determines to what degree the way is generalized; higher
@@ -89,15 +90,24 @@ public:
     */
   void setEpsilon(double epsilon);
 
-  virtual void setOsmMap(const OsmMap* map) { _map = map->shared_from_this(); }
+  void setRemoveNodesSharedByWays(bool remove) { _removeNodesSharedByWays = remove; }
+
+  virtual void setOsmMap(OsmMap* map) { _map = map->shared_from_this(); }
 
 private:
 
   friend class RdpWayGeneralizerTest;
 
+  // distance in meters that determines to what degree a way is generalized; higher values result in
+  // more generalization (more nodes removed).
   double _epsilon;
 
-  ConstOsmMapPtr _map;
+  // If true, the any node shared by ways will not be removed by generalization. Its arguable that
+  // this shouldn't be an option and shared nodes should never be removed, but leaving it optional
+  // for now in case there is a use case where they should be removed.
+  bool _removeNodesSharedByWays;
+
+  OsmMapPtr _map;
 
   /*
     Generates a set of points that make up a generalized set of the input points
@@ -122,6 +132,17 @@ private:
     const std::shared_ptr<const Node> splitPoint,
     const std::shared_ptr<const Node> lineToBeReducedStartPoint,
     const std::shared_ptr<const Node> lineToBeReducedEndPoint) const;
+
+  /*
+   * Takes in the way node IDs before the way was generalized and after it was generalized and
+   * constructs a final set of node IDs with the IDs that aren't allowed to be removed added back
+   * in (shared node IDs). This is necessary because it was too difficult to inject the logic to
+   * keep shared nodes into the recursive generalization function, so we run the logic after the
+   * generalization instead.
+   */
+  QList<long> _getUpdatedWayNodeIdsForThoseNotAllowedToBeRemoved(
+    const QSet<long>& nodeIdsNotAllowedToBeRemoved, const QList<long>& nodeIdsBeforeGeneralization,
+    const QList<long>& generalizedNodeIds);
 };
 
 }
Clone this wiki locally