marVector Class Reference

#include <marVector.h>

List of all members.

Public Member Functions

 marVector (size_t s=3)
 marVector (double *v, size_t s)
 marVector (const marVector &v)
virtual ~marVector ()
marVectoroperator= (const marVector &o)
marVectoroperator= (double o)
marVectoroperator= (double *o)
 operator double * () const
double & operator() (size_t i)
const double & operator() (size_t i) const
bool operator== (const marVector &o) const
bool operator!= (const marVector &o) const
marVector operator+ (const marVector &o)
marVector operator+ (double o)
marVector operator+ (double *o)
marVectoroperator+= (const marVector &o)
marVectoroperator+= (double o)
marVectoroperator+= (double *o)
marVector operator- (const marVector &o)
marVector operator- (double o)
marVector operator- (double *o)
marVectoroperator-= (const marVector &o)
marVectoroperator-= (double o)
marVectoroperator-= (double *o)
marVector operator * (double o)
marVectoroperator *= (double o)
marVector operator/ (double o)
marVectoroperator/= (double o)
double dot (const marVector &o)
double dot (double *o)
marVector cross (const marVector &o)
marVector cross (double *o)
int scross (const marVector &o)
int scross (double *o)
double norm2 ()
marVector normalize ()
int snormalize ()
size_t size () const

Private Attributes

bool shallowCopy
size_t _size
double * _data

Friends

std::ostream & operator<< (std::ostream &os, const marVector &v)


Detailed Description

Definition at line 7 of file marVector.h.


Constructor & Destructor Documentation

marVector::marVector ( size_t  s = 3  ) 

Definition at line 12 of file marVector.cpp.

References _data, and _size.

Referenced by normalize().

00013         :shallowCopy(false)
00014 {
00015         if (s!=0)
00016         {
00017                 _data=new double[s];
00018                 _size=s;
00019         }
00020         else
00021         {
00022                 _data=NULL;
00023                 _size=0;
00024                 assert(false);
00025         }
00026 }

Here is the caller graph for this function:

marVector::marVector ( double *  v,
size_t  s 
)

Definition at line 40 of file marVector.cpp.

References _data, and _size.

00041         :shallowCopy(true)
00042 {
00043         if (s!=0)
00044         {
00045                 _size=s;
00046                 _data=v;
00047 // PS ->                _data=new double[_size];
00048 // PS ->                for (int i=0;i<_size;i++)
00049 // PS ->                {
00050 // PS ->                        _data[i]=v[i];
00051 // PS ->                }
00052                 
00053         }
00054         else
00055         {
00056                 _data=NULL;
00057                 _size=0;
00058                 assert(false);
00059         }
00060         
00061 }

marVector::marVector ( const marVector v  ) 

Definition at line 28 of file marVector.cpp.

References _data, and _size.

00029         :shallowCopy(false)
00030 {
00031         _size=v._size;
00032         _data=new double[_size];
00033         int i;
00034         for (i=0;i<_size;i++)
00035         {
00036                 _data[i]=v._data[i];
00037         }
00038 }

marVector::~marVector (  )  [virtual]

Definition at line 66 of file marVector.cpp.

References _data, and shallowCopy.

00067 {
00068         if (!shallowCopy) 
00069         {
00070                 delete _data;
00071         }
00072         else
00073         {
00074                 _data=NULL;
00075         }
00076 }


Member Function Documentation

marVector & marVector::operator= ( const marVector o  ) 

Definition at line 115 of file marVector.cpp.

References _data, _size, and shallowCopy.

00116 {
00117         _size=o._size;
00118         if (!(_data==NULL)&&(!shallowCopy))
00119         {
00120                 delete _data;
00121         }
00122         shallowCopy=false;
00123         _data=new double[_size];
00124         int i;
00125         for (i=0;i<_size;i++)
00126         {
00127                 _data[i]=o._data[i];
00128         }
00129         return (*this);
00130 }

marVector & marVector::operator= ( double  o  ) 

Definition at line 132 of file marVector.cpp.

References _data, _size, and shallowCopy.

