Go to the documentation of this file.
26 #include <RobotAPI/interface/core/Trajectory.h>
33 #include <boost/multi_index_container.hpp>
34 #include <boost/multi_index/hashed_index.hpp>
35 #include <boost/multi_index/random_access_index.hpp>
36 #include <boost/multi_index/ordered_index.hpp>
37 #include <boost/multi_index/member.hpp>
83 using TrajMap = std::map<double, std::vector< DoubleSeqPtr > >;
93 data.resize(
s.data.size());
95 for (
auto& elem :
s.data)
97 data[i++].reset(
new Ice::DoubleSeq(*elem));
107 template<
class T =
double>
112 throw LocalException(
"Ptr to trajectory is NULL");
115 std::vector<T> result;
116 result.reserve(numDim);
117 for (std::size_t i = 0; i < numDim; ++i)
125 return getPositionsAs<double>();
136 throw LocalException(
"Ptr to trajectory is NULL");
139 for (std::size_t i = 0; i < numDim; ++i)
147 std::map<std::string, T> result;
153 double getDeriv(
size_t dim,
size_t derivation)
const;
154 const std::vector< DoubleSeqPtr >&
getData()
const;
159 for (
size_t d = 0; d < rhs.
data.size(); ++d)
161 stream << (rhs.
data[d] && rhs.
data[d]->size() > 0 ?
to_string(rhs.
data[d]->at(0)) : std::string(
"-"));
162 if (d <= rhs.
data.size() - 1)
171 mutable std::vector< DoubleSeqPtr >
data;
184 typedef boost::multi_index::multi_index_container <
186 boost::multi_index::indexed_by <
187 boost::multi_index::hashed_unique<boost::multi_index::tag<TagTimestamp>, boost::multi_index::member<TrajData, double, &TrajData::timestamp> >,
188 boost::multi_index::ordered_unique<boost::multi_index::tag<TagOrdered>, boost::multi_index::member<TrajData, double, &TrajData::timestamp> >
191 using timestamp_view =
typename boost::multi_index::index<TrajDataContainer, TagTimestamp>::type;
192 using ordered_view =
typename boost::multi_index::index<TrajDataContainer, TagOrdered>::type;
198 template <
typename T>
199 Trajectory(
const std::vector<T>&
data,
const Ice::DoubleSeq timestamps = Ice::DoubleSeq(),
const std::string& dimensionName =
"",
typename std::enable_if_t<std::is_arithmetic_v< T > >* t = 0)
201 if (
data.size() == 0)
205 Ice::DoubleSeq dvec(
data.begin(),
data.end());
216 template <
typename T>
217 Trajectory(
const std::vector<std::vector<T>>&
data,
const Ice::DoubleSeq timestamps = Ice::DoubleSeq(),
const Ice::StringSeq& dimensionNames = {})
219 if (
data.size() == 0)
225 for (
const auto& subvec :
data)
227 Ice::DoubleSeq dvec(subvec.begin(), subvec.end());
228 addDimension(dvec, tempTimestamps, i < dimensionNames.size() ? dimensionNames.at(i++) :
"");
234 template <
typename T>
235 Trajectory(
const std::vector<std::vector<std::vector<T> > >&
data,
const Ice::DoubleSeq timestamps = Ice::DoubleSeq(),
const Ice::StringSeq& dimensionNames = {})
237 this->dataVec =
data;
238 this->timestamps = timestamps;
239 this->dimensionNames = dimensionNames;
250 size_t addDimension(
const Ice::DoubleSeq&
values,
const Ice::DoubleSeq& timestamps = Ice::DoubleSeq(),
const std::string name =
"");
264 typename ordered_view::const_iterator
begin()
const;
265 typename ordered_view::const_iterator
end()
const;
266 typename ordered_view::const_reverse_iterator
rbegin()
const;
267 typename ordered_view::const_reverse_iterator
rend()
const;
270 std::vector<DoubleSeqPtr>&
operator[](
double timestamp);
273 std::vector<DoubleSeqPtr>&
getStates(
double t);
274 std::vector<DoubleSeqPtr>
getStates(
double t)
const;
275 Ice::DoubleSeq
getStates(
double t,
size_t derivation)
const;
277 std::map<std::string, T>
getStatesMap(
double t,
size_t derivation = 0)
const
279 std::map<std::string, T> result;
280 size_t dimensions =
dim();
282 for (
size_t dim = 0;
dim < dimensions;
dim++)
290 double getState(
double t,
size_t dim = 0,
size_t derivation = 0);
291 double getState(
double t,
size_t dim = 0,
size_t derivation = 0)
const;
292 std::vector<Ice::DoubleSeq >
getAllStates(
double t,
int maxDeriv = 1);
293 Ice::DoubleSeq
getDerivations(
double t,
size_t dimension,
size_t derivations)
const;
305 Ice::DoubleSeq
getDimensionData(
size_t dimension,
size_t derivation = 0)
const;
307 Eigen::VectorXd
getDimensionDataAsEigen(
size_t dimension,
size_t derivation,
double startTime,
double endTime)
const;
308 Eigen::MatrixXd
toEigen(
size_t derivation,
double startTime,
double endTime)
const;
309 Eigen::MatrixXd
toEigen(
size_t derivation = 0)
const;
331 double getLength(
size_t derivation = 0)
const;
332 double getLength(
size_t derivation,
double startTime,
double endTime)
const;
333 double getLength(
size_t dimension,
size_t derivation)
const;
334 double getLength(
size_t dimension,
size_t derivation,
double startTime,
double endTime)
const;
336 double getSquaredLength(
size_t dimension,
size_t derivation,
double startTime,
double endTime)
const;
337 double getMax(
size_t dimension,
size_t derivation,
double startTime,
double endTime)
const;
338 double getMin(
size_t dimension,
size_t derivation,
double startTime,
double endTime)
const;
339 double getWithFunc(
const double & (*foo)(
const double&,
const double&),
double initValue,
size_t dimension,
size_t derivation,
double startTime,
double endTime)
const;
340 double getAmplitude(
size_t dimension,
size_t derivation,
double startTime,
double endTime)
const;
350 Ice::DoubleSeq
getMinima(
size_t dimension,
size_t derivation,
double startTime,
double endTime)
const;
351 Ice::DoubleSeq
getMaxima(
size_t dimension,
size_t derivation,
double startTime,
double endTime)
const;
352 Ice::DoubleSeq
getMinimaTimestamps(
size_t dimension,
size_t derivation,
double startTime,
double endTime)
const;
353 Ice::DoubleSeq
getMaximaTimestamps(
size_t dimension,
size_t derivation,
double startTime,
double endTime)
const;
363 void reconstructFromDerivativeForDim(
double valueAtFirstTimestamp,
size_t trajDimension,
size_t sourceDimOfSystemState,
size_t targetDimOfSystemState);
381 static Ice::DoubleSeq
NormalizeTimestamps(
const Ice::DoubleSeq& timestamps,
const double startTime = 0.0,
const double endTime = 1.0);
382 static Ice::DoubleSeq
GenerateTimestamps(
double startTime = 0.0,
double endTime = 1.0,
double stepSize = 0.001);
383 template <
typename T>
391 void scaleValue(
const Ice::DoubleSeq& factor);
397 void clear(
bool keepMetaData =
false);
398 void setPositionEntry(
const double t,
const size_t dimIndex,
const double& y);
399 void setEntries(
const double t,
const size_t dimIndex,
const Ice::DoubleSeq& y);
400 bool dataExists(
double t,
size_t dimension = 0,
size_t derivation = 0)
const;
403 std::map<double, Ice::DoubleSeq>
getStatesAround(
double t,
size_t derivation,
size_t extend)
const;
411 void serialize(
const ObjectSerializerBasePtr& obj,
const Ice::Current& = Ice::emptyCurrent)
const override;
412 void deserialize(
const ObjectSerializerBasePtr&,
const Ice::Current& = Ice::emptyCurrent)
override;
415 VariantDataClassPtr
clone(
const Ice::Current&
c = Ice::emptyCurrent)
const override;
417 std::string
output(
const Ice::Current&
c = Ice::emptyCurrent)
const override;
419 bool validate(
const Ice::Current&
c = Ice::emptyCurrent)
override;
425 dimensionNames = dimNames;
428 void setLimitless(
const LimitlessStateSeq& limitlessStates);
434 double __interpolate(
typename ordered_view::const_iterator itMap,
size_t dimension,
size_t derivation)
const;
435 double __gaussianFilter(
double filterRadius,
typename ordered_view::iterator centerIt,
size_t trajNum,
size_t dim);
442 virtual double __interpolate(
double t, ordered_view::const_iterator itPrev, ordered_view::const_iterator itNext,
size_t dimension,
size_t derivation)
const;
443 double __interpolate(
double t,
size_t dimension,
size_t derivation)
const;
VariantDataClassPtr clone(const Ice::Current &c=Ice::emptyCurrent) const override
double getTimestamp() const
TrajectoryPtr cloneMetaData() const
static void CopyMetaData(const Trajectory &source, Trajectory &destination)
Ice::DoubleSeq getMinimaTimestamps(size_t dimension, size_t derivation, double startTime, double endTime) const
double getMin(size_t dimension, size_t derivation, double startTime, double endTime) const
void gaussianFilter(double filterRadius)
gaussianFilter smoothes the trajectory
void scaleValue(const Ice::DoubleSeq &factor)
Eigen::VectorXd getPositionsAsVectorXd() const
double getSquaredLength(size_t dimension, size_t derivation) const
void addDerivationsToDimension(size_t dimension, const double t, const Ice::DoubleSeq &derivs)
TrajectoryPtr normalize(const double startTime=0.0, const double endTime=1.0)
friend std::ostream & operator<<(std::ostream &stream, const TrajData &rhs)
std::vector< Ice::DoubleSeq > getAllStates(double t, int maxDeriv=1)
void setLimitless(const LimitlessStateSeq &limitlessStates)
std::map< std::string, T > getPositionsAsNameValueMap() const
void negateDim(size_t trajDimension)
negateDim changes the sign of all values of the given dimension.
void clear(bool keepMetaData=false)
typename boost::multi_index::index< TrajDataContainer, TagTimestamp >::type timestamp_view
Ice::ObjectPtr ice_clone() const override
TrajDataContainer & data()
static Ice::DoubleSeq GenerateTimestamps(double startTime=0.0, double endTime=1.0, double stepSize=0.001)
TrajData & operator=(const TrajData &s)
void __fillAllEmptyFields()
Ice::DoubleSeq getDiscreteDifferentiationForDim(size_t trajDimension, size_t derivation) const
std::map< double, Ice::DoubleSeq > getStatesAround(double t, size_t derivation, size_t extend) const
double getState(double t, size_t dim=0, size_t derivation=0)
ordered_view::const_reverse_iterator rbegin() const
double getDiscretDifferentiationForDimAtT(double t, size_t trajDimension, size_t derivation) const
size_t addDimension(const Ice::DoubleSeq &values, const Ice::DoubleSeq ×tamps=Ice::DoubleSeq(), const std::string name="")
ordered_view::const_iterator end() const
std::vector< DoubleSeqPtr > & operator[](double timestamp)
Eigen::VectorXd getDimensionDataAsEigen(size_t dimension, size_t derivation) const
std::map< double, std::vector< DoubleSeqPtr > > TrajMap
double getLength(size_t derivation=0) const
Returns the sum of a all subsequent distances of the entries in the trajectories over all dimensions.
std::vector< T > getPositionsAs() const
void writePositionsToNameValueMap(std::map< std::string, T > &map) const
ordered_view::const_reverse_iterator rend() const
TrajectoryPtr calculateTimeOptimalTrajectory(double maxVelocity, double maxAcceleration, double maxDeviation, IceUtil::Time const ×tep)
Ice::Int getType(const Ice::Current &c=Ice::emptyCurrent) const override
void ice_preMarshal() override
TrajectoryPtr getPart(double startTime, double endTime, size_t numberOfDerivations=0) const
TrajDataContainer dataMap
Trajectory(const std::vector< std::vector< std::vector< T > > > &data, const Ice::DoubleSeq timestamps=Ice::DoubleSeq(), const Ice::StringSeq &dimensionNames={})
double getMax(size_t dimension, size_t derivation, double startTime, double endTime) const
void shiftValue(const Ice::DoubleSeq &shift)
ordered_view::const_iterator begin() const
Iterators that iterates in incremental order of the timestamps through the trajectory.
void removeDerivation(size_t derivation)
void reconstructFromDerivativeForDim(double valueAtFirstTimestamp, size_t trajDimension, size_t sourceDimOfSystemState, size_t targetDimOfSystemState)
double __gaussianFilter(double filterRadius, typename ordered_view::iterator centerIt, size_t trajNum, size_t dim)
static Ice::DoubleSeq GenerateTimestamps(const std::vector< T > &values)
void ice_postUnmarshal() override
std::string output(const Ice::Current &c=Ice::emptyCurrent) const override
void differentiateDiscretly(size_t derivation)
Eigen::VectorXf getPositionsAsVectorXf() const
Ice::DoubleSeq getMinima(size_t dimension, size_t derivation, double startTime, double endTime) const
Calculate all minima.
std::string getDimensionName(size_t dim) const
void setDimensionNames(const Ice::StringSeq dimNames)
DoubleSeqPtr operator[](size_t dim) const
static Trajectory NormalizeTimestamps(const Trajectory &traj, const double startTime=0.0, const double endTime=1.0)
const Ice::StringSeq & getDimensionNames() const
void setEntries(const double t, const size_t dimIndex, const Ice::DoubleSeq &y)
std::vector< DoubleSeqPtr > __calcBaseDataAtTimestamp(const double &t) const
void differentiateDiscretlyForDim(size_t trajDimension, size_t derivation)
std::vector< DoubleSeqPtr > & getStates(double t)
typename boost::multi_index::index< TrajDataContainer, TagOrdered >::type ordered_view
std::map< std::string, T > getStatesMap(double t, size_t derivation=0) const
size_t size() const
Returns number of data entries (i.e.
Ice::DoubleSeq getDimensionData(size_t dimension, size_t derivation=0) const
getDimensionData gets all entries for one dimensions with order of increasing timestamps
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
void shiftTime(double shift)
armarx::core::time::DateTime Time
const std::string & to_string(const std::string &s)
void removeDimension(size_t dimension)
Ice::DoubleSeq getMaxima(size_t dimension, size_t derivation, double startTime, double endTime) const
void addPositionsToDimension(size_t dimension, const Ice::DoubleSeq &values, const Ice::DoubleSeq ×tamps)
double getDeriv(size_t dim, size_t derivation) const
Trajectory & operator+=(const Trajectory traj)
static Ice::DoubleSeq DifferentiateDiscretly(const Ice::DoubleSeq ×tamps, const Ice::DoubleSeq &values, int derivationCount=1)
timestamp_view::iterator __fillBaseDataAtTimestamp(const double &t)
Eigen::MatrixXd toEigen(size_t derivation, double startTime, double endTime) const
double getAmplitude(size_t dimension, size_t derivation, double startTime, double endTime) const
boost::multi_index::multi_index_container< TrajData, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< boost::multi_index::tag< TagTimestamp >, boost::multi_index::member< TrajData, double, &TrajData::timestamp > >, boost::multi_index::ordered_unique< boost::multi_index::tag< TagOrdered >, boost::multi_index::member< TrajData, double, &TrajData::timestamp > > > > TrajDataContainer
Trajectory(const std::vector< T > &data, const Ice::DoubleSeq timestamps=Ice::DoubleSeq(), const std::string &dimensionName="", typename std::enable_if_t< std::is_arithmetic_v< T > > *t=0)
Ice::FloatSeq getTimestampsFloat() const
The Trajectory class represents n-dimensional sampled trajectories.
std::vector< DoubleSeqPtr > data
Trajectory & operator=(const Trajectory &source)
std::vector< double > getPositions() const
std::shared_ptr< Object > ObjectPtr
bool validate(const Ice::Current &c=Ice::emptyCurrent) override
size_t dim() const
dim returns the trajectory dimension count for this trajectory (e.g.
void serialize(const ObjectSerializerBasePtr &obj, const Ice::Current &=Ice::emptyCurrent) const override
double getTimeLength() const
Difference between biggest and smallest timestamp.
bool dataExists(double t, size_t dimension=0, size_t derivation=0) const
Ice::DoubleSeq getTimestamps() const
double getWithFunc(const double &(*foo)(const double &, const double &), double initValue, size_t dimension, size_t derivation, double startTime, double endTime) const
static void CopyData(const Trajectory &source, Trajectory &destination)
Ice::DoubleSeq getMaximaTimestamps(size_t dimension, size_t derivation, double startTime, double endTime) const
double getPosition(size_t dim) const
double s(double t, double s0, double v0, double a0, double j)
double __interpolate(typename ordered_view::const_iterator itMap, size_t dimension, size_t derivation) const
Ice::DoubleSeq getDerivations(double t, size_t dimension, size_t derivations) const
This file offers overloads of toIce() and fromIce() functions for STL container types.
Trajectory(const std::vector< std::vector< T >> &data, const Ice::DoubleSeq timestamps=Ice::DoubleSeq(), const Ice::StringSeq &dimensionNames={})
Constructor to add n-dimensions with m-values.
static VariantTypeId addTypeName(const std::string &typeName)
Register a new type for the use in a Variant.
std::shared_ptr< Ice::DoubleSeq > DoubleSeqPtr
const std::vector< DoubleSeqPtr > & getData() const
void deserialize(const ObjectSerializerBasePtr &, const Ice::Current &=Ice::emptyCurrent) override
LimitlessStateSeq getLimitless() const
void setPositionEntry(const double t, const size_t dimIndex, const double &y)