ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/diamesh/src/m3d_cpfront2.cpp
Revision: 250
Committed: Fri Jun 25 15:03:39 2010 UTC (14 years, 10 months ago) by louhichi
Original Path: magic/lib/diamesh/diamesh/src/m3d_cpfront2.cpp
File size: 7368 byte(s)
Log Message:
Mise a jour pour le 64 bits de diamesh

File Contents

# User Rev Content
1 5 #include <stdio.h>
2     #include "m3d_struct.h"
3     #include "m3d_const.h"
4     #include "m3d_hotes.h"
5     #include "m3d_macro.h"
6     #include "prototype.h"
7     extern GEST_MEM *gest ;
8     /* face existante */
9     extern int debug ;
10     extern int check ;
11     extern float dimp ;
12     extern float eps, eps2, eps3, eps4 ;
13     extern int tab_plan[4] ;
14     extern float tab_vn[5][3] ;/* normales entieres du tetra */
15     int m3d_cpfront2(float *coord,FACE *face,NOEUD *noe_p,FACE **finter,int *nb_face,int *ierr)
16     {
17     FACE *courant, *tab_face[4] ;
18     FACE *face1, *face2, *face3 ;
19     NOEUD *nj1, *nj2, *nj3, *n1, *n2, *n3, *nzero ;
20     int i, j, k, is_inter, min_j ;
21     OBJET *tete, *obj ;
22     int nb;
23     FACE *tab[NB_MAX_INTER] ;
24     int tab_mark[NB_MAX_INTER] ;
25     float vmin[3], vmax[3] ;
26     CONNEC *connec ;
27     int nb_noeud = 0 ;
28     float delta_x, delta_y, delta_z, coeff;
29     int ii, ij ;
30     float v01[3] , v12[3], v02[3], v03[3], v13[3], v23[3] ;
31     float v45[3], v56[3], v46[3] ;
32     int in0 , in1 , in2 , in3 ;
33     float vmin2[3], vmax2[3] ;
34     int j1, j2, j3, num_c, nb_oct ;
35     OCT *tab_oct[NB_MAX_CONNEC] ;
36    
37     nb = 0 ;
38    
39     nzero = NULL ;
40     face1 = NULL ;
41     face2 = NULL ;
42     face3 = NULL ;
43    
44     nj1 = face->n1 ;
45     nj2 = face->n2 ;
46     nj3 = face->n3 ;
47     num_c = noe_p->num ;
48    
49     j1 = nj1->num ;
50     j2 = nj2->num ;
51     j3 = nj3->num ;
52    
53     in0 = 3 * j1 ;
54     in1 = 3 * j2 ;
55     in2 = 3 * j3 ;
56     in3 = 3 * num_c ;
57    
58     nb = 1;
59     tab[0] = face ;
60     tab_mark[0] = face->mark ;
61 louhichi 250 face->mark = (size_t)face ;
62 5
63     tab_plan[0] = FAUX ;
64     tab_plan[1] = FAUX ;
65     tab_plan[2] = FAUX ;
66     tab_plan[3] = FAUX ;
67    
68     /* recherche des faces */
69     min_j = min(j3,j2) ;
70     min_j = min(min_j,num_c) ;
71     if (min_j==j3)
72     {
73     n1 = nj3 ;
74     n2 = nj2 ;
75     n3 = noe_p ;
76     }
77     else if (min_j==j2)
78     {
79     n1 = nj2 ;
80     n2 = noe_p ;
81     n3 = nj3 ;
82     }
83     else
84     {
85     n1 = noe_p ;
86     n2 = nj3 ;
87     n3 = nj2 ;
88     }
89     /* recherche de la face n1,n2,n3 */
90     face2 = m3d_recface(coord,n1,n2,n3) ;
91     if (face2 != NULL) tab_plan[2] = VRAI ;
92     /* recherche de la face j1 j3 num_c */
93     min_j = min(j1,j3) ;
94     min_j = min(min_j,num_c) ;
95     if (min_j==j1)
96     {
97     n1 = nj1 ;
98     n2 = nj3 ;
99     n3 = noe_p ;
100     }
101     else if (min_j==j3)
102     {
103     n1 = nj3 ;
104     n2 = noe_p ;
105     n3 = nj1 ;
106     }
107     else
108     {
109     n1 = noe_p ;
110     n2 = nj1 ;
111     n3 = nj3 ;
112     }
113     /* recherche de la face n1,n2,n3 */
114     face3 = m3d_recface(coord,n1,n2,n3) ;
115     if (face3 != NULL) tab_plan[3] = VRAI ;
116     /* recherche de la face j2 j1 num_c */
117     min_j = min(j2,j1) ;
118     min_j = min(min_j,num_c) ;
119     if (min_j==j2)
120     {
121     n1 = nj2 ;
122     n2 = nj1 ;
123     n3 = noe_p ;
124     }
125     else if (min_j==j1)
126     {
127     n1 = nj1 ;
128     n2 = noe_p ;
129     n3 = nj2 ;
130     }
131     else
132     {
133     n1 = noe_p ;
134     n2 = nj2 ;
135     n3 = nj1 ;
136     }
137     /* recherche de la face n1,n2,n3 */
138     face1 = m3d_recface(coord,n1,n2,n3) ;
139     if (face1 != NULL) tab_plan[1] = VRAI ;
140    
141    
142     /* donnees communes */
143    
144     VECTEUR(v01,(coord+in0),(coord+in1))
145     VECTEUR(v12,(coord+in1),(coord+in2))
146     VECTEUR(v02,(coord+in0),(coord+in2))
147     VECTEUR(v03,(coord+in0),(coord+in3))
148     VECTEUR(v13,(coord+in1),(coord+in3))
149     VECTEUR(v23,(coord+in2),(coord+in3))
150    
151     /* calcul des normales exterieures */
152     /* face 0 2 1 */
153    
154     tab_vn[0][0] = PVECX(v02,v01) ;
155     tab_vn[0][1] = PVECY(v02,v01) ;
156     tab_vn[0][2] = PVECZ(v02,v01) ;
157     /* face 0 1 3 */
158     tab_vn[1][0] = PVECX(v01,v03) ;
159     tab_vn[1][1] = PVECY(v01,v03) ;
160     tab_vn[1][2] = PVECZ(v01,v03) ;
161     /* face 1 2 3 */
162     tab_vn[2][0] = PVECX(v12,v13) ;
163     tab_vn[2][1] = PVECY(v12,v13) ;
164     tab_vn[2][2] = PVECZ(v12,v13) ;
165     /* face 0 3 2 */
166     tab_vn[3][0] = PVECX(v03,v02) ;
167     tab_vn[3][1] = PVECY(v03,v02) ;
168     tab_vn[3][2] = PVECZ(v03,v02) ;
169    
170     /* recherche des faces avec lesquelles il peut y avoir intersection */
171     BOITE(nj1,nj2,nj3,noe_p,vmin,vmax)
172    
173     eps = max(vmax[0]-vmin[0],vmax[1]-vmin[1]) ;
174     eps = max(eps,vmax[2]-vmin[2]) ;
175    
176     eps = eps * 0.001 ;
177     eps2 = eps * eps ;
178     eps3 = eps2 * eps ;
179     eps4 = eps3 * eps ;
180     nb_oct = 0 ;
181     *ierr = FAUX ;
182    
183     m3d_rec_oct(vmin,vmax,gest->root,&nb_oct,tab_oct,ierr) ;
184     if (*ierr == VRAI)
185     {
186     *nb_face = 0 ;
187     return(VRAI) ;
188     }
189    
190     *nb_face = 0 ;
191    
192     for (i=0;i<nb_oct;i++)
193     {
194     /* faces de peau stockees en tant qu'objet */
195     obj = tab_oct[i]->lis_obj ;
196     /* parcours de la liste des objets */
197     while (obj !=NULL)
198     {
199     courant = obj->ref;/* adresse de l'adresse de la structure face */
200     if (courant!=NULL)
201     if (courant->mark!=DESTROYED)
202     {
203     /* face */
204 louhichi 250 if (courant->mark!=(size_t)face)
205 5 {
206     tab[nb] = courant ;
207     tab_mark[nb] = courant->mark ;
208     nb++ ;
209 louhichi 250 courant->mark = (size_t)face ;
210 5
211     is_inter = 1 ;
212     /* test sur les boites englobantes */
213    
214     BOITE(courant->n1,courant->n2,courant->n3,nzero,vmin2,vmax2)
215     if (vmin2[2]>vmax[2] + 2.) is_inter = 0 ;
216     if (vmax2[2]<vmin[2] - 2.) is_inter = 0 ;
217    
218     if (vmin2[1]>vmax[1] + 2.) is_inter = 0 ;
219     if (vmax2[1]<vmin[1] - 2.) is_inter = 0 ;
220    
221     if (vmin2[0]>vmax[0] + 2.) is_inter = 0 ;
222     if (vmax2[0]<vmin[0] - 2.) is_inter = 0 ;
223    
224     if (is_inter)
225     if (m3d_intersection(coord,in0,in1,in2,in3,3*(courant->n1->num),3*(courant->n2->num),3*(courant->n3->num)))
226     {
227     /* on ne peut detruire la face */
228     /* reset des flags */
229     for (k=0;k<nb;k++)
230     {
231     courant = (FACE*)(tab[k]) ;
232     courant->mark = tab_mark[k] ;
233     }
234     *nb_face = 0 ;
235     return(VRAI) ;
236     }
237     }
238     }
239     obj = obj->suivant ;/* passer au suivant dans la liste */
240     }
241     /* faces crees */
242     /* autres faces lies aux tetraedres */
243     connec = tab_oct[i]->lis_con ;
244     while (connec != NULL)
245     {
246     if ((connec->tetra)->mark != KILLED)
247     {
248     tab_face[0] = (connec->tetra)->face1 ;
249     tab_face[1] = (connec->tetra)->face2 ;
250     tab_face[2] = (connec->tetra)->face3 ;
251     tab_face[3] = (connec->tetra)->face4 ;
252     for (k=0;k<4;k++)
253     {
254     courant = tab_face[k] ;
255 louhichi 250 if ((courant->mark!=(size_t)face)&&(courant!=face))
256 5 {
257     tab[nb] = courant ;
258     tab_mark[nb] = courant->mark ;
259     nb++ ;
260 louhichi 250 courant->mark = (size_t)face ;
261 5
262     is_inter = 1 ;
263     /* test sur les boites englobantes */
264    
265     BOITE(courant->n1,courant->n2,courant->n3,nzero,vmin2,vmax2)
266     if (vmin2[2]>vmax[2] + 2.) is_inter = 0 ;
267     if (vmax2[2]<vmin[2] - 2.) is_inter = 0 ;
268    
269     if (vmin2[1]>vmax[1] + 2.) is_inter = 0 ;
270     if (vmax2[1]<vmin[1] - 2.) is_inter = 0 ;
271    
272     if (vmin2[0]>vmax[0] + 2.) is_inter = 0 ;
273     if (vmax2[0]<vmin[0] - 2.) is_inter = 0 ;
274    
275     if (is_inter)
276     if (m3d_intersection(coord,in0,in1,in2,in3,3*(courant->n1->num),3*(courant->n2->num),3*(courant->n3->num)))
277     {
278     if (courant->hist == 0)
279     {
280     /* on ne peut detruire la face */
281     for (k=0;k<nb;k++)
282     {
283     courant = (FACE*)(tab[k]) ;
284     courant->mark = tab_mark[k] ;
285     }
286     *nb_face = 0 ;
287     return(VRAI) ;
288     }
289     /* sinon on stocke la face */
290     finter[(*nb_face)] = courant ;
291     (*nb_face)++ ;
292     }
293     }
294     }
295     }
296     connec = connec->suivant ;
297     }
298     }
299     /* reset des flags */
300     for (i=0;i<nb;i++)
301     {
302     courant = (FACE*)(tab[i]) ;
303     courant->mark = tab_mark[i] ;
304     }
305     if (*nb_face == 0)
306     {
307     return(FAUX) ; /* pas d'intersection apres destruction */
308     }
309     return(FAUX) ;
310     }