Visual Servoing Platform  version 3.0.0
vpRfstack.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 "rfstack.c" contient les procedures de gestion
32  * de la pile d'elimination de faces (Remove Faces STACK).
33  *
34  * Authors:
35  * Jean-Luc CORRE
36  *
37  *****************************************************************************/
38 
39 
40 
41 
42 
43 
44 #include <visp3/core/vpConfig.h>
45 
46 #ifndef DOXYGEN_SHOULD_SKIP_THIS
47 #include <visp3/robot/vpMy.h>
48 #include <visp3/robot/vpArit.h>
49 #include <visp3/robot/vpView.h>
50 #include <visp3/robot/vpRfstack.h>
51 #include <stdio.h>
52 #include <string.h>
53 #define STACKSIZE 32
54 
55 
56 static int stack[STACKSIZE] = {vpDEFAULT_REMOVE}; /* pile */
57 static int *sp = stack; /* sommet */
58 
59 
60 /*
61  * La procedure "fprintf_rfstack" affiche le sommet
62  * de la pile des drapeaux d'elimination de faces.
63  * Entree :
64  * fp Fichier en sortie.
65  */
66 void
67 fprintf_rfstack (FILE *fp)
68 {
69  int flg;
70  flg = 0; /* nul si element unique */
71 
72  if (*sp == IS_INSIDE) {
73  fprintf (fp, "(null)\n");
74  return;
75  }
76  fprintf (fp, "(");
77  if (*sp & IS_ABOVE) {
78  //if (flg) fprintf (fp, " "); Removed since if (flg) cannot be true
79  flg ++;
80  fprintf (fp, "above");
81  }
82  if (*sp & IS_BELOW) {
83  if (flg) fprintf (fp, " ");
84  flg ++;
85  fprintf (fp, "below");
86  }
87  if (*sp & IS_RIGHT) {
88  if (flg) fprintf (fp, " ");
89  flg ++;
90  fprintf (fp, "right");
91  }
92  if (*sp & IS_LEFT) {
93  if (flg) fprintf (fp, " ");
94  flg ++;
95  fprintf (fp, "left");
96  }
97  if (*sp & IS_BACK) {
98  if (flg) fprintf (fp, " ");
99  flg ++;
100  fprintf (fp, "back");
101  }
102  if (*sp & IS_FRONT) {
103  /*if (flg)*/ fprintf (fp, " ");
104  flg ++;
105  fprintf (fp, "front");
106  }
107  fprintf (fp, ")\n");
108 }
109 
110 /*
111  * La procedure "get_rfstack" retourne les drapeaux au sommet
112  * de la pile des drapeaux d'elimination de faces.
113  * Sortie :
114  * Pointeur sur les drapeaux d'elimination du sommet de la pile.
115  */
116 int *
117 get_rfstack (void)
118 {
119  return (sp);
120 }
121 
122 /*
123  * La procedure "load_rfstack" charge des drapeaux au sommet
124  * de la pile des drapeaux d'elimination de faces.
125  * Entree :
126  * i Niveau a charger.
127  */
128 void
129 load_rfstack (int i)
130 {
131  *sp = i;
132 }
133 
134 /*
135  * La procedure "pop_rfstack" depile les drapeaux au sommet
136  * de la pile des drapeaux d'elimination de faces.
137  */
138 void
139 pop_rfstack (void)
140 {
141  static char proc_name[] = "pop_rfstack";
142 
143  if (sp == stack) {
144  fprintf (stderr, "%s: stack underflow\n", proc_name);
145  return;
146  }
147  else sp--;
148 }
149 
150 /*
151  * La procedure "push_rfstack" empile et duplique les drapeaux du sommet
152  * de la pile des drapeaux d'elimination de faces.
153  */
154 void
155 push_rfstack (void)
156 {
157  static char proc_name[] = "push_rfstack";
158 
159  if (sp == stack + STACKSIZE - 1) {
160  fprintf (stderr, "%s: stack overflow\n", proc_name);
161  return;
162  }
163  sp++;
164  *sp = *(sp - 1);
165 }
166 
167 /*
168  * La procedure "swap_rfstack" echange les deux premiers elements
169  * de la pile des drapeaux d'elimination de faces.
170  */
171 void
172 swap_rfstack (void)
173 {
174  int *ip, tmp;
175 
176  ip = (sp == stack) ? sp + 1 : sp - 1;
177  SWAP(*sp, *ip, tmp);
178 }
179 
180 /*
181  * La procedure "add_rfstack" ajoute des drapeaux au sommet
182  * de la pile des drapeaux d'elimination de faces.
183  */
184 void
185 add_rfstack (int i)
186 {
187  *sp |= i;
188 }
189 
190 /*
191  * La procedure "sub_rfstack" soustrait des drapeaux au sommet
192  * de la pile des drapeaux d'elimination de faces.
193  */
194 void
195 sub_rfstack (int i)
196 {
197  *sp &= ~i;
198 }
199 
200 #endif
201