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