Follow this link to skip to the main content

claraty::Vector< T > Class Template Reference

#include <vector.h>

List of all members.

Public Member Functions

 Vector (Vector_Orientation o=ROW_VECTOR)
 Vector (int size, Vector_Orientation o=ROW_VECTOR)
template<class In>
 Vector (int size, In start, Vector_Orientation o=ROW_VECTOR)
 Vector (int size, const T &filler, Vector_Orientation o=ROW_VECTOR)
 Vector (const N_2D_Array< T > &rhs, Vector_Orientation o=ROW_VECTOR)
 Vector (N_2D_Array< T > &rhs, Vector_Orientation o=ROW_VECTOR)
 Vector (const Vector< T > &rhs)
 Vector (const std::vector< T > &rhs)
 Vector (const Point< T > &pt)
Vector_Orientation get_orientation () const
void set_orientation (Vector_Orientation o)
Vector transpose () const
 operator Point () const
 Vector (const vnl_vector< T > &rhs)
 operator vnl_vector_ref ()
Vectoroperator= (const T &rhs)
Vectoroperator= (const Vector< T > &rhs)
Vector< T > operator== (const Vector< T > &rhs)
void resize (int sz)
void resize (int newNumRows, int newNumCols)
dot (const Vector &v) const
magnitude () const
Vector< T > cross (const Vector< T > &v) const
T & operator() (int c)
const T & operator() (int c) const
 operator void * () const
int get_size () const
int ncols () const
int get_num_of_cols () const
int nrows () const
int get_num_of_rows () const
bool is_square () const
Vectoroperator+= (const T &rhs)
Vectoroperator-= (const T &rhs)
Vectoroperator *= (const T &rhs)
Vectoroperator/= (const T &rhs)
Vectoroperator+= (const Vector &rhs)
Vectoroperator-= (const Vector &rhs)
sum_of_squares () const
Vector abs () const
average () const
sum () const
min_value (int *min_index=NULL) const
max_value (int *max_index=NULL) const

Private Member Functions

template<class Op>
Vectorscalar_apply (Op op, const T &rhs)
template<class Pred>
pick_extreme (int *extreme_index, Pred pred) const

Private Attributes

Vector_Orientation orientation


Detailed Description

template<class T>
class claraty::Vector< T >

Definition at line 63 of file vector.h.


Constructor & Destructor Documentation

template<class T>
claraty::Vector< T >::Vector ( Vector_Orientation  o = ROW_VECTOR  )  [inline]

Definition at line 70 of file vector.h.

00071     : std::vector<T>(), orientation(o) { }

template<class T>
claraty::Vector< T >::Vector ( int  size,
Vector_Orientation  o = ROW_VECTOR 
) [inline]

Definition at line 73 of file vector.h.

00074     : std::vector<T>(size), orientation(o) { }

template<class T>
template<class In>
claraty::Vector< T >::Vector ( int  size,
In  start,
Vector_Orientation  o = ROW_VECTOR 
) [inline]

Definition at line 77 of file vector.h.

00078     : std::vector<T>(size), orientation(o) {
00079     for (int i = 0; i < size; ++i, ++start)
00080       (*this)[i] = *start;
00081   }

template<class T>
claraty::Vector< T >::Vector ( int  size,
const T &  filler,
Vector_Orientation  o = ROW_VECTOR 
) [inline]

Definition at line 83 of file vector.h.

00084     : std::vector<T>(size, filler), orientation(o) { }

template<class T>
claraty::Vector< T >::Vector ( const N_2D_Array< T > &  rhs,
Vector_Orientation  o = ROW_VECTOR 
) [inline]

Definition at line 86 of file vector.h.

00087     : std::vector<T>(rhs.begin(), rhs.end()), orientation(o) { }

template<class T>
claraty::Vector< T >::Vector ( N_2D_Array< T > &  rhs,
Vector_Orientation  o = ROW_VECTOR 
) [inline]

Definition at line 89 of file vector.h.

00090     : std::vector<T>(rhs.begin(), rhs.end()), orientation(o) { }

template<class T>
claraty::Vector< T >::Vector ( const Vector< T > &  rhs  )  [inline]

Definition at line 93 of file vector.h.

