Visual Servoing Platform  version 3.0.0
vpVwstack.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 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 "vwstack.c" contient les procedures de gestion
32  * de la pile des points de vue (VieW STACK).
33  *
34  * Authors:
35  * Jean-Luc CORRE
36  *
37  *****************************************************************************/
38 
39 #include <visp3/core/vpConfig.h>
40 
41 #ifndef DOXYGEN_SHOULD_SKIP_THIS
42 
43 #include <stdio.h>
44 #include <string.h>
45 #include <limits>
46 #include <cmath> // std::fabs()
47 
48 // #include <varargs.h> /* modif Fedora
49 #include <stdarg.h>
50 
51 #include <visp3/robot/vpMy.h>
52 #include <visp3/robot/vpArit.h>
53 #include <visp3/robot/vpView.h>
54 #include <visp3/robot/vpVwstack.h>
55 
56 
57 #define STACKSIZE 4
58 
59 
60 static View_parameters stack[STACKSIZE]= { vpDEFAULT_VIEW };
61 static View_parameters *sp = stack;
62 
63 /*
64  * La procedure "fprintf_vwstack" affiche un parametre du sommet
65  * de la pile des prises de vue.
66  * Entree :
67  * fp Fichier de sortie.
68  * argv Argument a afficher.
69  * Si argv est nul, tous les parametres sont affiches.
70  */
71 void
72 fprintf_vwstack (FILE *fp, char *argv)
73 {
74  static char proc_name[] = "fprintf_vwstack";
75 
76  if (argv == NULL || strcmp (argv, "type") == 0) {
77  const char *typetoa;
78 
79  switch (sp->type) {
80  case PARALLEL :
81  typetoa = "parallel";
82  break;
83  case PERSPECTIVE :
84  typetoa = "perspective";
85  break;
86  default :
87  typetoa = "unknown";
88  break;
89  }
90  fprintf (fp, "(type\t%s)\n", typetoa);
91  if (argv != NULL) return;
92  }
93  if (argv == NULL || strcmp (argv, "cop") == 0) {
94  fprintf (fp, "(cop\t%.3f\t%.3f\t%.3f)\n",
95  sp->cop.x, sp->cop.y, sp->cop.z);
96  if (argv != NULL) return;
97  }
98  if (argv == NULL || strcmp (argv, "vrp") == 0) {
99  fprintf (fp, "(vrp\t%.3f\t%.3f\t%.3f)\n",
100  sp->vrp.x, sp->vrp.y, sp->vrp.z);
101  if (argv != NULL) return;
102  }
103  if (argv == NULL || strcmp (argv, "vpn") == 0) {
104  fprintf (fp, "(vpn\t%.3f\t%.3f\t%.3f)\n",
105  sp->vpn.x, sp->vpn.y, sp->vpn.z);
106  if (argv != NULL) return;
107  }
108  if (argv == NULL || strcmp (argv, "vup") == 0) {
109  fprintf (fp, "(vup\t%.3f\t%.3f\t%.3f)\n",
110  sp->vup.x, sp->vup.y, sp->vup.z);
111  if (argv != NULL) return;
112  }
113  if (argv == NULL || strcmp (argv, "window") == 0) {
114  fprintf (fp, "(window\t%.3f\t%.3f\t%.3f\t%.3f)\n",
115  sp->vwd.umin,sp->vwd.umax,sp->vwd.vmin,sp->vwd.vmax);
116  if (argv != NULL) return;
117  }
118  if (argv == NULL || strcmp (argv, "depth") == 0) {
119  fprintf (fp, "(depth\t%.3f\t%.3f)\n",
120  sp->depth.front, sp->depth.back);
121  if (argv != NULL) return;
122  }
123  if (argv != NULL)
124  fprintf (stderr, "%s: argument unknown\n", proc_name);
125 }
126 
127 /*
128  * La procedure "get_vwstack" retourne le point de vue au sommet
129  * de la pile des points de vue.
130  * Sortie :
131  * Pointeur sur le point de vue du sommet de la pile.
132  */
133 View_parameters *
134 get_vwstack (void)
135 {
136  return (sp);
137 }
138 
139 /*
140  * La procedure "load_vwstack" charge un point de vue au sommet
141  * de la pile des points de vue.
142  * Entree :
143  * vp Point de vue a charger.
144  */
145 void
146 load_vwstack (View_parameters *vp)
147 {
148  *sp = *vp;
149 }
150 
151 /*
152  * La procedure "pop_vwstack" depile le point de vue au sommet
153  * de la pile des points de vue.
154  */
155 void
156 pop_vwstack (void)
157 {
158  static char proc_name[] = "pop_vwstack";
159 
160  if (sp == stack) {
161  fprintf (stderr, "%s: stack underflow\n", proc_name);
162  return;
163  }
164  else sp--;
165 }
166 
167 /*
168  * La procedure "push_vwstack" empile et duplique le point de vue au sommet
169  * de la pile des points de vue.
170  */
171 void
172 push_vwstack (void)
173 {
174  static char proc_name[] = "push_vwstack";
175 
176  if (sp == stack + STACKSIZE - 1) {
177  fprintf (stderr, "%s: stack overflow\n", proc_name);
178  return;
179  }
180  sp++;
181  *sp = *(sp - 1);
182 }
183 
184 /*
185  * La procedure "swap_vwstack" echange les deux premiers elements
186  * de la pile des points de vue.
187  */
188 void
189 swap_vwstack (void)
190 {
191  View_parameters *vp, tmp;
192 
193  vp = (sp == stack) ? sp + 1 : sp - 1;
194  SWAP(*sp, *vp, tmp);
195 }
196 
197 /*
198  * La procedure "add_vwstack" modifie un agrument du point de vue au sommet
199  * de la pile des points de vue.
200  * Entree :
201  * va_alist Nom de l'argument a modifier suivi de ses parametres.
202  */
203 
204 void
205 add_vwstack (const char* path, ... )
206 //add_vwstack (va_alist)
207 // va_dcl
208 {
209  static char proc_name[] = "add_vwstack";
210 
211  va_list ap;
212  char *argv;
213 
214  va_start (ap,path);
215  argv = va_arg (ap, char *);
216  if (strcmp (argv, "cop") == 0) {
217  /* initialise le centre de projection */
218  SET_COORD3(sp->cop,
219  (float) va_arg (ap, double),
220  (float) va_arg (ap, double),
221  (float) va_arg (ap, double));
222  }
223  else if (strcmp (argv, "depth") == 0) {
224  /* initialise les distances des plans de decoupage */
225  sp->depth.front = (float) va_arg (ap, double);
226  sp->depth.back = (float) va_arg (ap, double);
227  }
228  else if (strcmp (argv, "type") == 0) {
229  /* initialise le type de projection */
230  sp->type = (Type) va_arg (ap, int);
231  }
232  else if (strcmp (argv, "vpn") == 0) {
233  /* initialise le vecteur normal au plan */
234  float x = (float) va_arg (ap, double);
235  float y = (float) va_arg (ap, double);
236  float z = (float) va_arg (ap, double);
237 
238  //if (x == 0 && y == 0 && z == 0)
239  if (std::fabs(x) <= std::numeric_limits<double>::epsilon() && std::fabs(y) <= std::numeric_limits<double>::epsilon() && std::fabs(z) <= std::numeric_limits<double>::epsilon())
240  fprintf (stderr, "%s: bad vpn\n", proc_name);
241  else {
242  SET_COORD3(sp->vpn,x,y,z);
243  }
244  }
245  else if (strcmp (argv, "vrp") == 0) {
246  /* initialise le vecteur de reference */
247  SET_COORD3(sp->vrp,
248  (float) va_arg (ap, double),
249  (float) va_arg (ap, double),
250  (float) va_arg (ap, double));
251  }
252  else if (strcmp (argv, "vup") == 0) {
253  /* initialise le vecteur haut du plan */
254  float x = (float) va_arg (ap, double);
255  float y = (float) va_arg (ap, double);
256  float z = (float) va_arg (ap, double);
257 
258  //if (x == 0 && y == 0 && z == 0)
259  if (std::fabs(x) <= std::numeric_limits<double>::epsilon() && std::fabs(y) <= std::numeric_limits<double>::epsilon() && std::fabs(z) <= std::numeric_limits<double>::epsilon())
260  fprintf (stderr, "%s: bad vup\n", proc_name);
261  else {
262  SET_COORD3(sp->vup,x,y,z);
263  }
264  }
265  else if (strcmp (argv, "window") == 0) {
266  /* initialise la fenetre de projection */
267  sp->vwd.umin = (float) va_arg (ap, double);
268  sp->vwd.umax = (float) va_arg (ap, double);
269  sp->vwd.vmin = (float) va_arg (ap, double);
270  sp->vwd.vmax = (float) va_arg (ap, double);
271  }
272  else
273  fprintf (stderr, "%s: bad argument\n", proc_name);
274  va_end (ap);
275 }
276 
277 #endif
278