Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpBoundio.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 https://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#include <visp3/core/vpConfig.h>
42#include <visp3/core/vpException.h>
43
44#ifndef DOXYGEN_SHOULD_SKIP_THIS
45#include "vpArit.h"
46#include "vpBoundio.h"
47#include "vpLex.h"
48#include "vpMy.h"
49#include "vpSkipio.h"
50#include "vpToken.h"
51
52#include <errno.h>
53#include <stdio.h>
54#include <stdlib.h>
55
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 */
91void 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 throw vpException(vpException::fatalError, "Error in fscanf_Face_list");
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 throw vpException(vpException::fatalError, "Error in fscanf_Face_list");
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 */
158void 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 throw vpException(vpException::fatalError, "Error in fscanf_Point3f_list");
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) ? static_cast<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) ? static_cast<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) ? static_cast<float>(myint) : myfloat;
201 }
202}
203END_VISP_NAMESPACE
204#endif
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ fatalError
Fatal error.
Definition vpException.h:72