EMAN::Vec3< Type > Class Template Reference
[unit test in Python]

The Vec3 object is a templated object, intended to instantiated with basic types such as int, float, double etc. More...

#include <vec3.h>

Inheritance diagram for EMAN::Vec3< Type >:

Inheritance graph
[legend]
Collaboration diagram for EMAN::Vec3< Type >:

Collaboration graph
[legend]

List of all members.

Public Types

typedef Type type
 One can always cast to the type of a Vec3 by accessing Vec3<Type>::type.

Public Member Functions

 Vec3 ()
 contruct a Vec3 object with all elements equal to 0.
template<typename Type2, typename Type3, typename Type4>
 Vec3 (const Type2 &x, const Type3 &y, const Type4 &z=0)
 contruct a Vec3 object given (x,y) or (x,y,z) values.
template<typename Type2>
 Vec3 (const vector< Type2 > &v)
 Construct a Vec3 object given a std::vector object.
template<typename Type2>
 Vec3 (const Vec3< Type2 > &v)
 Copy constructor copies vector elements.
 ~Vec3 ()
 Destructor.
float normalize ()
 Normalize the vector and return its length before the normalization.
float length () const
 Calculate its length.
Type squared_length () const
 Calculate its squared length.
template<typename Type2>
Type dot (const Vec3< Type2 > &v) const
 Calculate the dot product of 'this' vector with a second vector.
template<typename Type2>
Vec3< Type > cross (const Vec3< Type2 > &v) const
 Calculate the cross product of 'this' vector with a second vector.
vector< Type > as_list () const
 Return the values of this vector as a std::vector.
template<typename Type2>
void set_value (const vector< Type2 > &v)
 Set new values using a std::vector object.
template<typename Type2>
void set_value_at (int index, const Type2 &value)
 Set values at a particular index.
void set_value (const Type &x, const Type &y, const Type &z)
 Set new values to this vector object.
Type operator[] (int i) const
 Get the ith item of the vector.
Type & operator[] (int i)
 Get the ith item of the vector.
Type at (int i)
 Get the ith item of the vector.
template<typename Type2>
Vec3< Type > & operator+= (const Vec3< Type2 > &v)
 'this' += v; Add the 2 vectors by adding item by item.
template<typename Type2>
Vec3< Type > & operator+= (const Type2 &d)
 'this' += d.
template<typename Type2>
Vec3< Type > & operator-= (const Vec3< Type2 > &v)
 'this' -= v; Minus the 2 vectors item by item.
template<typename Type2>
Vec3< Type > & operator-= (const Type2 &d)
 'this' -= d; Minus a number from each item of 'this' vector.
template<typename Type2>
Vec3< Type > & operator*= (const Type2 &d)
 'this' *= d; Multiply a number on each item of 'this' vector.
template<typename Type2>
Vec3< Type > & operator/= (const Type2 &d)
 'this' /= d; Divide a number on each item of 'this' vector.
template<typename Type2>
 operator vector< Type2 > () const

Private Attributes

Type vec [3]


Detailed Description

template<typename Type>
class EMAN::Vec3< Type >

The Vec3 object is a templated object, intended to instantiated with basic types such as int, float, double etc.

You may try to use other more generic types such as classes but you may get bad results. Note that the normalize and length operations are precise only to 32 bits Note there are convenient typedef so one needn't bother about using template terminology typedef Vec3<float> Vec3f; typedef Vec3<int> Vec3i; typedef Vec3<double> Vec3d; // Not recommended for use unless precision is addressed in this class

Author:
David Woolford (based on the work of who ever wrote the original Vec3f and Vec3i classes - extracted into a template)
Date:
August 2008 ?

Definition at line 66 of file vec3.h.


Member Typedef Documentation

template<typename Type>
typedef Type EMAN::Vec3< Type >::type

One can always cast to the type of a Vec3 by accessing Vec3<Type>::type.

Definition at line 71 of file vec3.h.


Constructor & Destructor Documentation

template<typename Type>
EMAN::Vec3< Type >::Vec3 (  )  [inline]

contruct a Vec3 object with all elements equal to 0.

Definition at line 75 of file vec3.h.

