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