ViSP
vpTmstack.cpp
1 /****************************************************************************
2  *
3  * $Id: vpTmstack.cpp 5284 2015-02-09 14:24:10Z fspindle $
4  *
5 * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  * Description:
34  * Le module "tmstack.c" contient les procedures de gestion
35  * de la pile de matrices de transformation (Transformation
36  * Matrix STACK).
37  *
38  * Authors:
39  * Jean-Luc CORRE
40  *
41  *****************************************************************************/
42 
43 
44 
45 
46 #include <visp/vpMy.h>
47 #include <visp/vpArit.h>
48 #include <visp/vpTmstack.h>
49 #include <math.h>
50 #include <stdio.h>
51 #include <string.h>
52 #include <visp/vpConfig.h>
53 
54 #ifndef DOXYGEN_SHOULD_SKIP_THIS
55 
56 #define STACKSIZE 32
57 
58 
59 static Matrix stack[STACKSIZE]/* = IDENTITY_MATRIX*/; /* pile */
60 static Matrix *sp = stack; /* sommet */
61 
62 
63 /*
64  * La procedure "get_tmstack" retourne la matrice au sommet
65  * de la pile des matrices de transformation.
66  * Sortie :
67  * Pointeur de la matrice au sommet de la pile.
68  */
69 Matrix *
70 get_tmstack (void)
71 {
72  return (sp);
73 }
74 
75 /*
76  * La procedure "load_tmstack" charge une matrice au sommet
77  * de la pile des matrices de transformation.
78  * Entree :
79  * m Matrice a charger.
80  */
81 void
82 load_tmstack (Matrix m)
83 {
84  //bcopy ((char *) m, (char *) *sp, sizeof (Matrix));
85  memmove ((char *) *sp, (char *) m, sizeof (Matrix));
86 }
87 
88 /*
89  * La procedure "pop_tmstack" depile la matrice au sommet
90  * de la pile des matrices de transformation.
91  */
92 void
93 pop_tmstack (void)
94 {
95  static char proc_name[] = "pop_tmstack";
96 
97  if (sp == stack) {
98  fprintf (stderr, "%s: stack underflow\n", proc_name);
99  return;
100  }
101  else sp--;
102 }
103 
104 /*
105  * La procedure "push_tmstack" empile et duplique le sommet
106  * de la pile des matrices de transformation.
107  */
108 void
109 push_tmstack (void)
110 {
111  static char proc_name[] = "push_tmstack";
112 
113  if (sp == stack + STACKSIZE - 1) {
114  fprintf (stderr, "%s: stack overflow\n", proc_name);
115  return;
116  }
117  sp++;
118  //bcopy ((char *) (sp - 1), (char *) sp, sizeof (Matrix));
119  memmove ((char *) sp, (char *) (sp - 1), sizeof (Matrix));
120 }
121 
122 /*
123  * La procedure "swap_tmstack" echange les deux premieres matrices
124  * de la pile des matrices de transformation.
125  */
126 void
127 swap_tmstack (void)
128 {
129  Matrix *mp, tmp;
130 
131  mp = (sp == stack) ? sp + 1 : sp - 1;
132 // bcopy ((char *) *sp, (char *) tmp, sizeof (Matrix));
133 // bcopy ((char *) *mp, (char *) *sp, sizeof (Matrix));
134 // bcopy ((char *) tmp, (char *) *mp, sizeof (Matrix));
135  memmove ((char *) tmp, (char *) *sp, sizeof (Matrix));
136  memmove ((char *) *sp, (char *) *mp, sizeof (Matrix));
137  memmove ((char *) *mp, (char *) tmp, sizeof (Matrix));
138 }
139 
140 /*
141  * La procedure "postmult_tmstack" postmultiplie la matrice au sommet
142  * de la pile des matrices de transformation.
143  * Entree :
144  * m Matrice multiplicative.
145  */
146 void
147 postmult_tmstack (Matrix m)
148 {
149  postmult_matrix (*sp, m);
150 }
151 
152 /*
153  * La procedure "postrotate_tmstack" postmultiplie la matrice au sommet
154  * de la pile des matrices de transformation par une rotation.
155  * Entree :
156  * vp Vecteur de rotation.
157  */
158 void
159 postrotate_tmstack (Vector *vp)
160 {
161  Matrix m;
162 
163  Rotate_to_Matrix (vp, m);
164  postmult3_matrix (*sp, m);
165 }
166 
167 /*
168  * La procedure "postscale_tmstack" postmultiplie la matrice au sommet
169  * de la pile des matrices de transformation par une homothetie.
170  * Entree :
171  * vp Vecteur d'homothetie.
172  */
173 void
174 postscale_tmstack (Vector *vp)
175 {
176  postscale_matrix (*sp, vp);
177 }
178 
179 /*
180  * La procedure "posttranslate_tmstack" postmultiplie la matrice au sommet
181  * de la pile des matrices de transformation par une translation.
182  * Entree :
183  * vp Vecteur de translation.
184  */
185 void
186 posttranslate_tmstack (Vector *vp)
187 {
188  posttrans_matrix (*sp, vp);
189 }
190 
191 /*
192  * La procedure "premult_tmstack" premultiplie la matrice au sommet
193  * de la pile des matrices de transformation.
194  * Entree :
195  * m Matrice multiplicative.
196  */
197 void
198 premult_tmstack (Matrix m)
199 {
200  premult_matrix (*sp, m);
201 }
202 
203 /*
204  * La procedure "prerotate_tmstack" premultiplie la matrice au sommet
205  * de la pile des matrices de transformation par une rotation.
206  * Entree :
207  * vp Vecteur de rotation.
208  */
209 void
210 prerotate_tmstack (Vector *vp)
211 {
212  Matrix m;
213 
214  Rotate_to_Matrix (vp, m);
215  premult3_matrix (*sp, m);
216 }
217 
218 /*
219  * La procedure "prescale_tmstack" premultiplie la matrice au sommet
220  * de la pile des matrices de transformation par une homothetie.
221  * Entree :
222  * vp Vecteur d'homothetie.
223  */
224 void
225 prescale_tmstack (Vector *vp)
226 {
227  prescale_matrix (*sp, vp);
228 }
229 
230 /*
231  * La procedure "pretranslate_tmstack" premultiplie la matrice au sommet
232  * de la pile des matrices de transformation par une translation.
233  * Entree :
234  * vp Vecteur de translation.
235  */
236 void
237 pretranslate_tmstack (Vector *vp)
238 {
239  pretrans_matrix (*sp, vp);
240 }
241 
242 #endif
243