1 |
|
5 |
|
2 |
|
|
/* preparation au maillage */
|
3 |
|
|
/* SEGMENT */
|
4 |
|
|
struct st_segment
|
5 |
|
|
{
|
6 |
|
|
int n1 ;/* numero du noeud 1 */
|
7 |
|
|
int n2 ;/* numero du noeud 2 */
|
8 |
|
|
int card ;/* cardinalite */
|
9 |
|
|
int tabele[10] ;
|
10 |
|
|
struct st_segment *suivant ;/* chainage */
|
11 |
|
|
} ;
|
12 |
|
|
typedef struct st_segment SEGMENT ;
|
13 |
|
|
|
14 |
|
|
/* ELEMENT */
|
15 |
|
|
struct st_element
|
16 |
|
|
{
|
17 |
|
|
int num ;/* numero de l'element */
|
18 |
|
|
int mark ;
|
19 |
|
|
struct st_element *suivant ; /* chainage */
|
20 |
|
|
} ;
|
21 |
|
|
typedef struct st_element ELEMENT ;
|
22 |
|
|
|
23 |
|
|
/* SURFACE */
|
24 |
|
|
struct st_surface
|
25 |
|
|
{
|
26 |
|
|
struct st_element *ele ;/* tete de liste des elements de la surface fermee */
|
27 |
|
|
struct st_surface *suivant ;/* chainage */
|
28 |
|
|
struct st_envel *envel ;
|
29 |
|
|
int etat ;
|
30 |
|
|
};
|
31 |
|
|
typedef struct st_surface SURFACE ;
|
32 |
|
|
/* ENVEL = ensemble de surfaces = volume enveloppe */
|
33 |
|
|
struct st_envel
|
34 |
|
|
{
|
35 |
|
|
struct st_surface *surf_ext ;/* surface exterieure */
|
36 |
|
|
struct st_surface *surf_int ;/* surfaces interieures */
|
37 |
|
|
} ;
|
38 |
|
|
typedef struct st_envel ENVEL ;
|
39 |
|
|
|
40 |
|
|
/* structures employees */
|
41 |
|
|
|
42 |
|
|
struct st_noeud
|
43 |
|
|
{
|
44 |
|
|
int num ;
|
45 |
|
|
int mark ;
|
46 |
|
|
int mark2 ;
|
47 |
|
|
int flag ;
|
48 |
|
|
struct st_noeud *suivant ;
|
49 |
|
|
struct st_oct *oct ;
|
50 |
|
|
struct st_connec *lis_con ;
|
51 |
|
|
} ;
|
52 |
|
|
typedef struct st_noeud NOEUD ;
|
53 |
|
|
struct st_flag
|
54 |
|
|
{
|
55 |
|
|
unsigned val0:1 ;
|
56 |
|
|
unsigned val1:1 ;
|
57 |
|
|
unsigned val2:1 ;
|
58 |
|
|
unsigned val3:1 ;
|
59 |
|
|
/* alignement */
|
60 |
|
|
unsigned val4:1 ;
|
61 |
|
|
unsigned val5:1 ;
|
62 |
|
|
unsigned val6:1 ;
|
63 |
|
|
unsigned val7:1 ;
|
64 |
|
|
unsigned val8:1 ;
|
65 |
|
|
unsigned val9:1 ;
|
66 |
|
|
unsigned val10:1 ;
|
67 |
|
|
unsigned val11:1 ;
|
68 |
|
|
unsigned val12:1 ;
|
69 |
|
|
unsigned val13:1 ;
|
70 |
|
|
unsigned val14:1 ;
|
71 |
|
|
unsigned val15:1 ;
|
72 |
|
|
} ;
|
73 |
|
|
typedef struct st_flag FLAG ;
|
74 |
|
|
struct st_face
|
75 |
|
|
{
|
76 |
|
|
int nb_qua ;
|
77 |
|
|
int mark ;
|
78 |
|
|
int hist ;/* historique */
|
79 |
|
|
int essai ;
|
80 |
|
|
FLAG tab ;
|
81 |
|
|
struct st_noeud *n1 ;
|
82 |
|
|
struct st_noeud *n2 ;
|
83 |
|
|
struct st_noeud *n3 ;
|
84 |
|
|
struct st_tetra *tetra1 ;
|
85 |
|
|
struct st_tetra *tetra2 ;
|
86 |
|
|
struct st_face *prec ;
|
87 |
|
|
struct st_face *suivant ;
|
88 |
|
|
} ;
|
89 |
|
|
typedef struct st_face FACE ;
|
90 |
|
|
|
91 |
|
|
/* structure octree */
|
92 |
|
|
struct st_oct
|
93 |
|
|
{
|
94 |
|
|
float taille ;
|
95 |
|
|
float vec[3] ;
|
96 |
|
|
struct st_oct *tab_oct[8] ;
|
97 |
|
|
struct st_noeud *lis_noe ;/* liste des noeuds */
|
98 |
|
|
struct st_objet *lis_obj ;/* liste des faces */
|
99 |
|
|
struct st_connec *lis_con ;/* liste des tetraedres */
|
100 |
|
|
};
|
101 |
|
|
typedef struct st_oct OCT ;
|
102 |
|
|
|
103 |
|
|
/* structure objet */
|
104 |
|
|
struct st_objet
|
105 |
|
|
{
|
106 |
|
|
struct st_face *ref ;/* objet de reference */
|
107 |
|
|
struct st_objet *suivant ;/* chainage dans l'octree */
|
108 |
|
|
};
|
109 |
|
|
typedef struct st_objet OBJET ;
|
110 |
|
|
|
111 |
|
|
struct st_tetra /* ensemble de faces creees */
|
112 |
|
|
{
|
113 |
|
|
int num ;
|
114 |
|
|
int mark ;
|
115 |
|
|
struct st_face *face1 ;
|
116 |
|
|
struct st_face *face2 ;
|
117 |
|
|
struct st_face *face3 ;
|
118 |
|
|
struct st_face *face4 ;
|
119 |
|
|
};
|
120 |
|
|
typedef struct st_tetra TETRAEDRE ;
|
121 |
|
|
struct st_connec
|
122 |
|
|
{
|
123 |
|
|
struct st_tetra *tetra ;/* tetraedre de reference */
|
124 |
|
|
struct st_connec *suivant ;/* chainage des tetraedres coupant l'octree */
|
125 |
|
|
};
|
126 |
|
|
typedef struct st_connec CONNEC ;
|
127 |
|
|
struct st_gest_mem
|
128 |
|
|
{
|
129 |
|
|
/* preparation au maillage */
|
130 |
|
|
|
131 |
|
|
int lecture_donnees ;
|
132 |
|
|
int premiere_couche ;
|
133 |
|
|
int maillage_termine ;
|
134 |
|
|
int size ;
|
135 |
|
|
double cpu ;
|
136 |
|
|
float crit_2d_min ;
|
137 |
|
|
float xmin, ymin, zmin ;
|
138 |
|
|
float xmax, ymax, zmax ;
|
139 |
|
|
float coeff ;
|
140 |
|
|
int icode ;
|
141 |
|
|
/* int nb_tetra ;*/
|
142 |
|
|
int nb_good ;
|
143 |
|
|
int nb_medium ;
|
144 |
|
|
int nb_low ;
|
145 |
|
|
int nb_bad ;
|
146 |
|
|
float rap ;
|
147 |
|
|
/*int nb_noeud ;*/
|
148 |
|
|
SEGMENT **tab_seg ;
|
149 |
|
|
float *v_inter ;
|
150 |
|
|
|
151 |
|
|
/* maillage */
|
152 |
|
|
/* tableau de coordonnees */
|
153 |
|
|
float *vcorg ;
|
154 |
|
|
float *coord ;
|
155 |
|
|
|
156 |
|
|
/* tableau de connectivite */
|
157 |
|
|
int *numele ;
|
158 |
|
|
int nb_init ;/* nombre initial de noeuds */
|
159 |
|
|
int nb_info ;/* nombre de noeuds info */
|
160 |
|
|
int nb_2d ;/* nombre initial de mailles 2d */
|
161 |
|
|
int *tabele ;/* table des mailles 2d */
|
162 |
|
|
int *number ;/* numeros mosaic des noeuds de peau */
|
163 |
|
|
|
164 |
|
|
int numax ;
|
165 |
|
|
int numael ;
|
166 |
|
|
/* maillage quadratique */
|
167 |
|
|
float *coord2 ;
|
168 |
|
|
int *tablin ;
|
169 |
|
|
int *neww ;
|
170 |
|
|
int *old ;
|
171 |
|
|
int is_qua ;
|
172 |
|
|
int nb_noe_qua ;
|
173 |
|
|
int *numele2 ;
|
174 |
|
|
int *connec ;
|
175 |
|
|
int *tabcor ;
|
176 |
|
|
int *tabcoul ;
|
177 |
|
|
int *tab_rec ;
|
178 |
|
|
int *tab_ref ;
|
179 |
|
|
int *tab_card ;
|
180 |
|
|
int nb_rec ;
|
181 |
|
|
int card ;
|
182 |
|
|
/* m3d_maidft */
|
183 |
|
|
float *val_noeud ;
|
184 |
|
|
int *corresp ;
|
185 |
|
|
int *tab_voisin ;
|
186 |
|
|
OCT *root ;
|
187 |
|
|
char name[256] ;
|
188 |
|
|
char buffer[256] ;
|
189 |
|
|
char extension[256] ;
|
190 |
|
|
char start[256];
|
191 |
|
|
char end[256];
|
192 |
|
|
char release[256] ;
|
193 |
|
|
|
194 |
|
|
/* nouvelles structures : alloc par paquets */
|
195 |
|
|
/* listes de noeuds, faces, tetraedres ... */
|
196 |
|
|
ELEMENT *tab_ele ;
|
197 |
|
|
ELEMENT *tab_ele2 ;
|
198 |
|
|
SURFACE *tab_surf;
|
199 |
|
|
int nb_surf ;
|
200 |
|
|
FACE *front ;
|
201 |
|
|
SEGMENT *tab_segment[1000] ;
|
202 |
|
|
int nb_segment ;
|
203 |
|
|
NOEUD *tab_noeud[1000];
|
204 |
|
|
int nb_noeud ;
|
205 |
|
|
FACE *tab_face[1000] ;
|
206 |
|
|
int nb_face ;
|
207 |
|
|
TETRAEDRE *tab_tetra[1000] ;
|
208 |
|
|
int nb_tetra ;
|
209 |
|
|
OBJET *tab_objet[1000] ;
|
210 |
|
|
int nb_objet ;
|
211 |
|
|
CONNEC *tab_connec[1000] ;
|
212 |
|
|
int nb_connec ;
|
213 |
|
|
OCT *tab_oct[1000] ;
|
214 |
|
|
int nb_oct ;
|
215 |
|
|
/* surfaces enveloppes */
|
216 |
|
|
ENVEL *envel ;
|
217 |
|
|
|
218 |
|
|
} ;
|
219 |
|
|
|
220 |
|
|
typedef struct st_gest_mem GEST_MEM ;
|
221 |
|
|
|
222 |
|
|
/* ************************************************************ */
|
223 |
|
|
/* ------------------------------------------------------------ */
|
224 |
|
|
/* **************** definition de macros ******************** */
|
225 |
|
|
/* operateurs sur des structures, but : ameliorer l'alloc */
|
226 |
|
|
/* ------------------------------------------------------------ */
|
227 |
|
|
/* ************************************************************ */
|
228 |
|
|
#define NB_ENT 12
|
229 |
|
|
//#ifdef __STDC__
|
230 |
|
|
#define mknom(a,b) a##b
|
231 |
|
|
//#else
|
232 |
|
|
//#define mknom(a,b) a/**/b
|
233 |
|
|
//#endif
|
234 |
|
|
#define TAB(entite) mknom(gest->tab_,entite)
|
235 |
|
|
#define NBR(entite) mknom(gest->nb_,entite)
|
236 |
|
|
/* ------------------------------------------ */
|
237 |
|
|
/* cree et retourne l'adresse de la structure */
|
238 |
|
|
/* ------------------------------------------ */
|
239 |
|
|
#define NEW_ALLOC(entite,adresse) \
|
240 |
|
|
if (TAB(entite)[NBR(entite)>>NB_ENT] == NULL ) \
|
241 |
|
|
{\
|
242 |
|
|
TAB(entite)[NBR(entite)>>NB_ENT] = (struct mknom(st_,entite) *)calloc(1<<NB_ENT,sizeof(struct mknom(st_,entite))) ; \
|
243 |
|
|
gest->size = gest->size + sizeof(struct mknom(st_,entite)) * (1<< NB_ENT) ;\
|
244 |
|
|
if (debug) printf("alloc de %d entites de taille %d :%d\n",1<<NB_ENT,sizeof(struct mknom(st_,entite)),gest->size) ;\
|
245 |
|
|
}\
|
246 |
|
|
if ( TAB(entite)[NBR(entite)>>NB_ENT] == NULL ) adresse = NULL ; \
|
247 |
|
|
else {\
|
248 |
|
|
adresse = &(TAB(entite)[NBR(entite)>>NB_ENT][NBR(entite)-(NBR(entite)>>NB_ENT) * (1<<NB_ENT)]) ;\
|
249 |
|
|
NBR(entite) ++ ;\
|
250 |
|
|
}
|
251 |
|
|
/* ---------------------------------------------------------------- */
|
252 |
|
|
/* trouve l'adresse de la structure de type entite de numero numero */
|
253 |
|
|
/* ---------------------------------------------------------------- */
|
254 |
|
|
#define ADRESSE(entite,numero,adr)\
|
255 |
|
|
if (TAB(entite)[numero>>NB_ENT] == NULL) adr = NULL ; \
|
256 |
|
|
else adr = &(TAB(entite)[numero>>NB_ENT][numero - (numero>>NB_ENT)*(1<<NB_ENT)]) ;
|
257 |
|
|
|
258 |
|
|
#define ERREUR_ALLOC_NULL(adr) \
|
259 |
|
|
if (adr == NULL) {\
|
260 |
|
|
if (debug) printf("%s\n","Erreur alloc") ;\
|
261 |
|
|
m3d_erreur(ERR_ALLOC) ;\
|
262 |
|
|
return(NULL) ;\
|
263 |
|
|
}
|
264 |
|
|
|
265 |
|
|
#define ERREUR_ALLOC_FAUX(adr) \
|
266 |
|
|
if (adr == NULL) {\
|
267 |
|
|
if (debug) printf("%s\n","Erreur alloc") ;\
|
268 |
|
|
m3d_erreur(ERR_ALLOC) ;\
|
269 |
|
|
return(FAUX) ;\
|
270 |
|
|
}
|
271 |
|
|
#define ERREUR_ALLOC(adr) \
|
272 |
|
|
if (adr == NULL) {\
|
273 |
|
|
m3d_erreur(ERR_ALLOC) ;\
|
274 |
|
|
return(FAUX) ;\
|
275 |
|
|
}
|
276 |
|
|
|
277 |
|
|
/*
|
278 |
|
|
#define PREC(entite) mknom((entite),->prec)
|
279 |
|
|
#define SUIVANT(entite) mknom((entite),->suivant)
|
280 |
|
|
*/
|
281 |
|
|
#define PREC(entite) (entite)->prec
|
282 |
|
|
#define SUIVANT(entite) (entite)->suivant
|
283 |
|
|
|
284 |
|
|
/* suppression d'un objet d'une liste */
|
285 |
|
|
/* chainage suivant prec */
|
286 |
|
|
#define SUPPRIMER_LISTE(type,tete,fin,entite)\
|
287 |
|
|
{\
|
288 |
|
|
struct mknom(st_,type) *pcourant, *scourant ;\
|
289 |
|
|
pcourant = PREC(entite) ;\
|
290 |
|
|
scourant = SUIVANT(entite) ;\
|
291 |
|
|
if (pcourant== NULL) {\
|
292 |
|
|
if (scourant == NULL) { \
|
293 |
|
|
PREC(entite) = NULL ;\
|
294 |
|
|
SUIVANT(entite) = NULL ;\
|
295 |
|
|
tete = NULL ;\
|
296 |
|
|
fin = NULL ;\
|
297 |
|
|
}\
|
298 |
|
|
else {\
|
299 |
|
|
scourant->prec = NULL ;\
|
300 |
|
|
PREC(entite) = NULL ;\
|
301 |
|
|
SUIVANT(entite) = NULL ;\
|
302 |
|
|
tete = scourant ;\
|
303 |
|
|
}\
|
304 |
|
|
}\
|
305 |
|
|
else {\
|
306 |
|
|
if (scourant == NULL) \
|
307 |
|
|
{pcourant->suivant = NULL ;\
|
308 |
|
|
PREC(entite) = NULL ;\
|
309 |
|
|
SUIVANT(entite) = NULL ;\
|
310 |
|
|
fin = pcourant ;}\
|
311 |
|
|
else {pcourant->suivant = scourant ;\
|
312 |
|
|
scourant->prec = pcourant ;\
|
313 |
|
|
PREC(entite) = NULL ;\
|
314 |
|
|
SUIVANT(entite) = NULL ;}\
|
315 |
|
|
}\
|
316 |
|
|
}
|
317 |
|
|
|
318 |
|
|
#define INSERER_FIN_LISTE(tete,fin,entite)\
|
319 |
|
|
if (tete == NULL)\
|
320 |
|
|
/* insertion dans une liste vide */\
|
321 |
|
|
{\
|
322 |
|
|
tete = entite ;\
|
323 |
|
|
fin = entite ;\
|
324 |
|
|
}\
|
325 |
|
|
/* sinon insertion en queue de liste, la tete est inchangee */\
|
326 |
|
|
else {\
|
327 |
|
|
SUIVANT(fin) = entite ;\
|
328 |
|
|
PREC(entite) = fin ;\
|
329 |
|
|
SUIVANT(entite) = NULL ;\
|
330 |
|
|
fin = entite ;\
|
331 |
|
|
}
|
332 |
|
|
|
333 |
|
|
#define INSERER_TETE_LISTE(tete,fin,entite)\
|
334 |
|
|
PREC(entite) = NULL ;\
|
335 |
|
|
if (tete != NULL) {\
|
336 |
|
|
/* la queue est inchangee */\
|
337 |
|
|
SUIVANT(entite) = tete ;\
|
338 |
|
|
PREC(tete) = entite ;\
|
339 |
|
|
tete = entite ;\
|
340 |
|
|
}\
|
341 |
|
|
else {\
|
342 |
|
|
SUIVANT(entite) = NULL ;\
|
343 |
|
|
tete = entite ;\
|
344 |
|
|
fin = entite ;\
|
345 |
|
|
}
|
346 |
|
|
|
347 |
|
|
#define INSERE_TETE(tete,entite)\
|
348 |
|
|
SUIVANT(entite) = tete ;\
|
349 |
|
|
tete = entite ;
|
350 |
|
|
|
351 |
|
|
#define INIT_ALLOC(entite)\
|
352 |
|
|
{\
|
353 |
|
|
int i ;\
|
354 |
|
|
for (i=0;i<1000;i++)\
|
355 |
|
|
{\
|
356 |
|
|
TAB(entite)[i] = NULL ;\
|
357 |
|
|
NBR(entite) = 0 ;\
|
358 |
|
|
}\
|
359 |
|
|
}
|
360 |
|
|
|
361 |
|
|
#define FREE_ALLOC(entite)\
|
362 |
|
|
{\
|
363 |
|
|
int i ;\
|
364 |
|
|
i = 0 ;\
|
365 |
|
|
while (TAB(entite)[i] !=NULL)\
|
366 |
|
|
{\
|
367 |
|
|
free(TAB(entite)[i]) ;\
|
368 |
|
|
TAB(entite)[i] = NULL ;\
|
369 |
|
|
i++ ;\
|
370 |
|
|
}\
|
371 |
|
|
}
|
372 |
|
|
|
373 |
|
|
#define TRI_REEL(tab,nb_val,iordre)\
|
374 |
|
|
{\
|
375 |
|
|
int i ;\
|
376 |
|
|
for (i=0;i<nb_val;i++) iordre[i] = i+1 ;\
|
377 |
|
|
trirea(tab,&nb_val,iordre) ; \
|
378 |
|
|
}
|
379 |
|
|
|
380 |
|
|
#define BOITE(n1,n2,n3,n4,vmin,vmax)\
|
381 |
|
|
vmin[0] = min(coord[x(n1->num)],coord[x(n2->num)]) ;\
|
382 |
|
|
vmin[0] = min(vmin[0],coord[x(n3->num)]) ;\
|
383 |
|
|
if (n4 != NULL) vmin[0] = min(vmin[0],coord[x(n4->num)]) ;\
|
384 |
|
|
vmin[1] = min(coord[y(n1->num)],coord[y(n2->num)]) ;\
|
385 |
|
|
vmin[1] = min(vmin[1],coord[y(n3->num)]) ;\
|
386 |
|
|
if (n4 != NULL) vmin[1] = min(vmin[1],coord[y(n4->num)]) ;\
|
387 |
|
|
vmin[2] = min(coord[z(n1->num)],coord[z(n2->num)]) ;\
|
388 |
|
|
vmin[2] = min(vmin[2],coord[z(n3->num)]) ;\
|
389 |
|
|
if (n4 != NULL) vmin[2] = min(vmin[2],coord[z(n4->num)]) ;\
|
390 |
|
|
vmax[0] = max(coord[x(n1->num)],coord[x(n2->num)]) ;\
|
391 |
|
|
vmax[0] = max(vmax[0],coord[x(n3->num)]) ;\
|
392 |
|
|
if (n4 != NULL) vmax[0] = max(vmax[0],coord[x(n4->num)]) ;\
|
393 |
|
|
vmax[1] = max(coord[y(n1->num)],coord[y(n2->num)]) ;\
|
394 |
|
|
vmax[1] = max(vmax[1],coord[y(n3->num)]) ;\
|
395 |
|
|
if (n4 != NULL) vmax[1] = max(vmax[1],coord[y(n4->num)]) ;\
|
396 |
|
|
vmax[2] = max(coord[z(n1->num)],coord[z(n2->num)]) ;\
|
397 |
|
|
vmax[2] = max(vmax[2],coord[z(n3->num)]) ;\
|
398 |
|
|
if (n4 != NULL) vmax[2] = max(vmax[2],coord[z(n4->num)]) ;
|
399 |
|
|
|
400 |
|
|
#define NOEUD_TETRA(tetra,noeud)\
|
401 |
|
|
if (((tetra->face2)->n1 != (tetra->face1)->n1) && ((tetra->face2)->n1 != (tetra->face1)->n2) && ((tetra->face2)->n1 != (tetra->face1)->n3)) \
|
402 |
|
|
noeud = (tetra->face2)->n1 ;\
|
403 |
|
|
else if (((tetra->face2)->n2 != (tetra->face1)->n1) && ((tetra->face2)->n2 != (tetra->face1)->n2) && ((tetra->face2)->n2 != (tetra->face1)->n3)) \
|
404 |
|
|
noeud = (tetra->face2)->n2 ;\
|
405 |
|
|
else noeud = (tetra->face2)->n3 ;
|