1 // Created on: 1995-09-08
2 // Created by: Laurent BOURESCHE
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16 
17 #include <BSplCLib.hxx>
18 #include <TColStd_Array1OfInteger.hxx>
19 #include <TColStd_Array1OfReal.hxx>
20 
21 #define No_Standard_RangeError
22 #define No_Standard_OutOfRange
23 
24 //=======================================================================
25 //struct : BSplCLib_BezierArrays
26 //purpose: Auxiliary structure providing standard definitions of bspline
27 //         knots for bezier (using stack allocation)
28 //=======================================================================
29 
30 class BSplCLib_BezierArrays
31 {
32  public:
BSplCLib_BezierArrays(Standard_Integer Degree)33   BSplCLib_BezierArrays (Standard_Integer Degree)
34   : knots (aKnots[0], 1, 2), mults (aMults[0], 1, 2)
35   {
36     aKnots[0] = 0.;
37     aKnots[1] = 1.;
38     aMults[0] = aMults[1] = Degree + 1;
39   }
40 
41  private:
42   Standard_Real aKnots[2];
43   Standard_Integer aMults[2];
44 
45  public:
46   TColStd_Array1OfReal    knots;
47   TColStd_Array1OfInteger mults;
48 };
49 
50 //=======================================================================
51 //function : IncreaseDegree
52 //purpose  :
53 //=======================================================================
54 
IncreaseDegree(const Standard_Integer NewDegree,const TColgp_Array1OfPnt & Poles,const TColStd_Array1OfReal * Weights,TColgp_Array1OfPnt & NewPoles,TColStd_Array1OfReal * NewWeights)55 void BSplCLib::IncreaseDegree(const Standard_Integer      NewDegree,
56 			      const TColgp_Array1OfPnt&   Poles,
57 			      const TColStd_Array1OfReal* Weights,
58 			      TColgp_Array1OfPnt&         NewPoles,
59 			      TColStd_Array1OfReal*       NewWeights)
60 {
61   Standard_Integer deg = Poles.Length() - 1;
62   BSplCLib_BezierArrays bzarr(deg);
63   BSplCLib::IncreaseDegree(deg, NewDegree, 0,
64 			   Poles, Weights, bzarr.knots, bzarr.mults,
65 			   NewPoles, NewWeights, bzarr.knots, bzarr.mults);
66 }
67 
68 //=======================================================================
69 //function : IncreaseDegree
70 //purpose  :
71 //=======================================================================
72 
IncreaseDegree(const Standard_Integer NewDegree,const TColgp_Array1OfPnt2d & Poles,const TColStd_Array1OfReal * Weights,TColgp_Array1OfPnt2d & NewPoles,TColStd_Array1OfReal * NewWeights)73 void BSplCLib::IncreaseDegree(const Standard_Integer      NewDegree,
74 			      const TColgp_Array1OfPnt2d& Poles,
75 			      const TColStd_Array1OfReal* Weights,
76 			      TColgp_Array1OfPnt2d&       NewPoles,
77 			      TColStd_Array1OfReal*       NewWeights)
78 {
79   Standard_Integer deg = Poles.Length() - 1;
80   BSplCLib_BezierArrays bzarr(deg);
81   BSplCLib::IncreaseDegree(deg, NewDegree, 0,
82 			   Poles, Weights, bzarr.knots, bzarr.mults,
83 			   NewPoles, NewWeights, bzarr.knots, bzarr.mults);
84 }
85 
86 //=======================================================================
87 //function : PolesCoefficients
88 //purpose  :
89 //=======================================================================
90 
PolesCoefficients(const TColgp_Array1OfPnt & Poles,const TColStd_Array1OfReal * Weights,TColgp_Array1OfPnt & CachePoles,TColStd_Array1OfReal * CacheWeights)91 void BSplCLib::PolesCoefficients(const TColgp_Array1OfPnt&   Poles,
92 				 const TColStd_Array1OfReal* Weights,
93 				 TColgp_Array1OfPnt&         CachePoles,
94 				 TColStd_Array1OfReal*       CacheWeights)
95 {
96   Standard_Integer deg  = Poles.Length() - 1;
97   TColStd_Array1OfReal bidflatknots (FlatBezierKnots(deg), 1, 2*(deg+1));
98   BSplCLib::BuildCache(0.,1.,0,deg,bidflatknots,
99 		       Poles, Weights, CachePoles,CacheWeights);
100 }
101 
102 //=======================================================================
103 //function : PolesCoefficients
104 //purpose  :
105 //=======================================================================
106 
PolesCoefficients(const TColgp_Array1OfPnt2d & Poles,const TColStd_Array1OfReal * Weights,TColgp_Array1OfPnt2d & CachePoles,TColStd_Array1OfReal * CacheWeights)107 void BSplCLib::PolesCoefficients(const TColgp_Array1OfPnt2d& Poles,
108 				 const TColStd_Array1OfReal* Weights,
109 				 TColgp_Array1OfPnt2d&       CachePoles,
110 				 TColStd_Array1OfReal*       CacheWeights)
111 {
112   Standard_Integer deg  = Poles.Length() - 1;
113   TColStd_Array1OfReal bidflatknots (FlatBezierKnots(deg), 1, 2*(deg+1));
114   BSplCLib::BuildCache(0.,1.,0,deg,bidflatknots,
115 		       Poles, Weights, CachePoles,CacheWeights);
116 }
117 
118 //=======================================================================
119 //function : D0
120 //purpose  :
121 //=======================================================================
122 
D0(const Standard_Real U,const TColgp_Array1OfPnt & Poles,const TColStd_Array1OfReal * Weights,gp_Pnt & P)123 void BSplCLib::D0(const Standard_Real         U,
124 		  const TColgp_Array1OfPnt&   Poles,
125 		  const TColStd_Array1OfReal* Weights,
126 		  gp_Pnt&                     P)
127 {
128   Standard_Integer deg = Poles.Length() - 1;
129   BSplCLib_BezierArrays bzarr(deg);
130   BSplCLib::D0(U, 1, deg, 0, Poles, Weights, bzarr.knots, &bzarr.mults, P);
131 }
132 
133 //=======================================================================
134 //function : D0
135 //purpose  :
136 //=======================================================================
137 
D0(const Standard_Real U,const TColgp_Array1OfPnt2d & Poles,const TColStd_Array1OfReal * Weights,gp_Pnt2d & P)138 void BSplCLib::D0(const Standard_Real         U,
139 		  const TColgp_Array1OfPnt2d& Poles,
140 		  const TColStd_Array1OfReal* Weights,
141 		  gp_Pnt2d&                   P)
142 {
143   Standard_Integer deg = Poles.Length() - 1;
144   BSplCLib_BezierArrays bzarr(deg);
145   BSplCLib::D0(U, 1, deg, 0, Poles, Weights, bzarr.knots, &bzarr.mults, P);
146 }
147 
148 //=======================================================================
149 //function : D1
150 //purpose  :
151 //=======================================================================
152 
D1(const Standard_Real U,const TColgp_Array1OfPnt & Poles,const TColStd_Array1OfReal * Weights,gp_Pnt & P,gp_Vec & V)153 void BSplCLib::D1(const Standard_Real         U,
154 		  const TColgp_Array1OfPnt&   Poles,
155 		  const TColStd_Array1OfReal* Weights,
156 		  gp_Pnt&                     P,
157 		  gp_Vec&                     V)
158 {
159   Standard_Integer deg = Poles.Length() - 1;
160   BSplCLib_BezierArrays bzarr(deg);
161   BSplCLib::D1(U, 1, deg, 0, Poles, Weights, bzarr.knots, &bzarr.mults, P, V);
162 }
163 
164 //=======================================================================
165 //function : D1
166 //purpose  :
167 //=======================================================================
168 
D1(const Standard_Real U,const TColgp_Array1OfPnt2d & Poles,const TColStd_Array1OfReal * Weights,gp_Pnt2d & P,gp_Vec2d & V)169 void BSplCLib::D1(const Standard_Real         U,
170 		  const TColgp_Array1OfPnt2d& Poles,
171 		  const TColStd_Array1OfReal* Weights,
172 		  gp_Pnt2d&                   P,
173 		  gp_Vec2d&                   V)
174 {
175   Standard_Integer deg = Poles.Length() - 1;
176   BSplCLib_BezierArrays bzarr(deg);
177   BSplCLib::D1(U, 1, deg, 0, Poles, Weights, bzarr.knots, &bzarr.mults, P, V);
178 }
179 
180 
181 //=======================================================================
182 //function : D2
183 //purpose  :
184 //=======================================================================
185 
D2(const Standard_Real U,const TColgp_Array1OfPnt & Poles,const TColStd_Array1OfReal * Weights,gp_Pnt & P,gp_Vec & V1,gp_Vec & V2)186 void BSplCLib::D2(const Standard_Real         U,
187 		  const TColgp_Array1OfPnt&   Poles,
188 		  const TColStd_Array1OfReal* Weights,
189 		  gp_Pnt&                     P,
190 		  gp_Vec&                     V1,
191 		  gp_Vec&                     V2)
192 {
193   Standard_Integer deg = Poles.Length() - 1;
194   BSplCLib_BezierArrays bzarr(deg);
195   BSplCLib::D2(U, 1, deg, 0, Poles, Weights, bzarr.knots, &bzarr.mults, P, V1, V2);
196 }
197 
198 //=======================================================================
199 //function : D2
200 //purpose  :
201 //=======================================================================
202 
D2(const Standard_Real U,const TColgp_Array1OfPnt2d & Poles,const TColStd_Array1OfReal * Weights,gp_Pnt2d & P,gp_Vec2d & V1,gp_Vec2d & V2)203 void BSplCLib::D2(const Standard_Real         U,
204 		  const TColgp_Array1OfPnt2d& Poles,
205 		  const TColStd_Array1OfReal* Weights,
206 		  gp_Pnt2d&                   P,
207 		  gp_Vec2d&                   V1,
208 		  gp_Vec2d&                   V2)
209 {
210   Standard_Integer deg = Poles.Length() - 1;
211   BSplCLib_BezierArrays bzarr(deg);
212   BSplCLib::D2(U, 1, deg, 0, Poles, Weights, bzarr.knots, &bzarr.mults, P, V1, V2);
213 }
214 
215 
216 //=======================================================================
217 //function : D3
218 //purpose  :
219 //=======================================================================
220 
D3(const Standard_Real U,const TColgp_Array1OfPnt & Poles,const TColStd_Array1OfReal * Weights,gp_Pnt & P,gp_Vec & V1,gp_Vec & V2,gp_Vec & V3)221 void BSplCLib::D3(const Standard_Real         U,
222 		  const TColgp_Array1OfPnt&   Poles,
223 		  const TColStd_Array1OfReal* Weights,
224 		  gp_Pnt&                     P,
225 		  gp_Vec&                     V1,
226 		  gp_Vec&                     V2,
227 		  gp_Vec&                     V3)
228 {
229   Standard_Integer deg = Poles.Length() - 1;
230   BSplCLib_BezierArrays bzarr(deg);
231   BSplCLib::D3(U, 1, deg, 0, Poles, Weights, bzarr.knots, &bzarr.mults,
232 	       P, V1, V2, V3);
233 }
234 
235 //=======================================================================
236 //function : D3
237 //purpose  :
238 //=======================================================================
239 
D3(const Standard_Real U,const TColgp_Array1OfPnt2d & Poles,const TColStd_Array1OfReal * Weights,gp_Pnt2d & P,gp_Vec2d & V1,gp_Vec2d & V2,gp_Vec2d & V3)240 void BSplCLib::D3(const Standard_Real         U,
241 		  const TColgp_Array1OfPnt2d& Poles,
242 		  const TColStd_Array1OfReal* Weights,
243 		  gp_Pnt2d&                   P,
244 		  gp_Vec2d&                   V1,
245 		  gp_Vec2d&                   V2,
246 		  gp_Vec2d&                   V3)
247 {
248   Standard_Integer deg = Poles.Length() - 1;
249   BSplCLib_BezierArrays bzarr(deg);
250   BSplCLib::D3(U, 1, deg, 0, Poles, Weights, bzarr.knots, &bzarr.mults,
251 	       P, V1, V2, V3);
252 }
253 
254