1 |
/*****************************************************************
|
2 |
|
3 |
r3d_ins_triangle.cpp Type:Func
|
4 |
|
5 |
Insertion des triangles recuperes et initialisation du front
|
6 |
|
7 |
Date de creation : 14-8-1997 11 :55 :6
|
8 |
Derniere version : 14-8-1997 11 :55 :6
|
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 "prototype.h"
|
28 |
|
29 |
|
30 |
/**************************/
|
31 |
/* variables globales */
|
32 |
extern struct s_acis *acis;
|
33 |
extern struct environnement env;
|
34 |
extern struct s_mesh *mesh;
|
35 |
extern struct s_maillage *maillage;
|
36 |
extern struct s_param *para;
|
37 |
|
38 |
|
39 |
|
40 |
/**************************/
|
41 |
/* programme principal */
|
42 |
|
43 |
void r3d_ins_triangle(struct s_face *face,int nb_facette,int *tab_facette,struct s_octree **liste_oct)
|
44 |
{
|
45 |
int i,j,*test,nb_liste=0,nb_chaine;
|
46 |
int nb_segment,num;
|
47 |
char mess[255];
|
48 |
float du,dv,w[4],n2n1[4],n2n3[4],nor[4],cosa,sina,alpha,alpharef;
|
49 |
float u1,v1,u2,v2,u3,v3;
|
50 |
struct s_mfacette *mfacette;
|
51 |
struct s_front *ft,*ftd,*ftp,*ft_courant,*ftref;
|
52 |
struct s_segment *seg;
|
53 |
struct s_triangle *tri;
|
54 |
struct s_mtriangle *mtri;
|
55 |
struct s_quadtree *liste[2];
|
56 |
struct s_noeud *no,*no1f,*no2f,*no3f;
|
57 |
struct s_mnoeud *mno1,*mno2,*mno3;
|
58 |
|
59 |
if (nb_facette==0)
|
60 |
{
|
61 |
aff_text(R3D_INS_TRI_NEW);
|
62 |
return; /* nouvelle face */
|
63 |
}
|
64 |
else
|
65 |
{
|
66 |
sprintf(mess,R3D_INS_TRI_OLD,nb_facette);
|
67 |
aff_text(mess);
|
68 |
}
|
69 |
nb_segment=mesh->nb_segment;
|
70 |
for (j=0;j<nb_facette;j++)
|
71 |
{
|
72 |
mfacette=ADRESSE(tab_facette[j],mfacette,maillage->);
|
73 |
if (mfacette->nb_mtriangle>1)
|
74 |
for (i=0;i<mfacette->nb_mtriangle;i++)
|
75 |
{
|
76 |
mtri=mfacette->mtriangle[i];
|
77 |
mno1=ADRESSE(mtri->n1,mnoeud,maillage->);
|
78 |
mno2=ADRESSE(mtri->n2,mnoeud,maillage->);
|
79 |
mno3=ADRESSE(mtri->n3,mnoeud,maillage->);
|
80 |
NEW_ENTITE(tri,triangle,mesh->);
|
81 |
tri->num=mesh->nb_triangle-1;
|
82 |
tri->n1=r3d_gene_noeud(mno1,liste_oct,nb_liste);
|
83 |
tri->n2=r3d_gene_noeud(mno2,liste_oct,nb_liste);
|
84 |
tri->n3=r3d_gene_noeud(mno3,liste_oct,nb_liste);
|
85 |
no=ADRESSE(tri->n1,noeud,mesh->);
|
86 |
if (no->indice!=face->num)
|
87 |
{
|
88 |
eval_face(face,&no->u,&no->v,INVERSE,&no->x,&no->y,&no->z,0.,0.);
|
89 |
no->dens=eval_fdn2b(face,no->u,no->v,TOTAL);
|
90 |
no->indice=face->num;
|
91 |
}
|
92 |
no=ADRESSE(tri->n2,noeud,mesh->);
|
93 |
if (no->indice!=face->num)
|
94 |
{
|
95 |
eval_face(face,&no->u,&no->v,INVERSE,&no->x,&no->y,&no->z,0.,0.);
|
96 |
no->dens=eval_fdn2b(face,no->u,no->v,TOTAL);
|
97 |
no->indice=face->num;
|
98 |
}
|
99 |
no=ADRESSE(tri->n3,noeud,mesh->);
|
100 |
if (no->indice!=face->num)
|
101 |
{
|
102 |
eval_face(face,&no->u,&no->v,INVERSE,&no->x,&no->y,&no->z,0.,0.);
|
103 |
no->dens=eval_fdn2b(face,no->u,no->v,TOTAL);
|
104 |
no->indice=face->num;
|
105 |
}
|
106 |
tri->creation=RECUPERER;
|
107 |
no=ADRESSE(tri->n1,noeud,mesh->);
|
108 |
NEW_POINTEUR(num,triangle,no->);
|
109 |
no->triangle[num]=tri;
|
110 |
no=ADRESSE(tri->n2,noeud,mesh->);
|
111 |
NEW_POINTEUR(num,triangle,no->);
|
112 |
no->triangle[num]=tri;
|
113 |
no=ADRESSE(tri->n3,noeud,mesh->);
|
114 |
NEW_POINTEUR(num,triangle,no->);
|
115 |
no->triangle[num]=tri;
|
116 |
tri->type=FACE;
|
117 |
tri->num_ent=face->num;
|
118 |
tri->crit=m2d_cal_qual(tri->n1,tri->n2,tri->n3);
|
119 |
if (mesh->nb_triangle==1)
|
120 |
{
|
121 |
mesh->critmin=tri->crit;
|
122 |
mesh->critmax=tri->crit;
|
123 |
mesh->critmoy=0.;
|
124 |
mesh->tabcrit[0]=0;
|
125 |
mesh->tabcrit[1]=0;
|
126 |
mesh->tabcrit[2]=0;
|
127 |
mesh->tabcrit[3]=0;
|
128 |
}
|
129 |
mesh->critmoy=mesh->critmoy+tri->crit;
|
130 |
if (mesh->critmin>tri->crit) mesh->critmin=tri->crit;
|
131 |
if (mesh->critmax<tri->crit) mesh->critmax=tri->crit;
|
132 |
if (tri->crit>0.75) mesh->tabcrit[3]++;
|
133 |
else if (tri->crit>0.5) mesh->tabcrit[2]++;
|
134 |
else if (tri->crit>0.25) mesh->tabcrit[1]++;
|
135 |
else mesh->tabcrit[0]++;
|
136 |
r3d_ins_segment(face,tri->n1,tri->n2,&(tri->segment[0]));
|
137 |
r3d_ins_segment(face,tri->n2,tri->n3,&(tri->segment[1]));
|
138 |
r3d_ins_segment(face,tri->n3,tri->n1,&(tri->segment[2]));
|
139 |
}
|
140 |
}
|
141 |
for (i=0;i<mesh->nb_front_tot;i++)
|
142 |
{
|
143 |
ft=ADRESSE(i,front,mesh->);
|
144 |
if (ft->seg->front>1) m2d_ac_front(&ft,1);
|
145 |
}
|
146 |
for (i=nb_segment;i<mesh->nb_segment;i++)
|
147 |
{
|
148 |
seg=ADRESSE(i,segment,mesh->);
|
149 |
if (seg->front==1)
|
150 |
{
|
151 |
m2d_ac_front(&ft,2);
|
152 |
ft->n1=seg->n1;
|
153 |
ft->n2=seg->n2;
|
154 |
ft->seg=seg;
|
155 |
ft->seg->front=1;
|
156 |
no=ADRESSE(ft->n1,noeud,mesh->);
|
157 |
if (no->indice!=face->num)
|
158 |
{
|
159 |
eval_face(face,&no->u,&no->v,INVERSE,&no->x,&no->y,&no->z,0.,0.);
|
160 |
no->dens=eval_fdn2b(face,no->u,no->v,TOTAL);
|
161 |
no->indice=face->num;
|
162 |
}
|
163 |
no=ADRESSE(ft->n2,noeud,mesh->);
|
164 |
if (no->indice!=face->num)
|
165 |
{
|
166 |
eval_face(face,&no->u,&no->v,INVERSE,&no->x,&no->y,&no->z,0.,0.);
|
167 |
no->dens=eval_fdn2b(face,no->u,no->v,TOTAL);
|
168 |
no->indice=face->num;
|
169 |
}
|
170 |
m2d_ord_front(ft);
|
171 |
}
|
172 |
else seg->front=0;
|
173 |
}
|
174 |
/* chainage du front */
|
175 |
if (mesh->nb_front==0)
|
176 |
{
|
177 |
aff_text(R3D_INS_TRI_REC);
|
178 |
}
|
179 |
w[0]=0.;w[1]=0.;w[2]=1;
|
180 |
nb_chaine=0;
|
181 |
test=(int *)calloc(mesh->nb_front_tot,sizeof(int));
|
182 |
ERREUR_ALLOC(test);
|
183 |
for (ft=mesh->vide_front;ft!=NULL;ft=ft->suivant)
|
184 |
test[ft->num]=1;
|
185 |
while (nb_chaine!=mesh->nb_front)
|
186 |
{
|
187 |
ft=mesh->tete_front;
|
188 |
while (test[ft->num]==1)
|
189 |
ft=ft->suivant;
|
190 |
ftd=ft;
|
191 |
test[ftd->num]=1;
|
192 |
do
|
193 |
{
|
194 |
ftp=ft;
|
195 |
no=ADRESSE(ft->n2,noeud,mesh->);
|
196 |
nb_liste=0;
|
197 |
qu_rechercher(no->u,no->v,0.,mesh->root,liste,&nb_liste);
|
198 |
no1f=ADRESSE(ft->n1,noeud,mesh->);
|
199 |
no2f=ADRESSE(ft->n2,noeud,mesh->);
|
200 |
if (mesh->rev_u!=0.) du=0.5*mesh->rev_u-no1f->u; else du=0.;
|
201 |
if (mesh->rev_v!=0.) dv=0.5*mesh->rev_v-no1f->v; else dv=0.;
|
202 |
eval_decale(&u1,du,no1f->u,U);
|
203 |
eval_decale(&v1,dv,no1f->v,V);
|
204 |
eval_decale(&u2,du,no2f->u,U);
|
205 |
eval_decale(&v2,dv,no2f->v,V);
|
206 |
n2n1[0]=u1-u2;
|
207 |
n2n1[1]=v1-v2;
|
208 |
n2n1[2]=0.;
|
209 |
PVEC(nor,w,n2n1);
|
210 |
NORME(n2n1);
|
211 |
NORME(nor);
|
212 |
ftref=NULL;
|
213 |
for (i=0;i<liste[0]->nb_front;i++)
|
214 |
{
|
215 |
ft_courant=liste[0]->front[i];
|
216 |
if (ft_courant->n1==ft->n2)
|
217 |
{
|
218 |
no3f=ADRESSE(ft_courant->n2,noeud,mesh->);
|
219 |
eval_decale(&u3,du,no3f->u,U);
|
220 |
eval_decale(&v3,dv,no3f->v,V);
|
221 |
n2n3[0]=u3-u2;
|
222 |
n2n3[1]=v3-v2;
|
223 |
n2n3[2]=0.;
|
224 |
NORME(n2n3);
|
225 |
cosa=PSCA(n2n1,n2n3);
|
226 |
sina=PSCA(nor,n2n3);
|
227 |
if (cosa>1.) cosa=1.;
|
228 |
if (cosa<-1.) cosa=(-1.);
|
229 |
alpha=(float)acos((double)cosa);
|
230 |
if (sina<(-0.0001)) alpha=(-alpha);
|
231 |
if (alpha<0.) alpha=alpha+2*PI;
|
232 |
if (ftref==NULL)
|
233 |
{
|
234 |
alpharef=alpha;
|
235 |
ftref=ft_courant;
|
236 |
}
|
237 |
else if (alpha>alpharef)
|
238 |
{
|
239 |
alpharef=alpha;
|
240 |
ftref=ft_courant;
|
241 |
}
|
242 |
}
|
243 |
}
|
244 |
ft=ftref;
|
245 |
test[ft->num]=1;
|
246 |
ftp->suiv=ft;
|
247 |
ft->prec=ftp;
|
248 |
nb_chaine++;
|
249 |
}
|
250 |
while(ft!=ftd);
|
251 |
ftp->suiv=ftd;
|
252 |
ftd->prec=ftp;
|
253 |
}
|
254 |
free(test);
|
255 |
}
|