00133 {
00134         if (_size!=0)
00135         {
00136                 if (!(_data==NULL)&&(!shallowCopy))
00137                 {
00138                         delete _data;
00139                 }
00140                 shallowCopy=false;
00141                 _data=new double[_size];
00142                 int i;
00143                 for (i=0;i<_size;i++)
00144                 {
00145                         _data[i]=o;
00146                 }
00147         }
00148         else
00149         {
00150                 assert(false);
00151         }
00152         return (*this);
00153 }

marVector & marVector::operator= ( double *  o  ) 

Definition at line 155 of file marVector.cpp.

References _data, _size, and shallowCopy.

00156 {
00157         if (_size!=0)
00158         {
00159                 if (!(_data==NULL)&&(!shallowCopy))
00160                 {
00161                         delete _data;
00162                 }
00163                 shallowCopy=false;
00164                 _data=new double[_size];
00165                 int i;
00166                 for (i=0;i<_size;i++)
00167                 {
00168                         _data[i]=o[i];
00169                 }
00170         }
00171         else
00172         {
00173                 assert(false);
00174         }
00175         return (*this);
00176 }

marVector::operator double * (  )  const

Definition at line 96 of file marVector.cpp.

References _data.

00097 { 
00098         return(_data);
00099 }

double & marVector::operator() ( size_t  i  ) 

Definition at line 103 of file marVector.cpp.

References _data.

00104 { 
00105         return(_data[i]);
00106 }

const double & marVector::operator() ( size_t  i  )  const

Definition at line 108 of file marVector.cpp.

References _data.

00109 {
00110         return(_data[i]);
00111 }

bool marVector::operator== ( const marVector o  )  const

Definition at line 180 of file marVector.cpp.

References _data, and _size.

00181 {
00182     bool equal=true;
00183         
00184     if(_size!=o._size)
00185         {
00186                 return(false);
00187         }
00188         
00189         int i;
00190         for(i=0;i<_size && equal;i++)
00191         {
00192                 equal=equal && (_data[i]==o._data[i]); 
00193         }
00194     return(equal);
00195 }

bool marVector::operator!= ( const marVector o  )  const

Definition at line 197 of file marVector.cpp.

00198 {
00199         return(!((*this)==o));
00200 }

marVector marVector::operator+ ( const marVector o  ) 

Definition at line 204 of file marVector.cpp.

References _data, and _size.

00205 {
00206         marVector result(*this);
00207         size_t s=result._size;
00208         
00209         if ((o._size!=s) || (s==0))
00210         {
00211                 assert(false);
00212         }
00213         else 
00214         {
00215                 for (int i=0;i < s;i++)
00216                 {
00217                         result._data[i] +=o._data[i];
00218                 }
00219         }
00220         return result;
00221 }

marVector marVector::operator+ ( double  o  ) 

Definition at line 223 of file marVector.cpp.

References _data, and _size.

00224 {
00225         marVector result(*this);
00226         size_t s=result._size;
00227         
00228         if (s==0)
00229         {
00230                 assert(false);
00231         }
00232         else 
00233         {
00234                 for (int i=0;i < s;i++)
00235                 {
00236                         result._data[i] +=o;
00237                 }
00238         }
00239         return result;
00240 }

marVector marVector::operator+ ( double *  o  ) 

Definition at line 242 of file marVector.cpp.

References _data, and _size.

00243 {
00244         marVector result(*this);
00245         size_t s=result._size;
00246         
00247         if (s==0)
00248         {
00249                 assert(false);
00250         }
00251         else 
00252         {
00253                 for (int i=0;i < s;i++)
00254                 {
00255                         result._data[i] +=o[i];
00256                 }
00257         }
00258         return result;
00259 }

marVector & marVector::operator+= ( const marVector o  ) 

Definition at line 263 of file marVector.cpp.

References _data, and _size.

00264 {
00265         if ((o._size!=_size) || (_size==0))
00266         {
00267                 assert(false);          
00268         }
00269         else 
00270         {
00271                 for (int i=0;i < _size;i++)
00272                 {
00273                         _data[i] +=o._data[i];
00274                 }
00275         }
00276         return (*this);
00277 }

marVector & marVector::operator+= ( double  o  ) 

Definition at line 279 of file marVector.cpp.

References _data, and _size.

