ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/sld_courbe.cpp
Revision: 34
Committed: Wed Aug 15 18:04:10 2007 UTC (17 years, 9 months ago) by bournival
Original Path: magic/lib/geometrie/geometrie/src/sld_courbe.cpp
File size: 8437 byte(s)
Log Message:
Sylvain,
Je coupe les coques maintenant, alors je dois les importer d'un efaçon un peu différente.
Quelques autres trucs ailleur, surtout pour les coques et poutres

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 bournival 34 {
56 foucault 27 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 bournival 34 if (swArete ==NULL)
72     {
73     fonction.GetParID((char*)idarete.c_str(),swArete);
74     while(swArete==NULL)
75     {
76     fonction.GetParID((char*)idarete.c_str(),swArete);
77     }
78    
79     }
80 foucault 27 swArete->IGetCurve(&swCurve);
81     initialiser();
82     }
83    
84     void SLD_COURBE::initialiser()
85     {
86     VARIANT_BOOL isClosed;//TRUE for closed curves, FALSE for other types
87     VARIANT_BOOL isPeriodic;// TRUE for periodic curves, FALSE for other types
88     VARIANT_BOOL retval;//TRUE if the operation was successful, FALSE if not
89     swCurve->GetEndParams ( &t_min, &t_max, &isClosed, &isPeriodic, &retval );
90     if(isPeriodic==1) periodique=1; else periodique=0;
91     stcourbe=NULL;
92     swCurve->IsLine(&retval);
93     if (retval==1)
94     {
95     CComVariant vRetval;
96     vRetval=swCurve->get_LineParams();
97     SafeDoubleArray sda(vRetval);
98     double origine[3];
99     double dir[3];
100     origine[0]=sda[0];
101     origine[1]=sda[1];
102     origine[2]=sda[2];
103     dir[0]=sda[3];
104     dir[1]=sda[4];
105     dir[2]=sda[5];
106     stcourbe=new ST_LINE(origine,dir);
107     return;
108     }
109     swCurve->IsCircle(&retval);
110     if (retval==1)
111     {
112     CComVariant vRetval;
113     vRetval=swCurve->get_CircleParams();
114     SafeDoubleArray sda(vRetval);
115     double origine[3];
116     double axe[3];
117     double rayon;
118     origine[0]=sda[0];
119     origine[1]=sda[1];
120     origine[2]=sda[2];
121     axe[0]=sda[3];
122     axe[1]=sda[4];
123     axe[2]=sda[5];
124     rayon=sda[6];
125     stcourbe=new ST_CIRCLE(origine,axe,rayon);
126     return;
127     }
128     swCurve->IsEllipse(&retval);
129     if (retval==1)
130     {
131     CComVariant vRetval;
132     vRetval=swCurve->GetEllipseParams();
133     SafeDoubleArray sda(vRetval);
134     double origine[3];
135     double dirx[3];
136     double diry[3];
137     double rayona;
138     double rayonb;
139     origine[0]=sda[0];
140     origine[1]=sda[1];
141     origine[2]=sda[2];
142     rayona=sda[3];
143     dirx[0]=sda[4];
144     dirx[1]=sda[5];
145     dirx[2]=sda[6];
146     rayonb=sda[7];
147     diry[0]=sda[8];
148     diry[1]=sda[9];
149     diry[2]=sda[10];
150     OT_VECTEUR_3D x(dirx[0],dirx[1],dirx[2]);
151     OT_VECTEUR_3D y(diry[0],diry[1],diry[2]);
152     OT_VECTEUR_3D z=x&y;
153     double *dirz=z.get_xyz();
154     stcourbe=new ST_ELLIPSE(origine,dirz,dirx,rayona,rayonb);
155     return;
156     }
157     CComVariant vRetval;
158     swCurve->GetBCurveParams(False,&vRetval);
159     SafeDoubleArray sda(vRetval);
160     int dim,ordre,num,periode;
161     OPERATEUR::doubleto2int(sda[0],dim,ordre);
162     OPERATEUR::doubleto2int(sda[1],num,periode);
163     std::vector<double> knots;
164     for (int i=0;i<num+ordre;i++)
165     knots.insert(knots.end(),sda[2+i]);
166     std::vector<double> points;
167     std::vector<double> poids;
168     for (int i=0;i<num;i++)
169     {
170     points.insert(points.end(),sda[2+num+ordre+dim*i]);
171     points.insert(points.end(),sda[2+num+ordre+dim*i+1]);
172     points.insert(points.end(),sda[2+num+ordre+dim*i+2]);
173     if (dim==4) poids.insert(poids.end(),sda[2+num+ordre+dim*i+3]);
174     else poids.insert(poids.end(),1.);
175     }
176     stcourbe=new ST_B_SPLINE(ordre-1,knots,points,poids);
177     }
178    
179    
180     void SLD_COURBE::evaluer(double t,double *xyz)
181     {
182     if (stcourbe!=NULL)
183     {
184     stcourbe->evaluer(t,xyz);
185     return;
186     }
187     CComVariant vparam;
188     swCurve->Evaluate(t,&vparam);
189     SafeDoubleArray param(vparam);
190     xyz[0]=param[0];
191     xyz[1]=param[1];
192     xyz[2]=param[2];
193     }
194    
195     void SLD_COURBE::deriver(double t,double *dxyz)
196     {
197     if (stcourbe!=NULL)
198     {
199     stcourbe->deriver(t,dxyz);
200     return;
201     }
202     CComVariant vparam;
203     swCurve->Evaluate(t,&vparam);
204     SafeDoubleArray param(vparam);
205     dxyz[0]=param[3];
206     dxyz[1]=param[4];
207     dxyz[2]=param[5];
208     }
209    
210     void SLD_COURBE::deriver_seconde(double t,double *ddxyz,double*dxyz,double*xyz)
211     {
212     if (stcourbe!=NULL)
213     {
214     stcourbe->deriver_seconde(t,ddxyz,dxyz,xyz);
215     return;
216     }
217     double epsilon=(t_max-t_min)*10e-6;
218     double t1,t2;
219     if(t-epsilon<t_min)
220     {
221     t1=t_min;
222     t2=t_min+2*epsilon;
223     }
224     else if(t+epsilon>t_max)
225     {
226     t1=t_max-2*epsilon;
227     t2=t_max;
228     }
229     else
230     {
231     t1=t-epsilon;
232     t2=t+epsilon;
233     }
234     CComVariant vparam1;
235     CComVariant vparam2;
236     swCurve->Evaluate(t1,&vparam1);
237     swCurve->Evaluate(t2,&vparam2);
238     SafeDoubleArray param1(vparam1);
239     SafeDoubleArray param2(vparam2);
240     ddxyz[0]=(param2[3]-param1[3])/(2*epsilon);
241     ddxyz[1]=(param2[4]-param1[4])/(2*epsilon);
242     ddxyz[2]=(param2[5]-param1[5])/(2*epsilon);
243    
244     //différent cas
245     if(dxyz!=NULL)
246     {
247     CComVariant vparam;
248     swCurve->Evaluate(t,&vparam);
249     SafeDoubleArray param(vparam);
250     dxyz[0]=param[3];
251     dxyz[1]=param[4];
252     dxyz[2]=param[5];
253     if(xyz!=NULL)
254     {
255     xyz[0]=param[0];
256     xyz[1]=param[1];
257     xyz[2]=param[2];
258     }
259     }
260     }
261    
262     void SLD_COURBE::inverser(double& t,double *xyz,double precision)
263     {
264     if (stcourbe!=NULL)
265     {
266     stcourbe->inverser(t,xyz,precision);
267     return;
268     }
269     CComVariant retval;
270     swCurve->GetClosestPointOn ( xyz[0], xyz[1], xyz[2], &retval ) ;
271     SafeDoubleArray vretval(retval);
272     t=vretval[3];
273     }
274    
275     double SLD_COURBE::get_tmin(void)
276     {
277     if (stcourbe!=NULL)
278     {
279     return stcourbe->get_tmin();
280     }
281     return tmin;
282     }
283    
284     double SLD_COURBE::get_tmax(void)
285     {
286     if (stcourbe!=NULL)
287     {
288     return stcourbe->get_tmax();
289     }
290     return tmax;
291     }
292    
293    
294    
295     double SLD_COURBE::get_longueur(double t1,double t2,double precis)
296     {
297     if (stcourbe!=NULL)
298     {
299     return stcourbe->get_longueur(t1,t2,precis);
300     }
301     double retval;
302     swCurve->GetLength2(t1,t2,&retval);
303     return retval;
304     }
305    
306    
307     int SLD_COURBE::est_periodique(void)
308     {
309     if (stcourbe!=NULL)
310     {
311     return stcourbe->est_periodique();
312     }
313     return periodique;
314     }
315    
316    
317     double SLD_COURBE::get_periode(void)
318     {
319     if (stcourbe!=NULL)
320     {
321     return stcourbe->get_periode();
322     }
323     return t_max-t_min;
324     }
325    
326     void SLD_COURBE::enregistrer(std::ostream& o)
327     {
328     o << "%" << get_id() << "=COURBE_SLD("<< idoriginal.c_str() << ");"<<std::endl;
329     }
330    
331    
332     int SLD_COURBE::get_type_geometrique(TPL_LISTE_ENTITE<double> &param)
333     {
334     if (stcourbe!=NULL)
335     return stcourbe->get_type_geometrique(param);
336     return 0;
337     }
338    
339     void SLD_COURBE::get_param_NURBS(int& indx_premier_ptctr,TPL_LISTE_ENTITE<double> &param)
340     {
341     stcourbe->get_param_NURBS(indx_premier_ptctr,param);
342     }
343    
344    
345    
346    
347    
348     #endif
349    
350