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

File Contents

# User Rev Content
1 1 /*****************************************************************
2    
3     m3d_i_tetra.cpp Type:func
4    
5     Insertion d un nouveau tetraedre
6    
7     Date de creation : 11-3-1999 15 :24 :8
8     Derniere version : 11-3-1999 15 :24 :8
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 <math.h>
24     #include "const.h"
25     #include "memoire.h"
26     #include "struct.h"
27     #include "struct3d.h"
28     #include "prototype.h"
29    
30    
31     /**************************/
32     /* variables globales */
33     extern struct environnment env;
34     extern struct s_mesh *mesh;
35    
36    
37    
38     /**************************/
39     /* programme principal */
40    
41     int m3d_i_tetra(struct s_tetra **tetr,struct s_front3d *ft,int n4,int type,struct s_front3d **list_inter,int *nb_inter)
42     {
43     struct s_noeud *no1,*no2,*no3,*no4,*no;
44     struct s_tetra *tet,*tettmp;
45     struct s_triangle *tri1,*tri2,*tri3,*tri4;
46     struct s_front3d *fttmp;
47     struct s_octree *oc,**liste_oc;
48     float x,y,z,longueur,vol,vol1,vol2,vol3,vol4;
49     int num,inter;
50     int i,j,*test_ft,nb_liste,invalid,n1,n2,n3,npetit;
51     char mess[255];
52    
53     no1=ADRESSE(ft->n1,noeud,mesh->);
54     no2=ADRESSE(ft->n2,noeud,mesh->);
55     no3=ADRESSE(ft->n3,noeud,mesh->);
56     no4=ADRESSE(n4,noeud,mesh->);
57     /* existance du tetraedre */
58     //for (i=0;i<no1->nb_tetra;i++)
59     // for (j=0;j<no2->nb_tetra;j++)
60     // for (k=0;k<no3->nb_tetra;k++)
61     // for (l=0;l<no4->nb_tetra;l++)
62     // if (no1->tetra[i]==no2->tetra[j])
63     // if (no1->tetra[i]==no3->tetra[k])
64     // if (no1->tetra[i]==no4->tetra[l])
65     // return(NONVALIDE);
66     n1=ft->n1;
67     n2=ft->n2;
68     n3=ft->n3;
69     MINI(npetit,n1,n2);
70     MINI(npetit,npetit,n3);
71     MINI(npetit,npetit,n4);
72     no=ADRESSE(npetit,noeud,mesh->);
73     tettmp=no->tete_tet_petit;
74     while (tettmp!=NULL)
75     {
76     if (((tettmp->n1==n1) && (tettmp->n2==n2) && (tettmp->n3==n3) && (tettmp->n4==n4))
77     || ((tettmp->n1==n1) && (tettmp->n2==n2) && (tettmp->n4==n3) && (tettmp->n3==n4))
78     || ((tettmp->n1==n1) && (tettmp->n3==n2) && (tettmp->n2==n3) && (tettmp->n4==n4))
79     || ((tettmp->n1==n1) && (tettmp->n3==n2) && (tettmp->n4==n3) && (tettmp->n2==n4))
80     || ((tettmp->n1==n1) && (tettmp->n4==n2) && (tettmp->n2==n3) && (tettmp->n3==n4))
81     || ((tettmp->n1==n1) && (tettmp->n4==n2) && (tettmp->n3==n3) && (tettmp->n2==n4))
82    
83     || ((tettmp->n2==n1) && (tettmp->n1==n2) && (tettmp->n3==n3) && (tettmp->n4==n4))
84     || ((tettmp->n2==n1) && (tettmp->n1==n2) && (tettmp->n4==n3) && (tettmp->n3==n4))
85     || ((tettmp->n2==n1) && (tettmp->n3==n2) && (tettmp->n1==n3) && (tettmp->n4==n4))
86     || ((tettmp->n2==n1) && (tettmp->n3==n2) && (tettmp->n4==n3) && (tettmp->n1==n4))
87     || ((tettmp->n2==n1) && (tettmp->n4==n2) && (tettmp->n1==n3) && (tettmp->n3==n4))
88     || ((tettmp->n2==n1) && (tettmp->n4==n2) && (tettmp->n3==n3) && (tettmp->n1==n4))
89    
90     || ((tettmp->n3==n1) && (tettmp->n1==n2) && (tettmp->n2==n3) && (tettmp->n4==n4))
91     || ((tettmp->n3==n1) && (tettmp->n1==n2) && (tettmp->n4==n3) && (tettmp->n2==n4))
92     || ((tettmp->n3==n1) && (tettmp->n2==n2) && (tettmp->n1==n3) && (tettmp->n4==n4))
93     || ((tettmp->n3==n1) && (tettmp->n2==n2) && (tettmp->n4==n3) && (tettmp->n1==n4))
94     || ((tettmp->n3==n1) && (tettmp->n4==n2) && (tettmp->n1==n3) && (tettmp->n2==n4))
95     || ((tettmp->n3==n1) && (tettmp->n4==n2) && (tettmp->n2==n3) && (tettmp->n1==n4))
96    
97    
98     || ((tettmp->n4==n1) && (tettmp->n1==n2) && (tettmp->n2==n3) && (tettmp->n3==n4))
99     || ((tettmp->n4==n1) && (tettmp->n1==n2) && (tettmp->n3==n3) && (tettmp->n2==n4))
100     || ((tettmp->n4==n1) && (tettmp->n2==n2) && (tettmp->n1==n3) && (tettmp->n3==n4))
101     || ((tettmp->n4==n1) && (tettmp->n2==n2) && (tettmp->n3==n3) && (tettmp->n1==n4))
102     || ((tettmp->n4==n1) && (tettmp->n3==n2) && (tettmp->n1==n3) && (tettmp->n2==n4))
103     || ((tettmp->n4==n1) && (tettmp->n3==n2) && (tettmp->n2==n3) && (tettmp->n1==n4)))
104     return(NONVALIDE);
105     tettmp=tettmp->suiv;
106     }
107    
108     /* validite de la solution */
109     (*nb_inter)=0;
110     liste_oc=(struct s_octree **)calloc(mesh->nb_octree+1,sizeof(struct s_octree *));
111     ERREUR_ALLOC(liste_oc);
112     test_ft=(int *)calloc(mesh->nb_front3d_tot,sizeof(int));
113     ERREUR_ALLOC(test_ft);
114     nb_liste=0;
115     x=0.25*(no1->x+no2->x+no3->x+no4->x);
116     y=0.25*(no1->y+no2->y+no3->y+no4->y);
117     z=0.25*(no1->z+no2->z+no3->z+no4->z);
118     longueur=(float)sqrt((double)((x-no1->x)*(x-no1->x)+(y-no1->y)*(y-no1->y)+(z-no1->z)*(z-no1->z)));
119     oc_rechercher(x,y,z,1.2*longueur,mesh->first,liste_oc,&nb_liste);
120     for (i=0;i<nb_liste;i++)
121     {
122     oc=liste_oc[i];
123     for (j=0;j<oc->nb_front3d;j++)
124     {
125     fttmp=oc->front3d[j];
126     if (test_ft[fttmp->num]==0)
127     {
128     test_ft[fttmp->num]=1;
129     inter=m3d_intersection(no1->num,no2->num,no3->num,no4->num,fttmp->n1,fttmp->n2,fttmp->n3);
130     if (inter==VRAI)
131     {
132     list_inter[*nb_inter]=fttmp;
133     (*nb_inter)++;
134     }
135     }
136     }
137     }
138     free(liste_oc);
139     free(test_ft);
140     if (*nb_inter>0)
141     return(NONVALIDE);
142    
143     /* evaluation de la situation locale */
144     m3d_i_triangle(&tri1,ft->n1,ft->n3,ft->n2,LIMITE);
145     m3d_i_triangle(&tri2,ft->n1,ft->n2,n4,LIMITE);
146     m3d_i_triangle(&tri3,ft->n2,ft->n3,n4,LIMITE);
147     m3d_i_triangle(&tri4,ft->n1,n4,ft->n3,LIMITE);
148     vol=m3d_cal_vol(ft->n1,ft->n2,ft->n3,n4);
149     if (tri1!=NULL)
150     if ((tri1->tetra[0]!=NULL)&&(tri1->type!=FACE)) vol1=tri1->tetra[0]->vol; else vol1=(-1.);
151     if (tri2!=NULL)
152     if ((tri2->tetra[0]!=NULL)&&(tri2->type!=FACE)) vol2=tri2->tetra[0]->vol; else vol2=(-1.);
153     if (tri3!=NULL)
154     if ((tri3->tetra[0]!=NULL)&&(tri3->type!=FACE)) vol3=tri3->tetra[0]->vol; else vol3=(-1.);
155     if (tri4!=NULL)
156     if ((tri4->tetra[0]!=NULL)&&(tri4->type!=FACE)) vol4=tri4->tetra[0]->vol; else vol4=(-1.);
157     if (type==CREATION)
158     {
159     longueur=0.25*(no1->dens+no2->dens+no3->dens+no4->dens);
160     if (vol<0.01178511302*longueur*longueur*longueur)
161     {
162     invalid=0;
163     if ((vol1>0.)&&(vol1<0.01178511302*longueur*longueur*longueur)) invalid=1;
164     if ((vol2>0.)&&(vol2<0.01178511302*longueur*longueur*longueur)) invalid=1;
165     if ((vol3>0.)&&(vol3<0.01178511302*longueur*longueur*longueur)) invalid=1;
166     if ((vol4>0.)&&(vol4<0.01178511302*longueur*longueur*longueur)) invalid=1;
167     if (invalid==1)
168     return(NONVALIDE);
169     }
170     }
171    
172    
173     /* insertion du tetra */
174     if (tri1==NULL) m3d_i_triangle(&tri1,ft->n1,ft->n3,ft->n2,CREATION);
175     if (tri2==NULL) m3d_i_triangle(&tri2,ft->n1,ft->n2,n4,CREATION);
176     if (tri3==NULL) m3d_i_triangle(&tri3,ft->n2,ft->n3,n4,CREATION);
177     if (tri4==NULL) m3d_i_triangle(&tri4,ft->n1,n4,ft->n3,CREATION);
178    
179    
180    
181     NEW_ENTITE(tet,tetra,mesh->);
182     tet->num=mesh->nb_tetra-1;
183     tet->n1=ft->n1;
184     tet->n2=ft->n2;
185     tet->n3=ft->n3;
186     tet->n4=n4;
187     tet->type=BODY;
188     tet->num_ent=0;
189     tet->crit=m3d_cal_qual(tet->n1,tet->n2,tet->n3,tet->n4);
190     tet->vol=vol;
191     tet->etat=ACTIF;
192     if (tet->crit<mesh->critmin) mesh->critmin=tet->crit;
193     if (tet->crit>mesh->critmax) mesh->critmax=tet->crit;
194     if (tet->crit<0.00001)
195     {
196     sprintf(mess,"Tetra inverse. Etape numero %d.",tet->num);
197     aff_text(mess);
198     }
199     tet->triangle[0]=tri1;
200     tet->triangle[1]=tri2;
201     tet->triangle[2]=tri3;
202     tet->triangle[3]=tri4;
203     if ((tri1->type!=FACE)&&(tri1->front==1)) tri1->tetra[1]=tet; else tri1->tetra[0]=tet;
204     if ((tri2->type!=FACE)&&(tri2->front==1)) tri2->tetra[1]=tet; else tri2->tetra[0]=tet;
205     if ((tri3->type!=FACE)&&(tri3->front==1)) tri3->tetra[1]=tet; else tri3->tetra[0]=tet;
206     if ((tri4->type!=FACE)&&(tri4->front==1)) tri4->tetra[1]=tet; else tri4->tetra[0]=tet;
207     NEW_POINTEUR(num,tetra,no1->);
208     no1->tetra[num]=tet;
209     NEW_POINTEUR(num,tetra,no2->);
210     no2->tetra[num]=tet;
211     NEW_POINTEUR(num,tetra,no3->);
212     no3->tetra[num]=tet;
213     NEW_POINTEUR(num,tetra,no4->);
214     no4->tetra[num]=tet;
215     m3d_ord_tet(tet);
216     *tetr=tet;
217    
218    
219     MINI(npetit,tet->n1,tet->n2);
220     MINI(npetit,npetit,tet->n3);
221     MINI(npetit,npetit,tet->n4);
222     no=ADRESSE(npetit,noeud,mesh->);
223     if (no->tete_tet_petit==NULL)
224     {
225     no->tete_tet_petit=tet;
226     no->queue_tet_petit=tet;
227     }
228     else
229     {
230     no->queue_tet_petit->suiv=tet;
231     no->queue_tet_petit=tet;
232     }
233    
234    
235    
236     return(VALIDE);
237     }