00280 {
00281         if (_size==0)
00282         {
00283                 assert(false);  
00284         }
00285         else 
00286         {
00287                 for (int i=0;i < _size;i++)
00288                 {
00289                         _data[i] +=o;
00290                 }
00291         }
00292     return(*this);
00293 }

marVector & marVector::operator+= ( double *  o  ) 

Definition at line 295 of file marVector.cpp.

References _data, and _size.

00296 {
00297         if (_size==0)
00298         {
00299                 assert(false);          
00300         }
00301         else 
00302         {
00303                 for (int i=0;i < _size;i++)
00304                 {
00305                         _data[i] +=o[i];
00306                 }
00307         }
00308     return(*this);
00309 }

marVector marVector::operator- ( const marVector o  ) 

Definition at line 313 of file marVector.cpp.

References _data, and _size.

00314 {
00315         marVector result(*this);
00316         size_t s=result._size;
00317         
00318         if ((o._size !=s) || (s==0))
00319         {
00320                 assert(false);          
00321         }
00322         else 
00323         {
00324                 for (int i=0;i < s;i++)
00325                 {
00326                         result._data[i] -=o._data[i];
00327                 }
00328         }
00329         return result;
00330 }

marVector marVector::operator- ( double  o  ) 

Definition at line 332 of file marVector.cpp.

References _data, and _size.

00333 {
00334         marVector result(*this);
00335         size_t s=result._size;
00336         
00337         if (s==0)
00338         {
00339                 assert(false);  
00340         }
00341         else 
00342         {
00343                 for (int i=0;i < s;i++)
00344                 {
00345                         result._data[i] -=o;
00346                 }
00347         }
00348         return result;
00349 }

marVector marVector::operator- ( double *  o  ) 

Definition at line 351 of file marVector.cpp.

References _data, and _size.

00352 {
00353         marVector result(*this);
00354         size_t s=result._size;
00355         
00356         if (s==0)
00357         {
00358                 assert(false);          
00359         }
00360         else 
00361         {
00362                 for (int i=0;i < s;i++)
00363                 {
00364                         result._data[i] -=o[i];
00365                 }
00366         }
00367         return result;
00368 }

marVector & marVector::operator-= ( const marVector o  ) 

Definition at line 372 of file marVector.cpp.

References _data, and _size.

00373 {
00374         if ((o._size!=_size) || (_size==0))
00375         {
00376                 assert(false);          
00377         }
00378         else 
00379         {
00380                 for (int i=0;i < _size;i++)
00381                 {
00382                         _data[i] -=o._data[i];
00383                 }
00384         }
00385         return (*this);
00386 }

marVector & marVector::operator-= ( double  o  ) 

Definition at line 388 of file marVector.cpp.

References _data, and _size.

00389 {
00390         if (_size==0)
00391         {
00392                 assert(false);  
00393         }
00394         else 
00395         {
00396                 for (int i=0;i < _size;i++)
00397                 {
00398                         _data[i] -=o;
00399                 }
00400         }
00401     return(*this);
00402 }

marVector & marVector::operator-= ( double *  o  ) 

Definition at line 404 of file marVector.cpp.

References _data, and _size.

00405 {
00406         if (_size==0)
00407         {
00408                 assert(false);          
00409         }
00410         else 
00411         {
00412                 for (int i=0;i < _size;i++)
00413                 {
00414                         _data[i] -=o[i];
00415                 }
00416         }
00417     return(*this);
00418 }

marVector marVector::operator * ( double  o  ) 

Definition at line 422 of file marVector.cpp.

References _data, and _size.

00423 {
00424         marVector result(*this);
00425         size_t s=result._size;
00426         
00427         if (s==0)
00428         {
00429                 assert(false);  
00430         }
00431         else 
00432         {
00433                 for (int i=0;i < s;i++)
00434                 {
00435                         result._data[i]*=o;
00436                 }
00437         }
00438         return result;
00439 }

marVector & marVector::operator *= ( double  o  ) 

Definition at line 443 of file marVector.cpp.

References _data, and _size.

