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

File Contents

# Content
1 /*****************************************************************
2
3 m3d_gen_noe.cpp Type:func
4
5 Generation d un noeud en 3D
6
7 Date de creation : 11-3-1999 14 :14 :4
8 Derniere version : 11-3-1999 14 :14 :4
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 #define RAPPROCHE 0
37 #define ELOINGNE 1
38
39 struct proche
40 {
41 struct s_front3d *ft;
42 float dis;
43 int type;
44 };
45
46 /**************************/
47 /* programme principal */
48
49 int m3d_gen_noe(struct s_front3d *ft,int *num,int type)
50 {
51 struct s_noeud *no1,*no2,*no3,*no;
52 struct proche list_proche[100];
53 int nb_proche,ok;
54 float n1n2[4],n1n3[4],normal[4],nmilieu[4],med[4];
55 float d1a,d1b,d1,d2;
56 float dismin;
57 struct s_octree *oc,**liste;
58 struct s_front3d *ft2;
59 int *test_ft;
60 int nb_liste,numref,i,j;
61 float vec[4],disref;
62 float x,y,z;
63
64 if (type==CREATION)
65 {
66 no1=ADRESSE(ft->n1,noeud,mesh->);
67 no2=ADRESSE(ft->n2,noeud,mesh->);
68 no3=ADRESSE(ft->n3,noeud,mesh->);
69 VEC(n1n2,no1,no2);
70 VEC(n1n3,no1,no3);
71 PVEC(normal,n1n2,n1n3);
72 NORME(normal);
73 nmilieu[0]=0.5*(no1->x+no2->x);
74 nmilieu[1]=0.5*(no1->y+no2->y);
75 nmilieu[2]=0.5*(no1->z+no2->z);
76 med[0]=no3->x-nmilieu[0];
77 med[1]=no3->y-nmilieu[1];
78 med[2]=no3->z-nmilieu[2];
79 NORME(med);
80 d1a=ft->longueur; /* respect en terme de qualite */
81 d1b=0.333333333*(no1->dens+no2->dens+no3->dens); /* respect en terme de taille */
82 d1=0.35*d1a+0.65*d1b;
83 d2=d1*d1-4./9.*med[3]*med[3];
84 if (d2<0.) d2=d1b;
85 d2=(float)sqrt((double)d2);
86 d2=d2/ft->etat;
87 x=0.3333333*(no1->x+no2->x+no3->x)+d2*normal[0];
88 y=0.3333333*(no1->y+no2->y+no3->y)+d2*normal[1];
89 z=0.3333333*(no1->z+no2->z+no3->z)+d2*normal[2];
90 liste=(struct s_octree **)calloc(mesh->nb_octree+1,sizeof(struct s_octree *));
91 ERREUR_ALLOC(liste);
92 test_ft=(int *)calloc(mesh->nb_front3d_tot,sizeof(int));
93 ERREUR_ALLOC(test_ft);
94 nb_liste=0;
95 oc_rechercher(x,y,z,d2*1.2,mesh->first,liste,&nb_liste);
96 disref=100.*d2;
97 numref=(-1);
98 for (i=0;i<nb_liste;i++)
99 {
100 oc=liste[i];
101 nb_proche=0;
102 for (j=0;j<oc->nb_front3d;j++)
103 {
104 ft2=oc->front3d[j];
105 if (test_ft[ft2->num]==0)
106 {
107 test_ft[ft2->num]=1;
108 no=ADRESSE(ft2->n1,noeud,mesh->);
109 vec[0]=no->x-x;
110 vec[1]=no->y-y;
111 vec[2]=no->z-z;
112 NORME(vec);
113 if (vec[3]<disref)
114 {
115 numref=ft2->n1;
116 disref=vec[3];
117 }
118 no=ADRESSE(ft2->n2,noeud,mesh->);
119 vec[0]=no->x-x;
120 vec[1]=no->y-y;
121 vec[2]=no->z-z;
122 NORME(vec);
123 if (vec[3]<disref)
124 {
125 numref=ft2->n2;
126 disref=vec[3];
127 }
128 no=ADRESSE(ft2->n3,noeud,mesh->);
129 vec[0]=no->x-x;
130 vec[1]=no->y-y;
131 vec[2]=no->z-z;
132 NORME(vec);
133 if (vec[3]<disref)
134 {
135 numref=ft2->n3;
136 disref=vec[3];
137 }
138 if (ft2!=ft)
139 {
140 if (ft2->tri!=NULL) dismin=eval_dis_no_tri(x,y,z,ft2->tri); else dismin=3.*d2;
141 if (dismin<d2)
142 {
143 list_proche[nb_proche].ft=ft2;
144 list_proche[nb_proche].dis=dismin;
145 if (dismin<d2) list_proche[nb_proche].type=RAPPROCHE;
146 else list_proche[nb_proche].type=ELOINGNE;
147 nb_proche++;
148 }
149 }
150
151 }
152 }
153 }
154 free(liste);
155 free(test_ft);
156 /* il y a un noeud proche */
157 if (numref!=(-1))
158 if (disref<d2)
159 if (numref!=ft->n1)
160 if (numref!=ft->n2)
161 if (numref!=ft->n3)
162 {
163 *num=numref;
164 return(EXISTE);
165 }
166 /* il n y a pas de noeud proche mais il y a des faces de front proche */
167 if (nb_proche>0)
168 {
169 num[0]=0;
170 for (i=0;i<nb_proche;i++)
171 {
172 ft2=list_proche[i].ft;
173 ok=0;
174 for (j=1;j<=num[0];j++)
175 if (ft2->n1==num[j]) ok=1;
176 if ((ok==0)&&(ft2->n1!=ft->n1)&&(ft2->n1!=ft->n2)&&(ft2->n1!=ft->n3))
177 {
178 num[0]++;
179 num[num[0]]=ft2->n1;
180 }
181 ok=0;
182 for (j=1;j<=num[0];j++)
183 if (ft2->n2==num[j]) ok=1;
184 if ((ok==0)&&(ft2->n2!=ft->n1)&&(ft2->n2!=ft->n2)&&(ft2->n2!=ft->n3))
185 {
186 num[0]++;
187 num[num[0]]=ft2->n2;
188 }
189 ok=0;
190 for (j=1;j<=num[0];j++)
191 if (ft2->n3==num[j]) ok=1;
192 if ((ok==0)&&(ft2->n3!=ft->n1)&&(ft2->n3!=ft->n2)&&(ft2->n3!=ft->n3))
193 {
194 num[0]++;
195 num[num[0]]=ft2->n3;
196 }
197 }
198 return(MULTIEXISTE);
199 }
200 NEW_ENTITE(no,noeud,mesh->);
201 no->num=mesh->nb_noeud-1;
202 no->x=x;
203 no->y=y;
204 no->z=z;
205 no->etat=ACTIF;
206 *num=no->num;
207 return(CREATION);
208 }
209 if (type==UPDATE)
210 {
211 no=ADRESSE((*num),noeud,mesh->);
212 no->creation=CONSTRUIT;
213 no->type=BODY;
214 no->num_ent=1;
215 no->dens=eval_fdn3(no->x,no->y,no->z);
216 return(UPDATE);
217 }
218 return(0);
219 }
220