0024157: Parallelization of assembly part of BO
[occt.git] / src / GeomConvert / GeomConvert_BSplineCurveToBezierCurve.cxx
1 // Created on: 1996-03-12
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22
23 #include <GeomConvert_BSplineCurveToBezierCurve.ixx>
24
25 #include <TColgp_Array1OfPnt.hxx>
26 #include <TColStd_Array1OfReal.hxx>
27
28
29 //=======================================================================
30 //function : GeomConvert_BSplineCurveToBezierCurve
31 //purpose  : 
32 //=======================================================================
33
34 GeomConvert_BSplineCurveToBezierCurve::GeomConvert_BSplineCurveToBezierCurve (const Handle(Geom_BSplineCurve)& BasisCurve)
35 {
36   myCurve = Handle(Geom_BSplineCurve)::DownCast(BasisCurve->Copy());
37   Standard_Real Uf = myCurve->FirstParameter();
38   Standard_Real Ul = myCurve->LastParameter();
39   myCurve->Segment(Uf,Ul);
40   myCurve->IncreaseMultiplicity(myCurve->FirstUKnotIndex(),
41                                 myCurve->LastUKnotIndex(),
42                                 myCurve->Degree());
43 }
44
45
46 //=======================================================================
47 //function : GeomConvert_BSplineCurveToBezierCurve
48 //purpose  : 
49 // 01/12/1997 PMN: On elimine d'eventuelles micro-courbe PRO11516
50 //=======================================================================Real I
51
52 GeomConvert_BSplineCurveToBezierCurve::GeomConvert_BSplineCurveToBezierCurve
53 (const Handle(Geom_BSplineCurve)& BasisCurve, 
54  const Standard_Real U1, 
55  const Standard_Real U2,
56  const Standard_Real ParametricTolerance)
57 {
58   if (U2 - U1 < ParametricTolerance)
59       Standard_DomainError::Raise("GeomConvert_BSplineCurveToBezierSurface");
60
61   Standard_Real Uf = U1, Ul = U2; 
62   Standard_Real PTol = ParametricTolerance/2 ;
63
64   Standard_Integer I1, I2;
65   myCurve = Handle(Geom_BSplineCurve)::DownCast(BasisCurve->Copy());
66
67   myCurve->LocateU(U1, PTol, I1, I2);
68   if (I1==I2) { // On est sur le noeud
69     if ( myCurve->Knot(I1) > U1) Uf = myCurve->Knot(I1);
70   }
71
72   myCurve->LocateU(U2, PTol, I1, I2);
73   if (I1==I2) { // On est sur le noeud
74     if ( myCurve->Knot(I1) < U2) Ul = myCurve->Knot(I1);
75   }
76
77   myCurve->Segment(Uf,Ul);
78   myCurve->IncreaseMultiplicity(myCurve->FirstUKnotIndex(),
79                                 myCurve->LastUKnotIndex(),
80                                 myCurve->Degree());
81 }
82
83
84 //=======================================================================
85 //function : Arc
86 //purpose  : 
87 //=======================================================================
88
89 Handle(Geom_BezierCurve) GeomConvert_BSplineCurveToBezierCurve::Arc
90 (const Standard_Integer Index)
91 {
92   if ( Index < 1 || Index > myCurve->NbKnots()-1) {
93     Standard_OutOfRange::Raise("GeomConvert_BSplineCurveToBezierCurve");
94   }
95   Standard_Integer Deg = myCurve->Degree();
96
97   TColgp_Array1OfPnt Poles(1,Deg+1);
98
99   Handle(Geom_BezierCurve) C;
100   if ( myCurve->IsRational()) {
101     TColStd_Array1OfReal Weights(1,Deg+1);
102     for ( Standard_Integer i = 1; i <= Deg+1; i++) {
103       Poles(i)   = myCurve->Pole(i+Deg*(Index-1));
104       Weights(i) = myCurve->Weight(i+Deg*(Index-1));
105     }
106     C = new Geom_BezierCurve(Poles,Weights);
107   }
108   else {
109     for ( Standard_Integer i = 1; i <= Deg+1; i++) {
110       Poles(i)   = myCurve->Pole(i+Deg*(Index-1));
111     }
112     C = new Geom_BezierCurve(Poles);
113   }
114   return C;
115 }
116
117
118 //=======================================================================
119 //function : Arcs
120 //purpose  : 
121 //=======================================================================
122
123 void GeomConvert_BSplineCurveToBezierCurve::Arcs
124 (TColGeom_Array1OfBezierCurve& Curves)
125 {
126   Standard_Integer n = NbArcs();
127   for ( Standard_Integer i = 1; i <= n; i++) {
128     Curves(i) = Arc(i);
129   } 
130 }
131
132 //=======================================================================
133 //function : Knots
134 //purpose  : 
135 //=======================================================================
136
137 void GeomConvert_BSplineCurveToBezierCurve::Knots
138      (TColStd_Array1OfReal& TKnots) const
139 {
140  Standard_Integer ii, kk;
141   for (ii = 1, kk = TKnots.Lower();
142        ii <=myCurve->NbKnots(); ii++, kk++)
143     TKnots(kk) = myCurve->Knot(ii);
144 }
145
146 //=======================================================================
147 //function : NbArcs
148 //purpose  : 
149 //=======================================================================
150
151 Standard_Integer GeomConvert_BSplineCurveToBezierCurve::NbArcs() const 
152 {
153   return (myCurve->NbKnots()-1);
154 }