Skip to content

Commit

Permalink
more consistent and general asVector(); delete file added by mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed May 12, 2021
1 parent f6820ba commit 2466be8
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 24 deletions.
Empty file removed doc/source/doxygen_objdb_11356.tmp
Empty file.
20 changes: 14 additions & 6 deletions libs/math/include/mrpt/math/TPoint2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,23 @@ struct TPoint2D_ : public TPoseOrPoint,
}
}

/**
* Transformation into vector.
/** Gets the pose as a vector of doubles.
* \tparam Vector It can be std::vector<double>, Eigen::VectorXd, etc.
*/
template <typename U>
void asVector(std::vector<U>& v) const
template <typename Vector>
void asVector(Vector& v) const
{
v.resize(2);
v[0] = static_cast<U>(this->x);
v[1] = static_cast<U>(this->y);
v[0] = TPoint2D_data<T>::x;
v[1] = TPoint2D_data<T>::y;
}
/// \overload
template <typename Vector>
Vector asVector() const
{
Vector v;
asVector(v);
return v;
}

bool operator<(const TPoint2D_& p) const;
Expand Down
17 changes: 13 additions & 4 deletions libs/math/include/mrpt/math/TPoint3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,26 @@ struct TPoint3D_ : public TPoseOrPoint,
TPoint3D_data<T>::z *= f;
return *this;
}
/**
* Transformation into vector.
/** Gets the pose as a vector of doubles.
* \tparam Vector It can be std::vector<double>, Eigen::VectorXd, etc.
*/
template <class VECTORLIKE>
void asVector(VECTORLIKE& v) const
template <typename Vector>
void asVector(Vector& v) const
{
v.resize(3);
v[0] = TPoint3D_data<T>::x;
v[1] = TPoint3D_data<T>::y;
v[2] = TPoint3D_data<T>::z;
}
/// \overload
template <typename Vector>
Vector asVector() const
{
Vector v;
asVector(v);
return v;
}

/**
* Translation.
*/
Expand Down
16 changes: 13 additions & 3 deletions libs/math/include/mrpt/math/TPose2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,26 @@ struct TPose2D : public TPoseOrPoint,
default: throw std::out_of_range("index out of range");
}
}
/**
* Transformation into vector.
/** Gets the pose as a vector of doubles.
* \tparam Vector It can be std::vector<double>, Eigen::VectorXd, etc.
*/
void asVector(std::vector<double>& v) const
template <typename Vector>
void asVector(Vector& v) const
{
v.resize(3);
v[0] = x;
v[1] = y;
v[2] = phi;
}
/// \overload
template <typename Vector>
Vector asVector() const
{
Vector v;
asVector(v);
return v;
}

/** Returns a human-readable textual representation of the object (eg: "[x y
* yaw]", yaw in degrees)
* \sa fromString
Expand Down
16 changes: 13 additions & 3 deletions libs/math/include/mrpt/math/TPose3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ struct TPose3D : public TPoseOrPoint,
* Pose's spatial coordinates norm.
*/
double norm() const { return std::sqrt(square(x) + square(y) + square(z)); }
/**
* Gets the pose as a vector of doubles.
/** Gets the pose as a vector of doubles.
* \tparam Vector It can be std::vector<double>, Eigen::VectorXd, etc.
*/
void asVector(std::vector<double>& v) const
template <typename Vector>
void asVector(Vector& v) const
{
v.resize(6);
v[0] = x;
Expand All @@ -120,6 +121,15 @@ struct TPose3D : public TPoseOrPoint,
v[4] = pitch;
v[5] = roll;
}
/// \overload
template <typename Vector>
Vector asVector() const
{
Vector v;
asVector(v);
return v;
}

/** Returns a human-readable textual representation of the object (eg: "[x y
* z yaw pitch roll]", angles in degrees.)
* \sa fromString
Expand Down
16 changes: 14 additions & 2 deletions libs/math/include/mrpt/math/TTwist2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,26 @@ struct TTwist2D : public internal::ProvideStaticResize<TTwist2D>
default: throw std::out_of_range("index out of range");
}
}
/** Transformation into vector */
void asVector(std::vector<double>& v) const
/** Gets the twist as a vector of doubles.
* \tparam Vector It can be std::vector<double>, Eigen::VectorXd, etc.
*/
template <typename Vector>
void asVector(Vector& v) const
{
v.resize(3);
v[0] = vx;
v[1] = vy;
v[2] = omega;
}
/// \overload
template <typename Vector>
Vector asVector() const
{
Vector v;
asVector(v);
return v;
}

/** Transform the (vx,vy) components for a counterclockwise rotation of
* `ang` radians. */
void rotate(const double ang);
Expand Down
15 changes: 9 additions & 6 deletions libs/math/include/mrpt/math/TTwist3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,21 @@ struct TTwist3D : public internal::ProvideStaticResize<TTwist3D>
wz *= k;
}

/** Transformation into vector [vx vy vz wx wy wz] */
template <typename VECTORLIKE>
void asVector(VECTORLIKE& v) const
/** Transformation into vector [vx vy vz wx wy wz].
* \tparam Vector It can be std::vector<double>, Eigen::VectorXd, etc.
*/
template <typename Vector>
void asVector(Vector& v) const
{
v.resize(6);
for (int i = 0; i < 6; i++)
v[i] = (*this)[i];
}
template <typename VECTORLIKE>
VECTORLIKE asVector() const
/// \overload
template <typename Vector>
Vector asVector() const
{
VECTORLIKE v;
Vector v;
asVector(v);
return v;
}
Expand Down

0 comments on commit 2466be8

Please sign in to comment.