Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpBound.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 fichier "bound.c" contient les procedures de gestion des scenes de
32 *modele geometrique surfacique.
33 *
34 * Authors:
35 * Jean-Luc CORRE
36 */
37
38#include <visp3/core/vpConfig.h>
39#include <visp3/core/vpException.h>
40
41#ifndef DOXYGEN_SHOULD_SKIP_THIS
42#include "vpArit.h"
43#include "vpBound.h"
44#include "vpMy.h"
45#include <errno.h>
46#include <math.h>
47#include <stdio.h>
48#include <stdlib.h>
49#include <string.h>
50
52/*
53 * La procedure "free_Bound" libere la memoire d'une surface.
54 * Les champs "bound.face.edge" ne sont pas utilises.
55 * Entree :
56 * bp Surface a liberer.
57 */
58 void free_Bound(Bound *bp)
59{
60 Face *fp = bp->face.ptr;
61 Face *fend = fp + bp->face.nbr;
62
63 for (; fp < fend; fp++) { /* libere les polygones */
64 if (fp->vertex.ptr != fp->vertex.tbl)
65 free((char *)fp->vertex.ptr);
66 }
67 if (bp->face.ptr != NULL) { /* libere les faces */
68 free((char *)bp->face.ptr);
69 bp->face.ptr = NULL;
70 }
71 if (bp->point.ptr != NULL) { /* libere les points */
72 free((char *)bp->point.ptr);
73 bp->point.ptr = NULL;
74 }
75#ifdef face_normal
76 if (bp->normal.ptr != NULL) { /* libere les vecteurs */
77 free((char *)bp->normal.ptr);
78 bp->normal.ptr = NULL;
79 }
80#endif /* face_normal */
81 bp->is_display = FALSE;
82}
83
84/*
85 * La procedure "free_huge_Bound" libere une surface de taille maximale.
86 * La particularite de cette surface est le tableau unique des sommets.
87 * Entree :
88 * bp Surface a liberer.
89 */
90void free_huge_Bound(Bound *bp)
91{
92 bp->face.nbr = 1; /* pour la liberation en une fois */
93 free_Bound(bp);
94}
95
96/*
97 * La procedure "free_Bound_scene" libere une scene de surfaces.
98 * Entree :
99 * bsp Scene a liberer.
100 */
101void free_Bound_scene(Bound_scene *bsp)
102{
103 Bound *bp = bsp->bound.ptr;
104 Bound *bend = bp + bsp->bound.nbr;
105
106 for (; bp < bend; bp++) { /* libere les surfaces */
107 free_Bound(bp);
108 }
109 if (bsp->name != NULL) { /* libere le nom */
110 free((char *)bsp->name);
111 bsp->name = NULL;
112 }
113 if (bsp->bound.ptr != NULL) { /* libere le tableau */
114 free((char *)bsp->bound.ptr);
115 bsp->bound.ptr = NULL;
116 }
117}
118
119/*
120 * La procedure "malloc_Bound" alloue une surface.
121 * Les champs "bound.face.edge" ne sont pas utilises.
122 * Entree :
123 * bp Surface a allouer.
124 * type Type de la surface.
125 * polygonal Booleen indiquant si la surface est polygonale.
126 * fn Nombre de faces de la surface.
127 * pn Nombre de points de la surface.
128 */
129void malloc_Bound(Bound *bp, Type type, int polygonal, Index fn, Index pn)
130{
131 static char proc_name[] = "malloc_Bound";
132
133 if ((bp->face.nbr = fn) == 0) /* faces */
134 bp->face.ptr = NULL;
135 else if ((bp->face.ptr = (Face *)malloc(fn * sizeof(Face))) == NULL) {
136 perror(proc_name);
137 throw vpException(vpException::fatalError, "Error in malloc_Bound");
138 }
139
140 if ((bp->point.nbr = pn) == 0) /* points */
141 bp->point.ptr = NULL;
142 else if ((bp->point.ptr = (Point3f *)malloc(pn * sizeof(Point3f))) == NULL) {
143 perror(proc_name);
144 throw vpException(vpException::fatalError, "Error in malloc_Bound");
145 }
146
147#ifdef face_normal
148 /* normales aux sommets */
149 if ((bp->normal.nbr = (bp->is_polygonal ? 0 : pn)) == 0)
150 bp->normal.ptr = NULL;
151 else if ((bp->normal.ptr = (Vector *)malloc(pn * sizeof(Vector))) == NULL) {
152 perror(proc_name);
153 throw vpException(vpException::fatalError, "Error in malloc_Bound");
154 }
155#endif /* face_normal */
156
157 bp->type = type;
158 bp->is_display = TRUE;
159 bp->is_polygonal = static_cast<unsigned int>(polygonal);
160}
161
162/*
163 * La procedure "malloc_huge_Bound" alloue une surface de taille maximale.
164 * La surface est adaptee pour la reception de tout type de surface.
165 * La surface allouee peut etre utilisee comme une surface de travail.
166 * Sa taille est definie par les macros "..._NBR" de "world.h".
167 * FACE_NBR : son nombre de faces
168 * POINT_NBR : son nombre de points
169 * VECTOR_NBR : son monbre de vecteurs
170 * VERTEX_NBR : son nombre de sommets par face.
171 * La particularite de la surface vient de l'allocation en une seule fois
172 * d'un tableau de sommets. Les polygones des faces ne sont pas initialiser,
173 * exepte celui de la premiere face qui est la base du tableau des sommets.
174 * Les champs "bound.face.edge" ne sont pas utilises.
175 * Entree :
176 * bp Surface maximale a allouer.
177 */
178void malloc_huge_Bound(Bound *bp)
179{
180
181#ifdef face_normal
182 malloc_Bound(bp, (Type)BND_NULL, FALSE, FACE_NBR, POINT_NBR);
183#else
184 malloc_Bound(bp, (Type)BND_NULL, TRUE, FACE_NBR, POINT_NBR);
185#endif /* face_normal */
186 if ((bp->face.ptr->vertex.ptr = (Index *)malloc(FACE_NBR * VERTEX_NBR * sizeof(Index))) == NULL) {
187 static char proc_name[] = "malloc_Huge_Bound";
188 perror(proc_name);
189 throw vpException(vpException::fatalError, "Error in malloc_huge_Bound");
190 }
191}
192
193/*
194 * La procedure "malloc_Bound_scene" alloue une scene de surfaces.
195 * Stocke le nom de la scene et alloue l'espace memoire necessaire.
196 * Les champs "bound.face.edge" ne sont pas utilises.
197 * Entree :
198 * bsp Scene a allouer.
199 * name Nom de la scene.
200 * bn Nombre de surfaces de la scene.
201 */
202void malloc_Bound_scene(Bound_scene *bsp, const char *name, Index bn)
203{
204 static char proc_name[] = "malloc_Bound_scene";
205
206 if ((bsp->name = (char *)malloc((strlen(name) + 1) * sizeof(char))) == NULL) {
207 perror(proc_name);
208 exit(1);
209 }
210 if ((bsp->bound.nbr = bn) == 0)
211 bsp->bound.ptr = NULL;
212 else if ((bsp->bound.ptr = (Bound *)malloc(bn * sizeof(Bound))) == NULL) {
213 perror(proc_name);
214 throw vpException(vpException::fatalError, "Error in malloc_Bound_scene");
215 }
216 strcpy(bsp->name, name);
217 bsp->bound.nbr = 0;
218}
219END_VISP_NAMESPACE
220#endif
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ fatalError
Fatal error.
Definition vpException.h:72