00444 {
00445         if (_size==0)
00446         {
00447                 assert(false);  
00448         }
00449         else 
00450         {
00451                 for (int i=0;i < _size;i++)
00452                 {
00453                         _data[i]*=o;
00454                 }
00455         }
00456     return(*this);
00457 }

marVector marVector::operator/ ( double  o  ) 

Definition at line 461 of file marVector.cpp.

References _data, and _size.

00462 {
00463         marVector result(*this);
00464         size_t s=result._size;
00465         
00466         if (s==0)
00467         {
00468                 assert(false);  
00469         }
00470         else 
00471         {
00472                 for (int i=0;i < s;i++)
00473                 {
00474                         result._data[i] /=o;
00475                 }
00476         }
00477         return result;
00478 }

marVector & marVector::operator/= ( double  o  ) 

Definition at line 482 of file marVector.cpp.

References _data, and _size.

00483 {
00484         if (_size==0)
00485         {
00486                 assert(false);  
00487         }
00488         else 
00489         {
00490                 for (int i=0;i < _size;i++)
00491                 {
00492                         _data[i] /=o;
00493                 }
00494         }
00495     return(*this);
00496 }

double marVector::dot ( const marVector o  ) 

Definition at line 503 of file marVector.cpp.

References _data, and _size.

00504 {
00505     double result;
00506         if ((_size!=o._size) || (_size==0))
00507         {
00508                 assert(false); 
00509         }
00510         else
00511         {
00512                 result=0.0;
00513                 for (int i=0;i<_size;i++)
00514                 {
00515                         result+=(_data[i]*o._data[i]);
00516                 }
00517         }
00518         return result;
00519 }

double marVector::dot ( double *  o  ) 

Definition at line 521 of file marVector.cpp.

References _data, and _size.

00522 {
00523     double result;
00524         if (_size==0)
00525         {
00526                 assert(false); 
00527         }
00528         else
00529         {
00530                 result=0.0;
00531                 for (int i=0;i<_size;i++)
00532                 {
00533                         result+=(_data[i]*o[i]);
00534                 }
00535         }
00536         return result;
00537 }

marVector marVector::cross ( const marVector o  ) 

Definition at line 541 of file marVector.cpp.

References _data, and _size.

Referenced by scross().

00542 {
00543     marVector result(*this);
00544         if ((o._size!=_size) || (_size!=3))
00545         {
00546                 assert(false); 
00547         }
00548         else
00549         {
00550                 double S,s;
00551                 
00552                 // 1st element
00553                 S=_data[1]*o._data[2];
00554                 s=_data[2]*o._data[1];
00555                 result._data[0]=S - s;
00556                 
00557                 // 2nd element
00558                 S=_data[2]*o._data[0];
00559                 s=_data[0]*o._data[2];
00560                 result._data[1]=S - s;
00561                 
00562                 // 3rd element
00563                 S=_data[0]*o._data[1];
00564                 s=_data[1]*o._data[0];
00565                 result._data[2]=S - s;
00566         }
00567     return(result);    
00568 }

Here is the caller graph for this function:

marVector marVector::cross ( double *  o  ) 

Definition at line 570 of file marVector.cpp.

References _data, and _size.

00571 {
00572     marVector result(*this);
00573         if (_size!=3)
00574         {
00575                 assert(false); 
00576         }
00577         else
00578         {
00579                 double S,s;
00580                 
00581                 // 1st element
00582                 S=_data[1]*o[2];
00583                 s=_data[2]*o[1];
00584                 result._data[0]=S - s;
00585                 
00586                 // 2nd element
00587                 S=_data[2]*o[0];
00588                 s=_data[0]*o[2];
00589                 result._data[1]=S - s;
00590                 
00591                 // 3rd element
00592                 S=_data[0]*o[1];
00593                 s=_data[1]*o[0];
00594                 result._data[2]=S - s;
00595         }
00596     return(result);
00597 }

int marVector::scross ( const marVector o  ) 

Definition at line 599 of file marVector.cpp.

References _size, and cross().

00600 {
00601         if ((o._size!=_size) && (_size!=3))
00602         {
00603                 return (1);
00604         }
00605         else
00606         {
00607                 *this=cross(o);
00608                 return(0);
00609         } 
00610 }

Here is the call graph for this function:

int marVector::scross ( double *  o  ) 

