Ravelin
SVector6.h
1 /****************************************************************************
2  * Copyright 2013 Evan Drumwright
3  * This library is distributed under the terms of the Apache V2.0
4  * License (obtainable from http://www.apache.org/licenses/LICENSE-2.0).
5  ****************************************************************************/
6 
7 #ifndef SVECTOR6
8 #error This class is not to be included by the user directly. Use SForced.h, SForcef.h, SMomentumd.h, SMomentumf.h, SVelocityd.h, SVelocityf.h, SAcceld.h, or SAccelf.h instead.
9 #endif
10 
11 class POSE3;
12 class SFORCE;
13 class SVELOCITY;
14 class SACCEL;
15 class SMOMENTUM;
16 
18 
22 class SVECTOR6
23 {
24  public:
25  SVECTOR6();
26  SVECTOR6(boost::shared_ptr<const POSE3> pose);
27  SVECTOR6(boost::shared_ptr<POSE3> pose);
28  SVECTOR6(REAL x, REAL y, REAL z, REAL a, REAL b, REAL c);
29  SVECTOR6(REAL x, REAL y, REAL z, REAL a, REAL b, REAL c, boost::shared_ptr<const POSE3> pose);
30  SVECTOR6(REAL x, REAL y, REAL z, REAL a, REAL b, REAL c, boost::shared_ptr<POSE3> pose);
31  SVECTOR6(const REAL* array);
32  SVECTOR6(const REAL* array, boost::shared_ptr<const POSE3> pose);
33  SVECTOR6(const REAL* array, boost::shared_ptr<POSE3> pose);
34  SVECTOR6(const VECTOR3& upper, const VECTOR3& lower);
35  SVECTOR6(const VECTOR3& upper, const VECTOR3& lower, boost::shared_ptr<const POSE3> pose);
36  SVECTOR6(const VECTOR3& upper, const VECTOR3& lower, boost::shared_ptr<POSE3> pose);
37  unsigned size() const { return 6; }
38  static SVECTOR6 zero(boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>()) { return SVECTOR6(0,0,0,0,0,0, pose); }
39  static SVECTOR6 zero(boost::shared_ptr<POSE3> pose = boost::shared_ptr<POSE3>()) { return SVECTOR6(0,0,0,0,0,0, pose); }
40  SVECTOR6& set_zero() { std::fill_n(_data, 6, (REAL) 0.0); return *this; }
41  SVECTOR6& set_zero(boost::shared_ptr<const POSE3> pose) { std::fill_n(_data, 6, (REAL) 0.0); this->pose = pose; return *this; }
42  void set_lower(const VECTOR3& lower);
43  void set_upper(const VECTOR3& upper);
44  VECTOR3 get_lower() const;
45  VECTOR3 get_upper() const;
46  SVECTOR6& operator=(const SVECTOR6& source);
47  REAL& operator[](const unsigned i) { assert(i < 6); return _data[i]; }
48  const REAL& operator[](const unsigned i) const { assert(i < 6); return _data[i]; }
49  REAL* data() { return _data; }
50  const REAL* data() const { return _data; }
51  SVECTOR6 operator-() const;
52  SVECTOR6& operator/=(REAL scalar) { return operator*=((REAL) 1.0/scalar); }
53  SVECTOR6& operator*=(REAL scalar);
54  unsigned rows() const { return 6; }
55  unsigned columns() const { return 1; }
56  SVECTOR6& resize(unsigned rows, unsigned columns) { assert ((rows == 6 && columns == 1) || (columns == 1 && rows == 6)); return *this; }
57  SVECTOR6& resize(unsigned rows) { assert (rows == 6); return *this; }
58  COLUMN_ITERATOR begin() { return column_iterator_begin(); }
59  CONST_COLUMN_ITERATOR begin() const { return column_iterator_begin(); }
60  COLUMN_ITERATOR end() { return column_iterator_end(); }
61  CONST_COLUMN_ITERATOR end() const { return column_iterator_end(); }
70  SVECTOR6& negate() { std::transform(_data, _data+6, _data, std::negate<REAL>()); return *this; }
71  unsigned inc() const { return 1; }
72  unsigned leading_dim() const { return 6; }
73 
74  template <class V>
75  V& to_vector(V& v) const
76  {
77  const unsigned SPATIAL_DIM = 6;
78  v.resize(SPATIAL_DIM);
79  REAL* vdata = v.data();
80  CBLAS::copy(SPATIAL_DIM, _data, 1, vdata, inc());
81  return v;
82  }
83 
84 /*
85  template <class Vec>
86  static REAL dot(const SVECTOR6& v1, const Vec& v2)
87  {
88  const REAL* d1 = v1.data();
89  const REAL* d2 = v2.data();
90  return d1[3]+d2[0] + d1[4]+d2[1] + d1[5]+d2[2]+
91  d1[0]+d2[3] + d1[1]+d2[4] + d1[2]+d2[5];
92  }
93 */
94 
96  boost::shared_ptr<const POSE3> pose;
97 
98  template <class V>
99  static SVECTOR6 from_vector(const V& v, boost::shared_ptr<const POSE3> pose = boost::shared_ptr<const POSE3>())
100  {
101  const unsigned SPATIAL_DIM = 6;
102  if (v.size() != SPATIAL_DIM)
103  throw MissizeException();
104  SVECTOR6 s(pose);
105  REAL* sdata = s.data();
106  const REAL* vdata = v.data();
107  CBLAS::copy(SPATIAL_DIM, vdata, v.inc(), sdata, 1);
108  return s;
109  }
110 
111  protected:
112  REAL _data[6];
113 
114  public:
115 
116  template <class V>
117  SVECTOR6(const V& v)
118  {
119  const unsigned SPATIAL_DIM = 6;
120  #ifndef NEXCEPT
121  if (v.rows()*v.columns() != SPATIAL_DIM)
122  throw MissizeException();
123  #endif
124 
125  std::copy(v.column_iterator_begin(), v.column_iterator_end(), column_iterator_begin());
126  }
127 }; // end class
128 
129 inline std::ostream& operator<<(std::ostream& out, const SVECTOR6& v)
130 {
131  out << "Spatial vector (upper = " << v.get_upper() << ", lower= " << v.get_lower() << ") frame: " << v.pose;
132  return out;
133 }
134 
COLUMN_ITERATOR column_iterator_begin()
Gets an iterator to the beginning of the data.
Definition: SVector6.cpp:148
void set_lower(const VECTOR3 &lower)
Sets the lower 3-dimensional vector.
Definition: SVector6.cpp:241
A construct for iterating over a rectangular block of a matrix.
Definition: RowIterator.h:210
A spatial (six dimensional) momentum.
Definition: SMomentum.h:12
boost::shared_ptr< const POSE3 > pose
The frame that this vector is defined in.
Definition: SVector6.h:96
void set_upper(const VECTOR3 &upper)
Sets the upper 3-dimensional vector.
Definition: SVector6.cpp:249
VECTOR3 get_upper() const
Gets the upper 3-dimensional vector.
Definition: SVector6.cpp:235
ROW_ITERATOR row_iterator_begin()
Gets an iterator to the beginning of the data.
Definition: SVector6.cpp:202
SVECTOR6()
Constructs a zero vector.
Definition: SVector6.cpp:8
SVECTOR6 & operator=(const SVECTOR6 &source)
Copies this vector from another SVECTOR6.
Definition: SVector6.cpp:257
A spatial velocity (a twist)
Definition: SVelocity.h:15
SVECTOR6 & operator*=(REAL scalar)
Multiplies this vector by a scalar in place.
Definition: SVector6.cpp:270
A rigid body pose.
Definition: Pose3.h:15
A 6-dimensional floating-point vector for use with spatial algebra.
Definition: SVector6.h:22
A spatial (six dimensional) acceleration.
Definition: SAccel.h:14
VECTOR3 get_lower() const
Gets the lower 3-dimensional vector.
Definition: SVector6.cpp:229
A three-dimensional floating point vector used for representing points and vectors in 3D with associa...
Definition: Vector3.h:15
COLUMN_ITERATOR column_iterator_end()
Gets an iterator to the end of the data.
Definition: SVector6.cpp:161
A spatial force (a wrench)
Definition: SForce.h:14
A construct for iterating over a rectangular block of a matrix.
Definition: ColumnIterator.h:12
A construct for iterating over a rectangular block of a matrix.
Definition: ColumnIterator.h:215
A construct for iterating over a rectangular block of a matrix.
Definition: RowIterator.h:12
ROW_ITERATOR row_iterator_end()
Gets an iterator to the end of the data.
Definition: SVector6.cpp:215