diff --git a/CMakeLists.txt b/CMakeLists.txt index 9333afddeff9f41ed237b485d3d90bf9c0cfc171..2872f7af6c35b20a3dcc5f3626d9bcca592a978b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,7 @@ SET (${PROJECT_NAME}_HEADERS include/hpp/manipulation/graph/edge.hh include/hpp/manipulation/graph/node-selector.hh include/hpp/manipulation/graph/graph.hh + include/hpp/manipulation/graph/graph-component.hh include/hpp/manipulation/graph/fwd.hh ) diff --git a/include/hpp/manipulation/graph/graph-component.hh b/include/hpp/manipulation/graph/graph-component.hh new file mode 100644 index 0000000000000000000000000000000000000000..00cf37fdab06d1940f8ee81249121cdd077ea1d2 --- /dev/null +++ b/include/hpp/manipulation/graph/graph-component.hh @@ -0,0 +1,102 @@ +// Copyright (c) 2014, LAAS-CNRS +// Authors: Joseph Mirabel (joseph.mirabel@laas.fr) +// +// This file is part of hpp-manipulation. +// hpp-manipulation is free software: you can redistribute it +// and/or modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation, either version +// 3 of the License, or (at your option) any later version. +// +// hpp-manipulation is distributed in the hope that it will be +// useful, but WITHOUT ANY WARRANTY; without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// hpp-manipulation. If not, see <http://www.gnu.org/licenses/>. + +#ifndef HPP_MANIPULATION_GRAPH_GRAPHCOMPONENT_HH +# define HPP_MANIPULATION_GRAPH_GRAPHCOMPONENT_HH + +# include <string> +# include <ostream> +# include <hpp/util/exception.hh> + +# include "hpp/manipulation/config.hh" +# include "hpp/manipulation/fwd.hh" +# include "hpp/manipulation/graph/fwd.hh" + +namespace hpp { + namespace manipulation { + namespace graph { + HPP_MAKE_EXCEPTION ( HPP_MANIPULATION_DLLAPI, Bad_function_call ); + + /// Define common methods of the graph components. + class HPP_MANIPULATION_DLLAPI GraphComponent + { + public: + /// Get the component name. + const std::string& name() const; + + /// Set the component name. + void name(const std::string& name); + + /// Get the component by its ID. The validity of the GraphComponent + /// is not checked. + static GraphComponentWkPtr_t get(int id); + + /// Return the component id. + int id () const; + + /// Print the object in a stream. + virtual std::ostream& print (std::ostream& os) const; + + /// Add core::DifferentiableFunction to the component. + virtual void addNumericalConstraint (const DifferentiableFunctionPtr_t& function); + + /// Add core::LockedDof constraint to the component. + virtual void addLockedDofConstraint (const LockedDofPtr_t& constraint); + + /// Get a reference to the DifferentiableFunctions_t + const DifferentiableFunctions_t& numericalConstraints() const; + + /// Get a reference to the LockedDofs_t + const LockedDofs_t& lockedDofConstraints () const; + + /// Set the parent graph. + void parentGraph(const GraphWkPtr_t& parent); + + protected: + /// Initialize the component + void init (const GraphComponentWkPtr_t& weak); + + GraphComponent() : id_(-1) + {} + + /// Stores the numerical constraints. + DifferentiableFunctions_t numericalConstraints_; + /// List of LockedDof constraints + LockedDofs_t lockedDofConstraints_; + /// A weak pointer to the parent graph. + GraphWkPtr_t graph_; + + private: + /// Keep track of the created components in order to retrieve them + /// easily. + static std::vector < GraphComponentWkPtr_t > components; + + /// Name of the component. + std::string name_; + /// Weak pointer to itself. + GraphComponentWkPtr_t wkPtr_; + /// ID of the component (index in components vector). + int id_; + }; + + std::ostream& operator<< (std::ostream& os, + const hpp::manipulation::graph::GraphComponent& graphComp); + } // namespace graph + } // namespace manipulation + +} // namespace hpp + +#endif // HPP_MANIPULATION_GRAPH_GRAPHCOMPONENT_HH diff --git a/include/hpp/manipulation/graph/graph.hh b/include/hpp/manipulation/graph/graph.hh index c934afde50a02f6688a8334eeb8a95a4199f9041..1ad69b756b1fa53512b52e86cbc1759117fc34ad 100644 --- a/include/hpp/manipulation/graph/graph.hh +++ b/include/hpp/manipulation/graph/graph.hh @@ -17,125 +17,14 @@ #ifndef HPP_MANIPULATION_GRAPH_GRAPH_HH # define HPP_MANIPULATION_GRAPH_GRAPH_HH -# include <string> -# include <ostream> -# include <hpp/util/assertion.hh> -# include <hpp/util/exception.hh> - -# include "hpp/manipulation/robot.hh" - # include "hpp/manipulation/config.hh" # include "hpp/manipulation/fwd.hh" # include "hpp/manipulation/graph/fwd.hh" +# include "hpp/manipulation/graph/graph-component.hh" namespace hpp { namespace manipulation { namespace graph { - HPP_MAKE_EXCEPTION ( HPP_MANIPULATION_DLLAPI, Bad_function_call ); - - /// Define common methods of the graph components. - class HPP_MANIPULATION_DLLAPI GraphComponent - { - public: - /// Get the component name. - const std::string& name() const - { - return name_; - } - - /// Set the component name. - void name(const std::string& name) - { - name_ = name; - } - - /// Get the component by its ID. The validity of the GraphComponent - /// is not checked. - static GraphComponentWkPtr_t get(int id) - throw (std::out_of_range) - { -# ifdef HPP_DEBUG - if (id < 0 || id >= (int)components.size()) - throw std::out_of_range ("ID out of range."); -# endif // HPP_DEBUG - return components[id]; - }; - - /// Return the component id. - int id () const - { - return id_; - } - - /// Print the object in a stream. - virtual std::ostream& print (std::ostream& os) const - { - os << id () << " : " << name (); - return os; - } - - /// Add core::DifferentiableFunction to the component. - virtual void addNumericalConstraint (const DifferentiableFunctionPtr_t& function) - { - numericalConstraints_.push_back(function); - } - - /// Add core::LockedDof constraint to the component. - virtual void addLockedDofConstraint (const LockedDofPtr_t& constraint) - { - lockedDofConstraints_.push_back (constraint); - } - - /// Get a reference to the DifferentiableFunctions_t - const DifferentiableFunctions_t& numericalConstraints() const - { - return numericalConstraints_; - } - - /// Get a reference to the LockedDofs_t - const LockedDofs_t& lockedDofConstraints () const - { - return lockedDofConstraints_; - } - - /// Set the parent graph. - void parentGraph(const GraphWkPtr_t& parent) - { - graph_ = parent; - } - - protected: - /// Initialize the component - void init (const GraphComponentWkPtr_t& weak) - { - wkPtr_ = weak; - id_ = components.size(); - components.push_back (wkPtr_); - } - - GraphComponent() : id_(-1) - {} - - /// Stores the numerical constraints. - DifferentiableFunctions_t numericalConstraints_; - /// List of LockedDof constraints - LockedDofs_t lockedDofConstraints_; - /// A weak pointer to the parent graph. - GraphWkPtr_t graph_; - - private: - /// Keep track of the created components in order to retrieve them - /// easily. - static std::vector < GraphComponentWkPtr_t > components; - - /// Name of the component. - std::string name_; - /// Weak pointer to itself. - GraphComponentWkPtr_t wkPtr_; - /// ID of the component (index in components vector). - int id_; - }; - /// Description of the constraint graph /// This class contains a graph representing a robot with several /// end-effectors. @@ -240,9 +129,6 @@ namespace hpp { } // namespace graph } // namespace manipulation - HPP_MANIPULATION_DLLAPI std::ostream& operator<< (std::ostream& os, - const hpp::manipulation::graph::GraphComponent& graphComp); - } // namespace hpp #endif // HPP_MANIPULATION_GRAPH_GRAPH_HH diff --git a/include/hpp/manipulation/graph/node.hh b/include/hpp/manipulation/graph/node.hh index a340fcdd06d6072cd4484db7578b85f527781dcd..32784f41da02d9666e68b480e2ca69b8ae01658e 100644 --- a/include/hpp/manipulation/graph/node.hh +++ b/include/hpp/manipulation/graph/node.hh @@ -22,9 +22,10 @@ #include <hpp/core/constraint-set.hh> #include <hpp/core/config-projector.hh> +#include "hpp/manipulation/config.hh" #include "hpp/manipulation/fwd.hh" #include "hpp/manipulation/graph/fwd.hh" -#include "hpp/manipulation/graph/edge.hh" +#include "hpp/manipulation/graph/graph-component.hh" namespace hpp { namespace manipulation { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 51e4b199ff10777a192ce2504bf365d5d6eeb285..88497963da0f9dd7ddbb8dd091c989294c9d55c7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,6 +29,7 @@ ADD_LIBRARY(${LIBRARY_NAME} SHARED graph/node.cc graph/edge.cc graph/graph.cc + graph/graph-component.cc graph/node-selector.cc ) diff --git a/src/graph/graph-component.cc b/src/graph/graph-component.cc new file mode 100644 index 0000000000000000000000000000000000000000..4094fdf981a6b2a727e4c0f9840a95469147274c --- /dev/null +++ b/src/graph/graph-component.cc @@ -0,0 +1,93 @@ +// Copyright (c) 2014, LAAS-CNRS +// Authors: Joseph Mirabel (joseph.mirabel@laas.fr) +// +// This file is part of hpp-manipulation. +// hpp-manipulation is free software: you can redistribute it +// and/or modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation, either version +// 3 of the License, or (at your option) any later version. +// +// hpp-manipulation is distributed in the hope that it will be +// useful, but WITHOUT ANY WARRANTY; without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// hpp-manipulation. If not, see <http://www.gnu.org/licenses/>. + +#include "hpp/manipulation/graph/graph-component.hh" + +namespace hpp { + namespace manipulation { + namespace graph { + std::vector < GraphComponentWkPtr_t > GraphComponent::components = std::vector < GraphComponentWkPtr_t >(); + + const std::string& GraphComponent::name() const + { + return name_; + } + + void GraphComponent::name(const std::string& name) + { + name_ = name; + } + + GraphComponentWkPtr_t GraphComponent::get(int id) + { +# ifdef HPP_DEBUG + if (id < 0 || id >= (int)components.size()) + throw std::out_of_range ("ID out of range."); +# endif // HPP_DEBUG + return components[id]; + } + + int GraphComponent::id () const + { + return id_; + } + + std::ostream& GraphComponent::print (std::ostream& os) const + { + os << id () << " : " << name (); + return os; + } + + void GraphComponent::addNumericalConstraint (const DifferentiableFunctionPtr_t& function) + { + numericalConstraints_.push_back(function); + } + + void GraphComponent::addLockedDofConstraint (const LockedDofPtr_t& constraint) + { + lockedDofConstraints_.push_back (constraint); + } + + const DifferentiableFunctions_t& GraphComponent::numericalConstraints() const + { + return numericalConstraints_; + } + + const LockedDofs_t& GraphComponent::lockedDofConstraints () const + { + return lockedDofConstraints_; + } + + void GraphComponent::parentGraph(const GraphWkPtr_t& parent) + { + graph_ = parent; + } + + void GraphComponent::init (const GraphComponentWkPtr_t& weak) + { + wkPtr_ = weak; + id_ = components.size(); + components.push_back (wkPtr_); + } + + std::ostream& operator<< (std::ostream& os, + const hpp::manipulation::graph::GraphComponent& graphComp) + { + return graphComp.print (os); + } + } // namespace graph + } // namespace manipulation +} // namespace hpp diff --git a/src/graph/graph.cc b/src/graph/graph.cc index 95bfa1b65acdcf527b15b7f9bbf7fbd2fda8c98b..570035e506579ec25a14ed45dfcb1e970512e344 100644 --- a/src/graph/graph.cc +++ b/src/graph/graph.cc @@ -16,15 +16,15 @@ #include <hpp/util/assertion.hh> +#include "hpp/manipulation/robot.hh" #include "hpp/manipulation/graph/node-selector.hh" #include "hpp/manipulation/graph/node.hh" +#include "hpp/manipulation/graph/edge.hh" #include "hpp/manipulation/graph/graph.hh" namespace hpp { namespace manipulation { namespace graph { - std::vector < GraphComponentWkPtr_t > GraphComponent::components = std::vector < GraphComponentWkPtr_t >(); - GraphPtr_t Graph::create(RobotPtr_t robot) { Graph* ptr = new Graph; @@ -147,10 +147,4 @@ namespace hpp { } // namespace graph } // namespace manipulation - std::ostream& operator<< (std::ostream& os, - const hpp::manipulation::graph::GraphComponent& graphComp) - { - return graphComp.print (os); - } - } // namespace hpp diff --git a/src/graph/node.cc b/src/graph/node.cc index 2b3c408313a752cde872fbee8b1f19593fe2e0fa..db99a00bd6e6d1446348e54001e2b0478abd70e2 100644 --- a/src/graph/node.cc +++ b/src/graph/node.cc @@ -14,6 +14,9 @@ // received a copy of the GNU Lesser General Public License along with // hpp-manipulation. If not, see <http://www.gnu.org/licenses/>. +#include "hpp/manipulation/robot.hh" +#include "hpp/manipulation/graph/edge.hh" +#include "hpp/manipulation/graph/graph.hh" #include "hpp/manipulation/graph/node.hh" namespace hpp {