Computer Assited Medical Intervention Tool Kit  version 3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Tools.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * $CAMITK_LICENCE_BEGIN$
3  *
4  * CamiTK - Computer Assisted Medical Intervention ToolKit
5  * (c) 2001-2014 UJF-Grenoble 1, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
6  *
7  * Visit http://camitk.imag.fr for more information
8  *
9  * This file is part of CamiTK.
10  *
11  * CamiTK is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * CamiTK is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License version 3 for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
22  *
23  * $CAMITK_LICENCE_END$
24  ****************************************************************************/
25 
26 #ifndef TOOLS_TOOLS_H
27 #define TOOLS_TOOLS_H
28 
29 #include "MonitoringModel.hxx"
30 #include "math.h"
31 
33 double distance(double pos[3], double pos2[3]);
34 
43 double distanceToTrianglePlane(double point[3], double tri1[3], double tri2[3], double tri3[3]);
44 
46 double timeParameter2double(mml::TimeParameter& t);
47 
49 double dotProduct(double vec1[3], double vec2[3]);
50 
52 void crossProduct(double vec1[3], double vec2[3], double res[3]);
53 
55 void normalize(double vec[3]);
56 
58 double normOf(double vec[3]);
59 
60 // -------------------- distance --------------------
61 inline double distance(double pos[3], double pos2[3]){
62  return sqrt( (pos[0] - pos2[0])*(pos[0] - pos2[0])
63  + (pos[1] - pos2[1])*(pos[1] - pos2[1])
64  + (pos[2] - pos2[2])*(pos[2] - pos2[2]));
65 }
66 
67 // -------------------- dotProduct --------------------
68 inline double dotProduct(double vec1[3], double vec2[3])
69 {
70  return vec1[0]*vec2[0]+vec1[1]*vec2[1]+vec1[2]*vec2[2];
71 }
72 
73 // -------------------- distance --------------------
74 inline void crossProduct(double vec1[3], double vec2[3], double res[3])
75 {
76  res[0]=vec1[1]*vec1[2]-vec1[2]*vec1[1];
77  res[1]=vec1[2]*vec1[0]-vec1[0]*vec1[2];
78  res[2]=vec1[0]*vec1[1]-vec1[1]*vec1[0];
79 }
80 
81 // -------------------- normalize --------------------
82 inline void normalize(double vec[3])
83 {
84  double norm=sqrt(vec[0]*vec[0]+vec[1]*vec[1]+vec[2]*vec[2]);
85  if (norm >0){
86  vec[0]=vec[0]/norm;
87  vec[1]=vec[1]/norm;
88  vec[2]=vec[2]/norm;
89  }
90 }
91 
92 // -------------------- normOf --------------------
93 inline double normOf(double vec[3])
94 {
95  return sqrt(vec[0]*vec[0]+vec[1]*vec[1]+vec[2]*vec[2]);
96 }
97 
98 #endif // TOOLS_TOOLS_H
void normalize(double vec[3])
normalize vector
Definition: Tools.h:82
double distance(double pos[3], double pos2[3])
compute euclidian distance
Definition: Tools.h:61
double distanceToTrianglePlane(double point[3], double tri1[3], double tri2[3], double tri3[3])
compute the distance of a point to the plane defined by a 3D triangle.
double dotProduct(double vec1[3], double vec2[3])
compute dot product
Definition: Tools.h:68
double normOf(double vec[3])
norm of vector
Definition: Tools.h:93
void crossProduct(double vec1[3], double vec2[3], double res[3])
compute cross product
Definition: Tools.h:74
double timeParameter2double(mml::TimeParameter &t)
convert a TimeParameter (from xsd-cxx generetaed file) to double