]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/Contour/vectorFunctions.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / Contour / vectorFunctions.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
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
8 #
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.
15 #
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
20 #  liability.
21 #
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 # ------------------------------------------------------------------------ */
25
26 #include "vectorFunctions.h"
27 #include <stdio.h>
28
29 //Constructor
30 vectorFunctions::vectorFunctions()
31 {
32 }
33 //Destructor
34 vectorFunctions::~vectorFunctions()
35 {
36 }
37
38 //---------------------------------------------------------------
39 //Copy Vector1 in Vector2 (double)
40 void vectorFunctions::copyVector(std::vector<double>*Vector1,std::vector<double>*Vector2)
41 {
42         int size = Vector1->size();
43         Vector2->clear();
44         int i;
45         if(size != 0)
46         {
47                 for(i=0; i<size; i++)
48                 {
49                         Vector2->push_back( (*Vector1)[i] );
50                 }
51         }
52 }
53 //---------------------------------------------------------------
54 //Copy Vector1 in Vector2 (int)
55 void vectorFunctions::copyintVector(std::vector<int>*Vector1,std::vector<int>*Vector2)
56 {
57         int size = Vector1->size();
58         Vector2->clear();
59         int i;
60         if( size != 0)
61         {
62                 for(i=0; i<size; i++)
63                 {
64                         Vector2->push_back( (*Vector1)[i] );
65                 }
66         }
67 }
68 //------------------------------------------------------------------------------------------------------------------------------------------
69 //Print 2 vectors of the same size
70 void vectorFunctions::printVector(std::vector<double>*Vector1,std::vector<double>*Vector2)
71 {
72         int i;
73         if( Vector1->size() == Vector2->size() )
74         {
75                 for(i=0; i<Vector1->size(); i++)
76                 {
77                         printf("\n v1(%d) = %f, v2(%d) = %f",i,(*Vector1)[i],i,(*Vector2)[i]);
78                 }
79         }
80 }
81 //------------------------------------------------------------------------------------------------------------------------------------------
82 //Returns the average value of the vector
83 double vectorFunctions::promVector(std::vector<double>*Vector1, bool OnNormal)
84 {
85         int i;
86         double suma = 0,prom;
87         std::vector<double> tempv;
88         int size = Vector1->size();
89         if(size != 0)
90         {
91                 if(OnNormal == false)
92                 {
93                         for(i=0; i<size; i++)
94                         {
95                                 suma = suma + (*Vector1)[i];
96                         }
97                         return prom = suma/Vector1->size();
98                 }
99                 int pos;
100                 double maxval;
101                 copyVector(Vector1,&tempv);
102                 if(OnNormal == true)
103                 {
104                         pos = maxVector(Vector1,&maxval);
105                         for(i=0; i<size; i++)
106                         {
107                                 tempv.push_back((*Vector1)[i]/maxval);
108                         }
109                         suma = 0;
110                         for(i=0; i<tempv.size(); i++)
111                         {
112                                 suma = suma + tempv[i];
113                         }
114                         return prom = suma/tempv.size();
115                 }
116         }
117         return -1;
118 }
119 //------------------------------------------------------------------------------------------------------------------------------------------
120 //Returns the maximum value of the vector
121 int vectorFunctions::maxVector(std::vector<double>*Vector1,double *val)
122 {
123         int i, pos;
124         double max = -1;
125         if(Vector1->size() != 0)
126         {
127                 for(i=0; i<Vector1->size(); i++)
128                 {
129                         if( (*Vector1)[i]>max )
130                         {
131                                 max = (*Vector1)[i];
132                                 pos = i;
133                         }
134                 }
135                 *val = max;
136                 return pos;
137         }
138         return -1;
139 }
140 //------------------------------------------------------------------------------------------------------------------------------------------
141 //Returns the minimum value of the vector
142 int vectorFunctions::minVector(std::vector<double>*Vector1,double *val)
143 {
144         int i, pos;
145         double min = 99999;
146         if(Vector1->size() != 0)
147         {
148                 for(i=0; i<Vector1->size(); i++)
149                 {
150                         if( (*Vector1)[i]<min )
151                         {
152                                 min = (*Vector1)[i];
153                                 pos = i;
154                         }
155                 }
156                 *val = min;
157                 return pos;
158         }
159         return -1;
160 }
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)
164 {
165         int i, pos = -1;
166         double min = 10000, dist;
167         if(VectorX->size() != 0)
168         {
169                 for(i=0; i<VectorX->size(); i++)
170                 {
171                         dist = sqrt(pow(px-(*VectorX)[i],2) + pow(py-(*VectorY)[i],2));
172                         if(dist<min)
173                         {
174                                 min = dist;
175                                 pos = i;
176                         }
177                 }
178                 return pos;
179         }
180         return -1;
181 }
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)
186 {
187         int i,flag = -1;
188         double apr = 1.5;
189         if(vecX->size() != 0)
190         {
191                 for(i=0; i<vecX->size(); i++)
192                 {
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) )
194                         {
195                                 flag = i;
196                                 return i; 
197                         }
198                 }
199                 return flag;
200         }
201         return -1;
202 }