00075                          : vec[0](0),vec[1](0),vec[2](0)*/ {
00076 
00077                         vec[0] = static_cast<Type>(0);
00078                         vec[1] = static_cast<Type>(0);
00079                         vec[2] = static_cast<Type>(0);
00080                 }

template<typename Type>
template<typename Type2, typename Type3, typename Type4>
EMAN::Vec3< Type >::Vec3 ( const Type2 &  x,
const Type3 &  y,
const Type4 &  z = 0 
) [inline]

contruct a Vec3 object given (x,y) or (x,y,z) values.

Parameters:
x Value of the first item.
y Value of the second item.
z Value of the third item. If not specified, default to 0.

Definition at line 89 of file vec3.h.

00090                 {
00091                         vec[0] = static_cast<Type>(x);
00092                         vec[1] = static_cast<Type>(y);
00093                         vec[2] = static_cast<Type>(z);
00094                 }

template<typename Type>
template<typename Type2>
EMAN::Vec3< Type >::Vec3 ( const vector< Type2 > &  v  )  [inline]

Construct a Vec3 object given a std::vector object.

The std::vector object should have at least 3 items.

Parameters:
v The std::vector object. It should have at least 3 items.

Definition at line 101 of file vec3.h.

00102                 {
00103                         vec[0] = static_cast<Type>(v[0]);
00104                         vec[1] = static_cast<Type>(v[1]);
00105                         vec[2] = static_cast<Type>(v[2]);
00106                 }

template<typename Type>
template<typename Type2>
EMAN::Vec3< Type >::Vec3 ( const Vec3< Type2 > &  v  )  [inline]

Copy constructor copies vector elements.

Definition at line 111 of file vec3.h.

00112                 {
00113                         vec[0] = v[0];
00114                         vec[1] = v[1];
00115                         vec[2] = v[2];
00116                 }

template<typename Type>
EMAN::Vec3< Type >::~Vec3 (  )  [inline]

Destructor.

Definition at line 120 of file vec3.h.

00120 {}


Member Function Documentation

template<typename Type>
float EMAN::Vec3< Type >::normalize (  )  [inline]

Normalize the vector and return its length before the normalization.

Returns:
The length of the Vec before normalization.

Definition at line 127 of file vec3.h.

Referenced by EMAN::TetrahedralSym::get_asym_unit_points(), EMAN::PlatonicSym::get_asym_unit_points(), EMAN::OptimumOrientationGenerator::optimize_distances(), refalin3d_perturb(), EMAN::Transform3D::set_rotation(), EMAN::Transform::set_rotation(), and EMAN::MarchingCubes::surface_face_z().

00128                 {
00129                         // Warning - float precision
00130                         float len = length();
00131                         if (len != 0) {
00132                                 vec[0] = static_cast<Type> (vec[0] / len);
00133                                 vec[1] = static_cast<Type> (vec[1] / len);
00134                                 vec[2] = static_cast<Type> (vec[2] / len);
00135                         }
00136                         else {
00137                                 set_value(0, 0, 0);
00138                         }
00139                         return len;
00140                 }

template<typename Type>
float EMAN::Vec3< Type >::length (  )  const [inline]

Calculate its length.

Returns:
The vector's length Warning - float precision

Definition at line 147 of file vec3.h.

Referenced by EMAN::Vec3< int >::normalize(), EMAN::Transform3D::set_rotation(), EMAN::Quaternion::to_angle(), and EMAN::Quaternion::to_axis().

00148                 {
00149                         float t = (float)(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]);
00150                         return (float)sqrt(t);
00151                 }

template<typename Type>
Type EMAN::Vec3< Type >::squared_length (  )  const [inline]

Calculate its squared length.

no sqrt called

Returns:
The vector's length squared.

Definition at line 157 of file vec3.h.

Referenced by EMAN::Symmetry3D::get_touching_au_transforms().

00158                 {
00159                         return  vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2] ;
00160                 }

template<typename Type>
template<typename Type2>
Type EMAN::Vec3< Type >::dot ( const Vec3< Type2 > &  v  )  const [inline]

Calculate the dot product of 'this' vector with a second vector.

Parameters:
v The second vector to do the dot product.
Returns:
The dot product.

Definition at line 168 of file vec3.h.

