hpp-constraints  4.9.1
Definition of basic geometric constraints for motion planning
differentiable-function.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2014 CNRS
3 // Authors: Florent Lamiraux
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_HH
20 # define HPP_CONSTRAINTS_DIFFERENTIABLE_FUNCTION_HH
21 
22 # include <hpp/constraints/fwd.hh>
23 # include <hpp/constraints/config.hh>
25 
26 namespace hpp {
27  namespace constraints {
28 
31 
50  class HPP_CONSTRAINTS_DLLAPI DifferentiableFunction
51  {
52  public:
57  LiegroupElement operator () (vectorIn_t argument) const
58  {
59  assert (argument.size () == inputSize ());
60  LiegroupElement result (outputSpace_);
61  impl_compute (result, argument);
62  return result;
63  }
67  void value (LiegroupElementRef result,
68  vectorIn_t argument) const
69  {
70  assert (result.size () == outputSize ());
71  assert (argument.size () == inputSize ());
72  impl_compute (result, argument);
73  }
78  void jacobian (matrixOut_t jacobian, vectorIn_t argument) const
79  {
80  assert (argument.size () == inputSize ());
81  assert (jacobian.rows () == outputDerivativeSize ());
82  assert (jacobian.cols () == inputDerivativeSize ());
83  impl_jacobian (jacobian, argument);
84  }
85 
88  const ArrayXb& activeParameters () const
89  {
90  return activeParameters_;
91  }
92 
96  {
97  return activeDerivativeParameters_;
98  }
99 
102  {
103  return inputSize_;
104  }
111  {
112  return inputDerivativeSize_;
113  }
116  {
117  return outputSpace_;
118  }
121  {
122  return outputSpace_->nq ();
123  }
126  {
127  return outputSpace_->nv ();
128  }
132  const std::string& name () const
133  {
134  return name_;
135  }
136 
138  virtual std::ostream& print (std::ostream& o) const;
139 
140  std::string context () const {
141  return context_;
142  }
143 
144  void context (const std::string& c) {
145  context_ = c;
146  }
147 
157  void finiteDifferenceForward (matrixOut_t jacobian, vectorIn_t arg,
158  DevicePtr_t robot = DevicePtr_t (),
159  value_type eps = std::sqrt(Eigen::NumTraits<value_type>::epsilon())) const;
160 
170  void finiteDifferenceCentral (matrixOut_t jacobian, vectorIn_t arg,
171  DevicePtr_t robot = DevicePtr_t (),
172  value_type eps = std::sqrt(Eigen::NumTraits<value_type>::epsilon())) const;
173 
174  protected:
182  size_type sizeInputDerivative,
183  size_type sizeOutput,
184  std::string name = std::string ());
185 
193  size_type sizeInputDerivative,
194  const LiegroupSpacePtr_t& outputSpace,
195  std::string name = std::string ());
196 
198  virtual void impl_compute (LiegroupElementRef result,
199  vectorIn_t argument) const = 0;
200 
201  virtual void impl_jacobian (matrixOut_t jacobian,
202  vectorIn_t arg) const = 0;
203 
210 
219 
220  private:
221  std::string name_;
223  std::string context_;
224 
226  }; // class DifferentiableFunction
227  inline std::ostream&
228  operator<< (std::ostream& os, const DifferentiableFunction& f)
229  {
230  return f.print (os);
231  }
233  } // namespace constraints
234 } // namespace hpp
235 
236 
237 #endif // HPP_CONSTRAINTS_DIFFERENTIABLE_FUNCTION_HH
pinocchio::vectorIn_t vectorIn_t
Definition: fwd.hh:46
std::ostream & operator<<(std::ostream &os, const DifferentiableFunction &f)
Definition: differentiable-function.hh:228
ArrayXb activeParameters_
Definition: differentiable-function.hh:214
pinocchio::LiegroupSpacePtr_t LiegroupSpacePtr_t
Definition: fwd.hh:54
virtual std::ostream & print(std::ostream &o) const
Display object in a stream.
pinocchio::DevicePtr_t DevicePtr_t
Definition: fwd.hh:91
size_type outputDerivativeSize() const
Get dimension of output derivative vector.
Definition: differentiable-function.hh:125
size_type inputSize_
Dimension of input vector.
Definition: differentiable-function.hh:205
size_type inputDerivativeSize() const
Definition: differentiable-function.hh:110
LiegroupSpacePtr_t outputSpace_
Dimension of output vector.
Definition: differentiable-function.hh:209
size_type outputSize() const
Get dimension of output vector.
Definition: differentiable-function.hh:120
Vec3f c
pinocchio::ArrayXb ArrayXb
Definition: fwd.hh:65
Definition: differentiable-function-set.hh:33
size_type inputDerivativeSize_
Dimension of input derivative.
Definition: differentiable-function.hh:207
void value(LiegroupElementRef result, vectorIn_t argument) const
Definition: differentiable-function.hh:67
const std::string & name() const
Get function name.
Definition: differentiable-function.hh:132
assert(d.lhs()._blocks()==d.rhs()._blocks())
void jacobian(matrixOut_t jacobian, vectorIn_t argument) const
Definition: differentiable-function.hh:78
const ArrayXb & activeParameters() const
Definition: differentiable-function.hh:88
Definition: differentiable-function.hh:50
const ArrayXb & activeDerivativeParameters() const
Definition: differentiable-function.hh:95
void context(const std::string &c)
Definition: differentiable-function.hh:144
size_type inputSize() const
Get dimension of input vector.
Definition: differentiable-function.hh:101
std::string context() const
Definition: differentiable-function.hh:140
LiegroupSpacePtr_t outputSpace() const
Get output space.
Definition: differentiable-function.hh:115
pinocchio::size_type size_type
Definition: fwd.hh:35
Eigen::Ref< matrix_t > matrixOut_t
Definition: fwd.hh:44
pinocchio::value_type value_type
Definition: fwd.hh:36
virtual ~DifferentiableFunction()
Definition: differentiable-function.hh:53
ArrayXb activeDerivativeParameters_
Definition: differentiable-function.hh:218
Vec3f o