Skip to content
Snippets Groups Projects
Commit bcaae337 authored by Joseph Mirabel's avatar Joseph Mirabel Committed by Joseph Mirabel
Browse files

Add Roadmap::nearestNode.

parent 67406dd1
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
# include <hpp/core/constraint-set.hh> # include <hpp/core/constraint-set.hh>
# include "hpp/manipulation/fwd.hh" # include "hpp/manipulation/fwd.hh"
# include "hpp/manipulation/graph/fwd.hh"
# include "hpp/manipulation/graph/statistics.hh" # include "hpp/manipulation/graph/statistics.hh"
namespace hpp { namespace hpp {
...@@ -54,6 +55,13 @@ namespace hpp { ...@@ -54,6 +55,13 @@ namespace hpp {
/// Catch event 'New node added' /// Catch event 'New node added'
void push_node (const core::NodePtr_t& n); void push_node (const core::NodePtr_t& n);
/// Get the nearest neighbor in a given graph::Node and in a given
/// core::ConnectedComponent.
core::NodePtr_t nearestNode (const ConfigurationPtr_t& configuration,
const ConnectedComponentPtr_t& connectedComponent,
const graph::NodePtr_t& node,
value_type& minDistance) const;
protected: protected:
/// Register a new configuration. /// Register a new configuration.
void statInsert (const core::NodePtr_t& n); void statInsert (const core::NodePtr_t& n);
...@@ -66,6 +74,7 @@ namespace hpp { ...@@ -66,6 +74,7 @@ namespace hpp {
/// Keep track of the leaf that are explored. /// Keep track of the leaf that are explored.
/// There should be one histogram per foliation. /// There should be one histogram per foliation.
Histograms histograms_; Histograms histograms_;
graph::GraphPtr_t graph_;
}; };
/// \} /// \}
} // namespace manipulation } // namespace manipulation
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "hpp/manipulation/roadmap.hh" #include "hpp/manipulation/roadmap.hh"
#include <hpp/util/pointer.hh> #include <hpp/util/pointer.hh>
#include <hpp/core/connected-component.hh>
namespace hpp { namespace hpp {
namespace manipulation { namespace manipulation {
...@@ -65,6 +66,7 @@ namespace hpp { ...@@ -65,6 +66,7 @@ namespace hpp {
void Roadmap::constraintGraph (const graph::GraphPtr_t& graph) void Roadmap::constraintGraph (const graph::GraphPtr_t& graph)
{ {
graph_ = graph;
Histograms::iterator it = histograms_.begin(); Histograms::iterator it = histograms_.begin();
for (; it != histograms_.end();) { for (; it != histograms_.end();) {
if (HPP_DYNAMIC_PTR_CAST (graph::NodeHistogram, *it)) if (HPP_DYNAMIC_PTR_CAST (graph::NodeHistogram, *it))
...@@ -74,5 +76,27 @@ namespace hpp { ...@@ -74,5 +76,27 @@ namespace hpp {
} }
insertHistogram (graph::HistogramPtr_t (new graph::NodeHistogram (graph))); insertHistogram (graph::HistogramPtr_t (new graph::NodeHistogram (graph)));
} }
core::NodePtr_t Roadmap::nearestNode (const ConfigurationPtr_t& configuration,
const ConnectedComponentPtr_t& connectedComponent,
const graph::NodePtr_t& node,
value_type& minDistance) const
{
core::NodePtr_t result = NULL;
minDistance = std::numeric_limits <value_type>::infinity ();
for (core::Nodes_t::const_iterator itNode =
connectedComponent->nodes ().begin ();
itNode != connectedComponent->nodes ().end (); ++itNode) {
if (graph_->getNode (*(*itNode)->configuration ()) != node)
continue;
value_type d = (*distance()) (*(*itNode)->configuration (),
*configuration);
if (d < minDistance) {
minDistance = d;
result = *itNode;
}
}
return result;
}
} // namespace manipulation } // namespace manipulation
} // namespace hpp } // namespace hpp
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