claraty::Vector< T > Class Template Reference
#include <vector.h>
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 () | |
| Vector & | operator= (const T &rhs) |
| Vector & | operator= (const Vector< T > &rhs) |
| Vector< T > | operator== (const Vector< T > &rhs) |
| void | resize (int sz) |
| void | resize (int newNumRows, int newNumCols) |
| T | dot (const Vector &v) const |
| T | 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 |
| Vector & | operator+= (const T &rhs) |
| Vector & | operator-= (const T &rhs) |
| Vector & | operator *= (const T &rhs) |
| Vector & | operator/= (const T &rhs) |
| Vector & | operator+= (const Vector &rhs) |
| Vector & | operator-= (const Vector &rhs) |
| T | sum_of_squares () const |
| Vector | abs () const |
| T | average () const |
| T | sum () const |
| T | min_value (int *min_index=NULL) const |
| T | max_value (int *max_index=NULL) const |
Private Member Functions | |
| template<class Op> | |
| Vector & | scalar_apply (Op op, const T &rhs) |
| template<class Pred> | |
| T | 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
| claraty::Vector< T >::Vector | ( | Vector_Orientation | o = ROW_VECTOR |
) | [inline] |
| claraty::Vector< T >::Vector | ( | int | size, | |
| Vector_Orientation | o = ROW_VECTOR | |||
| ) | [inline] |
| 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 }
| claraty::Vector< T >::Vector | ( | int | size, | |
| const T & | filler, | |||
| Vector_Orientation | o = ROW_VECTOR | |||
| ) | [inline] |
| 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) { }
| 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) { }
| 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) { }
| claraty::Vector< T >::Vector | ( | const std::vector< T > & | rhs | ) | [inline] |
| 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 }
| 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
| Vector_Orientation claraty::Vector< T >::get_orientation | ( | ) | const [inline] |
Definition at line 105 of file vector.h.
Referenced by claraty::io_object(), claraty::match_orientations(), claraty::operator *(), claraty::operator+(), claraty::Vector< int >::operator+=(), claraty::operator-(), claraty::Vector< int >::operator-=(), and claraty::vector_transform().
00105 { return orientation; }
| void claraty::Vector< T >::set_orientation | ( | Vector_Orientation | o | ) | [inline] |
Definition at line 106 of file vector.h.
Referenced by claraty::Vector< T >::cross(), claraty::io_object(), and claraty::Vector< int >::transpose().
00106 { orientation = o; }
| 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 }
| 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 }
| claraty::Vector< T >::operator vnl_vector_ref | ( | ) | [inline] |
| Vector& claraty::Vector< T >::operator= | ( | const T & | rhs | ) | [inline] |
| 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 }
| Vector<T> claraty::Vector< T >::operator== | ( | const Vector< T > & | rhs | ) | [inline] |
| 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().
| 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 }
| 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().
| 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 }
| 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:

| T& claraty::Vector< T >::operator() | ( | int | c | ) | [inline] |
| const T& claraty::Vector< T >::operator() | ( | int | c | ) | const [inline] |
| 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 }
| int claraty::Vector< T >::get_size | ( | ) | const [inline] |
Definition at line 193 of file vector.h.
Referenced by claraty::io_object(), claraty::Vector< int >::is_square(), claraty::Vector< int >::ncols(), claraty::Vector< int >::nrows(), claraty::operator *(), claraty::operator+(), claraty::operator-(), claraty::Vector< int >::pick_extreme(), claraty::Trajectory::set(), and claraty::vector_transform().
| int claraty::Vector< T >::ncols | ( | ) | const [inline] |
Definition at line 194 of file vector.h.
Referenced by claraty::Vector< int >::get_num_of_cols(), claraty::match_orientations(), and claraty::Matrix< uint16_t >::operator=().
00194 { return orientation == ROW_VECTOR ? this->get_size() : 1; }
| 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(); }
| int claraty::Vector< T >::nrows | ( | ) | const [inline] |
Definition at line 196 of file vector.h.
Referenced by claraty::Vector< int >::get_num_of_rows(), claraty::match_orientations(), and claraty::Matrix< uint16_t >::operator=().
00196 { return orientation == COL_VECTOR ? this->get_size() : 1; }
| int claraty::Vector< T >::get_num_of_rows | ( | ) | const [inline] |
| bool claraty::Vector< T >::is_square | ( | ) | const [inline] |
| 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 }
| 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 }
| 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 }
| 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 }
| 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 }
| 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 }
| T claraty::Vector< T >::sum_of_squares | ( | ) | const [inline] |
| Vector claraty::Vector< T >::abs | ( | ) | const [inline] |
| T claraty::Vector< T >::average | ( | ) | const [inline] |
| T claraty::Vector< T >::sum | ( | ) | const [inline] |
| 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 }
| 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 }
| 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 }
| 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
Vector_Orientation claraty::Vector< T >::orientation [private] |
Definition at line 64 of file vector.h.
Referenced by claraty::Vector< T >::cross(), claraty::Vector< int >::get_orientation(), claraty::Vector< int >::ncols(), claraty::Vector< int >::nrows(), claraty::Vector< int >::operator+=(), claraty::Vector< int >::operator-=(), claraty::Vector< int >::operator=(), claraty::Vector< int >::resize(), claraty::Vector< int >::set_orientation(), and claraty::Vector< int >::transpose().
The documentation for this class was generated from the following file: