Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
vpRfstack.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See https://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Le module "rfstack.c" contient les procedures de gestion
33  * de la pile d'elimination de faces (Remove Faces STACK).
34  *
35  * Authors:
36  * Jean-Luc CORRE
37  *
38 *****************************************************************************/
39 
40 #include <visp3/core/vpConfig.h>
41 
42 #ifndef DOXYGEN_SHOULD_SKIP_THIS
43 #include "vpArit.h"
44 #include "vpMy.h"
45 #include "vpRfstack.h"
46 #include "vpView.h"
47 #include <stdio.h>
48 #include <string.h>
49 #define STACKSIZE 32
50 
51 static int stack[STACKSIZE] = { vpDEFAULT_REMOVE }; /* pile */
52 static int *sp = stack; /* sommet */
53 
54 BEGIN_VISP_NAMESPACE
55 /*
56  * La procedure "fprintf_rfstack" affiche le sommet
57  * de la pile des drapeaux d'elimination de faces.
58  * Entree :
59  * fp Fichier en sortie.
60  */
61 void fprintf_rfstack(FILE *fp)
62 {
63  int flg;
64  flg = 0; /* nul si element unique */
65 
66  if (*sp == IS_INSIDE) {
67  fprintf(fp, "(null)\n");
68  return;
69  }
70  fprintf(fp, "(");
71  if (*sp & IS_ABOVE) {
72  // if (flg) fprintf (fp, " "); Removed since if (flg) cannot be true
73  flg++;
74  fprintf(fp, "above");
75  }
76  if (*sp & IS_BELOW) {
77  if (flg)
78  fprintf(fp, " ");
79  flg++;
80  fprintf(fp, "below");
81  }
82  if (*sp & IS_RIGHT) {
83  if (flg)
84  fprintf(fp, " ");
85  flg++;
86  fprintf(fp, "right");
87  }
88  if (*sp & IS_LEFT) {
89  if (flg)
90  fprintf(fp, " ");
91  flg++;
92  fprintf(fp, "left");
93  }
94  if (*sp & IS_BACK) {
95  if (flg)
96  fprintf(fp, " ");
97  flg++;
98  fprintf(fp, "back");
99  }
100  if (*sp & IS_FRONT) {
101  /*if (flg)*/ fprintf(fp, " ");
102  flg++;
103  fprintf(fp, "front");
104  }
105  fprintf(fp, ")\n");
106 }
107 
108 /*
109  * La procedure "get_rfstack" retourne les drapeaux au sommet
110  * de la pile des drapeaux d'elimination de faces.
111  * Sortie :
112  * Pointeur sur les drapeaux d'elimination du sommet de la pile.
113  */
114 int *get_rfstack(void) { return (sp); }
115 
116 /*
117  * La procedure "load_rfstack" charge des drapeaux au sommet
118  * de la pile des drapeaux d'elimination de faces.
119  * Entree :
120  * i Niveau a charger.
121  */
122 void load_rfstack(int i) { *sp = i; }
123 
124 /*
125  * La procedure "pop_rfstack" depile les drapeaux au sommet
126  * de la pile des drapeaux d'elimination de faces.
127  */
128 void pop_rfstack(void)
129 {
130  if (sp == stack) {
131  static char proc_name[] = "pop_rfstack";
132  fprintf(stderr, "%s: stack underflow\n", proc_name);
133  return;
134  }
135  else
136  sp--;
137 }
138 
139 /*
140  * La procedure "push_rfstack" empile et duplique les drapeaux du sommet
141  * de la pile des drapeaux d'elimination de faces.
142  */
143 void push_rfstack(void)
144 {
145  if (sp == stack + STACKSIZE - 1) {
146  static char proc_name[] = "push_rfstack";
147  fprintf(stderr, "%s: stack overflow\n", proc_name);
148  return;
149  }
150  sp++;
151  *sp = *(sp - 1);
152 }
153 
154 /*
155  * La procedure "swap_rfstack" echange les deux premiers elements
156  * de la pile des drapeaux d'elimination de faces.
157  */
158 void swap_rfstack(void)
159 {
160  int *ip;
161 
162  ip = (sp == stack) ? sp + 1 : sp - 1;
163  int tmp;
164  // SWAP(*sp, *ip, tmp); // produce a cppcheck warning
165  tmp = *sp;
166  *sp = *ip;
167  *ip = tmp;
168 }
169 
170 /*
171  * La procedure "add_rfstack" ajoute des drapeaux au sommet
172  * de la pile des drapeaux d'elimination de faces.
173  */
174 void add_rfstack(int i) { *sp |= i; }
175 
176 /*
177  * La procedure "sub_rfstack" soustrait des drapeaux au sommet
178  * de la pile des drapeaux d'elimination de faces.
179  */
180 void sub_rfstack(int i) { *sp &= ~i; }
181 END_VISP_NAMESPACE
182 #endif