Definition at line 612 of file marVector.cpp.

References _size, and cross().

00613 {
00614         if (_size!=3)
00615         {
00616                 return (1);
00617         }
00618         else
00619         {
00620                 *this=cross(o);
00621                 return(0);
00622         } 
00623 }

Here is the call graph for this function:

double marVector::norm2 (  ) 

Definition at line 627 of file marVector.cpp.

References _data, and _size.

Referenced by marAxis::getAxisLenght(), normalize(), and snormalize().

00630 {
00631         
00632         double norme2=0.0;
00633         if (_size==0)
00634         {
00635                 assert(false);
00636         }
00637         else
00638         {
00639                 const double seuil1=pow( 2., 154. ),seuil2=1/seuil1;
00640                 double n1=0; /* les sommes partielles */
00641                 double n2=0;
00642                 double n3=0;
00643                 double n4;
00644                 int i;
00645                 for ( i=0; i<_size; i++ ) 
00646                 {
00647                         double x=_data[i];      /* x=abs(vecteur[i]) */
00648                         
00649                         if (x<0) 
00650                         { 
00651                                 x=-x;
00652                         }
00653                         /* sommation par classe */
00654                         if ( x > seuil1 ) 
00655                         {
00656                                 x *=seuil2;
00657                                 n1 +=x*x;
00658                         } 
00659                         else if ( x < seuil2 ) 
00660                         {
00661                                 x  *=seuil1;
00662                                 n2 +=x*x;
00663                         } 
00664                         else
00665                         {
00666                                 n3 +=x*x;
00667                         }
00668                 }
00669                 
00670                 n3=sqrt(n3);
00671                 if (n1>0)
00672                 {
00673                         n4=seuil1 * sqrt(n1);
00674                 }
00675                 else
00676                 {
00677                         n4=seuil2 * sqrt(n2);
00678                 }
00679                 
00680 // EED 
00681 /*
00682                 if (n3 < n4) 
00683                 {
00684                         n3 /=n4;
00685                         norme2=n4 * sqrt( 1 + n3*n3 );
00686                 } 
00687                 else 
00688                 {
00689                         n4 /=n3;
00690                         norme2=n3 * sqrt( 1 + n4*n4 );
00691                 }
00692 */
00693                 norme2=n3;
00694         }
00695         return norme2;
00696 }

Here is the caller graph for this function:

marVector marVector::normalize (  ) 

Definition at line 700 of file marVector.cpp.

References marVector(), and norm2().

00701 {
00702         marVector result=marVector(*this);
00703         result *= (1/result.norm2());
00704         return result;
00705 }

Here is the call graph for this function:

int marVector::snormalize (  ) 

Definition at line 707 of file marVector.cpp.

References norm2().

00708 {
00709         (*this)*=(1/this->norm2());
00710         return(0);
00711 }// renvoie 0 si OK, 1 sinon

Here is the call graph for this function:

size_t marVector::size (  )  const

Definition at line 717 of file marVector.cpp.

References _size.

Referenced by marMatrix::operator *(), and operator<<().

00718 {
00719         return _size;
00720 }

Here is the caller graph for this function:


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const marVector v 
) [friend]

Definition at line 83 of file marVector.cpp.

00084 {
00085         int i;
00086     for(i=0;i < v.size();i++) 
00087         {
00088                 os << " " << v(i);
00089         }
00090         os <<"\n";
00091     return(os);
00092 }


Member Data Documentation

bool marVector::shallowCopy [private]

Definition at line 92 of file marVector.h.

Referenced by operator=(), and ~marVector().

size_t marVector::_size [private]

Definition at line 93 of file marVector.h.

Referenced by cross(), dot(), marVector(), norm2(), operator *(), operator *=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), operator=(), operator==(), scross(), and size().

double* marVector::_data [private]

Definition at line 94 of file marVector.h.

Referenced by cross(), dot(), marVector(), norm2(), operator *(), operator *=(), operator double *(), operator()(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), operator=(), operator==(), and ~marVector().


The documentation for this class was generated from the following files:
Generated on Wed Jul 29 16:36:02 2009 for creaMaracasVisu_lib by  doxygen 1.5.3