Referenced by EMAN::operator*(), and EMAN::Transform3D::set_rotation().

00169                 {
00170                         return static_cast<Type>((vec[0] * v[0] + vec[1] * v[1] + vec[2] * v[2]));
00171                 }

template<typename Type>
template<typename Type2>
Vec3<Type> EMAN::Vec3< Type >::cross ( const Vec3< Type2 > &  v  )  const [inline]

Calculate the cross product of 'this' vector with a second vector.

Parameters:
v The second vector to do the cross product.
Returns:
The cross product.

Definition at line 179 of file vec3.h.

Referenced by EMAN::Quaternion::rotate(), and EMAN::Transform3D::set_rotation().

00180                 {
00181                         return Vec3<Type>((vec[1] * v[2] - vec[2] * v[1]),
00182                                                   (vec[2] * v[0] - vec[0] * v[2]),
00183                                                    (vec[0] * v[1] - vec[1] * v[0]));
00184                 }

template<typename Type>
vector<Type> EMAN::Vec3< Type >::as_list (  )  const [inline]

Return the values of this vector as a std::vector.

Returns:
The std::vector version of this vector.

Definition at line 189 of file vec3.h.

00190                 {
00191                         vector < Type > v(3);
00192                         v[0] = vec[0];
00193                         v[1] = vec[1];
00194                         v[2] = vec[2];
00195                         return v;
00196                 }

template<typename Type>
template<typename Type2>
void EMAN::Vec3< Type >::set_value ( const vector< Type2 > &  v  )  [inline]

Set new values using a std::vector object.

Parameters:
v A std::vector object used to set 'this' vector's value. It should have at least 3 items.

Definition at line 203 of file vec3.h.

Referenced by EMAN::Vec3< int >::normalize(), and EMAN::Quaternion::to_axis().

00204                 {
00205                         vec[0] =  static_cast<Type>(v[0]);
00206                         vec[1] =  static_cast<Type>(v[1]);
00207                         vec[2] =  static_cast<Type>(v[2]);
00208                 }

template<typename Type>
template<typename Type2>
void EMAN::Vec3< Type >::set_value_at ( int  index,
const Type2 &  value 
) [inline]

Set values at a particular index.

Parameters:
index The index to be set
value The value to be set

Definition at line 215 of file vec3.h.

Referenced by EMAN::Transform3D::get_pretrans().

00216                 {
00217                         vec[index] = static_cast<Type>(value);
00218                 }

template<typename Type>
void EMAN::Vec3< Type >::set_value ( const Type &  x,
const Type &  y,
const Type &  z 
) [inline]

Set new values to this vector object.

Parameters:
x Value of the first item.
y Value of the second item.
z Value of the third item.

Definition at line 225 of file vec3.h.

00226                 {
00227                         vec[0] =  x;
00228                         vec[1] =  y;
00229                         vec[2] =  z;
00230                 }

template<typename Type>
Type EMAN::Vec3< Type >::operator[] ( int  i  )  const [inline]

Get the ith item of the vector.

Used in the right side of the assignment.

Parameters:
i The index of the item to get. Its validality is not checked.
Returns:
The ith item of the vector.

Definition at line 239 of file vec3.h.

00240                 {
00241                         return vec[i];
00242                 }

template<typename Type>
Type& EMAN::Vec3< Type >::operator[] ( int  i  )  [inline]

Get the ith item of the vector.

Used in the left side of the assignment.

Parameters:
i The index of the item to get. Its validality is not checked.
Returns:
The ith item of the vector.

Definition at line 251 of file vec3.h.

00252                 {
00253                         return vec[i];
00254                 }

template<typename Type>
Type EMAN::Vec3< Type >::at ( int  i  )  [inline]

Get the ith item of the vector.

Used in the left side of the assignment.

Parameters:
i The index of the item to get. Its validality is not checked.
Returns:
The ith item of the vector.

Definition at line 263 of file vec3.h.

Referenced by EMAN::EMData::rot_scale_trans(), and EMAN::EMData::rot_scale_trans_background().

00264                 {
00265                         return vec[i];
00266                 }

template<typename Type>
template<typename Type2>
Vec3<Type>& EMAN::Vec3< Type >::operator+= ( const Vec3< Type2 > &  v  )  [inline]

