1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 #include "vectorFunctions.h"
30 vectorFunctions::vectorFunctions()
34 vectorFunctions::~vectorFunctions()
38 //---------------------------------------------------------------
39 //Copy Vector1 in Vector2 (double)
40 void vectorFunctions::copyVector(std::vector<double>*Vector1,std::vector<double>*Vector2)
42 int size = Vector1->size();
49 Vector2->push_back( (*Vector1)[i] );
53 //---------------------------------------------------------------
54 //Copy Vector1 in Vector2 (int)
55 void vectorFunctions::copyintVector(std::vector<int>*Vector1,std::vector<int>*Vector2)
57 int size = Vector1->size();
64 Vector2->push_back( (*Vector1)[i] );
68 //------------------------------------------------------------------------------------------------------------------------------------------
69 //Print 2 vectors of the same size
70 void vectorFunctions::printVector(std::vector<double>*Vector1,std::vector<double>*Vector2)
73 if( Vector1->size() == Vector2->size() )
75 for(i=0; i<Vector1->size(); i++)
77 printf("\n v1(%d) = %f, v2(%d) = %f",i,(*Vector1)[i],i,(*Vector2)[i]);
81 //------------------------------------------------------------------------------------------------------------------------------------------
82 //Returns the average value of the vector
83 double vectorFunctions::promVector(std::vector<double>*Vector1, bool OnNormal)
87 std::vector<double> tempv;
88 int size = Vector1->size();
95 suma = suma + (*Vector1)[i];
97 return prom = suma/Vector1->size();
101 copyVector(Vector1,&tempv);
104 pos = maxVector(Vector1,&maxval);
105 for(i=0; i<size; i++)
107 tempv.push_back((*Vector1)[i]/maxval);
110 for(i=0; i<tempv.size(); i++)
112 suma = suma + tempv[i];
114 return prom = suma/tempv.size();
119 //------------------------------------------------------------------------------------------------------------------------------------------
120 //Returns the maximum value of the vector
121 int vectorFunctions::maxVector(std::vector<double>*Vector1,double *val)
125 if(Vector1->size() != 0)
127 for(i=0; i<Vector1->size(); i++)
129 if( (*Vector1)[i]>max )
140 //------------------------------------------------------------------------------------------------------------------------------------------
141 //Returns the minimum value of the vector
142 int vectorFunctions::minVector(std::vector<double>*Vector1,double *val)
146 if(Vector1->size() != 0)
148 for(i=0; i<Vector1->size(); i++)
150 if( (*Vector1)[i]<min )
161 //------------------------------------------------------------------------------------------------------------------------------------------
162 //Find the minimal distance between an input point and an input lists of points
163 int vectorFunctions::nearPoint(std::vector<double>*VectorX, std::vector<double>*VectorY, double px, double py)
166 double min = 10000, dist;
167 if(VectorX->size() != 0)
169 for(i=0; i<VectorX->size(); i++)
171 dist = sqrt(pow(px-(*VectorX)[i],2) + pow(py-(*VectorY)[i],2));
182 //------------------------------------------------------------------------------------------------------------------------------------------
183 //Returns the position of the point in the lsts. (Aprox. + or - 1).
184 int vectorFunctions::findPointInLst(std::vector<double>*vecX, std::vector<double>*vecY, std::vector<double>*vecZ,
185 double x, double y, double z)
189 if(vecX->size() != 0)
191 for(i=0; i<vecX->size(); i++)
193 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) )