00094     : std::vector<T>(rhs), orientation(rhs.orientation) { }

template<class T>
claraty::Vector< T >::Vector ( const std::vector< T > &  rhs  )  [inline]

Definition at line 96 of file vector.h.

00097     : std::vector<T>(rhs), orientation(ROW_VECTOR) { }

template<class T>
claraty::Vector< T >::Vector ( const Point< T > &  pt  )  [inline]

Definition at line 99 of file vector.h.

00099                              : std::vector<T>(3), orientation(ROW_VECTOR) {
00100     (*this)[0] = pt.x();
00101     (*this)[1] = pt.y();
00102     (*this)[2] = pt.z();
00103   }

template<class T>
claraty::Vector< T >::Vector ( const vnl_vector< T > &  rhs  )  [inline]

Definition at line 129 of file vector.h.

00130     : std::vector<T>(rhs.begin(), rhs.end()), orientation(ROW_VECTOR) { }


Member Function Documentation

template<class T>
void claraty::Vector< T >::set_orientation ( Vector_Orientation  o  )  [inline]

template<class T>
Vector claraty::Vector< T >::transpose (  )  const [inline]

Definition at line 108 of file vector.h.

00108                            {
00109     Vector ret(*this);
00110     ret.set_orientation(orientation == ROW_VECTOR ? COL_VECTOR : ROW_VECTOR);
00111     return ret;
00112   }

template<class T>
claraty::Vector< T >::operator Point< T > (  )  const

Definition at line 312 of file vector.h.

00313 {
00314   Point<T> ret;
00315   size_t n = this->size();
00316 
00317   switch (n) {
00318   case 1:
00319     return Point<T>((*this)(0));
00320   case 2:
00321     return Point<T>((*this)(0), (*this)(1));
00322   case 3:
00323     return Point<T>((*this)(0), (*this)(1), (*this)(2));
00324   default:
00325     std::cerr << "vector error: cannot convert vector of size " << n
00326          << " to a Point object" << std::endl;
00327     return ret;
00328   }
00329 }

template<class T>
claraty::Vector< T >::operator vnl_vector_ref (  )  [inline]

Definition at line 135 of file vector.h.

00135 { return vnl_vector_ref<T>(this->size(), this->begin()); }

template<class T>
Vector& claraty::Vector< T >::operator= ( const T &  rhs  )  [inline]

Definition at line 138 of file vector.h.

00138                                   {
00139     std::fill(this->begin(), this->end(), rhs);
00140     return *this;
00141   }

template<class T>
Vector& claraty::Vector< T >::operator= ( const Vector< T > &  rhs  )  [inline]

Definition at line 143 of file vector.h.

00143                                           {
00144     if (this == &rhs)
00145       return *this;
00146     std::vector<T>::operator=(rhs);
00147     orientation = rhs.orientation;
00148     return *this;
00149   }

template<class T>
Vector<T> claraty::Vector< T >::operator== ( const Vector< T > &  rhs  )  [inline]

Definition at line 151 of file vector.h.

00151                                              {
00152     Vector<T> ret(rhs.size());
00153     std::transform(this->begin(), this->end(), rhs.begin(), ret.begin(),
00154                    std::equal_to<T>());
00155     return ret;
00156   }

template<class T>
void claraty::Vector< T >::resize ( int  sz  )  [inline]

Definition at line 158 of file vector.h.

Referenced by claraty::io_object(), and claraty::ME_Joint::ME_Joint().

00158                       {  // retain the current orientation
00159     std::vector<T>::resize(sz);
00160   }

template<class T>
void claraty::Vector< T >::resize ( int  newNumRows,
int  newNumCols 
) [inline]

Definition at line 162 of file vector.h.

00162                                               { // inherited
00163     if (newNumRows != 0 && newNumCols != 0 &&
00164         newNumRows != 1 && newNumCols != 1)
00165       // throw exception!
00166       std::cerr << "Illegal to resize a vector to be a matrix!" << std::endl;
00167     else {
00168       int length = newNumRows;
00169       orientation = COL_VECTOR;
00170       if (newNumCols != 1) {
00171         length = newNumCols;
00172         orientation = ROW_VECTOR;
00173       }
00174       std::vector<T>::resize(length);
00175     }
00176   }

