Computer Assisted Medical Intervention Tool Kit  version 5.2
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-2024 Univ. Grenoble Alpes, CNRS, Grenoble INP - UGA, TIMC, 38000 Grenoble, France
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 <cmath>
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  return vec1[0] * vec2[0] + vec1[1] * vec2[1] + vec1[2] * vec2[2];
70 }
71 
72 // -------------------- distance --------------------
73 inline void crossProduct(double vec1[3], double vec2[3], double res[3]) {
74  res[0] = vec1[1] * vec1[2] - vec1[2] * vec1[1];
75  res[1] = vec1[2] * vec1[0] - vec1[0] * vec1[2];
76  res[2] = vec1[0] * vec1[1] - vec1[1] * vec1[0];
77 }
78 
79 // -------------------- normalize --------------------
80 inline void normalize(double vec[3]) {
81  double norm = sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]);
82  if (norm > 0) {
83  vec[0] = vec[0] / norm;
84  vec[1] = vec[1] / norm;
85  vec[2] = vec[2] / norm;
86  }
87 }
88 
89 // -------------------- normOf --------------------
90 inline double normOf(double vec[3]) {
91  return sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]);
92 }
93 
94 #endif // TOOLS_TOOLS_H
void crossProduct(double vec1[3], double vec2[3], double res[3])
compute cross product
Definition: Tools.h:73
double timeParameter2double(mml::TimeParameter &t)
convert a TimeParameter (from xsd-cxx generetaed file) to double
Definition: Tools.cpp:69
double normOf(double vec[3])
norm of vector
Definition: Tools.h:90
double distance(double pos[3], double pos2[3])
compute euclidian distance
Definition: Tools.h:61
double dotProduct(double vec1[3], double vec2[3])
compute dot product
Definition: Tools.h:68
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.
Definition: Tools.cpp:32
void normalize(double vec[3])
normalize vector
Definition: Tools.h:80