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

File Contents

# Content
1 /*****************************************************************
2
3 eval_fdn3.c Type:Func
4
5 Calcul de de densite en 3D
6
7 Date de creation : Mon Jun 30 09:59:57 1997
8
9 Derniere version : Wed Jul 2 16:55:53 1997
10
11
12
13 Vincent FRANCOIS
14
15 *****************************************************************/
16
17
18
19
20
21 /**************************/
22 /* include */
23 #include <stdio.h>
24 #include <string.h>
25 #include <math.h>
26 #include <stdlib.h>
27 #include "const.h"
28 #include "memoire.h"
29 #include "struct.h"
30 #include "prototype.h"
31
32 /**************************/
33 /* variables globales */
34 extern struct environnement env;
35 extern struct s_mesh *mesh;
36
37
38
39
40 /**************************/
41 /* programme principal */
42
43 float eval_fdn3(float x,float y,float z)
44 {
45 struct s_noeud *no1,*no2,*no3;
46 struct s_octree **liste,*oc;
47 struct s_frontiere3d *fr;
48 int ok,terme,nn,i,k,num;
49 int *test_tri,*test_oc,nb_liste;
50 float n1n2[4],n1n3[4],n[4],t,xtmp,ytmp,ztmp,d,d1,d2,d3,dens,densi[4],dista[4],nume,deno,dismin;
51
52 test_tri=(int *)calloc(mesh->nb_frontiere3d+1,sizeof(int));
53 ERREUR_ALLOC(test_tri);
54 test_oc=(int *)calloc(mesh->nb_octree+1,sizeof(int));
55 ERREUR_ALLOC(test_oc);
56 liste=(struct s_octree **)calloc(mesh->nb_octree,sizeof(struct s_octree *));
57 ERREUR_ALLOC(liste);
58
59
60 ok=0;terme=0;nn=1;
61
62 while (ok!=2)
63 {
64 nb_liste=0;
65 oc_rechercher(x,y,z,nn*env.dens,mesh->first,liste,&nb_liste);
66 for (i=0;i<nb_liste;i++)
67 {
68 oc=liste[i];
69 if (test_oc[oc->num]==0)
70 {
71 test_oc[oc->num]=1;
72 for (k=0;k<oc->nb_frontiere3d;k++)
73 {
74 fr=oc->frontiere3d[k];
75 if (test_tri[fr->num]==0)
76 {
77 test_tri[fr->num]=1;
78 no1=fr->no1;
79 no2=fr->no2;
80 no3=fr->no3;
81 VEC(n1n2,no1,no2);
82 VEC(n1n3,no1,no3);
83 PVEC(n,n1n2,n1n3);
84 NORME(n);
85 n[3]=(-n[0]*no1->x-n[1]*no1->y-n[2]*no1->z);
86 t=(-n[0]*x-n[1]*y-n[2]*z-n[3]);
87 xtmp=x+t*n[0];
88 ytmp=y+t*n[1];
89 ztmp=z+t*n[2];
90 if (m3d_int_triangle(no1->num,no2->num,no3->num,xtmp,ytmp,ztmp)==1)
91 d=(float)fabs((double)(n[0]*x+n[1]*y+n[2]*z+n[3]));
92 else
93 {
94 d1=(float)sqrt((double)((x-no1->x)*(x-no1->x)+(y-no1->y)*(y-no1->y)+(z-no1->z)*(z-no1->z)));
95 d2=(float)sqrt((double)((x-no2->x)*(x-no2->x)+(y-no2->y)*(y-no2->y)+(z-no2->z)*(z-no2->z)));
96 d3=(float)sqrt((double)((x-no3->x)*(x-no3->x)+(y-no3->y)*(y-no3->y)+(z-no3->z)*(z-no3->z)));
97 d=0.3333333*(d1+d2+d3);
98 }
99 dens=0.333333*(no1->dens+no2->dens+no3->dens);
100 if (d<4*env.dens)
101 {
102 if (terme<4)
103 {
104 densi[terme]=dens;
105 dista[terme]=d;
106 terme++;
107 }
108 else
109 {
110 if (dista[0]<dista[1]) num=1; else num=0;
111 if (dista[num]<dista[2]) num=2;
112 if (dista[num]<dista[3]) num=3;
113 if (d<dista[num])
114 {
115 densi[num]=dens;
116 dista[num]=d;
117 }
118 }
119 }
120 }
121 }
122 }
123 }
124 nn++;
125 if (ok==1) ok=2;
126 else
127 {
128 if (nn>4) ok=1;
129 if ((nn>1)&&(terme>3)) ok=1;
130 }
131 }
132 free(test_tri);
133 free(test_oc);
134 free(liste);
135 if (terme==0) dens=env.dens;
136 else
137 {
138 dismin=dista[0];
139 for (i=1;i<terme;i++)
140 MINI(dismin,dismin,dista[i]);
141 nume=0.;
142 deno=0.;
143 for (i=0;i<terme;i++)
144 {
145 nume=nume+(4*env.dens-dista[i])*densi[i];
146 deno=deno+4*env.dens-dista[i];
147 }
148 nume=nume+dismin*env.dens;
149 deno=deno+dismin;
150 dens=nume/deno;
151 }
152 return(dens);
153 }