1 |
francois |
283 |
#include <stdio.h> |
2 |
|
|
#include <stdlib.h> |
3 |
|
|
#include <string.h> |
4 |
|
|
#include "m3d_const.h" |
5 |
|
|
#include "m3d_hotes.h" |
6 |
|
|
#include "m3d_struct.h" |
7 |
|
|
#include "m3d_erreur.h" |
8 |
|
|
#include "m3d_message.h" |
9 |
|
|
#include "prototype.h" |
10 |
|
|
|
11 |
|
|
|
12 |
|
|
extern int nb_max_ele; |
13 |
|
|
extern int nb_max_noe; |
14 |
|
|
extern int debug; |
15 |
|
|
extern GEST_MEM *gest; |
16 |
|
|
extern float dimp ; |
17 |
|
|
extern float crit_min ; |
18 |
|
|
extern int sortie ; |
19 |
|
|
extern int format ; |
20 |
|
|
extern char ext_out[MAX_LINE] ; |
21 |
|
|
extern int is_recover ; |
22 |
|
|
int m3d_recu(char *buffer) |
23 |
|
|
{ |
24 |
|
|
int erreur, i, i1, i2, i3, gtrouve = 0; |
25 |
|
|
int nb_noeud =0, nb_ele =0; |
26 |
|
|
int nb_00 = 0, nb_01 = 0, nb_02 = 0, nb_03 = 0, nb_04 = 0,nb_05 = 0, nb_06 = 0, nb_07 = 0, nb_08 = 0, nb_09 = 0 ; |
27 |
|
|
int nb_bad = 0 ; |
28 |
|
|
char mess[255],temp[MAX_LINE], *ext_res ; |
29 |
|
|
FILE *output ; |
30 |
|
|
float vmin[3], vmax[3]; |
31 |
|
|
float xmin, xmax ,ymin, ymax, zmin, zmax ; |
32 |
|
|
float delta, coeff; |
33 |
|
|
float *vcorg; |
34 |
|
|
float crit, cmin ; |
35 |
|
|
|
36 |
|
|
/* PRISE EN COMPTE DU NOM DU FICHIER */ |
37 |
|
|
|
38 |
|
|
gest->buffer[0] = 0 ; |
39 |
|
|
gest->name[0] = 0 ; |
40 |
|
|
gest->extension[0] = 0 ; |
41 |
|
|
/*ext_out[0] = 0 ;*/ |
42 |
|
|
ext_res = (char*)".SKIN" ; |
43 |
|
|
|
44 |
|
|
/* traitement du nom */ |
45 |
|
|
i = 0 ; |
46 |
|
|
temp[0] = 0 ; |
47 |
|
|
while (i<strlen(buffer)) |
48 |
|
|
{ |
49 |
|
|
if (strncmp (buffer+i,".",1) == 0) gtrouve = i ; |
50 |
|
|
i++ ; |
51 |
|
|
} |
52 |
|
|
i=gtrouve; |
53 |
|
|
strcpy(temp,buffer); |
54 |
|
|
temp[i]=0; |
55 |
|
|
strcpy(gest->name,temp) ; |
56 |
|
|
|
57 |
|
|
/* extension */ |
58 |
|
|
i++; |
59 |
|
|
temp[0] = 0 ; |
60 |
|
|
while (i<strlen(buffer)) |
61 |
|
|
{ |
62 |
|
|
strncat(temp,buffer+i,1) ; |
63 |
|
|
i++ ; |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
strcpy(gest->extension,temp) ; |
67 |
|
|
strcat(gest->buffer,gest->name) ; |
68 |
|
|
|
69 |
|
|
if (strlen(gest->extension) != 0) |
70 |
|
|
{ |
71 |
|
|
strncat(gest->buffer,".",1) ; |
72 |
|
|
strcat(gest->buffer,gest->extension) ; |
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
if (format == sortie) strcat(ext_out,gest->extension) ; |
76 |
|
|
else |
77 |
|
|
{ |
78 |
|
|
if (strlen(ext_out) == 0) strncat(ext_out,"DIAMESH",7) ; |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
temp[0] = 0 ; |
82 |
|
|
strcpy(temp,gest->name) ; |
83 |
|
|
strncat(temp,ext_res,5) ; |
84 |
|
|
/* ouverture du fichier resultat */ |
85 |
|
|
if ( (output = fopen(temp,"w")) == NULL) |
86 |
|
|
{ |
87 |
|
|
m3d_erreur(ERR_OPEN_RESU) ; |
88 |
|
|
return(FAUX) ; |
89 |
|
|
} |
90 |
|
|
fprintf(output,"\n\n===========================================================\n" ) ; |
91 |
|
|
fprintf(output," %s %s\n","VERSION :", gest->release) ; |
92 |
|
|
fprintf(output,"===========================================================\n" ) ; |
93 |
|
|
fprintf(output," %s %s\n", "FILE :", temp) ; |
94 |
|
|
fprintf(output,"===========================================================\n" ) ; |
95 |
|
|
|
96 |
|
|
|
97 |
|
|
/* INITIALISER LES TABLEAUX DE STOCKAGE */ |
98 |
|
|
/* table des elements 2D */ |
99 |
|
|
gest->tabele = (int*)calloc(3*nb_max_ele,sizeof(int)) ; |
100 |
|
|
ERREUR_ALLOC_FAUX(gest->tabele) |
101 |
|
|
|
102 |
|
|
gest->vcorg = (float*)calloc(3*nb_max_noe,sizeof(float)) ; |
103 |
|
|
vcorg = gest->vcorg ; |
104 |
|
|
ERREUR_ALLOC_FAUX(gest->vcorg) |
105 |
|
|
|
106 |
|
|
/* CHARGER LE FICHIER */ |
107 |
|
|
|
108 |
|
|
m3d_rec(&nb_noeud,&nb_ele,vcorg,gest->tabele,&erreur); |
109 |
|
|
if (erreur ==VRAI) |
110 |
|
|
{ |
111 |
|
|
return(FAUX) ; |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
gest->nb_init = nb_noeud ; |
115 |
|
|
gest->nb_2d = nb_ele ; |
116 |
|
|
|
117 |
|
|
for (i=0;i<3 * nb_ele;i++) gest->tabele[i] = gest->tabele[i] - 1 ; |
118 |
|
|
|
119 |
|
|
/* CALCULER LA BOITE ENGLOBANTE */ |
120 |
|
|
|
121 |
|
|
xmin = vcorg[x(0)] ; |
122 |
|
|
xmax = vcorg[x(0)] ; |
123 |
|
|
ymin = vcorg[y(0)]; |
124 |
|
|
ymax = vcorg[y(0)] ; |
125 |
|
|
zmin = vcorg[z(0)]; |
126 |
|
|
zmax = vcorg[z(0)] ; |
127 |
|
|
|
128 |
|
|
for (i=1;i<nb_noeud;i++) |
129 |
|
|
{ |
130 |
|
|
if (vcorg[x(i)]<xmin) xmin = vcorg[x(i)] ; |
131 |
|
|
else if (vcorg[x(i)]>xmax) xmax = vcorg[x(i)] ; |
132 |
|
|
|
133 |
|
|
if (vcorg[y(i)]<ymin) ymin = vcorg[y(i)] ; |
134 |
|
|
else if (vcorg[y(i)]>ymax) ymax = vcorg[y(i)] ; |
135 |
|
|
|
136 |
|
|
if (vcorg[z(i)]<zmin) zmin = vcorg[z(i)] ; |
137 |
|
|
else if (vcorg[z(i)]>zmax) zmax = vcorg[z(i)] ; |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
delta = max(xmax-xmin,ymax-ymin) ; |
141 |
|
|
delta = max(delta,zmax-zmin) ; |
142 |
|
|
coeff = dimp / delta ; |
143 |
|
|
gest->xmin = xmin ; |
144 |
|
|
gest->ymin = ymin ; |
145 |
|
|
gest->zmin = zmin ; |
146 |
|
|
gest->xmax = xmax ; |
147 |
|
|
gest->ymax = ymax ; |
148 |
|
|
gest->zmax = zmax ; |
149 |
|
|
gest->coeff = coeff ; |
150 |
|
|
|
151 |
|
|
for (i=0;i<nb_noeud;i++) |
152 |
|
|
{ |
153 |
|
|
vcorg[x(i)] = (vcorg[x(i)] - xmin) * coeff ; |
154 |
|
|
vcorg[y(i)] = (vcorg[y(i)] - ymin) * coeff ; |
155 |
|
|
vcorg[z(i)] = (vcorg[z(i)] - zmin) * coeff ; |
156 |
|
|
} |
157 |
|
|
|
158 |
|
|
/* ******************** */ |
159 |
|
|
/* examen de la qualite */ |
160 |
|
|
/* ******************** */ |
161 |
|
|
cmin = 2. ; |
162 |
|
|
for (i=0;i<nb_ele;i++) |
163 |
|
|
{ |
164 |
|
|
crit = m3d_cal2d(vcorg,gest->tabele[3*i],gest->tabele[3*i+1],gest->tabele[3*i+2]) ; |
165 |
|
|
if (crit<cmin) cmin = crit ; |
166 |
|
|
if (crit>0.9) nb_09 ++ ; |
167 |
|
|
else if (crit>0.8) nb_08 ++ ; |
168 |
|
|
else if (crit>0.7) nb_07 ++ ; |
169 |
|
|
else if (crit>0.6) nb_06 ++ ; |
170 |
|
|
else if (crit>0.5) nb_05 ++ ; |
171 |
|
|
else if (crit>0.4) nb_04 ++ ; |
172 |
|
|
else if (crit>0.3) nb_03 ++ ; |
173 |
|
|
else if (crit>0.2) nb_02 ++ ; |
174 |
|
|
else if (crit>0.1) nb_01 ++ ; |
175 |
|
|
else |
176 |
|
|
{ |
177 |
|
|
if (crit<0.02) nb_bad++ ; |
178 |
|
|
nb_00 ++ ; |
179 |
|
|
i1 = gest->tabele[3*i] ; |
180 |
|
|
i2 = gest->tabele[3*i+1] ; |
181 |
|
|
i3 = gest->tabele[3*i+2] ; |
182 |
|
|
fprintf(output,"Element %d - criterion %f \n",i+1,crit) ; |
183 |
|
|
} |
184 |
|
|
} |
185 |
|
|
gest->crit_2d_min = cmin ; |
186 |
|
|
crit_min = min(0.9 * cmin,0.1) ; |
187 |
|
|
|
188 |
|
|
fprintf(output,"%s%f\n\n",MESS_CRIT_2D_MIN,cmin) ; |
189 |
|
|
fprintf(output,"%s 0.9 : %d\n",MESS_CRIT_SUP,nb_09) ; |
190 |
|
|
fprintf(output,"%s 0.8 : %d\n",MESS_CRIT_SUP,nb_08) ; |
191 |
|
|
fprintf(output,"%s 0.7 : %d\n",MESS_CRIT_SUP,nb_07) ; |
192 |
|
|
fprintf(output,"%s 0.6 : %d\n",MESS_CRIT_SUP,nb_06) ; |
193 |
|
|
fprintf(output,"%s 0.5 : %d\n",MESS_CRIT_SUP,nb_05) ; |
194 |
|
|
fprintf(output,"%s 0.4 : %d\n",MESS_CRIT_SUP,nb_04) ; |
195 |
|
|
fprintf(output,"%s 0.3 : %d\n",MESS_CRIT_SUP,nb_03) ; |
196 |
|
|
fprintf(output,"%s 0.2 : %d\n",MESS_CRIT_SUP,nb_02) ; |
197 |
|
|
fprintf(output,"%s 0.1 : %d\n",MESS_CRIT_SUP,nb_01) ; |
198 |
|
|
fprintf(output,"%s 0.0 : %d\n",MESS_CRIT_SUP,nb_00) ; |
199 |
|
|
|
200 |
|
|
if (!is_recover) |
201 |
|
|
{ |
202 |
|
|
/* sprintf(mess,"%s%f\n",MESS_CRIT_2D_MIN,cmin) ; |
203 |
|
|
aff_text(mess); |
204 |
|
|
aff_text("\n"); |
205 |
|
|
sprintf(mess,"%s 0.9 : %d\n",MESS_CRIT_SUP,nb_09) ; |
206 |
|
|
aff_text(mess); |
207 |
|
|
sprintf(mess,"%s 0.8 : %d\n",MESS_CRIT_SUP,nb_08) ; |
208 |
|
|
aff_text(mess); |
209 |
|
|
sprintf(mess,"%s 0.7 : %d\n",MESS_CRIT_SUP,nb_07) ; |
210 |
|
|
aff_text(mess); |
211 |
|
|
sprintf(mess,"%s 0.6 : %d\n",MESS_CRIT_SUP,nb_06) ; |
212 |
|
|
aff_text(mess); |
213 |
|
|
sprintf(mess,"%s 0.5 : %d\n",MESS_CRIT_SUP,nb_05) ; |
214 |
|
|
aff_text(mess); |
215 |
|
|
sprintf(mess,"%s 0.4 : %d\n",MESS_CRIT_SUP,nb_04) ; |
216 |
|
|
aff_text(mess); |
217 |
|
|
sprintf(mess,"%s 0.3 : %d\n",MESS_CRIT_SUP,nb_03) ; |
218 |
|
|
aff_text(mess); |
219 |
|
|
sprintf(mess,"%s 0.2 : %d\n",MESS_CRIT_SUP,nb_02) ; |
220 |
|
|
aff_text(mess); |
221 |
|
|
sprintf(mess,"%s 0.1 : %d\n",MESS_CRIT_SUP,nb_01) ; |
222 |
|
|
aff_text(mess); |
223 |
|
|
sprintf(mess,"%s 0.0 : %d\n",MESS_CRIT_SUP,nb_00) ; |
224 |
|
|
aff_text(mess); */ |
225 |
|
|
} |
226 |
|
|
|
227 |
|
|
fclose(output) ; |
228 |
|
|
if (nb_bad != 0) |
229 |
|
|
{ |
230 |
|
|
m3d_erreur(ERR_QUAL_SKIN) ; |
231 |
|
|
return(FAUX) ; |
232 |
|
|
} |
233 |
|
|
gest->lecture_donnees = VRAI ; |
234 |
|
|
return(VRAI); |
235 |
|
|
} |