ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/occ_courbe.cpp
Revision: 906
Committed: Mon Nov 13 22:30:18 2017 UTC (7 years, 6 months ago) by couturad
File size: 14912 byte(s)
Log Message:
Nouveau opencascade commit 1

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