ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/sld_courbe.cpp
Revision: 5
Committed: Tue Jun 12 20:26:34 2007 UTC (17 years, 11 months ago)
Original Path: magic/lib/geometrie/geometrie/src/sld_courbe.cpp
File size: 8169 byte(s)
Log Message:

File Contents

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