From 413a0f9f814280ea208bbe881f71fdf413dabb74 Mon Sep 17 00:00:00 2001 From: Joseph Mirabel <jmirabel@laas.fr> Date: Fri, 11 Jul 2014 16:40:21 +0200 Subject: [PATCH] Update Class graph::Graph and graph::NodeSelector --- include/hpp/manipulation/graph/graph.hh | 33 ++++++++++++++++++- .../hpp/manipulation/graph/node-selector.hh | 20 +++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/include/hpp/manipulation/graph/graph.hh b/include/hpp/manipulation/graph/graph.hh index f601313a..1233156f 100644 --- a/include/hpp/manipulation/graph/graph.hh +++ b/include/hpp/manipulation/graph/graph.hh @@ -36,19 +36,50 @@ namespace hpp { class HPP_MANIPULATION_DLLAPI Graph { public: + /// Create a new Graph. + static GraphPtr_t create() + { + Graph* ptr = new Graph; + GraphPtr_t shPtr (ptr); + ptr->init (shPtr); + return shPtr; + } + + /// Create and insert a NodeSelector inside the graph. + NodeSelectorPtr_t createNodeSelector() + { + NodeSelectorPtr_t newNodeSelector = NodeSelector::create(); + nodeSelectors_.push_back(newNodeSelector); + return newNodeSelector; + } + /// Returns the states of a configuration. virtual Nodes_t getNode(const Configuration_t config) const; /// Select randomly outgoing edges of the given nodes. virtual Edges_t chooseEdge(const Nodes_t& node) const; + protected: + /// Initialization of the object. + void init (const GraphWkPtr_t& weak) + { + wkPtr_ = weak; + } + + /// Constructor + Graph () + {} + private: /// This list contains a node selector for each end-effector. - set::list < NodeSelectorPtr_t > nodeSelectors_; + std::vector < NodeSelectorPtr_t > nodeSelectors_; /// A set of constraints that will always be used, for example /// stability constraints. ConstraintPtr_t constraints_; + + /// Weak pointer to itself. + GraphWkPtr_t wkPtr_; }; // Class Graph } // namespace graph } // namespace manipulation diff --git a/include/hpp/manipulation/graph/node-selector.hh b/include/hpp/manipulation/graph/node-selector.hh index 581b7a45..d6708dcf 100644 --- a/include/hpp/manipulation/graph/node-selector.hh +++ b/include/hpp/manipulation/graph/node-selector.hh @@ -28,6 +28,15 @@ namespace hpp { class HPP_MANIPULATION_DLLAPI NodeSelector { public: + /// Create a new NodeSelector. + static NodeSelectorPtr_t create() + { + NodeSelector* ptr = new NodeSelector(); + NodeSelectorPtr_t shPtr (ptr); + ptr->init (shPtr); + return shPtr; + } + /// Create a nodes with the constraints NodePtr_t createNode (const ConstraintPtr_t& constraints) { @@ -42,6 +51,17 @@ namespace hpp { /// Select randomly an outgoing edge of the given node. virtual EdgePtr_t chooseEdge(const NodePtr_t& node) const; + protected: + /// Initialization of the object. + void init (const GraphWkPtr_t& weak) + { + wkPtr_ = weak; + } + + /// Constructor + NodeSelector () + {} + private: /// List of the states of one end-effector, ordered by priority. std::vector< NodePtr_t > orderedStates_; -- GitLab