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