template<class T>
T claraty::Vector< T >::dot ( const Vector< T > &  v  )  const

Definition at line 282 of file vector.h.

Referenced by claraty::Wheel_Locomotor_Model::map_mechanism_model_to_wheel_locomotor_model(), claraty::operator *(), claraty::Quaternion< T >::Quaternion(), and claraty::Vector< int >::sum_of_squares().

00283 {
00284   return std::inner_product(this->begin(), this->end(), v.begin(), T(0));
00285 }

template<class T>
T claraty::Vector< T >::magnitude (  )  const

Definition at line 288 of file vector.h.

Referenced by claraty::Wheel_Locomotor_Model::map_mechanism_model_to_wheel_locomotor_model(), claraty::norm(), and claraty::Quaternion< T >::Quaternion().

00289 {
00290   T mag_sq = 0.0;
00291   const size_t sz = this->size();
00292   for (size_t i = 0; i < sz; i++)
00293     mag_sq += (*this)[i] * (*this)[i];
00294   return T(sqrt(mag_sq));
00295 }

template<class T>
Vector< T > claraty::Vector< T >::cross ( const Vector< T > &  v  )  const

Definition at line 298 of file vector.h.

References claraty::Vector< T >::orientation, and claraty::Vector< T >::set_orientation().

Referenced by claraty::Quaternion< T >::Quaternion().

00299 {
00300   Vector<T> v(3);
00301   assert(this->size() == 3 && rhs.size() == 3);
00302   v[0] = (*this)[1] * rhs[2] - (*this)[2] * rhs[1];
00303   v[1] = (*this)[2] * rhs[0] - (*this)[0] * rhs[2];
00304   v[2] = (*this)[0] * rhs[1] - (*this)[1] * rhs[0];
00305   v.set_orientation(orientation);
00306   return v;
00307 }

Here is the call graph for this function:

template<class T>
T& claraty::Vector< T >::operator() ( int  c  )  [inline]

Definition at line 187 of file vector.h.

00187 { return (*this)[c]; }

template<class T>
const T& claraty::Vector< T >::operator() ( int  c  )  const [inline]

Definition at line 188 of file vector.h.

00188 { return (*this)[c]; }

template<class T>
claraty::Vector< T >::operator void * (  )  const

Definition at line 357 of file vector.h.

00358 {
00359   // Bool operator but using void * instead to avoid direct conversion to int
00360   // so when you type 3*array, you do not get 3, rather you get a compile error
00361 
00362   for (typename Vector<T>::const_iterator it = this->begin();
00363        it != this->end(); ++it)
00364     if (*it == 0)
00365       return (void *)false;
00366   return (void *)true;
00367 }

template<class T>
int claraty::Vector< T >::ncols (  )  const [inline]

template<class T>
int claraty::Vector< T >::get_num_of_cols (  )  const [inline]

Definition at line 195 of file vector.h.

Referenced by claraty::cross(), claraty::Unit_Vector< T >::set(), and claraty::sum().

00195 { return this->ncols(); }

template<class T>
int claraty::Vector< T >::nrows (  )  const [inline]

template<class T>
int claraty::Vector< T >::get_num_of_rows (  )  const [inline]

Definition at line 197 of file vector.h.

00197 { return this->nrows(); }

template<class T>
bool claraty::Vector< T >::is_square (  )  const [inline]

Definition at line 198 of file vector.h.

00198 { return this->get_size() == 1; }

template<class T>
Vector& claraty::Vector< T >::operator+= ( const T &  rhs  )  [inline]

Definition at line 201 of file vector.h.

00201                                    {
00202     return scalar_apply(std::plus<T>(), rhs);
00203   }

template<class T>
Vector& claraty::Vector< T >::operator-= ( const T &  rhs  )  [inline]

Definition at line 204 of file vector.h.

00204                                    {
00205     return scalar_apply(std::minus<T>(), rhs);
00206   }

template<class T>
Vector& claraty::Vector< T >::operator *= ( const T &  rhs  )  [inline]

Definition at line 207 of file vector.h.

00207                                    {
00208     return scalar_apply(std::multiplies<T>(), rhs);
00209   }

