vectorFunctions.cxx

Go to the documentation of this file.
00001 #include "vectorFunctions.h"
00002 #include <stdio.h>
00003 
00004 //Constructor
00005 vectorFunctions::vectorFunctions()
00006 {
00007 }
00008 //Destructor
00009 vectorFunctions::~vectorFunctions()
00010 {
00011 }
00012 
00013 //---------------------------------------------------------------
00014 //Copy Vector1 in Vector2 (double)
00015 void vectorFunctions::copyVector(std::vector<double>*Vector1,std::vector<double>*Vector2)
00016 {
00017         int size = Vector1->size();
00018         Vector2->clear();
00019         int i;
00020         if(size != 0)
00021         {
00022                 for(i=0; i<size; i++)
00023                 {
00024                         Vector2->push_back( (*Vector1)[i] );
00025                 }
00026         }
00027 }
00028 //---------------------------------------------------------------
00029 //Copy Vector1 in Vector2 (int)
00030 void vectorFunctions::copyintVector(std::vector<int>*Vector1,std::vector<int>*Vector2)
00031 {
00032         int size = Vector1->size();
00033         Vector2->clear();
00034         int i;
00035         if( size != 0)
00036         {
00037                 for(i=0; i<size; i++)
00038                 {
00039                         Vector2->push_back( (*Vector1)[i] );
00040                 }
00041         }
00042 }
00043 //------------------------------------------------------------------------------------------------------------------------------------------
00044 //Print 2 vectors of the same size
00045 void vectorFunctions::printVector(std::vector<double>*Vector1,std::vector<double>*Vector2)
00046 {
00047         int i;
00048         if( Vector1->size() == Vector2->size() )
00049         {
00050                 for(i=0; i<Vector1->size(); i++)
00051                 {
00052                         printf("\n v1(%d) = %f, v2(%d) = %f",i,(*Vector1)[i],i,(*Vector2)[i]);
00053                 }
00054         }
00055 }
00056 //------------------------------------------------------------------------------------------------------------------------------------------
00057 //Returns the average value of the vector
00058 double vectorFunctions::promVector(std::vector<double>*Vector1, bool OnNormal)
00059 {
00060         int i;
00061         double suma = 0,prom;
00062         std::vector<double> tempv;
00063         int size = Vector1->size();
00064         if(size != 0)
00065         {
00066                 if(OnNormal == false)
00067                 {
00068                         for(i=0; i<size; i++)
00069                         {
00070                                 suma = suma + (*Vector1)[i];
00071                         }
00072                         return prom = suma/Vector1->size();
00073                 }
00074                 int pos;
00075                 double maxval;
00076                 copyVector(Vector1,&tempv);
00077                 if(OnNormal == true)
00078                 {
00079                         pos = maxVector(Vector1,&maxval);
00080                         for(i=0; i<size; i++)
00081                         {
00082                                 tempv.push_back((*Vector1)[i]/maxval);
00083                         }
00084                         suma = 0;
00085                         for(i=0; i<tempv.size(); i++)
00086                         {
00087                                 suma = suma + tempv[i];
00088                         }
00089                         return prom = suma/tempv.size();
00090                 }
00091         }
00092         return -1;
00093 }
00094 //------------------------------------------------------------------------------------------------------------------------------------------
00095 //Returns the maximum value of the vector
00096 int vectorFunctions::maxVector(std::vector<double>*Vector1,double *val)
00097 {
00098         int i, pos;
00099         double max = -1;
00100         if(Vector1->size() != 0)
00101         {
00102                 for(i=0; i<Vector1->size(); i++)
00103                 {
00104                         if( (*Vector1)[i]>max )
00105                         {
00106                                 max = (*Vector1)[i];
00107                                 pos = i;
00108                         }
00109                 }
00110                 *val = max;
00111                 return pos;
00112         }
00113         return -1;
00114 }
00115 //------------------------------------------------------------------------------------------------------------------------------------------
00116 //Returns the minimum value of the vector
00117 int vectorFunctions::minVector(std::vector<double>*Vector1,double *val)
00118 {
00119         int i, pos;
00120         double min = 99999;
00121         if(Vector1->size() != 0)
00122         {
00123                 for(i=0; i<Vector1->size(); i++)
00124                 {
00125                         if( (*Vector1)[i]<min )
00126                         {
00127                                 min = (*Vector1)[i];
00128                                 pos = i;
00129                         }
00130                 }
00131                 *val = min;
00132                 return pos;
00133         }
00134         return -1;
00135 }
00136 //------------------------------------------------------------------------------------------------------------------------------------------
00137 //Find the minimal distance between an input point and an input lists of points
00138 int vectorFunctions::nearPoint(std::vector<double>*VectorX, std::vector<double>*VectorY, double px, double py)
00139 {
00140         int i, pos = -1;
00141         double min = 10000, dist;
00142         if(VectorX->size() != 0)
00143         {
00144                 for(i=0; i<VectorX->size(); i++)
00145                 {
00146                         dist = sqrt(pow(px-(*VectorX)[i],2) + pow(py-(*VectorY)[i],2));
00147                         if(dist<min)
00148                         {
00149                                 min = dist;
00150                                 pos = i;
00151                         }
00152                 }
00153                 return pos;
00154         }
00155         return -1;
00156 }
00157 //------------------------------------------------------------------------------------------------------------------------------------------
00158 //Returns the position of the point in the lsts. (Aprox. + or - 1).
00159 int vectorFunctions::findPointInLst(std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ, 
00160                                                                         double x, double y, double z)
00161 {
00162         int i,flag = -1;
00163         double apr = 1.5;
00164         if(vecX->size() != 0)
00165         {
00166                 for(i=0; i<vecX->size(); i++)
00167                 {
00168                         if( ((*vecX)[i]-apr <= x)&&(x <=(*vecX)[i]+apr)&&((*vecY)[i]-apr <= y)&&(y <=(*vecY)[i]+apr)&&((*vecZ)[i]-apr <= z)&&(z <=(*vecZ)[i]+apr) )
00169                         {
00170                                 flag = i;
00171                                 return i; 
00172                         }
00173                 }
00174                 return flag;
00175         }
00176         return -1;
00177 }

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1