EMAN2
Public Types | Public Member Functions | Private Attributes | List of all 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>

Public Types

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

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. More...
 
template<typename Type2 >
 Vec4 (const Vec4< Type2 > &v)
 Copy constructor copies vector elements. More...
 
 ~Vec4 ()
 Destructor. More...
 
float length () const
 Calculate its length. More...
 
float normalize ()
 Normalize the vector and return its length before the normalization. More...
 
template<typename Type2 >
void set_value (const vector< Type2 > &v)
 Set new values using a std::vector object. More...
 
template<typename Type2 >
void set_value_at (int index, const Type2 &value)
 Set values at a particular index. More...
 
void set_value (const Type &a, const Type &b, const Type &c, const Type &d)
 Set new values to this vector object. More...
 
Type at (int i)
 Get the ith item of the vector. More...
 
int number_of_element ()
 For python len More...
 
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. More...
 
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. More...
 
Type operator[] (int i) const
 Get the ith item of the vector. More...
 
Type & operator[] (int i)
 Get the ith item of the vector. More...
 

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

Member Typedef Documentation

◆ type

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

Constructor & Destructor Documentation

◆ Vec4() [1/4]

template<typename Type >
EMAN::Vec4< Type >::Vec4 ( )
inline

Definition at line 72 of file vec3.h.

73 {
74 vec[0] = static_cast<Type>(0);
75 vec[1] = static_cast<Type>(0);
76 vec[2] = static_cast<Type>(0);
77 vec[3] = static_cast<Type>(0);
78 }
Type vec[4]
Definition: vec3.h:249

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

◆ Vec4() [2/4]

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

82 {
83 vec[0] = static_cast<Type>(a);
84 vec[1] = static_cast<Type>(b);
85 vec[2] = static_cast<Type>(c);
86 vec[3] = static_cast<Type>(d);
87 }

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

◆ Vec4() [3/4]

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
vThe std::vector object. It should have at least 3 items.

Definition at line 94 of file vec3.h.

95 {
96 vec[0] = static_cast<Type>(v[0]);
97 vec[1] = static_cast<Type>(v[1]);
98 vec[2] = static_cast<Type>(v[2]);
99 vec[3] = static_cast<Type>(v[3]);
100 }

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

◆ Vec4() [4/4]

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

Copy constructor copies vector elements.

Definition at line 105 of file vec3.h.

106 {
107 vec[0] = v[0];
108 vec[1] = v[1];
109 vec[2] = v[2];
110 vec[2] = v[3];
111 }

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

◆ ~Vec4()

template<typename Type >
EMAN::Vec4< Type >::~Vec4 ( )
inline

Destructor.

Definition at line 115 of file vec3.h.

115{}

Member Function Documentation

◆ at()

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
iThe index of the item to get. Its validality is not checked.
Returns
The ith item of the vector.

Definition at line 190 of file vec3.h.

191 {
192 return vec[i];
193 }

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

◆ begin()

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

210 {
211 return &vec[0];
212 }

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

◆ end()

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

220 {
221 return &vec[4];
222 }

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

◆ length()

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

Calculate its length.

Returns
The vector's length Warning - float precision

Definition at line 121 of file vec3.h.

122 {
123 float t = (float)(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2] + vec[3] * vec[3]);
124 return (float)sqrt(t);
125 }
EMData * sqrt() const
return square root of current image

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

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

◆ normalize()

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

132 {
133 // Warning - float precision
134 float len = length();
135 if (len != 0) {
136 vec[0] = static_cast<Type> (vec[0] / len);
137 vec[1] = static_cast<Type> (vec[1] / len);
138 vec[2] = static_cast<Type> (vec[2] / len);
139 vec[3] = static_cast<Type> (vec[3] / len);
140 }
141 else {
142 set_value(0, 0, 0, 0);
143 }
144 return len;
145 }
void set_value(const vector< Type2 > &v)
Set new values using a std::vector object.
Definition: vec3.h:152
float length() const
Calculate its length.
Definition: vec3.h:121

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

◆ number_of_element()

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

200 {
201 return 4;
202 }

◆ operator[]() [1/2]

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
iThe index of the item to get. Its validality is not checked.
Returns
The ith item of the vector.

Definition at line 243 of file vec3.h.

244 {
245 return vec[i];
246 }

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

◆ operator[]() [2/2]

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
iThe index of the item to get. Its validality is not checked.
Returns
The ith item of the vector.

Definition at line 231 of file vec3.h.

232 {
233 return vec[i];
234 }

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

◆ set_value() [1/2]

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
xValue of the first item.
yValue of the second item.
zValue of the third item.

Definition at line 175 of file vec3.h.

176 {
177 vec[0] = a;
178 vec[1] = b;
179 vec[2] = c;
180 vec[3] = d;
181 }

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

◆ set_value() [2/2]

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
vA std::vector object used to set 'this' vector's value. It should have at least 3 items.

Definition at line 152 of file vec3.h.

153 {
154 vec[0] = static_cast<Type>(v[0]);
155 vec[1] = static_cast<Type>(v[1]);
156 vec[2] = static_cast<Type>(v[2]);
157 vec[3] = static_cast<Type>(v[3]);
158 }

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

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

◆ set_value_at()

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
indexThe index to be set
valueThe value to be set

Definition at line 165 of file vec3.h.

166 {
167 vec[index] = static_cast<Type>(value);
168 }

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

Member Data Documentation

◆ vec

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

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