1 // Created on: 1993-10-06
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <GeomFill_BezierCurves.ixx>
19 #include <GeomFill_Filling.hxx>
20 #include <GeomFill_Stretch.hxx>
21 #include <GeomFill_Coons.hxx>
22 #include <GeomFill_Curved.hxx>
24 #include <Precision.hxx>
25 #include <Geom_BezierCurve.hxx>
26 #include <Geom_BezierSurface.hxx>
27 #include <Standard_ConstructionError.hxx>
28 #include <Standard_NotImplemented.hxx>
29 #include <TColgp_Array1OfPnt.hxx>
30 #include <TColgp_Array2OfPnt.hxx>
31 #include <TColStd_Array2OfReal.hxx>
32 #include <TColStd_Array1OfReal.hxx>
35 //=======================================================================
36 //function : SetSameWeights
37 //purpose : Internal Use Only
38 // This function uses the following property of Rational
40 // if Wi = Weight(i); Pi = Pole(i); n = NbPoles
41 // with any a,b,c != 0,
43 // The transformation : Wi = a * b * c doesn't modify
44 // the geometry of the curve.
45 // Only the length of the derivatives are changed.
46 //=======================================================================
48 void SetSameWeights(TColStd_Array1OfReal& W1,
49 TColStd_Array1OfReal& W2,
50 TColStd_Array1OfReal& W3,
51 TColStd_Array1OfReal& W4 )
53 Standard_Real Eps = Precision::Confusion();
55 Standard_Integer NU = W1.Length();
56 Standard_Integer NV = W2.Length();
58 Standard_Real A = ( W1( 1) * W2( 1)) / ( W1( NU) * W2( NV));
59 Standard_Real B = ( W3( 1) * W4( 1)) / ( W3( NU) * W4( NV));
62 Standard_Real Alfa = W1( NU) / W2( 1);
63 for ( i=1; i<=NV; i++) {
66 Standard_Real Beta = W2( NV) / W3( NU);
67 for ( i=1; i<=NU; i++) {
70 Standard_Real Gamma = W3( 1) / W4( NV);
71 for ( i=1; i<=NV; i++) {
75 if ( Abs(A-B) > Eps) {
76 Standard_Real w = Pow( W1(1)/W4(1), 1./(Standard_Real)(NV-1));
78 for ( i=NV-1; i>=1; i--) {
86 //=======================================================================
88 //purpose : Internal Use Only
89 // This function is used to prepare the Filling: The Curves
90 // are arranged in this way:
102 //=======================================================================
104 Standard_Boolean Arrange(const Handle(Geom_BezierCurve)& C1,
105 const Handle(Geom_BezierCurve)& C2,
106 const Handle(Geom_BezierCurve)& C3,
107 const Handle(Geom_BezierCurve)& C4,
108 Handle(Geom_BezierCurve)& CC1,
109 Handle(Geom_BezierCurve)& CC2,
110 Handle(Geom_BezierCurve)& CC3,
111 Handle(Geom_BezierCurve)& CC4,
112 const Standard_Real Tol )
114 Handle(Geom_BezierCurve) GC[4];
115 Handle(Geom_BezierCurve) Dummy;
116 GC[0] = Handle(Geom_BezierCurve)::DownCast(C1->Copy());
117 GC[1] = Handle(Geom_BezierCurve)::DownCast(C2->Copy());
118 GC[2] = Handle(Geom_BezierCurve)::DownCast(C3->Copy());
119 GC[3] = Handle(Geom_BezierCurve)::DownCast(C4->Copy());
121 Standard_Integer i,j;
122 Standard_Boolean Trouve;
124 for (i=1; i<=3; i++) {
125 Trouve = Standard_False;
126 for ( j=i; j<=3 && !Trouve; j++) {
127 if (GC[j]->StartPoint().Distance( GC[i-1]->EndPoint()) < Tol) {
131 Trouve = Standard_True;
133 else if (GC[j]->EndPoint().Distance( GC[i-1]->EndPoint()) < Tol) {
134 GC[j] = Handle(Geom_BezierCurve)::DownCast(GC[j]->Reversed());
138 Trouve = Standard_True;
141 if (!Trouve) return Standard_False;
146 CC3 = Handle(Geom_BezierCurve)::DownCast( GC[2]->Reversed());
147 CC4 = Handle(Geom_BezierCurve)::DownCast( GC[3]->Reversed());
149 return Standard_True;
153 //=======================================================================
154 //function : GeomFill_BezierCurves
156 //=======================================================================
158 GeomFill_BezierCurves::GeomFill_BezierCurves()
163 //=======================================================================
164 //function : GeomFill_BezierCurves
166 //=======================================================================
168 GeomFill_BezierCurves::GeomFill_BezierCurves(const Handle(Geom_BezierCurve)& C1,
169 const Handle(Geom_BezierCurve)& C2,
170 const Handle(Geom_BezierCurve)& C3,
171 const Handle(Geom_BezierCurve)& C4,
172 const GeomFill_FillingStyle Type )
174 Init( C1, C2, C3, C4, Type);
178 //=======================================================================
179 //function : GeomFill_BezierCurves
181 //=======================================================================
183 GeomFill_BezierCurves::GeomFill_BezierCurves(const Handle(Geom_BezierCurve)& C1,
184 const Handle(Geom_BezierCurve)& C2,
185 const Handle(Geom_BezierCurve)& C3,
186 const GeomFill_FillingStyle Type )
188 Init( C1, C2, C3, Type);
192 //=======================================================================
193 //function : GeomFill_BezierCurves
195 //=======================================================================
197 GeomFill_BezierCurves::GeomFill_BezierCurves(const Handle(Geom_BezierCurve)& C1,
198 const Handle(Geom_BezierCurve)& C2,
199 const GeomFill_FillingStyle Type )
205 //=======================================================================
208 //=======================================================================
210 void GeomFill_BezierCurves::Init(const Handle(Geom_BezierCurve)& C1,
211 const Handle(Geom_BezierCurve)& C2,
212 const Handle(Geom_BezierCurve)& C3,
213 const Handle(Geom_BezierCurve)& C4,
214 const GeomFill_FillingStyle Type )
216 // On ordonne les courbes
217 Handle(Geom_BezierCurve) CC1, CC2, CC3, CC4;
219 Standard_Real Tol = Precision::Confusion();
221 Standard_Boolean IsOK =
223 Arrange( C1, C2, C3, C4, CC1, CC2, CC3, CC4, Tol);
225 Standard_ConstructionError_Raise_if
226 (!IsOK, " GeomFill_BezierCurves: Courbes non jointives");
228 // Mise en conformite des degres
229 Standard_Integer DegU = Max( CC1->Degree(), CC3->Degree());
230 Standard_Integer DegV = Max( CC2->Degree(), CC4->Degree());
232 if (Type == GeomFill_CoonsStyle) {
233 DegU = Max( DegU, 3);
234 DegV = Max( DegV, 3);
237 if ( CC1->Degree() < DegU ) CC1->Increase(DegU);
238 if ( CC2->Degree() < DegV ) CC2->Increase(DegV);
239 if ( CC3->Degree() < DegU ) CC3->Increase(DegU);
240 if ( CC4->Degree() < DegV ) CC4->Increase(DegV);
242 TColgp_Array1OfPnt P1(1,DegU+1);
243 TColgp_Array1OfPnt P3(1,DegU+1);
244 TColgp_Array1OfPnt P2(1,DegV+1);
245 TColgp_Array1OfPnt P4(1,DegV+1);
251 // Traitement des courbes rationelles
252 Standard_Boolean isRat = ( CC1->IsRational() || CC2->IsRational() ||
253 CC3->IsRational() || CC4->IsRational() );
255 TColStd_Array1OfReal W1(1,DegU+1);
256 TColStd_Array1OfReal W3(1,DegU+1);
257 TColStd_Array1OfReal W2(1,DegV+1);
258 TColStd_Array1OfReal W4(1,DegV+1);
265 if (CC1->IsRational()) {
268 if (CC2->IsRational()) {
271 if (CC3->IsRational()) {
274 if (CC4->IsRational()) {
279 GeomFill_Filling Caro;
281 // Mise en conformite des poids aux coins.
282 SetSameWeights( W1, W2, W3, W4);
285 case GeomFill_StretchStyle :
286 Caro = GeomFill_Stretch( P1, P2, P3, P4, W1, W2, W3, W4);
288 case GeomFill_CoonsStyle :
289 Caro = GeomFill_Coons ( P1, P4, P3, P2, W1, W4, W3, W2);
291 case GeomFill_CurvedStyle :
292 Caro = GeomFill_Curved ( P1, P2, P3, P4, W1, W2, W3, W4);
299 case GeomFill_StretchStyle :
300 Caro = GeomFill_Stretch( P1, P2, P3, P4);
302 case GeomFill_CoonsStyle :
303 Caro = GeomFill_Coons ( P1, P4, P3, P2);
305 case GeomFill_CurvedStyle :
306 Caro = GeomFill_Curved ( P1, P2, P3, P4);
311 Standard_Integer NbUPoles = Caro.NbUPoles();
312 Standard_Integer NbVPoles = Caro.NbVPoles();
313 TColgp_Array2OfPnt Poles(1,NbUPoles,1,NbVPoles);
317 if (Caro.isRational()) {
318 TColStd_Array2OfReal Weights(1,NbUPoles, 1,NbVPoles);
319 Caro.Weights(Weights);
320 mySurface = new Geom_BezierSurface(Poles,Weights);
323 mySurface = new Geom_BezierSurface(Poles);
328 //=======================================================================
331 //=======================================================================
333 void GeomFill_BezierCurves::Init(const Handle(Geom_BezierCurve)& C1,
334 const Handle(Geom_BezierCurve)& C2,
335 const Handle(Geom_BezierCurve)& C3,
336 const GeomFill_FillingStyle Type )
338 Handle(Geom_BezierCurve) C4;
339 TColgp_Array1OfPnt Poles(1,2);
340 Standard_Real Tol = Precision::Confusion();
342 if(C1->StartPoint().SquareDistance(C2->StartPoint()) > Tol &&
343 C1->StartPoint().SquareDistance(C2->EndPoint()) > Tol )
344 Poles( 1) = C1->StartPoint();
346 Poles( 1) = C1->EndPoint();
348 if(C3->StartPoint().SquareDistance(C2->StartPoint()) > Tol &&
349 C3->StartPoint().SquareDistance(C2->EndPoint()) > Tol )
350 Poles( 2) = C3->StartPoint();
352 Poles( 2) = C3->EndPoint();
353 // Poles(1) = C1->StartPoint();
354 // Poles(2) = C1->StartPoint();
355 C4 = new Geom_BezierCurve(Poles);
356 Init( C1, C2, C3, C4, Type);
360 //=======================================================================
363 //=======================================================================
365 void GeomFill_BezierCurves::Init(const Handle(Geom_BezierCurve)& C1,
366 const Handle(Geom_BezierCurve)& C2,
367 const GeomFill_FillingStyle Type )
369 Handle(Geom_BezierCurve)
370 CC1 = Handle(Geom_BezierCurve)::DownCast(C1->Copy());
371 Handle(Geom_BezierCurve)
372 CC2 = Handle(Geom_BezierCurve)::DownCast(C2->Copy());
374 Standard_Integer Deg1 = CC1->Degree();
375 Standard_Integer Deg2 = CC2->Degree();
377 Standard_Boolean isRat = ( CC1->IsRational() || CC2->IsRational());
379 if ( Type != GeomFill_CurvedStyle) {
380 Standard_Integer DegU = Max( Deg1, Deg2);
382 if ( CC1->Degree() < DegU ) CC1->Increase(DegU);
383 if ( CC2->Degree() < DegU ) CC2->Increase(DegU);
385 TColgp_Array2OfPnt Poles( 1, DegU+1, 1, 2);
386 TColgp_Array1OfPnt P1(1,DegU+1);
387 TColgp_Array1OfPnt P2(1,DegU+1);
392 for (i=1; i<=DegU+1; i++) {
397 TColStd_Array1OfReal W1(1,DegU+1);
398 TColStd_Array1OfReal W2(1,DegU+1);
402 if (CC1->IsRational()) {
405 if (CC2->IsRational()) {
408 TColStd_Array2OfReal Weights(1,DegU+1, 1,2);
409 for ( i=1; i<=DegU+1; i++) {
410 Weights(i, 1) = W1(i);
411 Weights(i, 2) = W2(i);
413 mySurface = new Geom_BezierSurface(Poles,Weights);
416 mySurface = new Geom_BezierSurface(Poles);
420 TColgp_Array1OfPnt P1(1,Deg1+1);
421 TColgp_Array1OfPnt P2(1,Deg2+1);
423 Standard_Real Eps = Precision::Confusion();
424 Standard_Boolean IsOK = Standard_False;
425 if ( CC1->StartPoint().IsEqual(CC2->StartPoint(),Eps)) {
426 IsOK = Standard_True;
428 else if ( CC1->StartPoint().IsEqual(CC2->EndPoint(),Eps)) {
430 IsOK = Standard_True;
432 else if ( CC1->EndPoint().IsEqual(CC2->StartPoint(),Eps)) {
434 IsOK = Standard_True;
436 else if ( CC1->EndPoint().IsEqual(CC2->EndPoint(),Eps)) {
439 IsOK = Standard_True;
442 Standard_ConstructionError_Raise_if
443 (!IsOK, " GeomFill_BezierCurves: Courbes non jointives");
448 TColStd_Array1OfReal W1(1,Deg1+1);
449 TColStd_Array1OfReal W2(1,Deg2+1);
453 GeomFill_Filling Caro;
455 if (CC1->IsRational()) {
458 if (CC2->IsRational()) {
461 Caro = GeomFill_Curved( P1, P2, W1, W2);
464 Caro = GeomFill_Curved( P1, P2);
467 Standard_Integer NbUPoles = Caro.NbUPoles();
468 Standard_Integer NbVPoles = Caro.NbVPoles();
469 TColgp_Array2OfPnt Poles(1,NbUPoles,1,NbVPoles);
473 if (Caro.isRational()) {
474 TColStd_Array2OfReal Weights(1,NbUPoles, 1,NbVPoles);
475 Caro.Weights(Weights);
476 mySurface = new Geom_BezierSurface(Poles,Weights);
479 mySurface = new Geom_BezierSurface(Poles);