EMAN2
Public Types | Public Member Functions | Private Attributes
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.

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

                {
                        vec[0] = static_cast<Type>(0);
                        vec[1] = static_cast<Type>(0);
                        vec[2] = static_cast<Type>(0);
                        vec[3] = static_cast<Type>(0);
                }
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.

References b, and EMAN::Vec4< Type >::vec.

                {
                        vec[0] = static_cast<Type>(a);
                        vec[1] = static_cast<Type>(b);
                        vec[2] = static_cast<Type>(c);
                        vec[3] = static_cast<Type>(d);
                }
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 98 of file vec3.h.

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

                {
                        vec[0] = static_cast<Type>(v[0]);
                        vec[1] = static_cast<Type>(v[1]);
                        vec[2] = static_cast<Type>(v[2]);
                        vec[3] = static_cast<Type>(v[3]);
                }
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 EMAN::Vec4< Type >::vec.

                {
                        vec[0] = v[0];
                        vec[1] = v[1];
                        vec[2] = v[2];
                        vec[2] = v[3];
                }
template<typename Type>
EMAN::Vec4< Type >::~Vec4 ( ) [inline]

Destructor.

Definition at line 119 of file vec3.h.

{}

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:
iThe 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.

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

                {
                        return vec[i];
                }
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.

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

                {
                        return &vec[0];
                }
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.

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

                {
                        return &vec[4];
                }
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(), t, and EMAN::Vec4< Type >::vec.

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

                {
                        float t = (float)(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2] + vec[3] * vec[3]);
                        return (float)sqrt(t);
                }
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::Vec4< Type >::length(), EMAN::Vec4< Type >::set_value(), and EMAN::Vec4< Type >::vec.

                {
                        // Warning - float precision
                        float len = length();
                        if (len != 0) {
                                vec[0] = static_cast<Type> (vec[0] / len);
                                vec[1] = static_cast<Type> (vec[1] / len);
                                vec[2] = static_cast<Type> (vec[2] / len);
                                vec[3] = static_cast<Type> (vec[3] / len);
                        }
                        else {
                                set_value(0, 0, 0, 0);  
                        }
                        return len;
                }
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.

                {
                        return 4;
                }
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 247 of file vec3.h.

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

                {
                        return vec[i];
                }
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 235 of file vec3.h.

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

                {
                        return vec[i];
                }
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 156 of file vec3.h.

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

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

                {
                        vec[0] =  static_cast<Type>(v[0]);
                        vec[1] =  static_cast<Type>(v[1]);
                        vec[2] =  static_cast<Type>(v[2]);
                        vec[3] =  static_cast<Type>(v[3]);
                }
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 179 of file vec3.h.

References b, and EMAN::Vec4< Type >::vec.

                {
                        vec[0] =  a;
                        vec[1] =  b;
                        vec[2] =  c;
                        vec[3] =  d;
                }
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 169 of file vec3.h.

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

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

Member Data Documentation

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

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