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 # ------------------------------------------------------------------------ */
27 #include "PlanesOperations.h"
29 /********************************************************************************************
30 ** Start of data viewmanagerData
31 *********************************************************************************************/
35 PlanesOperations::PlanesOperations()
40 PlanesOperations::~PlanesOperations()
46 double* PlanesOperations::getCrossProduct(double* vect0,double* vect1)
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]);
57 ** Returns the magnitud of the given vector
59 double PlanesOperations::getMagnitud(double* vect)
63 mag = sqrt(pow(vect[0],2) + pow(vect[1],2) + pow(vect[2],2));
65 //std::cout<<"mag "<<mag <<std::endl;
70 ** returns the unitary vector of the given vector
71 ** u = 1/|vect| . vect
73 double* PlanesOperations::getNormal(double* vect)
77 double mag = getMagnitud(vect);
79 vectnorm = new double[3];
82 vectnorm[0] = vect[0]/mag;
83 vectnorm[1] = vect[1]/mag;
84 vectnorm[2] = vect[2]/mag;
93 double* PlanesOperations::makeVector(double *podouble0, double *podouble1)
98 vect[0]= podouble1[0]-podouble0[0];
99 vect[1]= podouble1[1]-podouble0[1];
100 vect[2]= podouble1[2]-podouble0[2];
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]);
111 void PlanesOperations::getNormal(double* vect, double* vectnorm){
113 double mag = getMagnitud(vect);
116 vectnorm[0] = vect[0]/mag;
117 vectnorm[1] = vect[1]/mag;
118 vectnorm[2] = vect[2]/mag;
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];
132 double PlanesOperations::getDotProduct(double* vect0,double* vect1){
133 return vect0[0]*vect1[0] + vect0[1]*vect1[1] + vect0[2]*vect1[2];
136 void PlanesOperations::addVectors(double* vect0, double* vect1, double*vectres){
138 vectres[0]= vect0[0] + vect1[0];
139 vectres[1]= vect0[1] + vect1[1];
140 vectres[2]= vect0[2] + vect1[2];
143 void PlanesOperations::scalarVector(double* vect0, double scalar, double*vectres){
145 vectres[0]= vect0[0]*scalar;
146 vectres[1]= vect0[1]*scalar;
147 vectres[2]= vect0[2]*scalar;
150 vector<double> PlanesOperations::getCrossProduct(vector<double> vect0,vector<double> vect1){
152 vector<double> vectCross;
154 for(unsigned i = 0; i < vect0.size(); i++){
156 unsigned ii = (i + 1 == vect0.size())? 0: i + 1;
157 unsigned iii = (ii + 1 == vect0.size())? 0: ii + 1;
159 vectCross.push_back( vect0[ii]*vect1[iii]- vect0[iii]*vect1[ii] );
165 double PlanesOperations::getDotProduct(vector<double> vect0,vector<double> vect1){
169 for(unsigned i = 0; i < vect0.size(); i++) sum += vect0[i]*vect1[i];
173 vector<double> PlanesOperations::getNormal(vector<double> vect){
174 vector<double> vectnorm;
175 double mag = getMagnitud(vect);
177 for(unsigned i = 0; i < vect.size(); i++){
180 vectnorm.push_back(vect[i]/mag);
182 vectnorm.push_back(0);
187 double PlanesOperations::getMagnitud(vector<double> vect){
190 for(unsigned i = 0; i < vect.size(); i++) mag += pow(vect[i], 2);
194 //std::cout<<"mag "<<mag <<std::endl;
198 vector<double> PlanesOperations::makeVector(vector<double> podouble0, vector<double> podouble1){
200 vector<double> vector;
202 for(unsigned i = 0; i < podouble0.size(); i++){
203 vector.push_back(podouble1[i] - podouble0[i]);
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
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]);
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
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);