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.
18 #include <Geom_BezierCurve.hxx>
19 #include <Geom_BezierSurface.hxx>
20 #include <GeomFill_BezierCurves.hxx>
21 #include <GeomFill_Coons.hxx>
22 #include <GeomFill_Curved.hxx>
23 #include <GeomFill_Filling.hxx>
24 #include <GeomFill_Stretch.hxx>
25 #include <Precision.hxx>
26 #include <Standard_ConstructionError.hxx>
27 #include <Standard_NotImplemented.hxx>
28 #include <TColgp_Array1OfPnt.hxx>
29 #include <TColgp_Array2OfPnt.hxx>
30 #include <TColStd_Array1OfReal.hxx>
31 #include <TColStd_Array2OfReal.hxx>
33 //=======================================================================
34 //function : SetSameWeights
35 //purpose : Internal Use Only
36 // This function uses the following property of Rational
38 // if Wi = Weight(i); Pi = Pole(i); n = NbPoles
39 // with any a,b,c != 0,
41 // The transformation : Wi = a * b * c doesn't modify
42 // the geometry of the curve.
43 // Only the length of the derivatives are changed.
44 //=======================================================================
45 void SetSameWeights(TColStd_Array1OfReal& W1,
46 TColStd_Array1OfReal& W2,
47 TColStd_Array1OfReal& W3,
48 TColStd_Array1OfReal& W4 )
50 Standard_Real Eps = Precision::Confusion();
52 Standard_Integer NU = W1.Length();
53 Standard_Integer NV = W2.Length();
55 Standard_Real A = ( W1( 1) * W2( 1)) / ( W1( NU) * W2( NV));
56 Standard_Real B = ( W3( 1) * W4( 1)) / ( W3( NU) * W4( NV));
59 Standard_Real Alfa = W1( NU) / W2( 1);
60 for ( i=1; i<=NV; i++) {
63 Standard_Real Beta = W2( NV) / W3( NU);
64 for ( i=1; i<=NU; i++) {
67 Standard_Real Gamma = W3( 1) / W4( NV);
68 for ( i=1; i<=NV; i++) {
72 if ( Abs(A-B) > Eps) {
73 Standard_Real w = Pow( W1(1)/W4(1), 1./(Standard_Real)(NV-1));
75 for ( i=NV-1; i>=1; i--) {
83 //=======================================================================
85 //purpose : Internal Use Only
86 // This function is used to prepare the Filling: The Curves
87 // are arranged in this way:
99 //=======================================================================
101 Standard_Boolean Arrange(const Handle(Geom_BezierCurve)& C1,
102 const Handle(Geom_BezierCurve)& C2,
103 const Handle(Geom_BezierCurve)& C3,
104 const Handle(Geom_BezierCurve)& C4,
105 Handle(Geom_BezierCurve)& CC1,
106 Handle(Geom_BezierCurve)& CC2,
107 Handle(Geom_BezierCurve)& CC3,
108 Handle(Geom_BezierCurve)& CC4,
109 const Standard_Real Tol )
111 Handle(Geom_BezierCurve) GC[4];
112 Handle(Geom_BezierCurve) Dummy;
113 GC[0] = Handle(Geom_BezierCurve)::DownCast(C1->Copy());
114 GC[1] = Handle(Geom_BezierCurve)::DownCast(C2->Copy());
115 GC[2] = Handle(Geom_BezierCurve)::DownCast(C3->Copy());
116 GC[3] = Handle(Geom_BezierCurve)::DownCast(C4->Copy());
118 Standard_Integer i,j;
119 Standard_Boolean Trouve;
121 for (i=1; i<=3; i++) {
122 Trouve = Standard_False;
123 for ( j=i; j<=3 && !Trouve; j++) {
124 if (GC[j]->StartPoint().Distance( GC[i-1]->EndPoint()) < Tol) {
128 Trouve = Standard_True;
130 else if (GC[j]->EndPoint().Distance( GC[i-1]->EndPoint()) < Tol) {
131 GC[j] = Handle(Geom_BezierCurve)::DownCast(GC[j]->Reversed());
135 Trouve = Standard_True;
138 if (!Trouve) return Standard_False;
143 CC3 = Handle(Geom_BezierCurve)::DownCast( GC[2]->Reversed());
144 CC4 = Handle(Geom_BezierCurve)::DownCast( GC[3]->Reversed());
146 return Standard_True;
150 //=======================================================================
151 //function : GeomFill_BezierCurves
153 //=======================================================================
155 GeomFill_BezierCurves::GeomFill_BezierCurves()
160 //=======================================================================
161 //function : GeomFill_BezierCurves
163 //=======================================================================
165 GeomFill_BezierCurves::GeomFill_BezierCurves(const Handle(Geom_BezierCurve)& C1,
166 const Handle(Geom_BezierCurve)& C2,
167 const Handle(Geom_BezierCurve)& C3,
168 const Handle(Geom_BezierCurve)& C4,
169 const GeomFill_FillingStyle Type )
171 Init( C1, C2, C3, C4, Type);
175 //=======================================================================
176 //function : GeomFill_BezierCurves
178 //=======================================================================
180 GeomFill_BezierCurves::GeomFill_BezierCurves(const Handle(Geom_BezierCurve)& C1,
181 const Handle(Geom_BezierCurve)& C2,
182 const Handle(Geom_BezierCurve)& C3,
183 const GeomFill_FillingStyle Type )
185 Init( C1, C2, C3, Type);
189 //=======================================================================
190 //function : GeomFill_BezierCurves
192 //=======================================================================
194 GeomFill_BezierCurves::GeomFill_BezierCurves(const Handle(Geom_BezierCurve)& C1,
195 const Handle(Geom_BezierCurve)& C2,
196 const GeomFill_FillingStyle Type )
202 //=======================================================================
205 //=======================================================================
207 void GeomFill_BezierCurves::Init(const Handle(Geom_BezierCurve)& C1,
208 const Handle(Geom_BezierCurve)& C2,
209 const Handle(Geom_BezierCurve)& C3,
210 const Handle(Geom_BezierCurve)& C4,
211 const GeomFill_FillingStyle Type )
213 // On ordonne les courbes
214 Handle(Geom_BezierCurve) CC1, CC2, CC3, CC4;
216 Standard_Real Tol = Precision::Confusion();
218 Standard_Boolean IsOK =
220 Arrange( C1, C2, C3, C4, CC1, CC2, CC3, CC4, Tol);
222 Standard_ConstructionError_Raise_if
223 (!IsOK, " GeomFill_BezierCurves: Courbes non jointives");
225 // Mise en conformite des degres
226 Standard_Integer DegU = Max( CC1->Degree(), CC3->Degree());
227 Standard_Integer DegV = Max( CC2->Degree(), CC4->Degree());
229 if (Type == GeomFill_CoonsStyle) {
230 DegU = Max( DegU, 3);
231 DegV = Max( DegV, 3);
234 if ( CC1->Degree() < DegU ) CC1->Increase(DegU);
235 if ( CC2->Degree() < DegV ) CC2->Increase(DegV);
236 if ( CC3->Degree() < DegU ) CC3->Increase(DegU);
237 if ( CC4->Degree() < DegV ) CC4->Increase(DegV);
239 TColgp_Array1OfPnt P1(1,DegU+1);
240 TColgp_Array1OfPnt P3(1,DegU+1);
241 TColgp_Array1OfPnt P2(1,DegV+1);
242 TColgp_Array1OfPnt P4(1,DegV+1);
248 // Traitement des courbes rationelles
249 Standard_Boolean isRat = ( CC1->IsRational() || CC2->IsRational() ||
250 CC3->IsRational() || CC4->IsRational() );
252 TColStd_Array1OfReal W1(1,DegU+1);
253 TColStd_Array1OfReal W3(1,DegU+1);
254 TColStd_Array1OfReal W2(1,DegV+1);
255 TColStd_Array1OfReal W4(1,DegV+1);
262 if (CC1->IsRational()) {
265 if (CC2->IsRational()) {
268 if (CC3->IsRational()) {
271 if (CC4->IsRational()) {
276 GeomFill_Filling Caro;
278 // Mise en conformite des poids aux coins.
279 SetSameWeights( W1, W2, W3, W4);
282 case GeomFill_StretchStyle :
283 Caro = GeomFill_Stretch( P1, P2, P3, P4, W1, W2, W3, W4);
285 case GeomFill_CoonsStyle :
286 Caro = GeomFill_Coons ( P1, P4, P3, P2, W1, W4, W3, W2);
288 case GeomFill_CurvedStyle :
289 Caro = GeomFill_Curved ( P1, P2, P3, P4, W1, W2, W3, W4);
296 case GeomFill_StretchStyle :
297 Caro = GeomFill_Stretch( P1, P2, P3, P4);
299 case GeomFill_CoonsStyle :
300 Caro = GeomFill_Coons ( P1, P4, P3, P2);
302 case GeomFill_CurvedStyle :
303 Caro = GeomFill_Curved ( P1, P2, P3, P4);
308 Standard_Integer NbUPoles = Caro.NbUPoles();
309 Standard_Integer NbVPoles = Caro.NbVPoles();
310 TColgp_Array2OfPnt Poles(1,NbUPoles,1,NbVPoles);
314 if (Caro.isRational()) {
315 TColStd_Array2OfReal Weights(1,NbUPoles, 1,NbVPoles);
316 Caro.Weights(Weights);
317 mySurface = new Geom_BezierSurface(Poles,Weights);
320 mySurface = new Geom_BezierSurface(Poles);
325 //=======================================================================
328 //=======================================================================
330 void GeomFill_BezierCurves::Init(const Handle(Geom_BezierCurve)& C1,
331 const Handle(Geom_BezierCurve)& C2,
332 const Handle(Geom_BezierCurve)& C3,
333 const GeomFill_FillingStyle Type )
335 Handle(Geom_BezierCurve) C4;
336 TColgp_Array1OfPnt Poles(1,2);
337 Standard_Real Tol = Precision::Confusion();
339 if(C1->StartPoint().SquareDistance(C2->StartPoint()) > Tol &&
340 C1->StartPoint().SquareDistance(C2->EndPoint()) > Tol )
341 Poles( 1) = C1->StartPoint();
343 Poles( 1) = C1->EndPoint();
345 if(C3->StartPoint().SquareDistance(C2->StartPoint()) > Tol &&
346 C3->StartPoint().SquareDistance(C2->EndPoint()) > Tol )
347 Poles( 2) = C3->StartPoint();
349 Poles( 2) = C3->EndPoint();
350 // Poles(1) = C1->StartPoint();
351 // Poles(2) = C1->StartPoint();
352 C4 = new Geom_BezierCurve(Poles);
353 Init( C1, C2, C3, C4, Type);
357 //=======================================================================
360 //=======================================================================
362 void GeomFill_BezierCurves::Init(const Handle(Geom_BezierCurve)& C1,
363 const Handle(Geom_BezierCurve)& C2,
364 const GeomFill_FillingStyle Type )
366 Handle(Geom_BezierCurve)
367 CC1 = Handle(Geom_BezierCurve)::DownCast(C1->Copy());
368 Handle(Geom_BezierCurve)
369 CC2 = Handle(Geom_BezierCurve)::DownCast(C2->Copy());
371 Standard_Integer Deg1 = CC1->Degree();
372 Standard_Integer Deg2 = CC2->Degree();
374 Standard_Boolean isRat = ( CC1->IsRational() || CC2->IsRational());
376 if ( Type != GeomFill_CurvedStyle) {
377 Standard_Integer DegU = Max( Deg1, Deg2);
379 if ( CC1->Degree() < DegU ) CC1->Increase(DegU);
380 if ( CC2->Degree() < DegU ) CC2->Increase(DegU);
382 TColgp_Array2OfPnt Poles( 1, DegU+1, 1, 2);
383 TColgp_Array1OfPnt P1(1,DegU+1);
384 TColgp_Array1OfPnt P2(1,DegU+1);
389 for (i=1; i<=DegU+1; i++) {
394 TColStd_Array1OfReal W1(1,DegU+1);
395 TColStd_Array1OfReal W2(1,DegU+1);
399 if (CC1->IsRational()) {
402 if (CC2->IsRational()) {
405 TColStd_Array2OfReal Weights(1,DegU+1, 1,2);
406 for ( i=1; i<=DegU+1; i++) {
407 Weights(i, 1) = W1(i);
408 Weights(i, 2) = W2(i);
410 mySurface = new Geom_BezierSurface(Poles,Weights);
413 mySurface = new Geom_BezierSurface(Poles);
417 TColgp_Array1OfPnt P1(1,Deg1+1);
418 TColgp_Array1OfPnt P2(1,Deg2+1);
420 Standard_Real Eps = Precision::Confusion();
421 Standard_Boolean IsOK = Standard_False;
422 if ( CC1->StartPoint().IsEqual(CC2->StartPoint(),Eps)) {
423 IsOK = Standard_True;
425 else if ( CC1->StartPoint().IsEqual(CC2->EndPoint(),Eps)) {
427 IsOK = Standard_True;
429 else if ( CC1->EndPoint().IsEqual(CC2->StartPoint(),Eps)) {
431 IsOK = Standard_True;
433 else if ( CC1->EndPoint().IsEqual(CC2->EndPoint(),Eps)) {
436 IsOK = Standard_True;
440 throw Standard_OutOfRange("GeomFill_BezierCurves: Courbes non jointives");
445 TColStd_Array1OfReal W1(1,Deg1+1);
446 TColStd_Array1OfReal W2(1,Deg2+1);
450 GeomFill_Filling Caro;
452 if (CC1->IsRational()) {
455 if (CC2->IsRational()) {
458 Caro = GeomFill_Curved( P1, P2, W1, W2);
461 Caro = GeomFill_Curved( P1, P2);
464 Standard_Integer NbUPoles = Caro.NbUPoles();
465 Standard_Integer NbVPoles = Caro.NbVPoles();
466 TColgp_Array2OfPnt Poles(1,NbUPoles,1,NbVPoles);
470 if (Caro.isRational()) {
471 TColStd_Array2OfReal Weights(1,NbUPoles, 1,NbVPoles);
472 Caro.Weights(Weights);
473 mySurface = new Geom_BezierSurface(Poles,Weights);
476 mySurface = new Geom_BezierSurface(Poles);