hpp-constraints  4.9.1
Definition of basic geometric constraints for motion planning
differentiable-function-set.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2016 CNRS
3 // Authors: Joseph Mirabel
4 //
5 // This file is part of hpp-constraints.
6 // hpp-constraints is free software: you can redistribute it
7 // and/or modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation, either version
9 // 3 of the License, or (at your option) any later version.
10 //
11 // hpp-constraints is distributed in the hope that it will be
12 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Lesser Public License for more details. You should have
15 // received a copy of the GNU Lesser General Public License along with
16 // hpp-constraints. If not, see
17 // <http://www.gnu.org/licenses/>.
18 
19 #ifndef HPP_CONSTRAINTS_DIFFERENTIABLE_FUNCTION_SET_HH
20 # define HPP_CONSTRAINTS_DIFFERENTIABLE_FUNCTION_SET_HH
21 
22 # include <hpp/constraints/fwd.hh>
24 
25 namespace hpp {
26  namespace constraints {
29 
33  class HPP_CONSTRAINTS_DLLAPI DifferentiableFunctionSet :
35  {
36  public:
37  typedef std::vector<DifferentiableFunctionPtr_t> Functions_t;
38 
42  static DifferentiableFunctionSetPtr_t create (const std::string& name)
43  {
45  (new DifferentiableFunctionSet(name));
46  }
47 
49 
52 
54  const Functions_t& functions () const
55  {
56  return functions_;
57  }
58 
59  void add (const DifferentiableFunctionPtr_t& func)
60  {
61  if (functions_.empty()) {
62  inputSize_ = func->inputSize();
63  inputDerivativeSize_ = func->inputDerivativeSize();
64  activeParameters_ = func->activeParameters();
65  activeDerivativeParameters_ = func->activeDerivativeParameters();
66  } else {
67  assert (inputSize_ == func->inputSize());
68  assert (inputDerivativeSize_ == func->inputDerivativeSize());
69 
70  activeParameters_ =
71  activeParameters_ || func->activeParameters();
72  activeDerivativeParameters_ =
73  activeDerivativeParameters_ || func->activeDerivativeParameters();
74  }
75  functions_.push_back(func);
76  result_.push_back (LiegroupElement (func->outputSpace ()));
77  *outputSpace_ *= func->outputSpace ();
78  }
79 
82  {
83  const Functions_t& functions = other->functions();
84  for (Functions_t::const_iterator _f = functions.begin();
85  _f != functions.end(); ++_f)
86  add (*_f);
87  }
88 
90 
91  std::ostream& print (std::ostream& os) const;
92 
96  DifferentiableFunctionSet (const std::string& name)
97  : DifferentiableFunction (0, 0, 0, name)
98  {}
99 
101  : DifferentiableFunction (0, 0, 0, "Stack")
102  {}
103 
104  protected:
106  const
107  {
108  size_type row = 0;
109  std::size_t i = 0;
110  for (Functions_t::const_iterator _f = functions_.begin();
111  _f != functions_.end(); ++_f) {
112  const DifferentiableFunction& f = **_f;
113  f.impl_compute(result_ [i], arg);
114  result.vector ().segment(row, f.outputSize()) =
115  result_ [i].vector ();
116  row += f.outputSize(); ++i;
117  }
118  }
119  void impl_jacobian (matrixOut_t jacobian, ConfigurationIn_t arg) const
120  {
121  size_type row = 0;
122  for (Functions_t::const_iterator _f = functions_.begin();
123  _f != functions_.end(); ++_f) {
124  const DifferentiableFunction& f = **_f;
125  f.impl_jacobian(jacobian.middleRows(row, f.outputDerivativeSize()), arg);
126  row += f.outputDerivativeSize();
127  }
128  }
129  private:
130  Functions_t functions_;
131  mutable std::vector <LiegroupElement> result_;
132  }; // class DifferentiableFunctionSet
134  } // namespace constraints
135 } // namespace hpp
136 
137 #endif // HPP_CONSTRAINTS_DIFFERENTIABLE_FUNCTION_SET_HH
const vector_type & vector() const
DifferentiableFunctionSet()
Definition: differentiable-function-set.hh:100
size_type outputDerivativeSize() const
Get dimension of output derivative vector.
Definition: differentiable-function.hh:125
virtual void impl_compute(LiegroupElementRef result, vectorIn_t argument) const =0
User implementation of function evaluation.
size_type outputSize() const
Get dimension of output vector.
Definition: differentiable-function.hh:120
void impl_jacobian(matrixOut_t jacobian, ConfigurationIn_t arg) const
Definition: differentiable-function-set.hh:119
Definition: differentiable-function-set.hh:33
DifferentiableFunctionSet(const std::string &name)
Definition: differentiable-function-set.hh:96
static DifferentiableFunctionSetPtr_t create(const std::string &name)
Definition: differentiable-function-set.hh:42
pinocchio::ConfigurationIn_t ConfigurationIn_t
Definition: fwd.hh:88
assert(d.lhs()._blocks()==d.rhs()._blocks())
virtual ~DifferentiableFunctionSet()
Definition: differentiable-function-set.hh:48
Definition: differentiable-function.hh:50
boost::shared_ptr< DifferentiableFunction > DifferentiableFunctionPtr_t
Definition: fwd.hh:95
void add(const DifferentiableFunctionPtr_t &func)
Definition: differentiable-function-set.hh:59
pinocchio::size_type size_type
Definition: fwd.hh:35
Eigen::Ref< matrix_t > matrixOut_t
Definition: fwd.hh:44
virtual void impl_jacobian(matrixOut_t jacobian, vectorIn_t arg) const =0
std::vector< DifferentiableFunctionPtr_t > Functions_t
Definition: differentiable-function-set.hh:37
const Functions_t & functions() const
Get the stack of functions.
Definition: differentiable-function-set.hh:54
void impl_compute(LiegroupElementRef result, ConfigurationIn_t arg) const
Definition: differentiable-function-set.hh:105
boost::shared_ptr< DifferentiableFunctionSet > DifferentiableFunctionSetPtr_t
Definition: fwd.hh:97
void merge(const DifferentiableFunctionSetPtr_t &other)
The output columns selection of other is not taken into account.
Definition: differentiable-function-set.hh:81