ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/occ_courbe.cpp
Revision: 140
Committed: Tue Aug 12 18:05:10 2008 UTC (16 years, 9 months ago) by francois
Original Path: magic/lib/geometrie/geometrie/src/occ_courbe.cpp
File size: 13068 byte(s)
Log Message:
bug mise a jour precedente

File Contents

# User Rev Content
1 francois 139 //---------------------------------------------------------------------------
2     //------------------------------------------------------------
3     // Le projet MAGIC est un projet de recherche du département
4     // de génie mécanique de l'Université du Québec à
5     // Trois Rivières
6     // Les librairies ne peuvent être utilisées sans l'accord
7     // des auteurs (contact : francois@uqtr.ca)
8     //------------------------------------------------------------
9     //------------------------------------------------------------
10     //
11     // OCC_Courbe.cpp
12     //
13     //------------------------------------------------------------
14     //------------------------------------------------------------
15     // COPYRIGHT 2000
16     // Version du 02/03/2006 à 11H22
17     //------------------------------------------------------------
18     //------------------------------------------------------------
19    
20     #pragma hdrstop
21     #include "gestionversion.h"
22    
23     #ifdef BREP_OCC
24    
25     #include "occ_courbe.h"
26     #include "Geom_Line.hxx"
27     #include "gp_Lin.hxx"
28     #include "Geom_Circle.hxx"
29     #include "gp_Circ.hxx"
30     #include "Geom_Ellipse.hxx"
31     #include "gp_Elips.hxx"
32     #include "Geom_Hyperbola.hxx"
33     #include "gp_Hypr.hxx"
34     #include "Geom_Parabola.hxx"
35     #include "gp_Parab.hxx"
36     #include "Geom_BezierCurve.hxx"
37     #include "Geom_BSplineCurve.hxx"
38     #include "GCPnts_AbscissaPoint.hxx"
39     #include "GeomAdaptor_Curve.hxx"
40     #include "GeomAbs_CurveType.hxx"
41     #include "GeomAPI.hxx"
42     #include "Handle_Geom2d_Curve.hxx"
43     #include "gp_Pln.hxx"
44     #include "GeomAPI_ProjectPointOnCurve.hxx"
45     #include "ShapeAnalysis_Curve.hxx"
46     #include "occ_fonction1.h"
47     #include "BRep_Tool.hxx"
48     #include "GeomConvert.hxx"
49     #include <Geom_TrimmedCurve.hxx>
50     #include "constantegeo.h"
51     #include "ot_mathematique.h"
52    
53    
54    
55     #pragma package(smart_init)
56     OCC_COURBE::OCC_COURBE(unsigned long num,TopoDS_Edge crb,OCC_FONCTION1& fonc):MG_COURBE(num),edge(crb),fonction1(fonc)
57     {
58     double first, last;
59     Handle(Geom_Curve) courbe=BRep_Tool::Curve(edge, first, last);
60     t_min=courbe->FirstParameter();
61     t_max=courbe->LastParameter();
62     }
63     OCC_COURBE::OCC_COURBE(TopoDS_Edge crb, OCC_FONCTION1& fonc):MG_COURBE(),edge(crb), fonction1(fonc)
64     {
65     double first, last;
66     Handle(Geom_Curve) courbe=BRep_Tool::Curve(edge, first, last);
67     t_min=courbe->FirstParameter();
68     t_max=courbe->LastParameter();
69     }
70    
71     OCC_COURBE::OCC_COURBE(OCC_COURBE& mdd):MG_COURBE(mdd),edge(mdd.edge), fonction1(mdd.fonction1)
72     {
73     double first, last;
74     Handle(Geom_Curve) courbe=BRep_Tool::Curve(edge, first, last);
75     t_min=mdd.t_min;
76     t_max=mdd.t_max;
77     }
78     OCC_COURBE::~OCC_COURBE()
79     {
80     }
81     void OCC_COURBE::evaluer(double t, double *xyz)
82     {
83     double first, last;
84     Handle(Geom_Curve) courbe=BRep_Tool::Curve(edge, first, last);
85     gp_Pnt P;
86     courbe->D0(t,P);
87    
88     xyz[0]=P.X();
89     xyz[1]=P.Y();
90     xyz[2]=P.Z();
91     }
92     void OCC_COURBE::deriver(double t,double *xyz)
93     {
94     double first, last;
95     Handle(Geom_Curve) courbe=BRep_Tool::Curve(edge, first, last);
96     gp_Pnt P;
97     gp_Vec V;
98     courbe->D1(t, P, V);
99     xyz[0]=V.X();
100     xyz[1]=V.Y();
101     xyz[2]=V.Z();
102     }
103     void OCC_COURBE::deriver_seconde(double t,double *ddxyz,double *dxyz,double *xyz)
104     {
105     double first, last;
106     Handle(Geom_Curve) courbe=BRep_Tool::Curve(edge, first, last);
107     gp_Vec V1;
108     gp_Vec V2;
109     gp_Pnt P;
110    
111     courbe->D2(t,P,V1,V2);
112    
113     dxyz[0]=V1.X();
114     dxyz[1]=V1.Y();
115     dxyz[2]=V1.Z();
116    
117     ddxyz[0]=V2.X();
118     ddxyz[1]=V2.Y();
119     ddxyz[2]=V2.Z();
120    
121     xyz[0]=P.X();
122     xyz[1]=P.Y();
123     xyz[2]=P.Z();
124     }
125     void OCC_COURBE::inverser(double& t,double *xyz,double precision)
126     {
127    
128     double first, last;
129     Handle(Geom_Curve) courbe=BRep_Tool::Curve(edge, first, last);
130     //ShapeAnalysis_Curve SAC;
131     double tmin=courbe->FirstParameter();
132     double tmax=courbe->LastParameter();
133 francois 140 double xyz1[3],xyz2[3];
134 francois 139 evaluer(tmin,xyz1);
135     evaluer(tmax,xyz2);
136     double max=fabs(xyz1[0]);
137     if (max<xyz1[1]) max=xyz1[1];
138     if (max<xyz1[2]) max=xyz1[2];
139     if (max<xyz2[0]) max=xyz2[0];
140     if (max<xyz2[1]) max=xyz2[1];
141     if (max<xyz2[2]) max=xyz2[2];
142     double eps=10.*precision*max;
143     OT_VECTEUR_3D vec1(xyz,xyz1);
144     OT_VECTEUR_3D vec2(xyz,xyz2);
145     if (vec1.get_longueur()<eps) {t=tmin;return;}
146     if (vec2.get_longueur()<eps) {t=tmax;return;}
147     double u=xyz[0];
148     double v=xyz[1];
149     double w=xyz[2];
150     gp_Pnt P(u,v,w);
151     //gp_Pnt proj;
152     //Standard_Real param;
153    
154     //t=SAC.Project(courbe, P, precision, proj, param, Standard_True);*/
155    
156     GeomAPI_ProjectPointOnCurve PPC(P,courbe);
157     //PPC.Perform(P);
158     t=PPC.LowerDistanceParameter();
159    
160     }
161     int OCC_COURBE::est_periodique(void)
162     {
163     double first, last;
164     Handle(Geom_Curve) courbe=BRep_Tool::Curve(edge, first, last);
165     return courbe->IsPeriodic();
166     }
167     double OCC_COURBE::get_periode(void)
168     {
169     double first, last;
170     Handle(Geom_Curve) courbe=BRep_Tool::Curve(edge, first, last);
171     if(courbe->IsPeriodic()==0) return 0.;
172     return courbe->Period();
173     }
174     double OCC_COURBE::get_longueur(double t1,double t2,double precis)
175     {
176     double first, last;
177     Handle(Geom_Curve) courbe=BRep_Tool::Curve(edge, first, last);
178     double longueur;
179     GeomAdaptor_Curve cc(courbe);
180     longueur= GCPnts_AbscissaPoint::Length(cc,t1,t2,precis);
181    
182     return longueur;
183     }
184     void OCC_COURBE::enregistrer(std::ostream& o)
185     {
186     o <<"%"<<get_id()<<"=COURBE_OCC("<<fonction1.GetID(edge)<< ");" << std::endl;
187     }
188    
189     int OCC_COURBE::get_type_geometrique(TPL_LISTE_ENTITE<double> &param)
190     {
191    
192     double first, last;
193     Handle(Geom_Curve) courbe=BRep_Tool::Curve(edge, first, last);
194     Handle(Standard_Type) type=courbe->DynamicType();
195     //***droite
196     if(type==STANDARD_TYPE(Geom_Line))
197     {
198     Handle(Geom_Line) droite=Handle(Geom_Line)::DownCast(courbe);
199     gp_Lin lin=droite->Lin();
200    
201     double origine[3];
202     gp_Pnt centre=lin.Location();
203     origine[0]=centre.X();
204     origine[1]=centre.Y();
205     origine[2]=centre.Z();
206     double direction[3];
207     gp_Dir dir=lin.Direction();
208     direction[0]=dir.X();
209     direction[1]=dir.Y();
210     direction[2]=dir.Z();
211    
212     param.ajouter(origine[0]);
213     param.ajouter(origine[1]);
214     param.ajouter(origine[2]);
215     param.ajouter(direction[0]);
216     param.ajouter(direction[1]);
217     param.ajouter(direction[2]);
218    
219     return MGCo_LINE;
220    
221     }
222     //***circle
223     if(type==STANDARD_TYPE(Geom_Circle))
224     {
225     Handle(Geom_Circle) circle=Handle_Geom_Circle::DownCast(courbe);
226     gp_Circ Circ=circle->Circ();
227    
228     double origine[3];
229     gp_Pnt centre=Circ.Location();
230     origine[0]=centre.X();
231     origine[1]=centre.Y();
232     origine[2]=centre.Z();
233    
234     double direction[3];
235     gp_Ax1 axe=Circ.Axis();
236     gp_Dir dir=axe.Direction();
237     direction[0]=dir.X();
238     direction[1]=dir.Y();
239     direction[2]=dir.Z();
240     double rayon;
241     rayon=Circ.Radius();
242    
243     param.ajouter(origine[0]);
244     param.ajouter(origine[1]);
245     param.ajouter(origine[2]);
246     param.ajouter(direction[0]);
247     param.ajouter(direction[1]);
248     param.ajouter(direction[2]);
249     param.ajouter(rayon);
250    
251     return MGCo_CIRCLE;
252    
253     }
254     //*****ellipse
255     if(type==STANDARD_TYPE(Geom_Ellipse))
256     {
257     Handle(Geom_Ellipse) ellipse=Handle_Geom_Ellipse::DownCast(courbe);
258     gp_Elips Elips=ellipse->Elips();
259    
260     double origine[3];
261     gp_Pnt centre=Elips.Location();
262     origine[0]=centre.X();
263     origine[1]=centre.Y();
264     origine[2]=centre.Z();
265    
266     double Grayon;
267     Grayon=Elips.MajorRadius();
268     double Xdirectrise[3];
269     gp_Ax1 Xaxe=Elips.Directrix1();
270     gp_Dir dir=Xaxe.Direction();
271     Xdirectrise[0]=dir.X();
272     Xdirectrise[1]=dir.Y();
273     Xdirectrise[2]=dir.Z();
274     double Prayon;
275     Prayon=Elips.MinorRadius();
276     double Ydirectrise[3];
277     gp_Ax1 Yaxe=Elips.Directrix2();
278     gp_Dir dir1=Yaxe.Direction();
279     Ydirectrise[0]=dir1.X();
280     Ydirectrise[1]=dir1.Y();
281     Ydirectrise[2]=dir1.Z();
282    
283     param.ajouter(origine[0]);
284     param.ajouter(origine[1]);
285     param.ajouter(origine[2]);
286     param.ajouter(Grayon);
287     param.ajouter(Xdirectrise[0]);
288     param.ajouter(Xdirectrise[1]);
289     param.ajouter(Xdirectrise[2]);
290     param.ajouter(Prayon);
291     param.ajouter(Ydirectrise[0]);
292     param.ajouter(Ydirectrise[1]);
293     param.ajouter(Ydirectrise[2]);
294    
295    
296     return MGCo_ELLIPSE;
297     }
298     /* //*****hyperbole
299     if(type==STANDARD_TYPE(Geom_Hyperbola))
300     {
301     Handle(Geom_Hyperbola) hyperbole=Handle_Geom_Hyperbola::DownCast(courbe);
302     gp_Hypr Hyper=hyperbole->Hypr();
303     double origine[3];
304     gp_Pnt centre=Hyper.Location();
305     origine[0]=centre.X();
306     origine[1]=centre.Y();
307     origine[2]=centre.Z();
308    
309     double Grayon;
310     Grayon=Hyper.MajorRadius();
311     double Xdirectrise[3];
312     gp_Ax1 Xaxe=Hyper.Directrix1();
313     gp_Dir Xdir=Xaxe.Direction();
314     Xdirectrise[0]=Xdir.X();
315     Xdirectrise[1]=Xdir.Y();
316     Xdirectrise[2]=Xdir.Z();
317     double Prayon;
318     Prayon=Hyper.MinorRadius();
319     double Ydirectrise[3];
320     gp_Ax1 Yaxe=Hyper.Directrix1();
321     gp_Dir Ydir=Yaxe.Direction();
322     Ydirectrise[0]=Ydir.X();
323     Ydirectrise[1]=Ydir.Y();
324     Ydirectrise[2]=Ydir.Z();
325    
326    
327     param.ajouter(origine[0]);
328     param.ajouter(origine[1]);
329     param.ajouter(origine[2]);
330     param.ajouter(Grayon);
331     param.ajouter(Xdirectrise[0]);
332     param.ajouter(Xdirectrise[1]);
333     param.ajouter(Xdirectrise[2]);
334     param.ajouter(Prayon);
335     param.ajouter(Ydirectrise[0]);
336     param.ajouter(Ydirectrise[1]);
337     param.ajouter(Ydirectrise[2]);
338    
339    
340     return hyperbole->IsKind(STANDARD_TYPE(Geom_Hyperbola));
341     }
342     //*****parabole
343     if(type==STANDARD_TYPE(Geom_Parabola))
344     {
345     Handle(Geom_Parabola) parabole=Handle_Geom_Parabola::DownCast(courbe);
346     gp_Parab Parab=parabole->Parab();
347    
348     double origine[3];
349     gp_Pnt centre=Parab.Location();
350     origine[0]=centre.X();
351     origine[1]=centre.Y();
352     origine[2]=centre.Z();
353    
354     double focale;
355     focale=Parab.Focal();
356     double directrice[3];
357     gp_Ax1 dire=Parab.Directrix();
358     gp_Dir dir=dire.Direction();
359     directrice[0]=dir.X();
360     directrice[1]=dir.Y();
361     directrice[2]=dir.Z();
362    
363     param.ajouter(origine[0]);
364     param.ajouter(origine[1]);
365     param.ajouter(origine[2]);
366     param.ajouter(focale);
367     param.ajouter(directrice[0]);
368     param.ajouter(directrice[1]);
369     param.ajouter(directrice[2]);
370    
371     return parabole->IsKind(STANDARD_TYPE(Geom_Parabola));
372     } */
373     //*****Bspline
374     if(type==STANDARD_TYPE(Geom_BSplineCurve))
375     {
376     Handle(Geom_BSplineCurve) bspline=Handle_Geom_BSplineCurve::DownCast(courbe);
377    
378     //nombre des noeuds
379     int nb_knot=bspline->NbKnots();
380     //valeur de noeud
381     for(int i=1; i<=nb_knot; i++)
382     {
383     double valeur=bspline->Knot(i);
384     param.ajouter(valeur);
385     }
386     //point de controle et poids
387     gp_Pnt pctr;
388     double poids;
389     for(int u=1; u<=bspline->NbPoles(); u++)
390     {
391     pctr=bspline->Pole(u);
392     param.ajouter(pctr.X());
393     param.ajouter(pctr.Y());
394     param.ajouter(pctr.Z());
395     poids=bspline->Weight(u);
396     param.ajouter(poids);
397     }
398    
399     double Degree=bspline->Degree();
400     param.ajouter(Degree);
401    
402    
403     return MGCo_BSPLINE;
404     }
405    
406     }
407    
408     void OCC_COURBE::get_param_NURBS(int& indx_premier_ptctr,TPL_LISTE_ENTITE<double> &param)
409     {
410     //Conversion of the complete geometry of a shape into
411     //NURBS geometry
412     double first, last;
413     Handle(Geom_Curve) courbe=BRep_Tool::Curve(edge, first, last);
414     Handle(Geom_TrimmedCurve) curv=new Geom_TrimmedCurve(courbe, first, last);
415     Handle(Geom_BSplineCurve) bspline=GeomConvert::CurveToBSplineCurve(curv) ;
416    
417     // The first parameter indicate the code access
418     param.ajouter(1);
419     //The follewing two parameters of the list indicate the orders of the net points
420     param.ajouter(bspline->Degree()+1);
421     param.ajouter(0);
422    
423     //The follewing two parameters indicate the number of rows and colons of the control points
424     //respectively to the two parameters directions
425     param.ajouter(bspline->NbPoles());
426     param.ajouter(0);
427    
428     //this present the knot vector
429    
430     for(unsigned int i=1;i<=bspline->NbKnots();i++)
431     {
432     param.ajouter(bspline->Knot(i));
433     }
434    
435     // in the following we construct the control point vector
436     for(unsigned int j=1;j<=bspline->NbPoles();j++)
437     {
438     double w=bspline->Weight(j);
439     gp_Pnt point=bspline->Pole(j);
440     double x=point.X();
441     double y=point.Y();
442     double z=point.Z();
443     param.ajouter(x);
444     param.ajouter(y);
445     param.ajouter(z);
446     param.ajouter(w);
447     }
448     indx_premier_ptctr=5+bspline->NbKnots();
449    
450    
451     }
452     #endif