Visual Servoing Platform  version 3.6.1 under development (2024-04-26)
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 /*
55  * La procedure "fprintf_rfstack" affiche le sommet
56  * de la pile des drapeaux d'elimination de faces.
57  * Entree :
58  * fp Fichier en sortie.
59  */
60 void fprintf_rfstack(FILE *fp)
61 {
62  int flg;
63  flg = 0; /* nul si element unique */
64 
65  if (*sp == IS_INSIDE) {
66  fprintf(fp, "(null)\n");
67  return;
68  }
69  fprintf(fp, "(");
70  if (*sp & IS_ABOVE) {
71  // if (flg) fprintf (fp, " "); Removed since if (flg) cannot be true
72  flg++;
73  fprintf(fp, "above");
74  }
75  if (*sp & IS_BELOW) {
76  if (flg)
77  fprintf(fp, " ");
78  flg++;
79  fprintf(fp, "below");
80  }
81  if (*sp & IS_RIGHT) {
82  if (flg)
83  fprintf(fp, " ");
84  flg++;
85  fprintf(fp, "right");
86  }
87  if (*sp & IS_LEFT) {
88  if (flg)
89  fprintf(fp, " ");
90  flg++;
91  fprintf(fp, "left");
92  }
93  if (*sp & IS_BACK) {
94  if (flg)
95  fprintf(fp, " ");
96  flg++;
97  fprintf(fp, "back");
98  }
99  if (*sp & IS_FRONT) {
100  /*if (flg)*/ fprintf(fp, " ");
101  flg++;
102  fprintf(fp, "front");
103  }
104  fprintf(fp, ")\n");
105 }
106 
107 /*
108  * La procedure "get_rfstack" retourne les drapeaux au sommet
109  * de la pile des drapeaux d'elimination de faces.
110  * Sortie :
111  * Pointeur sur les drapeaux d'elimination du sommet de la pile.
112  */
113 int *get_rfstack(void) { return (sp); }
114 
115 /*
116  * La procedure "load_rfstack" charge des drapeaux au sommet
117  * de la pile des drapeaux d'elimination de faces.
118  * Entree :
119  * i Niveau a charger.
120  */
121 void load_rfstack(int i) { *sp = i; }
122 
123 /*
124  * La procedure "pop_rfstack" depile les drapeaux au sommet
125  * de la pile des drapeaux d'elimination de faces.
126  */
127 void pop_rfstack(void)
128 {
129  if (sp == stack) {
130  static char proc_name[] = "pop_rfstack";
131  fprintf(stderr, "%s: stack underflow\n", proc_name);
132  return;
133  } else
134  sp--;
135 }
136 
137 /*
138  * La procedure "push_rfstack" empile et duplique les drapeaux du sommet
139  * de la pile des drapeaux d'elimination de faces.
140  */
141 void push_rfstack(void)
142 {
143  if (sp == stack + STACKSIZE - 1) {
144  static char proc_name[] = "push_rfstack";
145  fprintf(stderr, "%s: stack overflow\n", proc_name);
146  return;
147  }
148  sp++;
149  *sp = *(sp - 1);
150 }
151 
152 /*
153  * La procedure "swap_rfstack" echange les deux premiers elements
154  * de la pile des drapeaux d'elimination de faces.
155  */
156 void swap_rfstack(void)
157 {
158  int *ip;
159 
160  ip = (sp == stack) ? sp + 1 : sp - 1;
161  int tmp;
162  // SWAP(*sp, *ip, tmp); // produce a cppcheck warning
163  tmp = *sp;
164  *sp = *ip;
165  *ip = tmp;
166 }
167 
168 /*
169  * La procedure "add_rfstack" ajoute des drapeaux au sommet
170  * de la pile des drapeaux d'elimination de faces.
171  */
172 void add_rfstack(int i) { *sp |= i; }
173 
174 /*
175  * La procedure "sub_rfstack" soustrait des drapeaux au sommet
176  * de la pile des drapeaux d'elimination de faces.
177  */
178 void sub_rfstack(int i) { *sp &= ~i; }
179 
180 #endif