]> Creatis software - creaRigidRegistration.git/blob - lib/PlanesOperations.cxx
Feature #1766 Add licence terms for all files.
[creaRigidRegistration.git] / lib / PlanesOperations.cxx
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and 
11 #  abiding by the rules of distribution of free software. You can  use, 
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
13 #  license as circulated by CEA, CNRS and INRIA at the following URL 
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability. 
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------      */                                                                    
26
27
28 #include "PlanesOperations.h"
29
30 /********************************************************************************************
31 ** Start of data viewmanagerData
32 *********************************************************************************************/
33
34 PlanesOperations::PlanesOperations()
35 {       
36 }
37
38
39 PlanesOperations::~PlanesOperations()
40 {
41
42 }
43
44
45 double* PlanesOperations::getCrossProduct(double* vect0,double* vect1)
46 {
47         double* vectCross;
48         vectCross = new double[3];
49         vectCross[0] = vect0[1]*vect1[2]-(vect0[2]*vect1[1]);
50         vectCross[1] = -(vect0[0]*vect1[2]-(vect0[2]*vect1[0]));
51         vectCross[2] = vect0[0]*vect1[1]-(vect0[1]*vect1[0]);
52
53         return vectCross;
54 }
55
56 double PlanesOperations::getDotProduct(double* vect0,double* vect1)
57 {
58         double vectDot;
59         vectDot = vect0[0]*vect1[0] + vect0[1]*vect1[1] + vect0[2]*vect1[2];
60         
61         return vectDot;
62 }
63 /**
64 **      Returns the magnitud of the given vector
65 **/
66 double PlanesOperations::getMagnitud(double* vect)
67 {
68         double mag;
69
70         mag = sqrt(pow(vect[0],2) + pow(vect[1],2) + pow(vect[2],2));
71
72         return mag;
73 }
74 /**
75 **      returns the unitary vector of the given vector
76 **      u = 1/|vect| . vect
77 **/
78 double* PlanesOperations::getNormal(double* vect)
79 {
80
81         double* vectnorm;
82         double mag = getMagnitud(vect);
83
84         vectnorm = new double[3];
85         
86         if(mag!=0){
87                 vectnorm[0] = vect[0]/mag;
88                 vectnorm[1] = vect[1]/mag;
89                 vectnorm[2] = vect[2]/mag;
90         }else{
91                 vectnorm[0] = 0;
92                 vectnorm[1] = 0;
93                 vectnorm[2] = 0;
94         }
95         return vectnorm;
96 }
97
98 double* PlanesOperations::makeVector(double podouble0[3], double podouble1[3])
99 {
100         double *vect;
101         vect = new double[3];
102
103         vect[0]= podouble1[0]-podouble0[0];
104         vect[1]= podouble1[1]-podouble0[1];
105         vect[2]= podouble1[2]-podouble0[2];
106
107         return vect;
108 }
109