ocra-recipes
Doxygen documentation for the ocra-recipes repository
VariableMapping.cpp
Go to the documentation of this file.
2 #include "ocra/optim/Variable.h"
3 
4 namespace ocra
5 {
6  // ------------------------------------------------------------
7  // --- VARIABLE MAPPING ---------------------------------------
8  // ------------------------------------------------------------
9 
10  VariableMapping::VariableMapping(const Variable& relative, const Variable& base)
11  :_relative(relative), _base(base), _validated(false)
12  {
13  _base.connect<EVT_CHANGE_DEPENDENCIES>(*this, &VariableMapping::invalidate);
14  _base.connect<EVT_RESIZE>(*this, &VariableMapping::invalidate);
15  _relative.connect<EVT_CHANGE_DEPENDENCIES>(*this, &VariableMapping::invalidate);
16  _relative.connect<EVT_RESIZE>(*this, &VariableMapping::invalidate);
17  }
18 
20  {
21  _relative.disconnect<EVT_RESIZE>(*this, &VariableMapping::invalidate);
22  _relative.disconnect<EVT_CHANGE_DEPENDENCIES>(*this, &VariableMapping::invalidate);
23  _base.disconnect<EVT_RESIZE>(*this, &VariableMapping::invalidate);
24  _base.disconnect<EVT_CHANGE_DEPENDENCIES>(*this, &VariableMapping::invalidate);
25  }
26 
27  const std::vector<int>& VariableMapping::getMapping() const
28  {
29  if (!_validated)
30  updateMapping();
31  return _mapping;
32  }
33 
35  {
36  return _base;
37  }
38 
40  {
41  return _relative;
42  }
43 
44  void VariableMapping::updateMapping() const
45  {
46  _base.getRelativeMappingOf(_relative, _mapping);
47  _validated = true;
48  }
49 
50  void VariableMapping::invalidate(int)
51  {
52  _validated = false;
53  }
54 }
55 
56 
57 // cmake:sourcegroup=Solvers
void getRelativeMappingOf(const Variable &subVariable, std::vector< int > &mapping) const
Returns the indexes of a subvariable in the variable.
Definition: Variable.cpp:175
Optimization-based Robot Controller namespace. a library of classes to write and solve optimization p...
This class represents a variable in a mathematical sense.
Definition: Variable.h:105
const std::vector< int > & getMapping() const
const Variable & getRelativeVariable() const
const Variable & getBaseVariable() const
Declaration file of the Variable class.
VariableMapping(const Variable &relative, const Variable &base)
void disconnect(Derived &object, void(Base::*callbackToErase)(int)) const
Disconnect non-static method.
void connect(Derived &object, void(Base::*newCallback)(int)) const
Call this method to register a non-static method as a callback.
Declaration file of the VariableMapping class.