Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpBoundio.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Le module "boundio.c" contient les procedures d'entree/sortie
32  * des types definis dans le module "bound.h".
33  * Les entrees non specifiees sont effectuees
34  * sur le fichier "source" de "lex.c".
35  * Pour les mots cles des "fprintf_..." voir "token.c".
36  *
37  * Authors:
38  * Jean-Luc CORRE
39  *
40  *****************************************************************************/
41 
42 
43 #include <visp3/core/vpConfig.h>
44 
45 #ifndef DOXYGEN_SHOULD_SKIP_THIS
46 #include "vpMy.h"
47 #include "vpArit.h"
48 #include "vpBoundio.h"
49 #include "vpToken.h"
50 #include "vpSkipio.h"
51 #include "vpLex.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)))
107  == NULL) {
108  static char proc_name[] = "fscanf_Face_list";
109  perror (proc_name);
110  exit (1);
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)))
139  == NULL) {
140  static char proc_name[] = "fscanf_Face_list";
141  perror (proc_name);
142  exit (1);
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[] = {
163  "float expected (coordinate ",
164  " of point)"
165  };
166  Point3f *pp; /* point courant */
167  Point3f *pend; /* borne de "pp" */
168 
169  /* Lecture du nombre de points de la liste. */
170 
171  if (lex () != T_INT)
172  lexerr ("start", "integer expected (number of points 3D)", NULL);
173  lp->nbr = (Index) myint;
174 /* FC printf("nbr %d\n",lp->nbr); */
175  /* Allocation dynamique la liste de points. */
176 
177  if (lp->nbr == 0)
178  lp->ptr = NULL;
179  else if ((lp->ptr = (Point3f *) malloc (lp->nbr * sizeof (Point3f)))
180  == NULL) {
181  static const char proc_name[] = "fscanf_Point3f_list";
182  perror (proc_name);
183  exit (1);
184  }
185 
186  /* Lecture des points de la liste un a un. */
187 
188  pp = lp->ptr;
189  pend = pp + lp->nbr;
190  for (; pp < pend; pp++) {
191  int t;
192 
193  if ((t = lex ()) != T_FLOAT && t != T_INT)
194  lexerr ("start", err_tbl[0], "X", err_tbl[1], NULL);
195 /* FC printf("X %d %f\n",myint, myfloat); */
196  pp->x = (t == T_INT) ? (float) myint : myfloat;
197 
198  if ((t = lex ()) != T_FLOAT && t != T_INT)
199  lexerr ("start", err_tbl[0], "Y", err_tbl[1], NULL);
200 /* FC printf("Y %d %f\n",myint, myfloat); */
201  pp->y = (t == T_INT) ? (float) myint : myfloat;
202 
203  if ((t = lex ()) != T_FLOAT && t != T_INT)
204  lexerr ("start", err_tbl[0], "Z", err_tbl[1], NULL);
205 /* FC printf("Z %d %f\n",myint, myfloat); */
206  pp->z = (t == T_INT) ? (float) myint : myfloat;
207  }
208 }
209 
210 #endif