ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/sld_courbe.cpp
Revision: 27
Committed: Thu Jul 5 15:26:40 2007 UTC (17 years, 10 months ago) by foucault
Original Path: magic/lib/geometrie/geometrie/src/sld_courbe.cpp
File size: 8272 byte(s)
Log Message:

File Contents

# User Rev Content
1 foucault 27 //------------------------------------------------------------
2     //------------------------------------------------------------
3     // MAGiC
4     // Jean Christophe Cuillière et Vincent FRANCOIS
5     // Département de Génie Mécanique - UQTR
6     //------------------------------------------------------------
7     // Le projet MAGIC est un projet de recherche du département
8     // de génie mécanique de l'Université du Québec à
9     // Trois Rivières
10     // Les librairies ne peuvent être utilisées sans l'accord
11     // des auteurs (contact : francois@uqtr.ca)
12     //------------------------------------------------------------
13     //------------------------------------------------------------
14     //
15     // sld_courbe.cpp
16     //
17     //------------------------------------------------------------
18     //------------------------------------------------------------
19     // COPYRIGHT 2000
20     // Version du 02/03/2006 à 11H22
21     //------------------------------------------------------------
22     //------------------------------------------------------------
23    
24    
25     #include "gestionversion.h"
26    
27     #ifdef BREP_SLD
28    
29     #include <system.hpp>
30     #include "sld_courbe.h"
31    
32     #include <atl\atlmod.h>
33    
34     #include "smartvars.h"
35     #include "sld_fonction.h"
36     #include "stline.h"
37     #include "stcircle.h"
38     #include "stellipse.h"
39     #include "stbspline.h"
40    
41     //TComModule& _Module=*static_cast<TComModule*>(NULL);
42    
43     //Premier constructeru bseoin tmin et tmax
44     SLD_COURBE::SLD_COURBE(unsigned long num,std::string idarete,SLD_FONCTION& fonc):MG_COURBE(num),fonction(fonc)
45     {
46     initialiser(idarete);
47     }
48    
49     SLD_COURBE::SLD_COURBE(std::string idarete,SLD_FONCTION& fonc):MG_COURBE(),fonction(fonc)
50     {
51     initialiser(idarete);
52     }
53    
54     SLD_COURBE::SLD_COURBE(std::string idarete,SLD_FONCTION& fonc, CComPtr<IEdge> & p_swEdge):MG_COURBE(),fonction(fonc), swArete(p_swEdge)
55     {
56     swArete->IGetCurve(&swCurve);
57     initialiser();
58     }
59    
60     SLD_COURBE::~SLD_COURBE()
61     {
62     if (swArete.p != NULL) swArete.p=NULL;
63     if (swCurve.p != NULL) swCurve.p=NULL;
64     if (stcourbe!=NULL) delete stcourbe;
65     }
66    
67     void SLD_COURBE::initialiser(std::string idarete)
68     {
69     idoriginal=idarete;
70     fonction.GetParID((char*)idarete.c_str(),swArete);
71     swArete->IGetCurve(&swCurve);
72     initialiser();
73     }
74    
75     void SLD_COURBE::initialiser()
76     {
77     VARIANT_BOOL isClosed;//TRUE for closed curves, FALSE for other types
78     VARIANT_BOOL isPeriodic;// TRUE for periodic curves, FALSE for other types
79     VARIANT_BOOL retval;//TRUE if the operation was successful, FALSE if not
80     swCurve->GetEndParams ( &t_min, &t_max, &isClosed, &isPeriodic, &retval );
81     if(isPeriodic==1) periodique=1; else periodique=0;
82     stcourbe=NULL;
83     swCurve->IsLine(&retval);
84     if (retval==1)
85     {
86     CComVariant vRetval;
87     vRetval=swCurve->get_LineParams();
88     SafeDoubleArray sda(vRetval);
89     double origine[3];
90     double dir[3];
91     origine[0]=sda[0];
92     origine[1]=sda[1];
93     origine[2]=sda[2];
94     dir[0]=sda[3];
95     dir[1]=sda[4];
96     dir[2]=sda[5];
97     stcourbe=new ST_LINE(origine,dir);
98     return;
99     }
100     swCurve->IsCircle(&retval);
101     if (retval==1)
102     {
103     CComVariant vRetval;
104     vRetval=swCurve->get_CircleParams();
105     SafeDoubleArray sda(vRetval);
106     double origine[3];
107     double axe[3];
108     double rayon;
109     origine[0]=sda[0];
110     origine[1]=sda[1];
111     origine[2]=sda[2];
112     axe[0]=sda[3];
113     axe[1]=sda[4];
114     axe[2]=sda[5];
115     rayon=sda[6];
116     stcourbe=new ST_CIRCLE(origine,axe,rayon);
117     return;
118     }
119     swCurve->IsEllipse(&retval);
120     if (retval==1)
121     {
122     CComVariant vRetval;
123     vRetval=swCurve->GetEllipseParams();
124     SafeDoubleArray sda(vRetval);
125     double origine[3];
126     double dirx[3];
127     double diry[3];
128     double rayona;
129     double rayonb;
130     origine[0]=sda[0];
131     origine[1]=sda[1];
132     origine[2]=sda[2];
133     rayona=sda[3];
134     dirx[0]=sda[4];
135     dirx[1]=sda[5];
136     dirx[2]=sda[6];
137     rayonb=sda[7];
138     diry[0]=sda[8];
139     diry[1]=sda[9];
140     diry[2]=sda[10];
141     OT_VECTEUR_3D x(dirx[0],dirx[1],dirx[2]);
142     OT_VECTEUR_3D y(diry[0],diry[1],diry[2]);
143     OT_VECTEUR_3D z=x&y;
144     double *dirz=z.get_xyz();
145     stcourbe=new ST_ELLIPSE(origine,dirz,dirx,rayona,rayonb);
146     return;
147     }
148     CComVariant vRetval;
149     swCurve->GetBCurveParams(False,&vRetval);
150     SafeDoubleArray sda(vRetval);
151     int dim,ordre,num,periode;
152     OPERATEUR::doubleto2int(sda[0],dim,ordre);
153     OPERATEUR::doubleto2int(sda[1],num,periode);
154     std::vector<double> knots;
155     for (int i=0;i<num+ordre;i++)
156     knots.insert(knots.end(),sda[2+i]);
157     std::vector<double> points;
158     std::vector<double> poids;
159     for (int i=0;i<num;i++)
160     {
161     points.insert(points.end(),sda[2+num+ordre+dim*i]);
162     points.insert(points.end(),sda[2+num+ordre+dim*i+1]);
163     points.insert(points.end(),sda[2+num+ordre+dim*i+2]);
164     if (dim==4) poids.insert(poids.end(),sda[2+num+ordre+dim*i+3]);
165     else poids.insert(poids.end(),1.);
166     }
167     stcourbe=new ST_B_SPLINE(ordre-1,knots,points,poids);
168     }
169    
170    
171     void SLD_COURBE::evaluer(double t,double *xyz)
172     {
173     if (stcourbe!=NULL)
174     {
175     stcourbe->evaluer(t,xyz);
176     return;
177     }
178     CComVariant vparam;
179     swCurve->Evaluate(t,&vparam);
180     SafeDoubleArray param(vparam);
181     xyz[0]=param[0];
182     xyz[1]=param[1];
183     xyz[2]=param[2];
184     }
185    
186     void SLD_COURBE::deriver(double t,double *dxyz)
187     {
188     if (stcourbe!=NULL)
189     {
190     stcourbe->deriver(t,dxyz);
191     return;
192     }
193     CComVariant vparam;
194     swCurve->Evaluate(t,&vparam);
195     SafeDoubleArray param(vparam);
196     dxyz[0]=param[3];
197     dxyz[1]=param[4];
198     dxyz[2]=param[5];
199     }
200    
201     void SLD_COURBE::deriver_seconde(double t,double *ddxyz,double*dxyz,double*xyz)
202     {
203     if (stcourbe!=NULL)
204     {
205     stcourbe->deriver_seconde(t,ddxyz,dxyz,xyz);
206     return;
207     }
208     double epsilon=(t_max-t_min)*10e-6;
209     double t1,t2;
210     if(t-epsilon<t_min)
211     {
212     t1=t_min;
213     t2=t_min+2*epsilon;
214     }
215     else if(t+epsilon>t_max)
216     {
217     t1=t_max-2*epsilon;
218     t2=t_max;
219     }
220     else
221     {
222     t1=t-epsilon;
223     t2=t+epsilon;
224     }
225     CComVariant vparam1;
226     CComVariant vparam2;
227     swCurve->Evaluate(t1,&vparam1);
228     swCurve->Evaluate(t2,&vparam2);
229     SafeDoubleArray param1(vparam1);
230     SafeDoubleArray param2(vparam2);
231     ddxyz[0]=(param2[3]-param1[3])/(2*epsilon);
232     ddxyz[1]=(param2[4]-param1[4])/(2*epsilon);
233     ddxyz[2]=(param2[5]-param1[5])/(2*epsilon);
234    
235     //différent cas
236     if(dxyz!=NULL)
237     {
238     CComVariant vparam;
239     swCurve->Evaluate(t,&vparam);
240     SafeDoubleArray param(vparam);
241     dxyz[0]=param[3];
242     dxyz[1]=param[4];
243     dxyz[2]=param[5];
244     if(xyz!=NULL)
245     {
246     xyz[0]=param[0];
247     xyz[1]=param[1];
248     xyz[2]=param[2];
249     }
250     }
251     }
252    
253     void SLD_COURBE::inverser(double& t,double *xyz,double precision)
254     {
255     if (stcourbe!=NULL)
256     {
257     stcourbe->inverser(t,xyz,precision);
258     return;
259     }
260     CComVariant retval;
261     swCurve->GetClosestPointOn ( xyz[0], xyz[1], xyz[2], &retval ) ;
262     SafeDoubleArray vretval(retval);
263     t=vretval[3];
264     }
265    
266     double SLD_COURBE::get_tmin(void)
267     {
268     if (stcourbe!=NULL)
269     {
270     return stcourbe->get_tmin();
271     }
272     return tmin;
273     }
274    
275     double SLD_COURBE::get_tmax(void)
276     {
277     if (stcourbe!=NULL)
278     {
279     return stcourbe->get_tmax();
280     }
281     return tmax;
282     }
283    
284    
285    
286     double SLD_COURBE::get_longueur(double t1,double t2,double precis)
287     {
288     if (stcourbe!=NULL)
289     {
290     return stcourbe->get_longueur(t1,t2,precis);
291     }
292     double retval;
293     swCurve->GetLength2(t1,t2,&retval);
294     return retval;
295     }
296    
297    
298     int SLD_COURBE::est_periodique(void)
299     {
300     if (stcourbe!=NULL)
301     {
302     return stcourbe->est_periodique();
303     }
304     return periodique;
305     }
306    
307    
308     double SLD_COURBE::get_periode(void)
309     {
310     if (stcourbe!=NULL)
311     {
312     return stcourbe->get_periode();
313     }
314     return t_max-t_min;
315     }
316    
317     void SLD_COURBE::enregistrer(std::ostream& o)
318     {
319     o << "%" << get_id() << "=COURBE_SLD("<< idoriginal.c_str() << ");"<<std::endl;
320     }
321    
322    
323     int SLD_COURBE::get_type_geometrique(TPL_LISTE_ENTITE<double> &param)
324     {
325     if (stcourbe!=NULL)
326     return stcourbe->get_type_geometrique(param);
327     return 0;
328     }
329    
330     void SLD_COURBE::get_param_NURBS(int& indx_premier_ptctr,TPL_LISTE_ENTITE<double> &param)
331     {
332     stcourbe->get_param_NURBS(indx_premier_ptctr,param);
333     }
334    
335    
336    
337    
338    
339     #endif
340    
341