mesh_conv::MC_v4d Class Reference

Basic class for 4D vector. More...

#include <MC_v4d.hpp>

Inheritance diagram for mesh_conv::MC_v4d:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 MC_v4d ()
 empty constructor of zero vector
 MC_v4d (const double &x, const double &y, const double &z, const double &w)
 direct constructor from x,y,z,w
 MC_v4d (const MC_v4d &_v)
 copy constructor
 MC_v4d (const double *_v)
 constructor from pointer to double
 MC_v4d (const std::string &s)
 constructor from a string "(x,y,z,w)"
 MC_v4d (const MC_matrix &M)
 constructor from a matrix only if size=(4,1) or (1,4)
 MC_v4d (const MC_v3d &vec)
 constructor from a MC_v3d (add 1 at the end)
 ~MC_v4d ()
 destructor
MC_v4d operator- () const
 change the opposite sign of the current vector (unary negation)
MC_v4doperator+= (const double &to_add)
 internal addition with a double
MC_v4doperator-= (const double &to_sub)
 internal substraction with a double
MC_v4doperator*= (const double &to_mult)
 internal multiplication with a double
MC_v4doperator/= (const double &to_subdiv)
 internal divide with a double
MC_v4doperator+= (const MC_v4d &to_add)
 internal addition
MC_v4doperator-= (const MC_v4d &to_sub)
 internal substraction
MC_v4dscale (const double &sx, const double &sy, const double &sz, const double &sw)
 internal scaling the vector
MC_v4dscale (const MC_v4d &scaling)
 internal scaling the vector
MC_v4dscale (const double &scaling)
 internal homogeneous scaling the vector
MC_v4d mask (const double &sx, const double &sy, const double &sz, const double &sw) const
 apply a pointwise mask to the vector (do not change it)
MC_v4d mask (const MC_v4d &scaling) const
 apply a pointwise mask the vector
MC_v4d scale (const double &scaling) const
 apply a pointwise mask to the vector
double dot (const MC_v4d &vec) const
 dot product between two vectors
double norm () const
 norm of the vector
MC_v4d normalized () const
 get the normalized vector.
