Go to the documentation of this file.
9 extern template class R<0>;
11 extern template class R<1>;
13 extern template class R<2>;
15 extern template class R<3>;
17 extern template class R<6>;
19 extern template class R<Eigen::Dynamic>;
26 template <
class _QualifiedState>
29 StateHandle<R<_QualifiedState::DimensionAtCompileTime>, _QualifiedState>
32 static constexpr
int DimensionAtCompileTime
33 = _QualifiedState::DimensionAtCompileTime;
37 using typename statespace::
38 StateHandle<R<DimensionAtCompileTime>, _QualifiedState>::State;
39 using typename statespace::
40 StateHandle<R<DimensionAtCompileTime>, _QualifiedState>
::StateSpace;
41 using typename statespace::
42 StateHandle<R<DimensionAtCompileTime>, _QualifiedState>::QualifiedState;
45 std::is_const<QualifiedState>::value,
70 return this->getStateSpace()->getValue(this->getState());
78 return this->getStateSpace()->setValue(this->getState(), _value);
87 N >= 0 || N == Eigen::Dynamic,
88 "Invalid dimension. The dimension should be non-negative.");
90 if (N == Eigen::Dynamic)
92 std::stringstream msg;
93 msg <<
"Invalid template parameter. Either pass a non-negative dimension "
94 <<
"as the template parameter (e.g., R<3>()).";
95 throw std::invalid_argument(msg.str());
101 R<N>::R(
int dimension) : mDimension(dimension)
104 N >= 0 || N == Eigen::Dynamic,
105 "Invalid dimension. The dimension should be non-negative.");
107 if (N != Eigen::Dynamic && N != dimension)
109 std::stringstream msg;
110 msg <<
"Invalid dimension argument. Either pass Eigen::Dynamic as the "
111 <<
"template parameter (e.g., Rn(3)) or pass the same dimension with "
112 <<
"the template parameter as the constructor parameter "
113 <<
"(e.g., R<3>(3)).";
114 throw std::invalid_argument(msg.str());
129 auto newState = createState();
130 copyState(stateIn, newState);
140 =
reinterpret_cast<double*
>(
reinterpret_cast<unsigned char*
>(_state));
142 return Eigen::Map<VectorNd>(valueBuffer, getDimension());
149 auto valueBuffer =
reinterpret_cast<const double*
>(
150 reinterpret_cast<const unsigned char*
>(_state));
152 return Eigen::Map<const VectorNd>(valueBuffer, getDimension());
160 if (
static_cast<std::size_t
>(_value.size()) != getDimension())
162 std::stringstream msg;
163 msg <<
"Value has incorrect size: expected " << getDimension() <<
", got "
164 << _value.size() <<
".";
165 throw std::invalid_argument(msg.str());
168 getMutableValue(_state) = _value;
175 return getDimension() *
sizeof(double);
182 auto state =
reinterpret_cast<State*
>(_buffer);
183 getMutableValue(state).setZero();
202 if (_state1 == _out || _state2 == _out)
203 throw std::invalid_argument(
"Output aliases input.");
205 auto state1 =
static_cast<const State*
>(_state1);
206 auto state2 =
static_cast<const State*
>(_state2);
207 auto out =
static_cast<State*
>(_out);
209 setValue(out, getValue(state1) + getValue(state2));
216 if (N == Eigen::Dynamic)
226 auto out =
static_cast<State*
>(_out);
228 setValue(out, VectorNd::Zero(getDimension()));
238 throw std::invalid_argument(
"Output aliases input.");
240 auto in =
static_cast<const State*
>(_in);
241 auto out =
static_cast<State*
>(_out);
243 setValue(out, -getValue(in));
251 auto destination =
static_cast<State*
>(_destination);
252 auto source =
static_cast<const State*
>(_source);
253 setValue(destination, getValue(source));
262 if (
static_cast<std::size_t
>(_tangent.size()) != getDimension())
264 std::stringstream msg;
265 msg <<
"Tangent vector has incorrect size: expected " << getDimension()
266 <<
", got " << _tangent.size() <<
".";
267 throw std::invalid_argument(msg.str());
270 auto out =
static_cast<State*
>(_out);
271 setValue(out, _tangent);
278 if (
static_cast<std::size_t
>(_tangent.size()) != getDimension())
279 _tangent.resize(getDimension());
281 auto in =
static_cast<const State*
>(_in);
282 _tangent = getValue(in);
289 auto val = getValue(
static_cast<const State*
>(_state));
291 Eigen::IOFormat cleanFmt(3, Eigen::DontAlignCols,
",",
",",
"",
"",
"[",
"]");
292 _os << val.format(cleanFmt);
void freeStateInBuffer(StateSpace::State *_state) const override
Free a state previously created by allocateStateInBuffer.
Definition: Rn-impl.hpp:189
ScopedState createState() const
Helper function to create a ScopedState.
Definition: Rn-impl.hpp:120
typename R< DimensionAtCompileTime >::VectorNd VectorNd
Definition: Rn-impl.hpp:35
Format of serialized trajectory in YAML.
Definition: algorithm.hpp:4
Eigen::Map< const VectorNd > getValue()
Gets the real vector stored in this state.
Definition: Rn-impl.hpp:68
StateSpace::State * allocateStateInBuffer(void *_buffer) const override
Create a new state in a pre-allocated buffer.
Definition: Rn-impl.hpp:180
Eigen::Map< VectorNd > getMutableValue(State *_state) const
Gets the mutable value stored in a Rn::State.
Definition: Rn-impl.hpp:137
Eigen::Map< const VectorNd > getValue(const State *_state) const
Gets the real vector stored in a State.
Definition: Rn-impl.hpp:147
void print(const StateSpace::State *_state, std::ostream &_os) const override
Print the n-dimensional vector represented by the state Format: [x_1, x_2, ..., x_n].
Definition: Rn-impl.hpp:287
void logMap(const StateSpace::State *_in, Eigen::VectorXd &_tangent) const override
Log mapping of Lie group element to a Lie algebra element.
Definition: Rn-impl.hpp:276
void compose(const StateSpace::State *_state1, const StateSpace::State *_state2, StateSpace::State *_out) const override
Lie group operation for this StateSpace.
Definition: Rn-impl.hpp:196
void getIdentity(StateSpace::State *_out) const override
Gets the identity element for this Lie group, such that:
Definition: Rn-impl.hpp:224
std::conditional< std::is_const< QualifiedState >::value, const VectorNd, VectorNd > ValueType
Definition: Rn-impl.hpp:47
RStateHandle(const StateSpace *_space, QualifiedState *_state)
Construct a handle for _state in _space.
Definition: Rn-impl.hpp:59
Wrap a State with its StateSpace to provide convenient accessor methods.
Definition: StateHandle.hpp:16
R()
Constructs a N dimensional real vector space only when the dimension is can be known in compile time.
Definition: Rn-impl.hpp:84
Represents a Lie group and its associated Lie algebra, i.e.
Definition: StateSpace.hpp:33
RStateHandle()
Construct and initialize to nullptr.
Definition: Rn-impl.hpp:50
void copyState(const StateSpace::State *_source, StateSpace::State *_destination) const override
Copy a state.
Definition: Rn-impl.hpp:248
std::size_t getDimension() const override
Get the dimension of this Lie group.
Definition: Rn-impl.hpp:214
ScopedState cloneState(const StateSpace::State *stateIn) const
Creates an identical clone of stateIn.
Definition: Rn-impl.hpp:127
void setValue(const VectorNd &_value)
Sets the real vector stored in this state.
Definition: Rn-impl.hpp:76
Point in a R<N>.
Definition: Rn.hpp:22
void getInverse(const StateSpace::State *_in, StateSpace::State *_out) const override
Gets the inverse of _in in this Lie group, such that:
Definition: Rn-impl.hpp:233
Definition: StateSpace.hpp:167
void expMap(const Eigen::VectorXd &_tangent, StateSpace::State *_out) const override
Exponential mapping of Lie algebra element to a Lie group element.
Definition: Rn-impl.hpp:258
std::size_t getStateSizeInBytes() const override
Gets the size of a State, in bytes.
Definition: Rn-impl.hpp:173
StateHandle for a Rn.
Definition: Rn-impl.hpp:27
Eigen::Matrix< double, N, 1 > VectorNd
Definition: Rn.hpp:37
void setValue(State *_state, const VectorNd &_value) const
Sets the real vector stored in a State.
Definition: Rn-impl.hpp:157