Visual Servoing Platform  version 3.5.1 under development (2022-09-25)
vpBoundio.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 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 http://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 /*
59  * La procedure "fscanf_Bound" lit en ascii une surface.
60  * Entree :
61  * bp Surface a lire.
62  */
63 void fscanf_Bound(Bound *bp)
64 {
65  /* Lecture du type polygonale de la surface. */
66 
67  skip_keyword(T_TYPE, "bound: keyword \"type\" expected");
68  if (lex() != T_INT)
69  lexerr("start", "bound_type: boolean expected (0=FALSE|~0=TRUE)", NULL);
70  bp->is_polygonal = (myint ? 1 : 0);
71 
72  /* Lecture de la liste de points de la surface. */
73 
74  skip_keyword(T_POINT_LIST, "bound: keyword \"point_list\" expected");
75  pusherr("bound_point_list: ");
76  fscanf_Point3f_list(&bp->point);
77  poperr();
78 
79  /* Lecture de la liste de faces de la surface. */
80 
81  skip_keyword(T_FACE_LIST, "bound: keyword \"face_list\" expected");
82  pusherr("bound_face_list: ");
83  fscanf_Face_list(&bp->face);
84  poperr();
85 }
86 
87 /*
88  * La procedure "fscanf_Face_list" lit en ascii une liste de faces.
89  * Entree :
90  * lp Liste de faces a lire.
91  */
92 void fscanf_Face_list(Face_list *lp)
93 {
94  Face *fp; /* face courante */
95  Face *fend; /* borne de "fp" */
96 
97  /* Lecture du nombre de faces de la liste */
98 
99  if (lex() != T_INT)
100  lexerr("start", "integer expected (number of faces)", NULL);
101  lp->nbr = (Index)myint;
102 
103  /* Allocation dynamique de la liste de faces. */
104 
105  if (lp->nbr == 0)
106  lp->ptr = NULL;
107  else if ((lp->ptr = (Face *)malloc(lp->nbr * sizeof(Face))) == NULL) {
108  static char proc_name[] = "fscanf_Face_list";
109  perror(proc_name);
110  throw vpException(vpException::fatalError, "Error in fscanf_Face_list");
111  }
112 
113  /* Lecture des faces de la liste une a une. */
114 
115  fp = lp->ptr;
116  fend = fp + lp->nbr;
117  for (; fp < fend; fp++) {
118  Vertex_list *vlp = &fp->vertex;
119  Index *vp; /* sommet courant */
120  Index *vend; /* borne de "vp" */
121 
122  /* Lecture du type polygonale de la face. */
123 
124  if (lex() != T_INT)
125  lexerr("start", "boolean expected (0=FALSE|~0=TRUE)", NULL);
126  fp->is_polygonal = (myint ? 1 : 0);
127 
128  /* Lecture du nombre de sommets de la face. */
129 
130  if (lex() != T_INT)
131  lexerr("start", "integer expected (number of vertices)", NULL);
132  vlp->nbr = (Index)myint;
133 
134  /* Allocation dynamique du polygone de la face. */
135 
136  if (vlp->nbr <= DEFAULT_VSIZE)
137  vlp->ptr = vlp->tbl;
138  else if ((vlp->ptr = (Index *)malloc(vlp->nbr * sizeof(Index))) == NULL) {
139  static char proc_name[] = "fscanf_Face_list";
140  perror(proc_name);
141  throw vpException(vpException::fatalError, "Error in fscanf_Face_list");
142  }
143 
144  /* Lecture des sommets de la face un a un. */
145 
146  vp = vlp->ptr;
147  vend = vp + vlp->nbr;
148  for (; vp < vend; *vp++ = (Index)myint)
149  if (lex() != T_INT)
150  lexerr("start", "integer expected (index of points 3D)", NULL);
151  }
152 }
153 
154 /*
155  * La procedure "fscanf_Point_list" lit en ascii une liste de points 3D.
156  * Entree :
157  * lp Liste de points a lire.
158  */
159 void fscanf_Point3f_list(Point3f_list *lp)
160 {
161  static const char *err_tbl[] = {"float expected (coordinate ", " of point)"};
162  Point3f *pp; /* point courant */
163  Point3f *pend; /* borne de "pp" */
164 
165  /* Lecture du nombre de points de la liste. */
166 
167  if (lex() != T_INT)
168  lexerr("start", "integer expected (number of points 3D)", NULL);
169  lp->nbr = (Index)myint;
170  /* FC printf("nbr %d\n",lp->nbr); */
171  /* Allocation dynamique la liste de points. */
172 
173  if (lp->nbr == 0)
174  lp->ptr = NULL;
175  else if ((lp->ptr = (Point3f *)malloc(lp->nbr * sizeof(Point3f))) == NULL) {
176  static const char proc_name[] = "fscanf_Point3f_list";
177  perror(proc_name);
178  throw vpException(vpException::fatalError, "Error in fscanf_Point3f_list");
179  }
180 
181  /* Lecture des points de la liste un a un. */
182 
183  pp = lp->ptr;
184  pend = pp + lp->nbr;
185  for (; pp < pend; pp++) {
186  int t;
187 
188  if ((t = lex()) != T_FLOAT && t != T_INT)
189  lexerr("start", err_tbl[0], "X", err_tbl[1], NULL);
190  /* FC printf("X %d %f\n",myint, myfloat); */
191  pp->x = (t == T_INT) ? (float)myint : myfloat;
192 
193  if ((t = lex()) != T_FLOAT && t != T_INT)
194  lexerr("start", err_tbl[0], "Y", err_tbl[1], NULL);
195  /* FC printf("Y %d %f\n",myint, myfloat); */
196  pp->y = (t == T_INT) ? (float)myint : myfloat;
197 
198  if ((t = lex()) != T_FLOAT && t != T_INT)
199  lexerr("start", err_tbl[0], "Z", err_tbl[1], NULL);
200  /* FC printf("Z %d %f\n",myint, myfloat); */
201  pp->z = (t == T_INT) ? (float)myint : myfloat;
202  }
203 }
204 
205 #endif
error that can be emited by ViSP classes.
Definition: vpException.h:72
@ fatalError
Fatal error.
Definition: vpException.h:96