MC_v4doperator*= (const MC_matrix &M)
 internal application of a matrix to the vector of MC_v4d (does the product x'=M*x)
MC_v4dset_v3d (const MC_v3d &vec)
 set only the 3d part without changing the 4th component
const double & operator() (const int &k_dim) const
 get operator (k_dim must be 0,1,2 or 3)
double & operator() (const int &k_dim)
 get operator (k_dim must be 0,1,2 or 3)
const double & operator[] (const int &k_dim) const
 get operator (k_dim must be 0,1,2 or 3)
double & operator[] (const int &k_dim)
 get operator (k_dim must be 0,1,2 or 3)
const double * pointer () const
 get the pointer on the vector

Private Attributes

double v [4]
 internal struct

Friends

MC_v4d operator+ (const MC_v4d &vec, const double &to_add)
 add a double value to the vector
MC_v4d operator- (const MC_v4d &vec, const double &to_sub)
 substract a double value to the vector
MC_v4d operator* (const MC_v4d &vec, const double &to_mult)
 multiply a double value to the vector
MC_v4d operator* (const double &to_mult, const MC_v4d &vec)
 multiply a double value to the vector
MC_v4d operator/ (const MC_v4d &vec, const double &to_subdiv)
 divide a double value to the vector
MC_v4d operator+ (const MC_v4d &vec, const MC_v4d &to_add)
 add a v4d to the vector
MC_v4d operator- (const MC_v4d &vec, const MC_v4d &to_sub)
 substract a v4d to the vector
std::ostream & operator<< (std::ostream &stream, const MC_v4d &v)
 write the vector under the form (x,y,z,w)
MC_v4doperator>> (std::istream &stream, MC_v4d &v)
 read the vector from a istream under the form (x,y,z,w)

Detailed Description

Basic class for 4D vector.

Internal structure is a static table of double[4]

Definition at line 40 of file MC_v4d.hpp.


Constructor & Destructor Documentation

mesh_conv::MC_v4d::MC_v4d (  ) 

empty constructor of zero vector

Definition at line 14 of file MC_v4d.cpp.

References v.

Referenced by mask(), mesh_conv::MC_quaternion::MC_quaternion(), normalized(), and operator-().

00015 {v[0]=0;v[1]=0;v[2]=0;v[3]=0;}

Here is the caller graph for this function:

mesh_conv::MC_v4d::MC_v4d ( const double &  x,
const double &  y,
const double &  z,
const double &  w 
)

direct constructor from x,y,z,w

Definition at line 17 of file MC_v4d.cpp.

References v.

00018 {v[0]=x;v[1]=y;v[2]=z;v[3]=w;}

mesh_conv::MC_v4d::MC_v4d ( const MC_v4d _v  ) 

copy constructor

Definition at line 46 of file MC_v4d.cpp.

References v.

00047 {v[0]=_v[0];v[1]=_v[1];v[2]=_v[2];v[3]=_v[3];}

mesh_conv::MC_v4d::MC_v4d ( const double *  _v  ) 

constructor from pointer to double

Warning:
the pointer must have a size >=3

Definition at line 49 of file MC_v4d.cpp.

References v.

00050 {v[0]=_v[0];v[1]=_v[1];v[2]=_v[2];v[3]=_v[3];}

mesh_conv::MC_v4d::MC_v4d ( const std::string &  s  ) 

constructor from a string "(x,y,z,w)"

exemple of degenerated cases "(5,;x 4,g,8)"->MC_v4d(5,4,0,8)

Definition at line 118 of file MC_v4d.cpp.

References mesh_conv::MC_string_tokenizer::tokenize(), and v.

00119 {
00120     std::vector <std::string> v_s=mesh_conv::MC_string_tokenizer::tokenize(s," (),;");
00121 
00122     int number_ok=0;
00123     for(unsigned int k=0;number_ok<3 && k<v_s.size();k++)
00124     {
00125         bool is_converted=false;
00126         double temp_value=MC_string_converter::value_of<double>(v_s[k],&is_converted);
00127         if(is_converted==true)
00128             v[number_ok++]=temp_value;
00129     }
00130 
00131 }

Here is the call graph for this function:

mesh_conv::MC_v4d::MC_v4d ( const MC_matrix M  ) 

constructor from a matrix only if size=(4,1) or (1,4)

Definition at line 185 of file MC_v4d.cpp.

References mesh_conv::MC_matrix::size_1(), mesh_conv::MC_matrix::size_2(), and v.

00186     {
00187         if( ( M.size_1()==4 && M.size_2()==1) ||
00188             ( M.size_2()==4 && M.size_1()==1) )
00189         {v[0]=M(0);v[1]=M(1);v[2]=M(2);v[3]=M(3);}
00190     }

Here is the call graph for this function:

mesh_conv::MC_v4d::MC_v4d ( const MC_v3d vec  ) 

constructor from a MC_v3d (add 1 at the end)

mesh_conv::MC_v4d::~MC_v4d (  ) 

destructor

Definition at line 20 of file MC_v4d.cpp.

00020 {}


Member Function Documentation

double mesh_conv::MC_v4d::dot ( const MC_v4d vec  )  const

dot product between two vectors

Definition at line 166 of file MC_v4d.cpp.

References v.

Referenced by norm(), and mesh_conv::MC_quaternion::slerp().

00167     {return v[0]*vec[0]+v[1]*vec[1]+v[2]*vec[2]+v[3]*vec[3];}

Here is the caller graph for this function:

MC_v4d mesh_conv::MC_v4d::mask ( const MC_v4d scaling  )  const

apply a pointwise mask the vector

Returns:
the masked vector

Definition at line 161 of file MC_v4d.cpp.

References MC_v4d(), and v.

00161 {return MC_v4d(v[0]*scaling[0],v[1]*scaling[1],v[2]*scaling[2],v[3]*scaling[3]);}

Here is the call graph for this function:

MC_v4d mesh_conv::MC_v4d::mask ( const double &  sx,
const double &  sy,
const double &  sz,
const double &  sw 
) const

apply a pointwise mask to the vector (do not change it)

Returns:
the masked vector

Definition at line 158 of file MC_v4d.cpp.

References MC_v4d(), and v.

00159     {return MC_v4d(v[0]*sx,v[1]*sy,v[2]*sz,v[3]*sw);}

Here is the call graph for this function:

double mesh_conv::MC_v4d::norm (  )  const

norm of the vector

Definition at line 168 of file MC_v4d.cpp.

References dot().

Referenced by mesh_conv::MC_quaternion::inverted(), normalized(), and mesh_conv::MC_quaternion::quat_interp().

00169     {return sqrt(dot(*this));}

Here is the call graph for this function:

Here is the caller graph for this function:

MC_v4d mesh_conv::MC_v4d::normalized (  )  const

get the normalized vector.

Returns:
a vector of norm 1 (return (0,0,1,0) if the vector is 0)

Definition at line 170 of file MC_v4d.cpp.

References MC_v4d(), and norm().

00171     {
00172         double epsilon=0.000001;
00173         double n=norm();
00174         if(n<epsilon)
00175         {std::cout<<"Warning in MC_v4d::normalized(), norm is "<<n<<std::endl; return MC_v4d(0,0,1,0);}
00176         return (*this)/n;
00177     }

Here is the call graph for this function:

double & mesh_conv::MC_v4d::operator() ( const int &  k_dim  ) 

get operator (k_dim must be 0,1,2 or 3)

Definition at line 28 of file MC_v4d.cpp.

References v.

00029 {
00030     if(k_dim<0 || k_dim>3)
00031     {std::cout<<"Error in MC_v4d("<<k_dim<<"), size must be 0,1,2 or 3"<<std::endl;}
00032     return v[k_dim];
00033 }

const double & mesh_conv::MC_v4d::operator() ( const int &  k_dim  )  const

get operator (k_dim must be 0,1,2 or 3)

Definition at line 22 of file MC_v4d.cpp.

References v.

00023 {
00024     if(k_dim<0 || k_dim>3)
00025     {std::cout<<"Error in const MC_v4d("<<k_dim<<"), size must be 0,1 or 2"<<std::endl;}
00026     return v[k_dim];
00027 }

MC_v4d & mesh_conv::MC_v4d::operator*= ( const MC_matrix M  ) 

internal application of a matrix to the vector of MC_v4d (does the product x'=M*x)

Definition at line 182 of file MC_v4d.cpp.

References mesh_conv::MC_matrix::internal_product().

00183     {M.internal_product(this); return *this;}

Here is the call graph for this function:

MC_v4d & mesh_conv::MC_v4d::operator*= ( const double &  to_mult  ) 

internal multiplication with a double

Definition at line 89 of file MC_v4d.cpp.

References v.

00090 {
00091     v[0]*=to_mult;v[1]*=to_mult;v[2]*=to_mult;v[3]*=to_mult;
00092     return *this;
00093 }

MC_v4d & mesh_conv::MC_v4d::operator+= ( const MC_v4d to_add  ) 

internal addition

Definition at line 103 of file MC_v4d.cpp.

References v.

00103                                               {
00104     v[0]+=to_add[0];v[1]+=to_add[1];v[2]+=to_add[2];v[3]+=to_add[3];
00105     return *this;
00106 }

MC_v4d & mesh_conv::MC_v4d::operator+= ( const double &  to_add  ) 

internal addition with a double

Definition at line 78 of file MC_v4d.cpp.

References v.

00079 {
00080     v[0]+=to_add;v[1]+=to_add;v[2]+=to_add;v[3]+=to_add;
00081     return *this;
00082 }

MC_v4d mesh_conv::MC_v4d::operator- (  )  const

change the opposite sign of the current vector (unary negation)

Returns:
a new vector with opposite sign

Definition at line 52 of file MC_v4d.cpp.

References MC_v4d(), and v.

00053 {return MC_v4d(-v[0],-v[1],-v[2],-v[3]);}

Here is the call graph for this function:

MC_v4d & mesh_conv::MC_v4d::operator-= ( const MC_v4d to_sub  ) 

internal substraction

Definition at line 107 of file MC_v4d.cpp.

References v.

00107                                               {
00108     v[0]-=to_sub[0];v[1]-=to_sub[1];v[2]-=to_sub[2];v[3]-=to_sub[3];return *this;
00109 }

MC_v4d & mesh_conv::MC_v4d::operator-= ( const double &  to_sub  ) 

internal substraction with a double

Definition at line 84 of file MC_v4d.cpp.

References v.

00085 {
00086     v[0]-=to_sub;v[1]-=to_sub;v[2]-=to_sub;v[3]-=to_sub;
00087     return *this;
00088 }

MC_v4d & mesh_conv::MC_v4d::operator/= ( const double &  to_subdiv  ) 

internal divide with a double

Definition at line 94 of file MC_v4d.cpp.

References v.

00095 {
00096     double epsilon=0.000001;
00097     if(fabs(to_subdiv)<epsilon)
00098     {std::cout<<"Error in MC_v4d("<<*this<<"/="<<to_subdiv<<", divide by zero"<<std::endl;exit(-1);}
00099 
00100     v[0]/=to_subdiv;v[1]/=to_subdiv;v[2]/=to_subdiv;v[3]/=to_subdiv;
00101     return *this;
00102 }

double & mesh_conv::MC_v4d::operator[] ( const int &  k_dim  ) 

get operator (k_dim must be 0,1,2 or 3)

Definition at line 40 of file MC_v4d.cpp.

References v.

00041 {
00042     if(k_dim<0 || k_dim>3)
00043     {std::cout<<"Error in MC_v4d["<<k_dim<<"], size must be 0,1,2 or 3"<<std::endl;}
00044     return v[k_dim];
00045 }

const double & mesh_conv::MC_v4d::operator[] ( const int &  k_dim  )  const

get operator (k_dim must be 0,1,2 or 3)

Definition at line 34 of file MC_v4d.cpp.

References v.

00035 {
00036     if(k_dim<0 || k_dim>3)
00037     {std::cout<<"Error in const MC_v4d["<<k_dim<<"], size must be 0,1,2 or 3"<<std::endl;}
00038     return v[k_dim];
00039 }

const double * mesh_conv::MC_v4d::pointer (  )  const

get the pointer on the vector

Warning:
use with care

Definition at line 194 of file MC_v4d.cpp.

References v.

00195     {return &v[0];}

MC_v4d mesh_conv::MC_v4d::scale ( const double &  scaling  )  const

apply a pointwise mask to the vector

Returns:
the masked vector

Definition at line 163 of file MC_v4d.cpp.

00163 {return (*this)*scaling;}

MC_v4d & mesh_conv::MC_v4d::scale ( const double &  scaling  ) 

internal homogeneous scaling the vector

Returns:
the new vector

Definition at line 162 of file MC_v4d.cpp.

00162 {return (*this)*=scaling;}

MC_v4d & mesh_conv::MC_v4d::scale ( const MC_v4d scaling  ) 

internal scaling the vector

Returns:
the new vector

Definition at line 160 of file MC_v4d.cpp.

References v.

00160 {v[0]*=scaling[0];v[1]*=scaling[1];v[2]*=scaling[2];v[3]*=scaling[3];return *this;}

MC_v4d & mesh_conv::MC_v4d::scale ( const double &  sx,
const double &  sy,
const double &  sz,
const double &  sw 
)

internal scaling the vector

Returns:
the new vector

Definition at line 156 of file MC_v4d.cpp.

References v.

00157     {v[0]*=sx;v[1]*=sy;v[2]*=sz;v[3]*=sw;return *this;}

MC_v4d & mesh_conv::MC_v4d::set_v3d ( const MC_v3d vec  ) 

set only the 3d part without changing the 4th component

Definition at line 191 of file MC_v4d.cpp.

References v.

Referenced by mesh_conv::operator*(), and mesh_conv::MC_quaternion::operator*=().

00192     {v[0]=vec[0];v[1]=vec[1];v[2]=vec[2];return *this;}

Here is the caller graph for this function:


Friends And Related Function Documentation

MC_v4d operator* ( const double &  to_mult,
const MC_v4d vec 
) [friend]

multiply a double value to the vector

Returns:
the new vector
MC_v4d operator* ( const MC_v4d vec,
const double &  to_mult 
) [friend]

multiply a double value to the vector

Returns:
the new vector
MC_v4d operator+ ( const MC_v4d vec,
const MC_v4d to_add 
) [friend]

add a v4d to the vector

Returns:
the new vector
MC_v4d operator+ ( const MC_v4d vec,
const double &  to_add 
) [friend]

add a double value to the vector

Returns:
the new vector
MC_v4d operator- ( const MC_v4d vec,
const MC_v4d to_sub 
) [friend]

substract a v4d to the vector

Returns:
the new vector
MC_v4d operator- ( const MC_v4d vec,
const double &  to_sub 
) [friend]

substract a double value to the vector

Returns:
the new vector
MC_v4d operator/ ( const MC_v4d vec,
const double &  to_subdiv 
) [friend]

divide a double value to the vector

Returns:
the new vector
std::ostream& operator<< ( std::ostream &  stream,
const MC_v4d v 
) [friend]

write the vector under the form (x,y,z,w)

MC_v4d& operator>> ( std::istream &  stream,
MC_v4d v 
) [friend]

read the vector from a istream under the form (x,y,z,w)


Member Data Documentation

double mesh_conv::MC_v4d::v[4] [private]

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

Generated on Sun Apr 18 20:24:48 2010 by  doxygen 1.6.1