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>

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.
int number_of_element ()
 For python __len__.
Type * begin ()
 Add this function to make it iterable in Python, so we can call list() or tuple() to convert Vec3f in python to a list or tuple.
Type * end ()
 Add this function to make it iterable in Python, so we can call list() or tuple() to convert Vec3f in python to a list or tuple.
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 () 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 275 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 280 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 284 of file vec3.h.

References EMAN::Vec3< Type >::vec.

00284                          : vec[0](0),vec[1](0),vec[2](0)*/ {
00285 
00286                         vec[0] = static_cast<Type>(0);
00287                         vec[1] = static_cast<Type>(0);
00288                         vec[2] = static_cast<Type>(0);
00289                 }

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 298 of file vec3.h.

References EMAN::Vec3< Type >::vec.

00299                 {
00300                         vec[0] = static_cast<Type>(x);
00301                         vec[1] = static_cast<Type>(y);
00302                         vec[2] = static_cast<Type>(z);
00303                 }

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 310 of file vec3.h.

References EMAN::Vec3< Type >::vec.

00311                 {
00312                         vec[0] = static_cast<Type>(v[0]);
00313                         vec[1] = static_cast<Type>(v[1]);
00314                         vec[2] = static_cast<Type>(v[2]);
00315                 }

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

Copy constructor copies vector elements.

Definition at line 320 of file vec3.h.

References v, and EMAN::Vec3< Type >::vec.

00321                 {
00322                         vec[0] = v[0];
00323                         vec[1] = v[1];
00324                         vec[2] = v[2];
00325                 }

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

Destructor.

Definition at line 329 of file vec3.h.

00329 {}


Member Function Documentation

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 398 of file vec3.h.

References v, and EMAN::Vec3< Type >::vec.

00399                 {
00400                         vector < Type > v(3);
00401                         v[0] = vec[0];
00402                         v[1] = vec[1];
00403                         v[2] = vec[2];
00404                         return v;
00405                 }

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 472 of file vec3.h.

References EMAN::Vec3< Type >::vec.

00473                 {
00474                         return vec[i];
00475                 }

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

Add this function to make it iterable in Python, so we can call list() or tuple() to convert Vec3f in python to a list or tuple.

Returns:
the iterator (here is the pointer) of the first element

Definition at line 491 of file vec3.h.

References EMAN::Vec3< Type >::vec.

00492                 {
00493                         return &vec[0];
00494                 }

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 388 of file vec3.h.

References v, and EMAN::Vec3< Type >::vec.

Referenced by EMAN::Quaternion::rotate().

00389                 {
00390                         return Vec3<Type>((vec[1] * v[2] - vec[2] * v[1]),
00391                                                   (vec[2] * v[0] - vec[0] * v[2]),
00392                                                    (vec[0] * v[1] - vec[1] * v[0]));
00393                 }

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 377 of file vec3.h.

References v, and EMAN::Vec3< Type >::vec.

Referenced by EMAN::operator *(), and EMAN::Symmetry3D::point_in_which_asym_unit().

00378                 {
00379                         return static_cast<Type>((vec[0] * v[0] + vec[1] * v[1] + vec[2] * v[2]));
00380                 }

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

Add this function to make it iterable in Python, so we can call list() or tuple() to convert Vec3f in python to a list or tuple.

Returns:
the iterator (here is the pointer) of the one beyond the last element.

Definition at line 501 of file vec3.h.

References EMAN::Vec3< Type >::vec.

00502                 {
00503                         return &vec[3];
00504                 }

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

Calculate its length.

Returns:
The vector's length Warning - float precision

Definition at line 356 of file vec3.h.

References sqrt(), t, and EMAN::Vec3< Type >::vec.

Referenced by EMAN::Vec3< Type >::normalize().

00357                 {
00358                         float t = (float)(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]);
00359                         return (float)sqrt(t);
00360                 }

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 336 of file vec3.h.

References EMAN::Vec3< Type >::length(), EMAN::Vec3< Type >::set_value(), and EMAN::Vec3< Type >::vec.

Referenced by EMAN::TetrahedralSym::get_asym_unit_points(), EMAN::PlatonicSym::get_asym_unit_points(), EMAN::OptimumOrientationGenerator::optimize_distances(), refalin3d_perturbquat(), and EMAN::Transform::set_rotation().

00337                 {
00338                         // Warning - float precision
00339                         float len = length();
00340                         if (len != 0) {
00341                                 vec[0] = static_cast<Type> (vec[0] / len);
00342                                 vec[1] = static_cast<Type> (vec[1] / len);
00343                                 vec[2] = static_cast<Type> (vec[2] / len);
00344                         }
00345                         else {
00346                                 set_value(0, 0, 0);
00347                         }
00348                         return len;
00349                 }

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

For python __len__.

Returns:
the number of elements in this container. it's always 3.

