Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::Vec4< Type > Class Template Reference

The Vec4 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::Vec4< Type >:

Collaboration graph
[legend]
List of all members.

Public Types

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

Public Member Functions

 Vec4 ()
template<typename Type2, typename Type3, typename Type4, typename Type5>
 Vec4 (const Type2 &a, const Type3 &b, const Type4 &c, const Type5 &d)
template<typename Type2>
 Vec4 (const vector< Type2 > &v)
 Construct a Vec3 object given a std::vector object.
template<typename Type2>
 Vec4 (const Vec4< Type2 > &v)
 Copy constructor copies vector elements.
 ~Vec4 ()
 Destructor.
float length () const
 Calculate its length.
float normalize ()
 Normalize the vector and return its length before the normalization.
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 &a, const Type &b, const Type &c, const Type &d)
 Set new values to this vector object.
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.
Type operator[] (int i) const
 Get the ith item of the vector.
Type & operator[] (int i)
 Get the ith item of the vector.

Private Attributes

Type vec [4]

Detailed Description

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

The Vec4 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

WARNING This class is not as complete as Vec4f, in that I have not yet implmented object operators

For now, only functionality is for normalization typedef Vec4<float> Vec4f; typedef Vec4<int> Vec4i; typedef Vec4<double> Vec4d; // Not recommended for use unless precision is addressed in this class

Author:
John Flanagan
Date:
July 2011

Definition at line 69 of file vec3.h.


Member Typedef Documentation

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

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

Definition at line 74 of file vec3.h.


Constructor & Destructor Documentation

template<typename Type>
EMAN::Vec4< Type >::Vec4  )  [inline]
 

Definition at line 76 of file vec3.h.

00077                 {
00078                         vec[0] = static_cast<Type>(0);
00079                         vec[1] = static_cast<Type>(0);
00080                         vec[2] = static_cast<Type>(0);
00081                         vec[3] = static_cast<Type>(0);
00082                 }

template<typename Type>
template<typename Type2, typename Type3, typename Type4, typename Type5>
EMAN::Vec4< Type >::Vec4 const Type2 &  a,
const Type3 &  b,
const Type4 &  c,
const Type5 &  d
[inline]
 

Definition at line 85 of file vec3.h.

00086                 {
00087                         vec[0] = static_cast<Type>(a);
00088                         vec[1] = static_cast<Type>(b);
00089                         vec[2] = static_cast<Type>(c);
00090                         vec[3] = static_cast<Type>(d);
00091                 }

template<typename Type>
template<typename Type2>
EMAN::Vec4< Type >::Vec4 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 98 of file vec3.h.

References v.

00099                 {
00100                         vec[0] = static_cast<Type>(v[0]);
00101                         vec[1] = static_cast<Type>(v[1]);
00102                         vec[2] = static_cast<Type>(v[2]);
00103                         vec[3] = static_cast<Type>(v[3]);
00104                 }

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

Copy constructor copies vector elements.

Definition at line 109 of file vec3.h.

References v.

00110                 {
00111                         vec[0] = v[0];
00112                         vec[1] = v[1];
00113                         vec[2] = v[2];
00114                         vec[2] = v[3];
00115                 }

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

Destructor.

Definition at line 119 of file vec3.h.

00119 {}


Member Function Documentation

template<typename Type>
Type EMAN::Vec4< 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 194 of file vec3.h.

00195                 {
00196                         return vec[i];
00197                 }

template<typename Type>
Type* EMAN::Vec4< 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 213 of file vec3.h.

00214                 {
00215                         return &vec[0];
00216                 }

template<typename Type>
Type* EMAN::Vec4< 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 223 of file vec3.h.

00224                 {
00225                         return &vec[4];
00226                 }

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

Calculate its length.

Returns:
The vector's length Warning - float precision

Definition at line 125 of file vec3.h.

References sqrt(), and t.

00126                 {
00127                         float t = (float)(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2] + vec[3] * vec[3]);
00128                         return (float)sqrt(t);
00129                 }

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

Normalize the vector and return its length before the normalization.

Returns:
The length of the Vec before normalization.

Definition at line 135 of file vec3.h.

References EMAN::length().

00136                 {
00137                         // Warning - float precision
00138                         float len = length();
00139                         if (len != 0) {
00140                                 vec[0] = static_cast<Type> (vec[0] / len);
00141                                 vec[1] = static_cast<Type> (vec[1] / len);
00142                                 vec[2] = static_cast<Type> (vec[2] / len);
00143                                 vec[3] = static_cast<Type> (vec[3] / len);
00144                         }
00145                         else {
00146                                 set_value(0, 0, 0, 0);  
00147                         }
00148                         return len;
00149                 }

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

For python __len__.

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

Definition at line 203 of file vec3.h.

00204                 {
00205                         return 4;
00206                 }

template<typename Type>
Type& EMAN::Vec4< 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 247 of file vec3.h.

00248                 {
00249                         return vec[i];
00250                 }

template<typename Type>
Type EMAN::Vec4< 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 235 of file vec3.h.

00236                 {
00237                         return vec[i];
00238                 }

template<typename Type>
void EMAN::Vec4< Type >::set_value const Type &  a,
const Type &  b,
const Type &  c,
const Type &  d
[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 179 of file vec3.h.

00180                 {
00181                         vec[0] =  a;
00182                         vec[1] =  b;
00183                         vec[2] =  c;
00184                         vec[3] =  d;
00185                 }

template<typename Type>
template<typename Type2>
void EMAN::Vec4< 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 156 of file vec3.h.

References v.

00157                 {
00158                         vec[0] =  static_cast<Type>(v[0]);
00159                         vec[1] =  static_cast<Type>(v[1]);
00160                         vec[2] =  static_cast<Type>(v[2]);
00161                         vec[3] =  static_cast<Type>(v[3]);
00162                 }

template<typename Type>
template<typename Type2>
void EMAN::Vec4< 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 169 of file vec3.h.

00170                 {
00171                         vec[index] = static_cast<Type>(value);
00172                 }


Member Data Documentation

template<typename Type>
Type EMAN::Vec4< Type >::vec[4] [private]
 

Definition at line 253 of file vec3.h.


The documentation for this class was generated from the following file:
Generated on Tue Jun 11 13:49:52 2013 for EMAN2 by  doxygen 1.3.9.1