9 #ifndef _CLASS_LINEAR_VARIABLE 10 #define _CLASS_LINEAR_VARIABLE 21 #include "serialization/archive.hpp" 22 #include "serialization/eigen-matrix.hpp" 25 template <
typename Numeric =
double,
bool Safe = true>
26 struct linear_variable :
public serialization::Serializable {
27 typedef Eigen::Matrix<Numeric, Eigen::Dynamic, 1>
vector_x_t;
28 typedef Eigen::Matrix<Numeric, Eigen::Dynamic, Eigen::Dynamic>
matrix_x_t;
42 : B_(
B), c_(
c), zero(false) {}
56 if (Safe &&
B().cols() != val.rows())
57 throw std::length_error(
58 "Cannot evaluate linear variable, variable value does not have the " 60 return B() * val +
c();
68 if (w1.
isZero())
return *
this;
74 if (Safe &&
B().rows() != w1.
B().rows())
75 throw std::length_error(
76 "Cannot add linear variables, variables do not have the same " 80 B_.block(0,
B().cols() - w1.
B().cols(),
B().rows(), w1.
B().cols()) +=
82 c_.tail(w1.
c().rows()) += w1.
c();
83 }
else if (
B().cols() <
101 if (w1.
isZero())
return *
this;
107 if (Safe &&
B().rows() != w1.
B().rows())
108 throw std::length_error(
109 "Cannot add linear variables, variables do not have the same " 111 else if (
B().cols() >
113 B_.block(0,
B().cols() - w1.
B().cols(),
B().rows(), w1.
B().cols()) -=
115 c_.tail(w1.
c().rows()) -= w1.
c();
116 }
else if (
B().cols() <
160 throw std::invalid_argument(
161 "Can't perform cross product on linear variables with dimensions != " 164 throw std::invalid_argument(
165 "Can't perform cross product on linear variables more than one " 168 if ((
B().squaredNorm() -
B().diagonal().squaredNorm() > MARGIN) ||
169 (other.
B().squaredNorm() - other.
B().diagonal().squaredNorm() > MARGIN))
170 throw std::invalid_argument(
171 "Can't perform cross product on linear variables if B is not " 200 vector_x_t::Zero(dim));
206 std::size_t
size()
const {
return zero ? 0 : std::max(B_.rows(), c_.size()); }
219 const double prec = Eigen::NumTraits<Numeric>::dummy_precision())
const {
220 return (*
this - other).norm() < prec;
230 template <
class Archive>
231 void serialize(Archive& ar,
const unsigned int version) {
235 ar& boost::serialization::make_nvp(
"B_", B_);
236 ar& boost::serialization::make_nvp(
"c_", c_);
237 ar& boost::serialization::make_nvp(
"zero", zero);
246 template <
typename N,
bool S>
253 template <
typename N,
bool S>
260 template <
typename N,
bool S>
265 template <
typename N,
bool S>
272 template <
typename N,
bool S>
279 template <
typename N,
bool S>
286 template <
typename BezierFixed,
typename BezierLinear,
typename X>
288 typename BezierFixed::t_point_t fixed_wps;
289 for (
typename BezierLinear::cit_point_t cit = bIn.waypoints().begin();
290 cit != bIn.waypoints().end(); ++cit)
291 fixed_wps.push_back(cit->operator()(x));
292 return BezierFixed(fixed_wps.begin(), fixed_wps.end(), bIn.T_min_,
296 template <
typename N,
bool S>
297 std::ostream& operator<<(std::ostream& os, const linear_variable<N, S>& l) {
298 return os <<
"linear_variable: \n \t B:\n" 299 << l.B() <<
"\t c: \n" 300 << l.c().transpose();
305 DEFINE_CLASS_TEMPLATE_VERSION(
306 SINGLE_ARG(
typename Numeric,
bool Safe),
308 #endif //_CLASS_LINEAR_VARIABLE std::size_t size() const
Get dimension of linear variable.
Definition: linear_variable.h:206
Eigen::Matrix< Numeric, 3, 1 > vector_3_t
Definition: linear_variable.h:29
Definition: bernstein.h:20
linear_variable(const vector_x_t &c)
Definition: linear_variable.h:37
linear_variable(const matrix_x_t &B, const vector_x_t &c)
Definition: linear_variable.h:41
Eigen::Matrix< Numeric, 3, 3 > matrix_3_t
Definition: linear_variable.h:30
const matrix_x_t & B() const
Definition: linear_variable.h:223
Eigen::Vector3d cross(const Eigen::VectorXd &a, const Eigen::VectorXd &b)
Definition: cross_implementation.h:14
static linear_variable_t X(size_t dim=0)
Get a linear variable equal to the variable.
Definition: linear_variable.h:198
bool isZero() const
Definition: linear_variable.h:225
BezierFixed evaluateLinear(const BezierLinear &bIn, const X x)
Definition: linear_variable.h:287
interface for a Curve of arbitrary dimension.
linear_variable_t & operator+=(const linear_variable_t &w1)
Add another linear variable.
Definition: linear_variable.h:67
bezier_curve< T, N, S, P > operator/(const bezier_curve< T, N, S, P > &p1, const double k)
Definition: bezier_curve.h:805
bool isApprox(const linear_variable_t &other, const double prec=Eigen::NumTraits< Numeric >::dummy_precision()) const
Check if actual linear variable and other are approximately equal given a precision treshold...
Definition: linear_variable.h:217
bezier_curve< T, N, S, P > operator+(const bezier_curve< T, N, S, P > &p1, const bezier_curve< T, N, S, P > &p2)
Definition: bezier_curve.h:748
Numeric norm() const
Get norm of linear variable (Norm of B plus norm of C).
Definition: linear_variable.h:210
static linear_variable_t Zero(size_t dim=0)
Get a linear variable equal to zero.
Definition: linear_variable.h:190
class allowing to create a Bezier curve of dimension 1 <= n <= 3.
const vector_x_t & c() const
Definition: linear_variable.h:224
bezier_curve< T, N, S, P > operator*(const bezier_curve< T, N, S, P > &p1, const double k)
Definition: bezier_curve.h:812
linear_variable_t & operator*=(const double d)
Multiply by a constant : p_i / d = B_i*x*d + c_i*d.
Definition: linear_variable.h:143
void serialize(Archive &ar, const unsigned int version)
Definition: linear_variable.h:231
vector_x_t operator()(const Eigen::Ref< const vector_x_t > &val) const
Linear evaluation for vector x.
Definition: linear_variable.h:54
friend class boost::serialization::access
Definition: linear_variable.h:228
linear_variable_t & operator-=(const linear_variable_t &w1)
Substract another linear variable.
Definition: linear_variable.h:100
linear_variable_t & operator/=(const double d)
Divide by a constant : p_i / d = B_i*x/d + c_i/d.
Definition: linear_variable.h:133
linear_variable(const linear_variable_t &other)
Definition: linear_variable.h:43
linear_variable()
Definition: linear_variable.h:33
double Numeric
Definition: effector_spline.h:26
linear_variable_t cross(const linear_variable_t &other) const
Compute the cross product of the current linear_variable and the other. This method of course only ma...
Definition: linear_variable.h:158
Eigen::Matrix< Numeric, Eigen::Dynamic, Eigen::Dynamic > matrix_x_t
Definition: linear_variable.h:28
linear_variable< Numeric > linear_variable_t
Definition: linear_variable.h:31
~linear_variable()
Definition: linear_variable.h:48
bezier_curve< T, N, S, P > operator-(const bezier_curve< T, N, S, P > &p1)
Definition: bezier_curve.h:755
Eigen::Matrix< Numeric, Eigen::Dynamic, 1 > vector_x_t
Definition: linear_variable.h:27
Matrix3 skew(const Point &x)
Definition: MathDefs.h:42