Definition at line 481 of file vec3.h.

00482                 {
00483                         return 3;
00484                 }

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 559 of file vec3.h.

References EMAN::Vec3< Type >::vec.

00559                                                          {
00560                         vec[0] = static_cast<Type>(vec[0]*d);
00561                         vec[1] = static_cast<Type>(vec[1]*d);
00562                         vec[2] = static_cast<Type>(vec[2]*d);
00563                         return *this;
00564                 }

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

Definition at line 579 of file vec3.h.

References v, and EMAN::Vec3< Type >::vec.

00579                                                {
00580                         vector<Type2> v(vec,vec+3);
00581                         return v;
00582                 }

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 523 of file vec3.h.

References EMAN::Vec3< Type >::vec.

00523                                                          {
00524                         vec[0] = static_cast<Type>(vec[0]+d);
00525                         vec[1] = static_cast<Type>(vec[1]+d);
00526                         vec[2] = static_cast<Type>(vec[2]+d);
00527                         return *this;
00528                 }

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 511 of file vec3.h.

References v, and EMAN::Vec3< Type >::vec.

00511                                                               {
00512                         vec[0] = static_cast<Type>(vec[0]+v[0]);
00513                         vec[1] = static_cast<Type>(vec[1]+v[1]);
00514                         vec[2] = static_cast<Type>(vec[2]+v[2]);
00515                         return *this;
00516                 }

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 547 of file vec3.h.

References EMAN::Vec3< Type >::vec.

00547                                                         {
00548                         vec[0] = static_cast<Type>(vec[0]-d);
00549                         vec[1] = static_cast<Type>(vec[1]-d);
00550                         vec[2] = static_cast<Type>(vec[2]-d);
00551                         return *this;
00552                 }

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 535 of file vec3.h.

References v, and EMAN::Vec3< Type >::vec.

00535                                                                {
00536                         vec[0] = static_cast<Type>(vec[0]-v[0]);
00537                         vec[1] = static_cast<Type>(vec[1]-v[1]);
00538                         vec[2] = static_cast<Type>(vec[2]-v[2]);
00539                         return *this;
00540                 }

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 571 of file vec3.h.

References EMAN::Vec3< Type >::vec.

00571                                                          {
00572                         vec[0] = static_cast<Type>(vec[0]/d);
00573                         vec[1] = static_cast<Type>(vec[1]/d);
00574                         vec[2] = static_cast<Type>(vec[2]/d);
00575                         return *this;
00576                 }

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 460 of file vec3.h.

References EMAN::Vec3< Type >::vec.

00461                 {
00462                         return vec[i];
00463                 }

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 448 of file vec3.h.

References EMAN::Vec3< Type >::vec.

00449                 {
00450                         return vec[i];
00451                 }

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 434 of file vec3.h.

References EMAN::Vec3< Type >::vec.

00435                 {
00436                         vec[0] =  x;
00437                         vec[1] =  y;
00438                         vec[2] =  z;
00439                 }

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 412 of file vec3.h.

References EMAN::Vec3< Type >::vec.

Referenced by wustl_mm::GraySkeletonCPP::VolumeSkeletonizer::CleanUpSkeleton(), EMAN::Vec3< Type >::normalize(), and EMAN::Quaternion::to_axis().

00413                 {
00414                         vec[0] =  static_cast<Type>(v[0]);
00415                         vec[1] =  static_cast<Type>(v[1]);
00416                         vec[2] =  static_cast<Type>(v[2]);
00417                 }

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 424 of file vec3.h.

References EMAN::Vec3< Type >::vec.

00425                 {
00426                         vec[index] = static_cast<Type>(value);
00427                 }

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 366 of file vec3.h.

References EMAN::Vec3< Type >::vec.

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

00367                 {
00368                         return  vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2] ;
00369                 }


Member Data Documentation

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

Definition at line 586 of file vec3.h.

Referenced by EMAN::Vec3< Type >::as_list(), EMAN::Vec3< Type >::at(), EMAN::Vec3< Type >::begin(), EMAN::Vec3< Type >::cross(), EMAN::Vec3< Type >::dot(), EMAN::Vec3< Type >::end(), EMAN::Vec3< Type >::length(), EMAN::Vec3< Type >::normalize(), EMAN::Vec3< Type >::operator *=(), EMAN::Vec3< Type >::operator vector(), EMAN::Vec3< Type >::operator+=(), EMAN::Vec3< Type >::operator-=(), EMAN::Vec3< Type >::operator/=(), EMAN::Vec3< Type >::operator[](), EMAN::Vec3< Type >::set_value(), EMAN::Vec3< Type >::set_value_at(), EMAN::Vec3< Type >::squared_length(), and EMAN::Vec3< Type >::Vec3().


The documentation for this class was generated from the following file:
Generated on Tue Jun 11 12:45:36 2013 for EMAN2 by  doxygen 1.4.7