]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/kernel/PlanesOperations.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / kernel / PlanesOperations.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
27 #include "PlanesOperations.h"
28
29 /********************************************************************************************
30 ** Start of data viewmanagerData
31 *********************************************************************************************/
32
33 using namespace std;
34
35 PlanesOperations::PlanesOperations()
36 {       
37 }
38
39
40 PlanesOperations::~PlanesOperations()
41 {
42
43 }
44
45
46 double* PlanesOperations::getCrossProduct(double* vect0,double* vect1)
47 {
48         double* vectCross;
49         vectCross = new double[3];
50         vectCross[0] = vect0[1]*vect1[2]-(vect0[2]*vect1[1]);
51         vectCross[1] = -(vect0[0]*vect1[2]-(vect0[2]*vect1[0]));
52         vectCross[2] = vect0[0]*vect1[1]-(vect0[1]*vect1[0]);
53
54         return vectCross;
55 }
56 /**
57 **      Returns the magnitud of the given vector
58 **/
59 double PlanesOperations::getMagnitud(double* vect)
60 {
61         double mag;
62
63         mag = sqrt(pow(vect[0],2) + pow(vect[1],2) + pow(vect[2],2));
64
65         //std::cout<<"mag "<<mag <<std::endl;
66
67         return mag;
68 }
69 /**
70 **      returns the unitary vector of the given vector
71 **      u = 1/|vect| . vect
72 **/
73 double* PlanesOperations::getNormal(double* vect)
74 {
75
76         double* vectnorm;
77         double mag = getMagnitud(vect);
78
79         vectnorm = new double[3];
80         
81         if(mag!=0){
82                 vectnorm[0] = vect[0]/mag;
83                 vectnorm[1] = vect[1]/mag;
84                 vectnorm[2] = vect[2]/mag;
85         }else{
86                 vectnorm[0] = 0;
87                 vectnorm[1] = 0;
88                 vectnorm[2] = 0;
89         }
90         return vectnorm;
91 }
92
93 double* PlanesOperations::makeVector(double *podouble0, double *podouble1)
94 {
95         double *vect;
96         vect = new double[3];
97
98         vect[0]= podouble1[0]-podouble0[0];
99         vect[1]= podouble1[1]-podouble0[1];
100         vect[2]= podouble1[2]-podouble0[2];
101
102         return vect;
103 }
104
105 void PlanesOperations::getCrossProduct(double* vect0,double* vect1, double* vectres){
106     vectres[0] = vect0[1]*vect1[2]-(vect0[2]*vect1[1]);
107     vectres[1] = -(vect0[0]*vect1[2]-(vect0[2]*vect1[0]));
108     vectres[2] = vect0[0]*vect1[1]-(vect0[1]*vect1[0]);
109 }
110
111 void PlanesOperations::getNormal(double* vect, double* vectnorm){
112
113     double mag = getMagnitud(vect);
114
115     if(mag!=0){
116             vectnorm[0] = vect[0]/mag;
117             vectnorm[1] = vect[1]/mag;
118             vectnorm[2] = vect[2]/mag;
119     }else{
120             vectnorm[0] = 0;
121             vectnorm[1] = 0;
122             vectnorm[2] = 0;
123     }
124 }
125
126 void PlanesOperations::makeVector(double* podouble0, double* podouble1, double* vectres){
127     vectres[0] = podouble1[0] - podouble0[0];
128     vectres[1] = podouble1[1] - podouble0[1];
129     vectres[2] = podouble1[2] - podouble0[2];
130 }
131
132 double PlanesOperations::getDotProduct(double* vect0,double* vect1){
133         return vect0[0]*vect1[0] + vect0[1]*vect1[1] + vect0[2]*vect1[2];
134 }
135
136 void PlanesOperations::addVectors(double* vect0, double* vect1, double*vectres){
137
138     vectres[0]= vect0[0] + vect1[0];
139     vectres[1]= vect0[1] + vect1[1];
140     vectres[2]= vect0[2] + vect1[2];
141 }
142
143 void PlanesOperations::scalarVector(double* vect0, double scalar, double*vectres){
144
145     vectres[0]= vect0[0]*scalar;
146     vectres[1]= vect0[1]*scalar;
147     vectres[2]= vect0[2]*scalar;
148 }
149
150 vector<double> PlanesOperations::getCrossProduct(vector<double> vect0,vector<double> vect1){
151   
152         vector<double> vectCross;
153         
154         for(unsigned i = 0; i < vect0.size(); i++){
155           
156           unsigned ii = (i + 1 == vect0.size())? 0: i + 1;
157           unsigned iii = (ii + 1 == vect0.size())? 0: ii + 1;
158           
159           vectCross.push_back( vect0[ii]*vect1[iii]- vect0[iii]*vect1[ii] );
160           
161         }
162         return vectCross;
163   
164 }
165 double  PlanesOperations::getDotProduct(vector<double> vect0,vector<double> vect1){
166   
167   double sum = 0;
168   
169   for(unsigned i = 0; i < vect0.size(); i++) sum += vect0[i]*vect1[i];
170   
171   return sum;
172 }
173 vector<double> PlanesOperations::getNormal(vector<double> vect){
174         vector<double> vectnorm;
175         double mag = getMagnitud(vect); 
176         
177         for(unsigned i = 0; i < vect.size(); i++){
178           
179           if(mag != 0){
180             vectnorm.push_back(vect[i]/mag);
181           }else{
182             vectnorm.push_back(0);
183           }
184         }
185         return vectnorm;
186 }
187 double  PlanesOperations::getMagnitud(vector<double> vect){
188   double mag = 0;
189   
190   for(unsigned i = 0; i < vect.size(); i++) mag += pow(vect[i], 2);
191   
192   mag = sqrt(mag);
193
194   //std::cout<<"mag "<<mag <<std::endl;
195
196   return mag;
197 }
198 vector<double> PlanesOperations::makeVector(vector<double> podouble0, vector<double> podouble1){
199   
200   vector<double> vector;
201   
202   for(unsigned i = 0; i < podouble0.size(); i++){    
203     vector.push_back(podouble1[i] - podouble0[i]);    
204   }
205   return vector;
206 }
207
208 /**
209 *    Adds to vectors, the result is in vectres;
210 *@param double* vect0, the first vector
211 *@param double* vect1, the second vector
212 *@param double* vectres, the resulting vector
213 */
214 vector<double> PlanesOperations::addVectors(vector<double> vect0, vector<double> vect1){
215     vector<double> vectres;
216     for(unsigned i = 0; i < vect0.size(); i++){
217         vectres.push_back(vect0[i] + vect1[i]);
218     }
219     return vectres;
220 }
221
222 /**
223 *    multiply a vector with a given scalar
224 *@param double* vect0, the vector
225 *@param double scalar, the scalar value
226 *@param double* vectres, the resulting vector
227 */
228 vector<double> PlanesOperations::scalarVector(vector<double> vect0, double scalar){
229     vector<double> vectres;
230     for(unsigned i = 0; i < vect0.size(); i++){
231         vectres.push_back(vect0[i]*scalar);
232     }
233     return vectres;
234 }
235