template<class T>
Vector& claraty::Vector< T >::operator/= ( const T &  rhs  )  [inline]

Definition at line 210 of file vector.h.

00210                                    {
00211     return scalar_apply(std::divides<T>(), rhs);
00212   }

template<class T>
Vector& claraty::Vector< T >::operator+= ( const Vector< T > &  rhs  )  [inline]

Definition at line 214 of file vector.h.

00214                                         {
00215     if (this->size() != rhs.size())
00216       std::cerr << "Unmatching vector sizes in vector addition" << std::endl;
00217     if (orientation != rhs.get_orientation())
00218       std::cerr << "Vector orientations don't match in vector addition"
00219                 << std::endl;
00220     std::transform(this->begin(), this->end(), rhs.begin(), this->begin(),
00221                    std::plus<T>());
00222     return *this;
00223   }

template<class T>
Vector& claraty::Vector< T >::operator-= ( const Vector< T > &  rhs  )  [inline]

Definition at line 224 of file vector.h.

00224                                         {
00225     if (this->size() != rhs.size())
00226       std::cerr << "Unmatching vector sizes in vector subtraction"
00227                 << std::endl;
00228     if (orientation != rhs.get_orientation())
00229       std::cerr << "Vector orientations don't match in vector subtraction"
00230                 << std::endl;
00231     std::transform(this->begin(), this->end(), rhs.begin(), this->begin(),
00232                    std::minus<T>());
00233     return *this;
00234   }

template<class T>
T claraty::Vector< T >::sum_of_squares (  )  const [inline]

Definition at line 236 of file vector.h.

00236 { return dot(*this); }

template<class T>
Vector claraty::Vector< T >::abs (  )  const [inline]

Definition at line 238 of file vector.h.

00238                      {
00239     Vector<T> ret(this->size());
00240     std::transform(this->begin(), this->end(), ret.begin(), cl_abs_op<T>());
00241     return ret;
00242   }

template<class T>
T claraty::Vector< T >::average (  )  const [inline]

Definition at line 243 of file vector.h.

00243 { return this->sum() / this->size(); }

template<class T>
T claraty::Vector< T >::sum (  )  const [inline]

Definition at line 244 of file vector.h.

Referenced by claraty::Vector< int >::average().

00244 { return std::accumulate(this->begin(), this->end(), T(0)); }

template<class T>
T claraty::Vector< T >::min_value ( int *  min_index = NULL  )  const [inline]

Definition at line 248 of file vector.h.

00248                                          {
00249     return pick_extreme(min_index, std::less<T>());
00250   }

template<class T>
T claraty::Vector< T >::max_value ( int *  max_index = NULL  )  const [inline]

Definition at line 251 of file vector.h.

00251                                          {
00252     return pick_extreme(max_index, std::greater<T>());
00253   }

template<class T>
template<class Op>
Vector& claraty::Vector< T >::scalar_apply ( Op  op,
const T &  rhs 
) [inline, private]

Definition at line 256 of file vector.h.

Referenced by claraty::Vector< int >::operator *=(), claraty::Vector< int >::operator+=(), claraty::Vector< int >::operator-=(), and claraty::Vector< int >::operator/=().

00256                                             {
00257     std::transform(this->begin(), this->end(), this->begin(),
00258                    bind2nd(op, rhs));
00259     return *this;
00260   }

template<class T>
template<class Pred>
T claraty::Vector< T >::pick_extreme ( int *  extreme_index,
Pred  pred 
) const [inline, private]

Definition at line 263 of file vector.h.

Referenced by claraty::Vector< int >::max_value(), and claraty::Vector< int >::min_value().

00263                                                       {
00264     if (this->size() == 0)
00265       return T(0);
00266     
00267     int best_index_placeholder = 0;
00268     int *best_ndx =
00269       extreme_index != NULL ? extreme_index : &best_index_placeholder;
00270     T best_value = (*this)[0];
00271     *best_ndx = 0;
00272     for (int i = 1; i < get_size(); i++)
00273       if (pred((*this)[i], best_value)) {
00274         best_value = (*this)[i];
00275         *best_ndx = i;
00276       }
00277     return best_value;
00278   }


Member Data Documentation


The documentation for this class was generated from the following file: