#include <vec3.h>
Collaboration diagram for EMAN::Vec4< Type >:
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] |
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
Definition at line 69 of file vec3.h.
typedef Type EMAN::Vec4< Type >::type |
One can always cast to the type of a Vec4 by accessing Vec4<Type>::type.
EMAN::Vec4< Type >::Vec4 | ( | ) | [inline] |
Definition at line 76 of file vec3.h.
References EMAN::Vec4< Type >::vec.
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 }
EMAN::Vec4< Type >::Vec4 | ( | const Type2 & | a, | |
const Type3 & | b, | |||
const Type4 & | c, | |||
const Type5 & | d | |||
) | [inline] |
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.
v | The std::vector object. It should have at least 3 items. |
Definition at line 98 of file vec3.h.
References EMAN::Vec4< Type >::vec.
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 }
EMAN::Vec4< Type >::Vec4 | ( | const Vec4< Type2 > & | v | ) | [inline] |
EMAN::Vec4< Type >::~Vec4 | ( | ) | [inline] |
Type EMAN::Vec4< Type >::at | ( | int | i | ) | [inline] |
Get the ith item of the vector.
Used in the left side of the assignment.
i | The index of the item to get. Its validality is not checked. |
Definition at line 194 of file vec3.h.
References EMAN::Vec4< Type >::vec.
00195 { 00196 return vec[i]; 00197 }
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.
Definition at line 213 of file vec3.h.
References EMAN::Vec4< Type >::vec.
00214 { 00215 return &vec[0]; 00216 }
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.
Definition at line 223 of file vec3.h.
References EMAN::Vec4< Type >::vec.
00224 { 00225 return &vec[4]; 00226 }
float EMAN::Vec4< Type >::length | ( | ) | const [inline] |
Calculate its length.
Definition at line 125 of file vec3.h.
References sqrt(), t, and EMAN::Vec4< Type >::vec.
Referenced by EMAN::Vec4< Type >::normalize().
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 }
float EMAN::Vec4< Type >::normalize | ( | ) | [inline] |
Normalize the vector and return its length before the normalization.
Definition at line 135 of file vec3.h.
References EMAN::Vec4< Type >::length(), EMAN::Vec4< Type >::set_value(), and EMAN::Vec4< Type >::vec.
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 }
int EMAN::Vec4< Type >::number_of_element | ( | ) | [inline] |
Type& EMAN::Vec4< Type >::operator[] | ( | int | i | ) | [inline] |
Get the ith item of the vector.
Used in the left side of the assignment.
i | The index of the item to get. Its validality is not checked. |
Definition at line 247 of file vec3.h.
References EMAN::Vec4< Type >::vec.
00248 { 00249 return vec[i]; 00250 }
Type EMAN::Vec4< Type >::operator[] | ( | int | i | ) | const [inline] |
Get the ith item of the vector.
Used in the right side of the assignment.
i | The index of the item to get. Its validality is not checked. |
Definition at line 235 of file vec3.h.
References EMAN::Vec4< Type >::vec.
00236 { 00237 return vec[i]; 00238 }
void EMAN::Vec4< Type >::set_value | ( | const Type & | a, | |
const Type & | b, | |||
const Type & | c, | |||
const Type & | d | |||
) | [inline] |
void EMAN::Vec4< Type >::set_value | ( | const vector< Type2 > & | v | ) | [inline] |
Set new values using a std::vector object.
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 EMAN::Vec4< Type >::vec.
Referenced by EMAN::Vec4< Type >::normalize().
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 }
void EMAN::Vec4< Type >::set_value_at | ( | int | index, | |
const Type2 & | value | |||
) | [inline] |
Set values at a particular index.
index | The index to be set | |
value | The value to be set |
Definition at line 169 of file vec3.h.
References EMAN::Vec4< Type >::vec.
00170 { 00171 vec[index] = static_cast<Type>(value); 00172 }
Type EMAN::Vec4< Type >::vec[4] [private] |
Definition at line 253 of file vec3.h.
Referenced by EMAN::Vec4< Type >::at(), EMAN::Vec4< Type >::begin(), EMAN::Vec4< Type >::end(), EMAN::Vec4< Type >::length(), EMAN::Vec4< Type >::normalize(), EMAN::Vec4< Type >::operator[](), EMAN::Vec4< Type >::set_value(), EMAN::Vec4< Type >::set_value_at(), and EMAN::Vec4< Type >::Vec4().