ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/outil/src/ot_fonctions.h
Revision: 253
Committed: Tue Jul 13 19:40:46 2010 UTC (14 years, 10 months ago) by francois
Content type: text/plain
File size: 7445 byte(s)
Log Message:
changement de hiearchie et utilisation de ccmake + mise a jour

File Contents

# User Rev Content
1 souaissa 107 //---------------------------------------------------------------------------
2    
3     #ifndef ot_fonctionsH
4     #define ot_fonctionsH
5     //---------------------------------------------------------------------------
6    
7     #ifdef WINDOWS_VERSION
8     #ifdef BUILT_DLL_OUTIL
9     #define DLLPORTOUTIL __declspec(dllexport)
10     #else
11     #define DLLPORTOUTIL __declspec(dllimport)
12     #endif
13     #else
14     #define DLLPORTOUTIL
15     #endif
16    
17     #include <math.h>
18     #include "ot_doubleprecision.h"
19     #include "ot_mathematique.h"
20     #include "ot_algorithme_geometrique.h"
21    
22    
23     #define PI 3.1415926535897932384626433832795
24    
25     double2 moment (double2 theta,vector<OT_VECTEUR_4DD>& ctrpts,int plan)
26     {
27    
28     //double li[]={78.10249676,78.10249676,78.10249676,78.10249676} ;
29     //double thi[]={39.80557109+10,140.19442891+10,219.80557109+10,320.19442891+10};
30    
31     int nb_pts=ctrpts.size();
32     double ordre=4.;
33     double2 zer=0.;
34     double2 sum=0.;
35     for(int i=0;i<nb_pts;i++)
36     {
37     //thi[i]=thi[i]*PI/180;
38     //double2 nori=ctrpts[i].norme();
39     double2 x=ctrpts[i].x()^2;
40     double2 y=ctrpts[i].y()^2;
41     double2 z=ctrpts[i].z()^2;
42     double2 nori;
43    
44     // double2 nori=ctrpts[i].norme();
45     double2 cosi=0.;
46     double2 sini=0.;
47     if(plan==12)
48     {
49     nori=(x+y)^0.5;
50     if (nori!=zer){
51     cosi=ctrpts[i].get_x()/nori;
52     sini=ctrpts[i].get_y()/nori;
53     }
54     }
55     if(plan==23)
56     {
57     nori=(y+z)^0.5;
58     if (nori!=zer){
59     cosi=ctrpts[i].get_y()/nori;
60     sini=ctrpts[i].get_z()/nori;
61     }
62    
63     }
64     if(plan==13)
65     {
66     nori=(x+z)^0.5;
67     if (nori!=zer){
68     cosi=ctrpts[i].get_x()/nori;
69     sini=ctrpts[i].get_z()/nori;
70     }
71     }
72     double2 costh=cos(theta);
73     double2 sinth=sin(theta);
74     double2 d_theta=sini*costh-cosi*sinth;
75     //sum=sum+ pow(li[i],4)*pow(d_theta,4);
76     double2 val1=nori^ordre;
77     double2 val2=d_theta^ordre;
78     double2 val=val1*val2;
79     sum=sum+ val;
80     }
81     return sum;
82     }
83    
84    
85     double2 Max(double2 a,double2 b)
86     {
87     return((a<b)? b : a);
88     }
89    
90     double2 Min(double2 a,double2 b)
91     {
92     return ((a>b)? b : a);
93     }
94    
95     double2 Sign(double2 a,double2 b)
96     {
97     double2 zer=0.;
98     double2 c=-1.;
99     if(b>=zer)
100     return a;
101     else
102     return c*a;
103     }
104    
105     void swap(double2& a,double2& b)
106     {
107     double2 tmp; tmp = a; a = b; b = tmp;
108     }
109     void Shift(double2&a,double2&b,double2&c,double2 d)
110     {
111     a=b;b=c;c=d;
112     }
113    
114     void min_Brak(double2 &ax,double2 &bx,double2 &cx,double2 &fa,double2 &fb,double2 &fc,vector<OT_VECTEUR_4DD>& ctrpts,int plan)
115     {
116     static const double2 GOLD=1.618034;
117     static const double2 GLIMIT=100.0;
118     static const double2 TINY=1.0e-20;
119     double2 ulim,u,r,q,fu;
120     double2(*func)(double2,vector<OT_VECTEUR_4DD>&,int)=&moment;
121     double2 dtheta=0.0001;
122     ax=0.;
123     bx=ax+dtheta;
124     cx=bx+dtheta;
125     double2 fva=(*func)(ax,ctrpts,plan);
126     double2 fvb=(*func)(bx,ctrpts,plan);
127     double2 fvc=(*func)(cx,ctrpts,plan);
128    
129     while (fvb> fva)
130     {
131     ax=bx;
132     bx=ax+dtheta;
133     fva=(*func)(ax,ctrpts,plan);
134     fvb=(*func)(bx,ctrpts,plan);
135     }
136    
137     if(fvb<fva)
138     {
139     cx=bx+dtheta;
140     while (fvb> fvc)
141     {
142     bx=cx;
143     cx=bx+dtheta;
144     fvb=(*func)(bx,ctrpts,plan);
145     fvc=(*func)(cx,ctrpts,plan);
146     }
147     }
148    
149     fa=(*func)(ax,ctrpts,plan);
150     fb=(*func)(bx,ctrpts,plan);
151     if(fb>fa)
152     {
153     swap(ax,bx);
154     swap(fb,fa);
155     }
156     cx=bx+GOLD*(bx-ax);
157     fc=(*func)(cx,ctrpts,plan);
158     double2 d=2.;
159     double2 zer=0.;
160     while(fb>fc)
161     {
162     r=(bx-ax)*(fb-fc);
163     q=(bx-cx)*(fb-fa);
164     u=bx-((bx-cx)*q-(bx-ax)*r)/(d*Sign(Max((q-r).get_fabs(),TINY),q-r));//(d*Sign(Max(abs(q-r),TINY),q-r));
165     ulim=bx+GLIMIT*(cx-bx);
166     if((bx-u)*(u-cx)>zer)
167     {
168     fu=(*func)(u,ctrpts,plan);
169     if(fu<fc)
170     {
171     ax=bx;
172     bx=u;
173     fa=fb;
174     fb=fu;
175     return;
176     }
177     else if(fu>fb)
178     {
179     cx=u;
180     fc=fu;
181     return;
182     }
183     u=cx+GOLD*(cx-bx);
184     fu=(*func)(u,ctrpts,plan);
185     }
186     else if((cx-u)*(u-ulim)>zer)
187     {
188     fu=(*func)(u,ctrpts,plan);
189     if(fu<fc)
190     {
191     bx=cx;
192     cx=u;
193     u=cx+GOLD*(cx-bx);
194     Shift(fb,fc,fu,(*func)(u,ctrpts,plan));
195     }
196     }
197     else if((u-ulim)*(ulim-cx)>=zer)
198     {
199     u=ulim;
200     fu=(*func)(u,ctrpts,plan);
201     }
202     else
203     {
204     u=cx+GOLD*(cx-bx);
205     fu=(*func)(u,ctrpts,plan);
206     }
207     Shift(ax,bx,cx,u);
208     Shift(fa,fb,fc,fu);
209     }
210     }
211    
212    
213    
214    
215     vector<OT_VECTEUR_4DD> system_axes(vector<OT_VECTEUR_4DD>& ctrpts)
216     {
217     vector<OT_VECTEUR_4DD> syst_axe;
218     int nb_points=ctrpts.size();
219     vector<OT_VECTEUR_4DD> ctrpts_proj;
220     OT_VECTEUR_4DD axe1,axe2,axe3,axe4;
221     double2 ax,bx,cx,fa,fb,fc;
222     int plan=12;
223     double2 z0=ctrpts[0].get_z() ;
224     double2 y0=ctrpts[0].get_z() ;
225     double2 x0=ctrpts[0].get_z() ;
226     int cmpt1=0;
227     int cmpt2=0;
228     int cmpt3=0;
229     for(int i=0;i<nb_points;i++)
230     {
231     if (ctrpts[i].get_x()==x0) cmpt1++;
232     if (ctrpts[i].get_y()==y0) cmpt2++;
233     if (ctrpts[i].get_z()==z0) cmpt3++;
234     }
235    
236     if(cmpt1==nb_points) plan=23;
237     if(cmpt2==nb_points) plan=13;
238     if(cmpt3==nb_points) plan=12;
239    
240    
241    
242     min_Brak(ax,bx,cx,fa,fb,fc,ctrpts,plan);
243     double theta= bx.get_x();
244     double c=cos(theta);
245     double s=sin(theta);
246     axe1.change_x(c);
247     axe1.change_y(s);
248     axe1.change_z(0.);
249     axe1.change_w(0.);
250     double e1_proj[3];
251     double e2_proj[3];
252     double normal[3];
253     normal[0] =(axe1.get_x()).get_x();
254     normal[1] =(axe1.get_y()).get_x();
255     normal[2] =(axe1.get_z()).get_x();
256     double root[3]={0.,0.,0.};
257     OT_ALGORITHME_GEOMETRIQUE algo;
258     int pris=0;
259     OT_MATRICE_3D P, P_1;
260    
261     for(int i=0;i<nb_points;i++)
262     {
263     double pnt[3];
264     double proj_pnt[3];
265     pnt[0] =(ctrpts[i].get_x()).get_x();
266     pnt[1] =(ctrpts[i].get_y()).get_x();
267     pnt[2] =(ctrpts[i].get_z()).get_x();
268    
269    
270     algo.Proj3D_Point_Plan (normal, root, pnt, proj_pnt);
271    
272     OT_VECTEUR_4DD pt_proj;
273    
274    
275     if ((proj_pnt[0]!=0.||proj_pnt[1]!=0.||proj_pnt[2]!=0)&&!pris)
276     {
277     e1_proj[0]=proj_pnt[0];
278     e1_proj[1]=proj_pnt[1];
279     e1_proj[2]=proj_pnt[2];
280     double norm=sqrt(pow(proj_pnt[0],2)+pow(proj_pnt[1],2)+pow(proj_pnt[2],2));
281    
282     e1_proj[0]=e1_proj[0]/norm;
283     e1_proj[1]=e1_proj[1]/norm;
284     e1_proj[2]=e1_proj[2]/norm;
285    
286     e2_proj[0]=normal[1]*e1_proj[2]-normal[2]*e1_proj[1];
287     e2_proj[1]=normal[2]*e1_proj[0]-normal[2]*e1_proj[2];
288     e2_proj[2]=normal[0]*e1_proj[1]-normal[2]*e1_proj[0];
289    
290     OT_VECTEUR_3D V1(e1_proj[0],e2_proj[0],normal[0]);
291     OT_VECTEUR_3D V2(e1_proj[1],e2_proj[1],normal[1]);
292     OT_VECTEUR_3D V3(e1_proj[2],e2_proj[2],normal[2]);
293    
294    
295    
296     P.change_vecteur1(V1);
297     P.change_vecteur2(V2);
298     P.change_vecteur3(V3);
299    
300     P_1=P.inverse();
301     pris=1;
302     }
303    
304     OT_VECTEUR_3D V_PT(proj_pnt[0],proj_pnt[1],proj_pnt[2]);
305    
306     OT_VECTEUR_3D V=P_1*V_PT;
307    
308    
309     pt_proj.change_x(V[0]);
310     pt_proj.change_y(V[1]);
311     pt_proj.change_z(V[2]);
312    
313     ctrpts_proj.insert(ctrpts_proj.end(),pt_proj);
314     }
315    
316     min_Brak(ax,bx,cx,fa,fb,fc,ctrpts_proj,plan);
317    
318     theta= bx.get_x();
319     c=cos(theta);
320     s=sin(theta);
321     OT_VECTEUR_3D Vp(c,s,0.);
322     double nnv_x=Vp*P.get_vecteur1();
323     double nnv_y=Vp*P.get_vecteur2();
324     double nnv_z=Vp*P.get_vecteur3();
325    
326     axe2.change_x(nnv_x);
327     axe2.change_y(nnv_y);
328     axe2.change_z(nnv_z);
329    
330     double2 val=axe1*axe2;
331    
332     axe3[0]=axe1[1]*axe2[2]-axe1[2]*axe2[1];
333     axe3[1]=axe1[2]*axe2[0]-axe1[2]*axe2[2];
334     axe3[2]=axe1[0]*axe2[1]-axe1[2]*axe2[0];
335    
336     axe3[3]=0.;
337    
338    
339     syst_axe.insert( syst_axe.end(),axe1);
340     syst_axe.insert( syst_axe.end(),axe2);
341     syst_axe.insert( syst_axe.end(),axe3);
342    
343     return syst_axe;
344     }
345    
346    
347    
348    
349     #endif