ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/occ_courbe.cpp
Revision: 897
Committed: Wed Jul 19 14:51:28 2017 UTC (7 years, 9 months ago) by francois
File size: 14193 byte(s)
Log Message:
mise a jour pour version compilee de OCC

File Contents

# User Rev Content
1 francois 283 //---------------------------------------------------------------------------
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 francois 897 #include "Geom2d_Curve.hxx"
43 francois 283 #include "gp_Pln.hxx"
44     #include "GeomAPI_ProjectPointOnCurve.hxx"
45     #include "ShapeAnalysis_Curve.hxx"
46 couturad 740 #include "occ_fonction.h"
47 francois 283 #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 couturad 740 OCC_COURBE::OCC_COURBE(unsigned long num,TopoDS_Edge crb,OCC_FONCTION& fonc):MG_COURBE(num),edge(crb),fonction1(fonc)
57 francois 283 {
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 couturad 740 OCC_COURBE::OCC_COURBE(TopoDS_Edge crb, OCC_FONCTION& fonc):MG_COURBE(),edge(crb), fonction1(fonc)
64 francois 283 {
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 francois 731
70     /* Handle(Standard_Type) type=courbe->DynamicType();
71     if (type==STANDARD_TYPE(Geom_Line)) std::cout << "Ligne" << std::endl;
72     if (type==STANDARD_TYPE(Geom_Circle)) std::cout << "Cercle" << std::endl;
73     if (type==STANDARD_TYPE(Geom_Ellipse)) std::cout << "Ellipse" << std::endl;
74     if (type==STANDARD_TYPE(Geom_BSplineCurve)) std::cout << "BSpline" << std::endl;
75     std::cout << courbe->IsClosed()<<std::endl;;
76     std::cout << courbe->IsPeriodic() << std::endl;;
77     if (courbe->IsPeriodic()) std::cout << "Pt=" << courbe->Period() << "|" << get_periode() << std::endl;
78     else if (courbe->IsClosed()) std::cout << "Pt=" << t_max-t_min << "|" << get_periode() << std::endl;*/
79 francois 283 }
80    
81     OCC_COURBE::OCC_COURBE(OCC_COURBE& mdd):MG_COURBE(mdd),edge(mdd.edge), fonction1(mdd.fonction1)
82     {
83     double first, last;
84     Handle(Geom_Curve) courbe=BRep_Tool::Curve(edge, first, last);
85     t_min=mdd.t_min;
86     t_max=mdd.t_max;
87     }
88     OCC_COURBE::~OCC_COURBE()
89     {
90     }
91     void OCC_COURBE::evaluer(double t, double *xyz)
92     {
93     double first, last;
94     Handle(Geom_Curve) courbe=BRep_Tool::Curve(edge, first, last);
95     gp_Pnt P;
96     courbe->D0(t,P);
97    
98     xyz[0]=P.X();
99     xyz[1]=P.Y();
100     xyz[2]=P.Z();
101     }
102     void OCC_COURBE::deriver(double t,double *xyz)
103     {
104     double first, last;
105     Handle(Geom_Curve) courbe=BRep_Tool::Curve(edge, first, last);
106     gp_Pnt P;
107     gp_Vec V;
108     courbe->D1(t, P, V);
109     xyz[0]=V.X();
110     xyz[1]=V.Y();
111     xyz[2]=V.Z();
112     }
113     void OCC_COURBE::deriver_seconde(double t,double *ddxyz,double *dxyz,double *xyz)
114     {
115     double first, last;
116     Handle(Geom_Curve) courbe=BRep_Tool::Curve(edge, first, last);
117     gp_Vec V1;
118     gp_Vec V2;
119     gp_Pnt P;
120    
121     courbe->D2(t,P,V1,V2);
122    
123     dxyz[0]=V1.X();
124     dxyz[1]=V1.Y();
125     dxyz[2]=V1.Z();
126    
127     ddxyz[0]=V2.X();
128     ddxyz[1]=V2.Y();
129     ddxyz[2]=V2.Z();
130    
131     xyz[0]=P.X();
132     xyz[1]=P.Y();
133     xyz[2]=P.Z();
134     }
135     void OCC_COURBE::inverser(double& t,double *xyz,double precision)
136     {
137    
138     double first, last;
139     Handle(Geom_Curve) courbe=BRep_Tool::Curve(edge, first, last);
140     //ShapeAnalysis_Curve SAC;
141     double tmin=courbe->FirstParameter();
142     double tmax=courbe->LastParameter();
143     double xyz1[3],xyz2[3];
144     evaluer(tmin,xyz1);
145     evaluer(tmax,xyz2);
146     double max=fabs(xyz1[0]);
147     if (max<fabs(xyz1[1])) max=fabs(xyz1[1]);
148     if (max<fabs(xyz1[2])) max=fabs(xyz1[2]);
149     if (max<fabs(xyz2[0])) max=fabs(xyz2[0]);
150     if (max<fabs(xyz2[1])) max=fabs(xyz2[1]);
151     if (max<fabs(xyz2[2])) max=fabs(xyz2[2]);
152     double eps=precision*max;
153     OT_VECTEUR_3D vec1(xyz,xyz1);
154     OT_VECTEUR_3D vec2(xyz,xyz2);
155     if (vec1.get_longueur()<eps) {
156     t=tmin;
157     return;
158     }
159     if (vec2.get_longueur()<eps) {
160     t=tmax;
161     return;
162     }
163     double u=xyz[0];
164     double v=xyz[1];
165     double w=xyz[2];
166     gp_Pnt P(u,v,w);
167     //gp_Pnt proj;
168     //Standard_Real param;
169    
170     //t=SAC.Project(courbe, P, precision, proj, param, Standard_True);*/
171    
172     GeomAPI_ProjectPointOnCurve PPC(P,courbe);
173     //PPC.Perform(P);
174     try
175     {
176     t=PPC.LowerDistanceParameter();
177     }
178     catch (...)
179     {
180     t=-1e308;
181     }
182    
183     }
184     int OCC_COURBE::est_periodique(void)
185     {
186     double first, last;
187     Handle(Geom_Curve) courbe=BRep_Tool::Curve(edge, first, last);
188 francois 731 // return courbe->IsPeriodic();
189     return courbe->IsClosed();
190 francois 283 }
191     double OCC_COURBE::get_periode(void)
192     {
193     double first, last;
194     Handle(Geom_Curve) courbe=BRep_Tool::Curve(edge, first, last);
195 francois 731 // if (courbe->IsPeriodic()==0) return 0.;
196     // return courbe->Period();
197     if (courbe->IsPeriodic()) return courbe->Period();
198     if (courbe->IsClosed()) return t_max-t_min;
199     return 0;
200 francois 283 }
201     double OCC_COURBE::get_longueur(double t1,double t2,double precis)
202     {
203     double first, last;
204     Handle(Geom_Curve) courbe=BRep_Tool::Curve(edge, first, last);
205     double longueur;
206     GeomAdaptor_Curve cc(courbe);
207     longueur= GCPnts_AbscissaPoint::Length(cc,t1,t2,precis);
208    
209     return longueur;
210     }
211 francois 763 void OCC_COURBE::enregistrer(std::ostream& o,double version)
212 francois 283 {
213     o <<"%"<<get_id()<<"=COURBE_OCC("<<fonction1.GetID(edge)<< ");" << std::endl;
214     }
215    
216     int OCC_COURBE::get_type_geometrique(TPL_LISTE_ENTITE<double> &param)
217     {
218    
219     double first, last;
220     Handle(Geom_Curve) courbe=BRep_Tool::Curve(edge, first, last);
221     Handle(Standard_Type) type=courbe->DynamicType();
222     //***droite
223     if (type==STANDARD_TYPE(Geom_Line))
224     {
225     Handle(Geom_Line) droite=Handle(Geom_Line)::DownCast(courbe);
226     gp_Lin lin=droite->Lin();
227    
228     double origine[3];
229     gp_Pnt centre=lin.Location();
230     origine[0]=centre.X();
231     origine[1]=centre.Y();
232     origine[2]=centre.Z();
233     double direction[3];
234     gp_Dir dir=lin.Direction();
235     direction[0]=dir.X();
236     direction[1]=dir.Y();
237     direction[2]=dir.Z();
238    
239     param.ajouter(origine[0]);
240     param.ajouter(origine[1]);
241     param.ajouter(origine[2]);
242     param.ajouter(direction[0]);
243     param.ajouter(direction[1]);
244     param.ajouter(direction[2]);
245    
246     return MGCo_LINE;
247    
248     }
249     //***circle
250     if (type==STANDARD_TYPE(Geom_Circle))
251     {
252     Handle(Geom_Circle) circle=Handle_Geom_Circle::DownCast(courbe);
253     gp_Circ Circ=circle->Circ();
254    
255     double origine[3];
256     gp_Pnt centre=Circ.Location();
257     origine[0]=centre.X();
258     origine[1]=centre.Y();
259     origine[2]=centre.Z();
260    
261     double direction[3];
262     gp_Ax1 axe=Circ.Axis();
263     gp_Dir dir=axe.Direction();
264     direction[0]=dir.X();
265     direction[1]=dir.Y();
266     direction[2]=dir.Z();
267     double rayon;
268     rayon=Circ.Radius();
269    
270     param.ajouter(origine[0]);
271     param.ajouter(origine[1]);
272     param.ajouter(origine[2]);
273     param.ajouter(direction[0]);
274     param.ajouter(direction[1]);
275     param.ajouter(direction[2]);
276     param.ajouter(rayon);
277    
278     return MGCo_CIRCLE;
279    
280     }
281     //*****ellipse
282     if (type==STANDARD_TYPE(Geom_Ellipse))
283     {
284     Handle(Geom_Ellipse) ellipse=Handle_Geom_Ellipse::DownCast(courbe);
285     gp_Elips Elips=ellipse->Elips();
286    
287     double origine[3];
288     gp_Pnt centre=Elips.Location();
289     origine[0]=centre.X();
290     origine[1]=centre.Y();
291     origine[2]=centre.Z();
292    
293     double Grayon;
294     Grayon=Elips.MajorRadius();
295     double Xdirectrise[3];
296     gp_Ax1 Xaxe=Elips.Directrix1();
297     gp_Dir dir=Xaxe.Direction();
298     Xdirectrise[0]=dir.X();
299     Xdirectrise[1]=dir.Y();
300     Xdirectrise[2]=dir.Z();
301     double Prayon;
302     Prayon=Elips.MinorRadius();
303     double Ydirectrise[3];
304     gp_Ax1 Yaxe=Elips.Directrix2();
305     gp_Dir dir1=Yaxe.Direction();
306     Ydirectrise[0]=dir1.X();
307     Ydirectrise[1]=dir1.Y();
308     Ydirectrise[2]=dir1.Z();
309    
310     param.ajouter(origine[0]);
311     param.ajouter(origine[1]);
312     param.ajouter(origine[2]);
313     param.ajouter(Grayon);
314     param.ajouter(Xdirectrise[0]);
315     param.ajouter(Xdirectrise[1]);
316     param.ajouter(Xdirectrise[2]);
317     param.ajouter(Prayon);
318     param.ajouter(Ydirectrise[0]);
319     param.ajouter(Ydirectrise[1]);
320     param.ajouter(Ydirectrise[2]);
321    
322    
323     return MGCo_ELLIPSE;
324     }
325     /* //*****hyperbole
326     if(type==STANDARD_TYPE(Geom_Hyperbola))
327     {
328     Handle(Geom_Hyperbola) hyperbole=Handle_Geom_Hyperbola::DownCast(courbe);
329     gp_Hypr Hyper=hyperbole->Hypr();
330     double origine[3];
331     gp_Pnt centre=Hyper.Location();
332     origine[0]=centre.X();
333     origine[1]=centre.Y();
334     origine[2]=centre.Z();
335    
336     double Grayon;
337     Grayon=Hyper.MajorRadius();
338     double Xdirectrise[3];
339     gp_Ax1 Xaxe=Hyper.Directrix1();
340     gp_Dir Xdir=Xaxe.Direction();
341     Xdirectrise[0]=Xdir.X();
342     Xdirectrise[1]=Xdir.Y();
343     Xdirectrise[2]=Xdir.Z();
344     double Prayon;
345     Prayon=Hyper.MinorRadius();
346     double Ydirectrise[3];
347     gp_Ax1 Yaxe=Hyper.Directrix1();
348     gp_Dir Ydir=Yaxe.Direction();
349     Ydirectrise[0]=Ydir.X();
350     Ydirectrise[1]=Ydir.Y();
351     Ydirectrise[2]=Ydir.Z();
352    
353    
354     param.ajouter(origine[0]);
355     param.ajouter(origine[1]);
356     param.ajouter(origine[2]);
357     param.ajouter(Grayon);
358     param.ajouter(Xdirectrise[0]);
359     param.ajouter(Xdirectrise[1]);
360     param.ajouter(Xdirectrise[2]);
361     param.ajouter(Prayon);
362     param.ajouter(Ydirectrise[0]);
363     param.ajouter(Ydirectrise[1]);
364     param.ajouter(Ydirectrise[2]);
365    
366    
367     return hyperbole->IsKind(STANDARD_TYPE(Geom_Hyperbola));
368     }
369     //*****parabole
370     if(type==STANDARD_TYPE(Geom_Parabola))
371     {
372     Handle(Geom_Parabola) parabole=Handle_Geom_Parabola::DownCast(courbe);
373     gp_Parab Parab=parabole->Parab();
374    
375     double origine[3];
376     gp_Pnt centre=Parab.Location();
377     origine[0]=centre.X();
378     origine[1]=centre.Y();
379     origine[2]=centre.Z();
380    
381     double focale;
382     focale=Parab.Focal();
383     double directrice[3];
384     gp_Ax1 dire=Parab.Directrix();
385     gp_Dir dir=dire.Direction();
386     directrice[0]=dir.X();
387     directrice[1]=dir.Y();
388     directrice[2]=dir.Z();
389    
390     param.ajouter(origine[0]);
391     param.ajouter(origine[1]);
392     param.ajouter(origine[2]);
393     param.ajouter(focale);
394     param.ajouter(directrice[0]);
395     param.ajouter(directrice[1]);
396     param.ajouter(directrice[2]);
397    
398     return parabole->IsKind(STANDARD_TYPE(Geom_Parabola));
399     } */
400     //*****Bspline
401     if (type==STANDARD_TYPE(Geom_BSplineCurve))
402     {
403     Handle(Geom_BSplineCurve) bspline=Handle_Geom_BSplineCurve::DownCast(courbe);
404    
405     //nombre des noeuds
406     int nb_knot=bspline->NbKnots();
407     //valeur de noeud
408     for (int i=1; i<=nb_knot; i++)
409     {
410     double valeur=bspline->Knot(i);
411     param.ajouter(valeur);
412     }
413     //point de controle et poids
414     gp_Pnt pctr;
415     double poids;
416     for (int u=1; u<=bspline->NbPoles(); u++)
417     {
418     pctr=bspline->Pole(u);
419     param.ajouter(pctr.X());
420     param.ajouter(pctr.Y());
421     param.ajouter(pctr.Z());
422     poids=bspline->Weight(u);
423     param.ajouter(poids);
424     }
425    
426     double Degree=bspline->Degree();
427     param.ajouter(Degree);
428    
429    
430     return MGCo_BSPLINE;
431     }
432    
433     }
434    
435     void OCC_COURBE::get_param_NURBS(int& indx_premier_ptctr,TPL_LISTE_ENTITE<double> &param)
436     {
437     //Conversion of the complete geometry of a shape into
438     //NURBS geometry
439     double first, last;
440     Handle(Geom_Curve) courbe=BRep_Tool::Curve(edge, first, last);
441     Handle(Geom_TrimmedCurve) curv=new Geom_TrimmedCurve(courbe, first, last);
442     Handle(Geom_BSplineCurve) bspline=GeomConvert::CurveToBSplineCurve(curv) ;
443    
444     // The first parameter indicate the code access
445     param.ajouter(1);
446     //The follewing two parameters of the list indicate the orders of the net points
447     param.ajouter(bspline->Degree()+1);
448     param.ajouter(0);
449    
450     //The follewing two parameters indicate the number of rows and colons of the control points
451     //respectively to the two parameters directions
452     param.ajouter(bspline->NbPoles());
453     param.ajouter(0);
454    
455     //this present the knot vector
456    
457     for (unsigned int i=1;i<=bspline->NbKnots();i++)
458     {
459     param.ajouter(bspline->Knot(i));
460     }
461    
462     // in the following we construct the control point vector
463     for (unsigned int j=1;j<=bspline->NbPoles();j++)
464     {
465     double w=bspline->Weight(j);
466     gp_Pnt point=bspline->Pole(j);
467     double x=point.X();
468     double y=point.Y();
469     double z=point.Z();
470     param.ajouter(x);
471     param.ajouter(y);
472     param.ajouter(z);
473     param.ajouter(w);
474     }
475     indx_premier_ptctr=5+bspline->NbKnots();
476    
477    
478     }
479     #endif