Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
vpBoundio.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 "boundio.c" contient les procedures d'entree/sortie
33  * des types definis dans le module "bound.h".
34  * Les entrees non specifiees sont effectuees
35  * sur le fichier "source" de "lex.c".
36  * Pour les mots cles des "fprintf_..." voir "token.c".
37  *
38  * Authors:
39  * Jean-Luc CORRE
40  *
41 *****************************************************************************/
42 
43 #include <visp3/core/vpConfig.h>
44 #include <visp3/core/vpException.h>
45 
46 #ifndef DOXYGEN_SHOULD_SKIP_THIS
47 #include "vpArit.h"
48 #include "vpBoundio.h"
49 #include "vpLex.h"
50 #include "vpMy.h"
51 #include "vpSkipio.h"
52 #include "vpToken.h"
53 
54 #include <errno.h>
55 #include <stdio.h>
56 #include <stdlib.h>
57 
58 BEGIN_VISP_NAMESPACE
59 /*
60  * La procedure "fscanf_Bound" lit en ascii une surface.
61  * Entree :
62  * bp Surface a lire.
63  */
64 void fscanf_Bound(Bound *bp)
65 {
66  /* Lecture du type polygonale de la surface. */
67 
68  skip_keyword(T_TYPE, "bound: keyword \"type\" expected");
69  if (lex() != T_INT)
70  lexerr("start", "bound_type: boolean expected (0=FALSE|~0=TRUE)", NULL);
71  bp->is_polygonal = (myint ? 1 : 0);
72 
73  /* Lecture de la liste de points de la surface. */
74 
75  skip_keyword(T_POINT_LIST, "bound: keyword \"point_list\" expected");
76  pusherr("bound_point_list: ");
77  fscanf_Point3f_list(&bp->point);
78  poperr();
79 
80  /* Lecture de la liste de faces de la surface. */
81 
82  skip_keyword(T_FACE_LIST, "bound: keyword \"face_list\" expected");
83  pusherr("bound_face_list: ");
84  fscanf_Face_list(&bp->face);
85  poperr();
86 }
87 
88 /*
89  * La procedure "fscanf_Face_list" lit en ascii une liste de faces.
90  * Entree :
91  * lp Liste de faces a lire.
92  */
93 void fscanf_Face_list(Face_list *lp)
94 {
95  Face *fp; /* face courante */
96  Face *fend; /* borne de "fp" */
97 
98  /* Lecture du nombre de faces de la liste */
99 
100  if (lex() != T_INT)
101  lexerr("start", "integer expected (number of faces)", NULL);
102  lp->nbr = (Index)myint;
103 
104  /* Allocation dynamique de la liste de faces. */
105 
106  if (lp->nbr == 0)
107  lp->ptr = NULL;
108  else if ((lp->ptr = (Face *)malloc(lp->nbr * sizeof(Face))) == NULL) {
109  static char proc_name[] = "fscanf_Face_list";
110  perror(proc_name);
111  throw vpException(vpException::fatalError, "Error in fscanf_Face_list");
112  }
113 
114  /* Lecture des faces de la liste une a une. */
115 
116  fp = lp->ptr;
117  fend = fp + lp->nbr;
118  for (; fp < fend; fp++) {
119  Vertex_list *vlp = &fp->vertex;
120  Index *vp; /* sommet courant */
121  Index *vend; /* borne de "vp" */
122 
123  /* Lecture du type polygonale de la face. */
124 
125  if (lex() != T_INT)
126  lexerr("start", "boolean expected (0=FALSE|~0=TRUE)", NULL);
127  fp->is_polygonal = (myint ? 1 : 0);
128 
129  /* Lecture du nombre de sommets de la face. */
130 
131  if (lex() != T_INT)
132  lexerr("start", "integer expected (number of vertices)", NULL);
133  vlp->nbr = (Index)myint;
134 
135  /* Allocation dynamique du polygone de la face. */
136 
137  if (vlp->nbr <= DEFAULT_VSIZE)
138  vlp->ptr = vlp->tbl;
139  else if ((vlp->ptr = (Index *)malloc(vlp->nbr * sizeof(Index))) == NULL) {
140  static char proc_name[] = "fscanf_Face_list";
141  perror(proc_name);
142  throw vpException(vpException::fatalError, "Error in fscanf_Face_list");
143  }
144 
145  /* Lecture des sommets de la face un a un. */
146 
147  vp = vlp->ptr;
148  vend = vp + vlp->nbr;
149  for (; vp < vend; *vp++ = (Index)myint)
150  if (lex() != T_INT)
151  lexerr("start", "integer expected (index of points 3D)", NULL);
152  }
153 }
154 
155 /*
156  * La procedure "fscanf_Point_list" lit en ascii une liste de points 3D.
157  * Entree :
158  * lp Liste de points a lire.
159  */
160 void fscanf_Point3f_list(Point3f_list *lp)
161 {
162  static const char *err_tbl[] = { "float expected (coordinate ", " of point)" };
163  Point3f *pp; /* point courant */
164  Point3f *pend; /* borne de "pp" */
165 
166  /* Lecture du nombre de points de la liste. */
167 
168  if (lex() != T_INT)
169  lexerr("start", "integer expected (number of points 3D)", NULL);
170  lp->nbr = (Index)myint;
171  /* FC printf("nbr %d\n",lp->nbr); */
172  /* Allocation dynamique la liste de points. */
173 
174  if (lp->nbr == 0)
175  lp->ptr = NULL;
176  else if ((lp->ptr = (Point3f *)malloc(lp->nbr * sizeof(Point3f))) == NULL) {
177  static const char proc_name[] = "fscanf_Point3f_list";
178  perror(proc_name);
179  throw vpException(vpException::fatalError, "Error in fscanf_Point3f_list");
180  }
181 
182  /* Lecture des points de la liste un a un. */
183 
184  pp = lp->ptr;
185  pend = pp + lp->nbr;
186  for (; pp < pend; pp++) {
187  int t;
188 
189  if ((t = lex()) != T_FLOAT && t != T_INT)
190  lexerr("start", err_tbl[0], "X", err_tbl[1], NULL);
191  /* FC printf("X %d %f\n",myint, myfloat); */
192  pp->x = (t == T_INT) ? (float)myint : myfloat;
193 
194  if ((t = lex()) != T_FLOAT && t != T_INT)
195  lexerr("start", err_tbl[0], "Y", err_tbl[1], NULL);
196  /* FC printf("Y %d %f\n",myint, myfloat); */
197  pp->y = (t == T_INT) ? (float)myint : myfloat;
198 
199  if ((t = lex()) != T_FLOAT && t != T_INT)
200  lexerr("start", err_tbl[0], "Z", err_tbl[1], NULL);
201  /* FC printf("Z %d %f\n",myint, myfloat); */
202  pp->z = (t == T_INT) ? (float)myint : myfloat;
203  }
204 }
205 END_VISP_NAMESPACE
206 #endif
error that can be emitted by ViSP classes.
Definition: vpException.h:60
@ fatalError
Fatal error.
Definition: vpException.h:72