Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpArit.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Le module contient les procedures arithmetiques.
32  *
33  * Authors:
34  * Jean-Luc CORRE
35  *
36  *****************************************************************************/
37 #ifndef vpArit_h
38 #define vpArit_h
39 
40 #include <visp3/core/vpConfig.h>
41 #include <visp3/robot/vpWireFrameSimulatorTypes.h>
42 #include <stdio.h>
43 
44 #ifndef DOXYGEN_SHOULD_SKIP_THIS
45 
46 #define ADD_COORD2(r,a,b) { (r).x = (a).x + (b).x;\
47  (r).y = (a).y + (b).y; }
48 
49 #define ADD_COORD3(r,a,b) { (r).x = (a).x + (b).x;\
50  (r).y = (a).y + (b).y;\
51  (r).z = (a).z + (b).z; }
52 
53 #define INC_COORD2(r,a) { (r).x += (a).x; (r).y += (a).y; }
54 
55 #define INC_COORD3(r,a) { (r).x += (a).x; (r).y += (a).y;\
56  (r).z += (a).z; }
57 
58 #define CROSS_PRODUCT(r,a,b) { (r).x = (a).y * (b).z - (a).z * (b).y;\
59  (r).y = (a).z * (b).x - (a).x * (b).z;\
60  (r).z = (a).x * (b).y - (a).y * (b).x; }
61 
62 #define DIF_COORD2(r,a,b) { (r).x = (a).x - (b).x;\
63  (r).y = (a).y - (b).y; }
64 
65 #define DIF_COORD3(r,a,b) { (r).x = (a).x - (b).x;\
66  (r).y = (a).y - (b).y;\
67  (r).z = (a).z - (b).z; }
68 
69 #define DOT_PRODUCT(a,b) ( ((a).x * (b).x) +\
70  ((a).y * (b).y) +\
71  ((a).z * (b).z) )
72 
73 #define LENGTH3(a) (sqrt((double) DOT_PRODUCT((a),(a))))
74 
75 #define MID_COORD3(r,a,b) { (r).x = ((a).x + (b).x) / 2.0;\
76  (r).y = ((a).y + (b).y) / 2.0;\
77  (r).z = ((a).z + (b).z) / 2.0; }
78 
79 #define MUL_COORD3(r,a,b,c) { (r).x *= (a); (r).y *= (b); (r).z *= (c); }
80 
81 #define PAR_COORD3(r,t,a,b) { (r).x = ((b).x - (a).x) * (t) + (a).x;\
82  (r).y = ((b).y - (a).y) * (t) + (a).y;\
83  (r).z = ((b).z - (a).z) * (t) + (a).z; }
84 
85 #define SET_COORD2(r,a,b) { (r).x = (a); (r).y = (b); }
86 
87 #define SET_COORD3(r,a,b,c) { (r).x = (a); (r).y = (b); (r).z = (c); }
88 
89 #define SUB_COORD2(r,a) { (r).x -= (a).x; (r).y -= (a).y; }
90 
91 #define SUB_COORD3(r,a) { (r).x -= (a).x; (r).y -= (a).y;\
92  (r).z -= (a).z; }
93 
94 #define COORD3_COL(x,y,z,m,i) ( ((x) * (m)[0][i]) +\
95  ((y) * (m)[1][i]) +\
96  ((z) * (m)[2][i]) +\
97  (m)[3][i] )
98 
99 #define COORD4_COL(x,y,z,w,m,i) ( ((x) * (m)[0][i]) +\
100  ((y) * (m)[1][i]) +\
101  ((z) * (m)[2][i]) +\
102  ((w) * (m)[3][i]) )
103 
104 #define M_POLY1(x,a,b) ((a) * (x) + (b))
105 #define M_POLY2(x,a,b,c) (M_POLY1((x),(a),(b)) * (x) + (c))
106 #define M_POLY3(x,a,b,c,d) (M_POLY2((x),(a),(b),(c)) * (x) + (d))
107 
108 
109 typedef struct {
110  int x, y;
111 } Point2i;
112 
113 typedef struct {
114  short x, y;
115 } Point2s;
116 
117 typedef struct {
118  int x, y, z;
119 } Point3i;
120 
121 typedef struct {
122  float x,y,z,w;
123 } Point4f;
124 
125 typedef struct {
126  float x,y,z;
127 } Vector;
128 
129 
130 #define IDENTITY_MATRIX { {1.0, 0.0, 0.0, 0.0},\
131  {0.0, 1.0, 0.0, 0.0},\
132  {0.0, 0.0, 1.0, 0.0},\
133  {0.0, 0.0, 0.0, 1.0} }
134 
135 
136 /*
137  * POSITION
138  * ________
139  *
140  * La structure "Position" definit le positionnement d'un objet.
141  * Matrice de positionnement = R.S.T
142  * avec R = Rx.Ry.Rz Matrice de rotation autour des axes (Ox,Oy,Oz),
143  * Les angles sont donnes en degres;
144  * S = Sx.Sy.Sz Matrice d'homothetie sur les axes;
145  * T = Tx.Ty.Tz Matrice de translation sur les axes.
146  */
147 typedef struct {
148  Vector rotate; /* vecteur rotation */
149  Vector scale; /* vecteur homothetie */
150  Vector translate; /* vecteur translation */
151 } AritPosition;
152 
153 #define IDENTITY_ROTATE { 0.0, 0.0, 0.0 }
154 #define IDENTITY_SCALE { 1.0, 1.0, 1.0 }
155 #define IDENTITY_TRANSLATE { 0.0, 0.0, 0.0 }
156 
157 #define IDENTITY_POSITION { IDENTITY_ROTATE,\
158  IDENTITY_SCALE,\
159  IDENTITY_TRANSLATE }
160 
161 void fprintf_matrix (FILE *fp, Matrix m);
162 void ident_matrix (Matrix m);
163 void premult_matrix (Matrix a, Matrix b);
164 void premult3_matrix (Matrix a, Matrix b);
165 void prescale_matrix (Matrix m, Vector *vp);
166 void pretrans_matrix (Matrix m, Vector *vp);
167 void postleft_matrix (Matrix m, char axis);
168 void postmult_matrix (Matrix a, Matrix b);
169 void postmult3_matrix (Matrix a, Matrix b);
170 void postscale_matrix (Matrix m, Vector *vp);
171 void posttrans_matrix (Matrix m, Vector *vp);
172 void transpose_matrix (Matrix m);
173 
174 float cosin_to_angle (float ca, float sa);
175 float norm_vector (Vector *vp);
176 void point_matrix (Point4f *p4, Point3f *p3, Matrix m);
177 void plane_norme (Vector *np, Point3f *ap, Point3f *bp, Point3f *cp);
178 void point_3D_3D (Point3f *ip, int size, Matrix m, Point3f *op);
179 void point_3D_4D (Point3f *p3, int size, Matrix m, Point4f *p4);
180 void rotate_vector (Vector *vp, float a, Vector *axis);
181 void upright_vector (Vector *vp, Vector *up);
182 
183 void Matrix_to_Position (Matrix m, AritPosition *pp);
184 void Matrix_to_Rotate (Matrix m, Vector *vp);
185 void Position_to_Matrix (AritPosition *pp, Matrix m);
186 void Rotate_to_Matrix (Vector *vp, Matrix m);
187 void Rotaxis_to_Matrix (float a, Vector *axis, Matrix m);
188 void Rotrans_to_Matrix (Vector *rp, Vector *tp, Matrix m);
189 void Scale_to_Matrix (Vector *vp, Matrix m);
190 void Translate_to_Matrix (Vector *vp, Matrix m);
191 
192 void fscanf_Point3f (Point3f *pp);
193 void fscanf_Vector (Vector *vp);
194 
195 #endif
196 #endif