ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/acismesh/r3d_m3d.cpp
Revision: 1
Committed: Mon Jun 11 22:53:07 2007 UTC (17 years, 11 months ago)
File size: 8628 byte(s)
Log Message:

File Contents

# User Rev Content
1 1 /*****************************************************************
2    
3     r3d_m3d.cpp Type:Func
4    
5     Remaillage tetraedrique
6    
7     Date de creation : 4-9-1997 10 :52 :10
8     Derniere version : 4-9-1997 10 :52 :10
9    
10     Vincent FRANCOIS
11    
12     *****************************************************************/
13    
14    
15    
16    
17    
18     /**************************/
19     /* include */
20     #include <stdio.h>
21     #include <string.h>
22     #include <stdlib.h>
23     #include <process.h>
24     #include <math.h>
25     #include "const.h"
26     #include "memoire.h"
27     #include "struct.h"
28     #include "struct3d.h"
29     #include "prototype.h"
30    
31    
32     /**************************/
33     /* variables globales */
34     extern struct s_acis *acis;
35     extern struct environnement env;
36     extern struct s_mesh *mesh;
37     extern struct s_maillage *maillage;
38     extern struct s_param *para;
39    
40    
41    
42     /**************************/
43     /* programme principal */
44    
45     void r3d_m3d(struct s_octree **liste)
46     {
47     char mess[255];
48     char string[255],string2[255];
49     int i,j,num;
50     struct s_mnoeud *mno1,*mno2,*mno3,*mno4;
51     struct s_mbodyette *mbo;
52     struct s_mtetra *mtet;
53     struct s_noeud *no;
54     struct s_facette *fa;
55     struct s_triangle *tri,*front,*fr;
56     struct s_tetra *tet;
57     int nb_front,nb_place,nb_liste=0;
58     int *tab_noeud1;
59     int *tab_noeud2;
60     int *tab_ele2;
61     int nb_noeud,nb_noeud2,mesh_nb_noeud,nb_triangle,nb_tetra;
62     FILE *fic;
63     int n1,n2,n3,n4;
64     float x,y,z;
65    
66     /* insertion des bodyette */
67     for (i=0;i<maillage->nb_mbodyette;i++)
68     {
69     mbo=ADRESSE(i,mbodyette,maillage->);
70     mtet=mbo->mtetra[0];
71     mno1=ADRESSE(mtet->n1,mnoeud,maillage->);
72     mno2=ADRESSE(mtet->n2,mnoeud,maillage->);
73     mno3=ADRESSE(mtet->n3,mnoeud,maillage->);
74     mno4=ADRESSE(mtet->n4,mnoeud,maillage->);
75     x=0.25*(mno1->x+mno2->x+mno3->x+mno4->x);
76     y=0.25*(mno1->y+mno2->y+mno3->y+mno4->y);
77     z=0.25*(mno1->z+mno2->z+mno3->z+mno4->z);
78     if (geo_app_point_body(x,y,z)==1)
79     {
80     for (j=0;j<mbo->nb_mtetra;j++)
81     {
82     mtet=mbo->mtetra[j];
83     NEW_ENTITE(tet,tetra,mesh->);
84     tet->num=mesh->nb_tetra-1;
85     tet->etat=ACTIF;
86     tet->n1=r3d_gene_noeud(ADRESSE(mtet->n1,mnoeud,maillage->),liste,nb_liste);
87     tet->n2=r3d_gene_noeud(ADRESSE(mtet->n2,mnoeud,maillage->),liste,nb_liste);
88     tet->n3=r3d_gene_noeud(ADRESSE(mtet->n3,mnoeud,maillage->),liste,nb_liste);
89     tet->n4=r3d_gene_noeud(ADRESSE(mtet->n4,mnoeud,maillage->),liste,nb_liste);
90     no=ADRESSE(tet->n1,noeud,mesh->);
91     no->etat=ACTIF;
92     no=ADRESSE(tet->n2,noeud,mesh->);
93     no->etat=ACTIF;
94     no=ADRESSE(tet->n3,noeud,mesh->);
95     no->etat=ACTIF;
96     no=ADRESSE(tet->n4,noeud,mesh->);
97     no->etat=ACTIF;
98    
99     }
100     mesh->nb_bodyette_attache++;
101     }
102     }
103     sprintf(mess,R3D_M3D_BODY,maillage->nb_mbodyette,mesh->nb_bodyette_attache);
104     aff_text(mess);
105     m3d_enreg(1);
106     /* creations des faces triangulaires */
107     for (i=0;i<mesh->nb_triangle;i++)
108     {
109     tri=ADRESSE(i,triangle,mesh->);
110     tri->front=1;
111     }
112     for (i=0;i<mesh->nb_tetra;i++)
113     {
114     tet=ADRESSE(i,tetra,mesh->);
115     r3d_ins_face(tet->n1,tet->n3,tet->n2);
116     r3d_ins_face(tet->n1,tet->n2,tet->n4);
117     r3d_ins_face(tet->n2,tet->n3,tet->n4);
118     r3d_ins_face(tet->n1,tet->n4,tet->n3);
119     }
120     /* creation du front */
121     front=NULL;
122     nb_front=0;
123     for (i=0;i<mesh->nb_triangle;i++)
124     {
125     tri=ADRESSE(i,triangle,mesh->);
126     if (tri->front==1)
127     {
128     nb_front++;
129     tri->suivant=front;
130     front=tri;
131     }
132     }
133     /* separation du front */
134     NEW_ALLOC(facette,mesh->);
135     nb_place=0;
136     while (nb_place!=nb_front)
137     {
138     fr=front;
139     while (fr->front!=1) fr=fr->suivant;
140     NEW_ENTITE(fa,facette,mesh->);
141     fa->num=mesh->nb_facette-1;
142     NEW_POINTEUR(num,triangle,fa->);
143     fa->triangle[num]=fr;
144     fr->front=0;
145     nb_place++;
146     for (i=0;i<fa->nb_triangle;i++)
147     {
148     fr=fa->triangle[i];
149     no=ADRESSE(fr->n1,noeud,mesh->);
150     for (j=0;j<no->nb_triangle;j++)
151     {
152     tri=no->triangle[j];
153     if (tri->front==1)
154     {
155     NEW_POINTEUR(num,triangle,fa->);
156     fa->triangle[num]=tri;
157     tri->front=0;
158     nb_place++;
159     }
160     }
161     no=ADRESSE(fr->n2,noeud,mesh->);
162     for (j=0;j<no->nb_triangle;j++)
163     {
164     tri=no->triangle[j];
165     if (tri->front==1)
166     {
167     NEW_POINTEUR(num,triangle,fa->);
168     fa->triangle[num]=tri;
169     tri->front=0;
170     nb_place++;
171     }
172     }
173     no=ADRESSE(fr->n3,noeud,mesh->);
174     for (j=0;j<no->nb_triangle;j++)
175     {
176     tri=no->triangle[j];
177     if (tri->front==1)
178     {
179     NEW_POINTEUR(num,triangle,fa->);
180     fa->triangle[num]=tri;
181     tri->front=0;
182     nb_place++;
183     }
184     }
185     }
186     }
187     sprintf(mess,R3D_M3D_RES,mesh->nb_facette);
188     aff_text(mess);
189     /* compression des donnees pour le front */
190     if (mesh->nb_facette>0)
191     {
192     tab_noeud1=(int *)calloc(mesh->nb_noeud+1,sizeof(int));
193     ERREUR_ALLOC(tab_noeud1);
194     tab_noeud2=(int *)calloc(mesh->nb_noeud+1,sizeof(int));
195     ERREUR_ALLOC(tab_noeud2);
196     tab_ele2=(int *)calloc(mesh->nb_triangle+1,sizeof(int));
197     ERREUR_ALLOC(tab_ele2);
198     nb_noeud=0;
199     nb_triangle=0;
200     for (i=0;i<mesh->nb_facette;i++)
201     {
202     fa=ADRESSE(i,facette,mesh->);
203     for (j=0;j<fa->nb_triangle;j++)
204     {
205     tri=fa->triangle[j];
206     tab_ele2[nb_triangle]=tri->num;
207     nb_triangle++;
208     if (tab_noeud1[tri->n1]==0)
209     {
210     nb_noeud++;
211     tab_noeud1[tri->n1]=nb_noeud;
212     tab_noeud2[nb_noeud]=tri->n1;
213     }
214     if (tab_noeud1[tri->n2]==0)
215     {
216     nb_noeud++;
217     tab_noeud1[tri->n2]=nb_noeud;
218     tab_noeud2[nb_noeud]=tri->n2;
219     }
220     if (tab_noeud1[tri->n3]==0)
221     {
222     nb_noeud++;
223     tab_noeud1[tri->n3]=nb_noeud;
224     tab_noeud2[nb_noeud]=tri->n3;
225     }
226    
227     }
228     }
229     /* enregistrement des donnees */
230     strcpy(string,env.fich);
231     string[strlen(string)-4]=0;
232     strcat(string,"r_2D.mai");
233     fic=fopen(string,"wt");
234     fprintf(fic,"%d %d \n",nb_noeud,nb_triangle);
235     for (i=0;i<nb_noeud;i++)
236     {
237     no=ADRESSE(tab_noeud2[i+1],noeud,mesh->);
238     if (no->type==VERTEX) strcpy(string2,"vertex");
239     if (no->type==EDGE) strcpy(string2,"edge");
240     if (no->type==FACE) strcpy(string2,"face");
241     fprintf(fic,"%d %f %f %f %s %d\n",i+1,no->x,no->y,no->z,string2,no->num_ent);
242     }
243     for (i=0;i<nb_triangle;i++)
244     {
245     tri=ADRESSE(tab_ele2[i],triangle,mesh->);
246     n1=tab_noeud1[tri->n1];
247     n2=tab_noeud1[tri->n2];
248     n3=tab_noeud1[tri->n3];
249     fprintf(fic,"3 %d %d %d face %d\n",n1,n2,n3,tri->num_ent);
250     }
251     fclose(fic);
252     minimize();
253     spawnl(P_WAIT,"Diamesh","Diamesh","-file",string,"-remesh",NULL);
254     restore();
255     /* recuperation du resultat */
256     string[strlen(string)-6]='3';
257     fic=fopen(string,"rt");
258     fgets(mess,255,fic);
259     sscanf(mess,"%d %d",&nb_noeud2,&nb_tetra);
260     mesh_nb_noeud=mesh->nb_noeud;
261     for (i=0;i<nb_noeud2;i++)
262     {
263     fgets(mess,255,fic);
264     if (i>=nb_noeud)
265     {
266     NEW_ENTITE(no,noeud,mesh->);
267     sscanf(mess,"%d %f %f %f",&num,&(no->x),&(no->y),&(no->z));
268     no->num=mesh->nb_noeud-1;
269     no->etat=ACTIF;
270     }
271     }
272     for (i=0;i<nb_tetra;i++)
273     {
274     fgets(mess,255,fic);
275     NEW_ENTITE(tet,tetra,mesh->);
276     sscanf(mess,"%d %d %d %d %d",&num,&n1,&n2,&n3,&n4);
277     tet->num=mesh->nb_tetra-1;
278     tet->etat=ACTIF;
279     if (n1<=nb_noeud) tet->n1=tab_noeud2[n1];
280     else tet->n1=mesh_nb_noeud+n1-nb_noeud-1;
281     if (n2<=nb_noeud) tet->n2=tab_noeud2[n2];
282     else tet->n2=mesh_nb_noeud+n2-nb_noeud-1;
283     if (n3<=nb_noeud) tet->n3=tab_noeud2[n3];
284     else tet->n3=mesh_nb_noeud+n3-nb_noeud-1;
285     if (n4<=nb_noeud) tet->n4=tab_noeud2[n4];
286     else tet->n4=mesh_nb_noeud+n4-nb_noeud-1;
287     no=ADRESSE(tet->n1,noeud,mesh->);
288     no->etat=ACTIF;
289     no=ADRESSE(tet->n2,noeud,mesh->);
290     no->etat=ACTIF;
291     no=ADRESSE(tet->n3,noeud,mesh->);
292     no->etat=ACTIF;
293     no=ADRESSE(tet->n4,noeud,mesh->);
294     no->etat=ACTIF;
295     }
296     fclose(fic);
297     free(tab_noeud1);
298     free(tab_noeud2);
299     free(tab_ele2);
300     }
301     m3d_fin();
302     m2d_resultat(5);
303     }