ViSP
vpBoundio.cpp
1 /****************************************************************************
2  *
3  * $Id: vpBoundio.cpp 5284 2015-02-09 14:24:10Z fspindle $
4  *
5 * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  * Description:
34  * Le module "boundio.c" contient les procedures d'entree/sortie
35  * des types definis dans le module "bound.h".
36  * Les entrees non specifiees sont effectuees
37  * sur le fichier "source" de "lex.c".
38  * Pour les mots cles des "fprintf_..." voir "token.c".
39  *
40  * Authors:
41  * Jean-Luc CORRE
42  *
43  *****************************************************************************/
44 
45 
46 #include "visp/vpConfig.h"
47 
48 
49 #ifndef DOXYGEN_SHOULD_SKIP_THIS
50 #include <visp/vpMy.h>
51 #include <visp/vpArit.h>
52 #include <visp/vpBound.h>
53 #include <visp/vpToken.h>
54 #include <visp/vpSkipio.h>
55 #include <visp/vpLex.h>
56 
57 #include <errno.h>
58 #include <stdio.h>
59 #include <stdlib.h>
60 void fscanf_Point3f_list (Point3f_list *);
61 void fscanf_Face_list (Face_list *);
62 
63 /*
64  * La procedure "fscanf_Bound" lit en ascii une surface.
65  * Entree :
66  * bp Surface a lire.
67  */
68 void fscanf_Bound (Bound *bp)
69 {
70  /* Lecture du type polygonale de la surface. */
71 
72  skip_keyword (T_TYPE, "bound: keyword \"type\" expected");
73  if (lex () != T_INT)
74  lexerr ("start","bound_type: boolean expected (0=FALSE|~0=TRUE)", NULL);
75  bp->is_polygonal = (myint ? 1 : 0);
76 
77  /* Lecture de la liste de points de la surface. */
78 
79  skip_keyword (T_POINT_LIST, "bound: keyword \"point_list\" expected");
80  pusherr ("bound_point_list: ");
81  fscanf_Point3f_list (&bp->point);
82  poperr ();
83 
84  /* Lecture de la liste de faces de la surface. */
85 
86  skip_keyword (T_FACE_LIST, "bound: keyword \"face_list\" expected");
87  pusherr ("bound_face_list: ");
88  fscanf_Face_list (&bp->face);
89  poperr ();
90 }
91 
92 /*
93  * La procedure "fscanf_Face_list" lit en ascii une liste de faces.
94  * Entree :
95  * lp Liste de faces a lire.
96  */
97 void fscanf_Face_list (Face_list *lp)
98 {
99  static char proc_name[] = "fscanf_Face_list";
100 
101  Face *fp; /* face courante */
102  Face *fend; /* borne de "fp" */
103 
104 
105  /* Lecture du nombre de faces de la liste */
106 
107  if (lex () != T_INT)
108  lexerr ("start","integer expected (number of faces)", NULL);
109  lp->nbr = (Index) myint;
110 
111  /* Allocation dynamique de la liste de faces. */
112 
113  if (lp->nbr == 0)
114  lp->ptr = NULL;
115  else if ((lp->ptr = (Face *) malloc (lp->nbr * sizeof (Face)))
116  == NULL) {
117  perror (proc_name);
118  exit (1);
119  }
120 
121  /* Lecture des faces de la liste une a une. */
122 
123  fp = lp->ptr;
124  fend = fp + lp->nbr;
125  for (; fp < fend; fp++) {
126  Vertex_list *lp = &fp->vertex;
127  Index *vp; /* sommet courant */
128  Index *vend; /* borne de "vp" */
129 
130  /* Lecture du type polygonale de la face. */
131 
132  if (lex () != T_INT)
133  lexerr ("start", "boolean expected (0=FALSE|~0=TRUE)", NULL);
134  fp->is_polygonal = (myint ? 1 : 0);
135 
136  /* Lecture du nombre de sommets de la face. */
137 
138  if (lex () != T_INT)
139  lexerr ("start", "integer expected (number of vertices)", NULL);
140  lp->nbr = (Index) myint;
141 
142  /* Allocation dynamique du polygone de la face. */
143 
144  if (lp->nbr <= DEFAULT_VSIZE)
145  lp->ptr = lp->tbl;
146  else if ((lp->ptr = (Index *) malloc (lp->nbr * sizeof (Index)))
147  == NULL) {
148  perror (proc_name);
149  exit (1);
150  }
151 
152  /* Lecture des sommets de la face un a un. */
153 
154  vp = lp->ptr;
155  vend = vp + lp->nbr;
156  for (; vp < vend; *vp++ = (Index) myint)
157  if (lex () != T_INT)
158  lexerr ("start", "integer expected (index of points 3D)", NULL);
159  }
160 }
161 
162 /*
163  * La procedure "fscanf_Point_list" lit en ascii une liste de points 3D.
164  * Entree :
165  * lp Liste de points a lire.
166  */
167 void fscanf_Point3f_list (Point3f_list *lp)
168 {
169  static const char proc_name[] = "fscanf_Point3f_list";
170 
171 static const char *err_tbl[] = {
172 "float expected (coordinate ",
173 " of point)"
174 };
175  Point3f *pp; /* point courant */
176  Point3f *pend; /* borne de "pp" */
177 
178  /* Lecture du nombre de points de la liste. */
179 
180  if (lex () != T_INT)
181  lexerr ("start", "integer expected (number of points 3D)", NULL);
182  lp->nbr = (Index) myint;
183 /* FC printf("nbr %d\n",lp->nbr); */
184  /* Allocation dynamique la liste de points. */
185 
186  if (lp->nbr == 0)
187  lp->ptr = NULL;
188  else if ((lp->ptr = (Point3f *) malloc (lp->nbr * sizeof (Point3f)))
189  == NULL) {
190  perror (proc_name);
191  exit (1);
192  }
193 
194  /* Lecture des points de la liste un a un. */
195 
196  pp = lp->ptr;
197  pend = pp + lp->nbr;
198  for (; pp < pend; pp++) {
199  int t;
200 
201  if ((t = lex ()) != T_FLOAT && t != T_INT)
202  lexerr ("start", err_tbl[0], "X", err_tbl[1], NULL);
203 /* FC printf("X %d %f\n",myint, myfloat); */
204  pp->x = (t == T_INT) ? (float) myint : myfloat;
205 
206  if ((t = lex ()) != T_FLOAT && t != T_INT)
207  lexerr ("start", err_tbl[0], "Y", err_tbl[1], NULL);
208 /* FC printf("Y %d %f\n",myint, myfloat); */
209  pp->y = (t == T_INT) ? (float) myint : myfloat;
210 
211  if ((t = lex ()) != T_FLOAT && t != T_INT)
212  lexerr ("start", err_tbl[0], "Z", err_tbl[1], NULL);
213 /* FC printf("Z %d %f\n",myint, myfloat); */
214  pp->z = (t == T_INT) ? (float) myint : myfloat;
215  }
216 }
217 
218 #endif