From ecfaff1b30de4e92c9ed8c8b27e891ccd316f961 Mon Sep 17 00:00:00 2001
From: Joseph Mirabel <jmirabel@laas.fr>
Date: Thu, 7 Jan 2016 11:02:26 +0100
Subject: [PATCH] Clear instead of clone histograms when clearing the roadmap

---
 include/hpp/manipulation/graph/statistics.hh | 6 ++++++
 src/roadmap.cc                               | 8 +++-----
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/include/hpp/manipulation/graph/statistics.hh b/include/hpp/manipulation/graph/statistics.hh
index ed93750a..934e9def 100644
--- a/include/hpp/manipulation/graph/statistics.hh
+++ b/include/hpp/manipulation/graph/statistics.hh
@@ -98,6 +98,8 @@ namespace hpp {
           virtual void add (const RoadmapNodePtr_t& node) = 0;
 
           virtual HistogramPtr_t clone () const = 0;
+
+          virtual void clear () = 0;
       };
 
       class HPP_MANIPULATION_DLLLOCAL LeafHistogram : public ::hpp::statistics::Statistics < LeafBin >
@@ -124,6 +126,8 @@ namespace hpp {
 
           statistics::DiscreteDistribution < RoadmapNodePtr_t > getDistrib () const;
 
+          void clear () { Parent::clear(); }
+
         private:
           /// The constraint that creates the foliation.
           ConstraintSetPtr_t constraint_;
@@ -151,6 +155,8 @@ namespace hpp {
 
           virtual HistogramPtr_t clone () const;
 
+          void clear () { Parent::clear(); }
+
         private:
           /// The constraint graph
           graph::GraphPtr_t graph_;
diff --git a/src/roadmap.cc b/src/roadmap.cc
index 7098d490..1fb44ec6 100644
--- a/src/roadmap.cc
+++ b/src/roadmap.cc
@@ -38,12 +38,10 @@ namespace hpp {
     void Roadmap::clear ()
     {
       Parent::clear ();
-      Histograms newHistograms;
-      Histograms::iterator it;
-      for (it = histograms_.begin(); it != histograms_.end(); ++it) {
-        newHistograms.push_back ((*it)->clone ());
+      for (Histograms::iterator it = histograms_.begin();
+          it != histograms_.end(); ++it) {
+        (*it)->clear ();
       }
-      histograms_ = newHistograms;
     }
 
     void Roadmap::push_node (const core::NodePtr_t& n)
-- 
GitLab