'this' += v; Add the 2 vectors by adding item by item.

Parameters:
v The vector used to be added to 'this' vector.
Returns:
The new 'this' as a result of add.

Definition at line 274 of file vec3.h.

00274                                                               {
00275                         vec[0] = static_cast<Type>(vec[0]+v[0]);
00276                         vec[1] = static_cast<Type>(vec[1]+v[1]);
00277                         vec[2] = static_cast<Type>(vec[2]+v[2]);
00278                         return *this;
00279                 }

template<typename Type>
template<typename Type2>
Vec3<Type>& EMAN::Vec3< Type >::operator+= ( const Type2 &  d  )  [inline]

'this' += d.

Add d to each item of this vector.

Parameters:
d The number used to be added to this vector.
Returns:
The new 'this' as a result of add.

Definition at line 286 of file vec3.h.

00286                                                          {
00287                         vec[0] = static_cast<Type>(vec[0]+d);
00288                         vec[1] = static_cast<Type>(vec[1]+d);
00289                         vec[2] = static_cast<Type>(vec[2]+d);
00290                         return *this;
00291                 }

template<typename Type>
template<typename Type2>
Vec3<Type>& EMAN::Vec3< Type >::operator-= ( const Vec3< Type2 > &  v  )  [inline]

'this' -= v; Minus the 2 vectors item by item.

Parameters:
v The vector used to be substracted from 'this' vector.
Returns:
The new 'this' as a result of substraction.

Definition at line 298 of file vec3.h.

00298                                                                {
00299                         vec[0] = static_cast<Type>(vec[0]-v[0]);
00300                         vec[1] = static_cast<Type>(vec[1]-v[1]);
00301                         vec[2] = static_cast<Type>(vec[2]-v[2]);
00302                         return *this;
00303                 }

template<typename Type>
template<typename Type2>
Vec3<Type>& EMAN::Vec3< Type >::operator-= ( const Type2 &  d  )  [inline]

'this' -= d; Minus a number from each item of 'this' vector.

Parameters:
d The number used to be substracted from 'this' vector.
Returns:
The new 'this' as a result of substraction.

Definition at line 310 of file vec3.h.

00310                                                         {
00311                         vec[0] = static_cast<Type>(vec[0]-d);
00312                         vec[1] = static_cast<Type>(vec[1]-d);
00313                         vec[2] = static_cast<Type>(vec[2]-d);
00314                         return *this;
00315                 }

template<typename Type>
template<typename Type2>
Vec3<Type>& EMAN::Vec3< Type >::operator*= ( const Type2 &  d  )  [inline]

'this' *= d; Multiply a number on each item of 'this' vector.

Parameters:
d The number to multiply.
Returns:
The new 'this' as a result of multiplication.

Definition at line 322 of file vec3.h.

00322                                                          {
00323                         vec[0] = static_cast<Type>(vec[0]*d);
00324                         vec[1] = static_cast<Type>(vec[1]*d);
00325                         vec[2] = static_cast<Type>(vec[2]*d);
00326                         return *this;
00327                 }

template<typename Type>
template<typename Type2>
Vec3<Type>& EMAN::Vec3< Type >::operator/= ( const Type2 &  d  )  [inline]

'this' /= d; Divide a number on each item of 'this' vector.

Parameters:
d The number to divide.
Returns:
The new 'this' as a result of division.

Definition at line 334 of file vec3.h.

00334                                                          {
00335                         vec[0] = static_cast<Type>(vec[0]/d);
00336                         vec[1] = static_cast<Type>(vec[1]/d);
00337                         vec[2] = static_cast<Type>(vec[2]/d);
00338                         return *this;
00339                 }

template<typename Type>
template<typename Type2>
EMAN::Vec3< Type >::operator vector< Type2 > (  )  const [inline]

Definition at line 342 of file vec3.h.

00342                                                {
00343                         vector<Type2> v(vec,vec+3);
00344                         return v;
00345                 }


Member Data Documentation

template<typename Type>
Type EMAN::Vec3< Type >::vec[3] [private]


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

Generated on Sat Nov 21 02:20:50 2009 for EMAN2 by  doxygen 1.5.6