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