1 // Created on: 1993-09-28
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1993-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
18 #include <GeomFill_Stretch.hxx>
19 #include <gp_Pnt.hxx>
20 #include <TColgp_HArray2OfPnt.hxx>
21 #include <TColStd_Array1OfReal.hxx>
22 #include <TColStd_HArray2OfReal.hxx>
23
24 //=======================================================================
25 //function : GeomFill_Stretch
26 //purpose :
27 //=======================================================================
GeomFill_Stretch()28 GeomFill_Stretch::GeomFill_Stretch()
29 {
30 }
31
32
33 //=======================================================================
34 //function : GeomFill_Stretch
35 //purpose :
36 //=======================================================================
37
GeomFill_Stretch(const TColgp_Array1OfPnt & P1,const TColgp_Array1OfPnt & P2,const TColgp_Array1OfPnt & P3,const TColgp_Array1OfPnt & P4)38 GeomFill_Stretch::GeomFill_Stretch(const TColgp_Array1OfPnt& P1,
39 const TColgp_Array1OfPnt& P2,
40 const TColgp_Array1OfPnt& P3,
41 const TColgp_Array1OfPnt& P4)
42 {
43 Init(P1, P2, P3, P4);
44 }
45
46
47 //=======================================================================
48 //function : GeomFill_Stretch
49 //purpose :
50 //=======================================================================
51
GeomFill_Stretch(const TColgp_Array1OfPnt & P1,const TColgp_Array1OfPnt & P2,const TColgp_Array1OfPnt & P3,const TColgp_Array1OfPnt & P4,const TColStd_Array1OfReal & W1,const TColStd_Array1OfReal & W2,const TColStd_Array1OfReal & W3,const TColStd_Array1OfReal & W4)52 GeomFill_Stretch::GeomFill_Stretch(const TColgp_Array1OfPnt& P1,
53 const TColgp_Array1OfPnt& P2,
54 const TColgp_Array1OfPnt& P3,
55 const TColgp_Array1OfPnt& P4,
56 const TColStd_Array1OfReal& W1,
57 const TColStd_Array1OfReal& W2,
58 const TColStd_Array1OfReal& W3,
59 const TColStd_Array1OfReal& W4)
60 {
61 Init(P1, P2, P3, P4, W1, W2, W3, W4);
62 }
63
64
65 //=======================================================================
66 //function : Init
67 //purpose :
68 //=======================================================================
69
Init(const TColgp_Array1OfPnt & P1,const TColgp_Array1OfPnt & P2,const TColgp_Array1OfPnt & P3,const TColgp_Array1OfPnt & P4)70 void GeomFill_Stretch::Init(const TColgp_Array1OfPnt& P1,
71 const TColgp_Array1OfPnt& P2,
72 const TColgp_Array1OfPnt& P3,
73 const TColgp_Array1OfPnt& P4)
74 {
75 Standard_DomainError_Raise_if
76 ( P1.Length() != P3.Length() || P2.Length() != P4.Length()," ");
77
78 Standard_Integer NPolU = P1.Length();
79 Standard_Integer NPolV = P2.Length();
80
81 IsRational = Standard_False;
82
83 Standard_Real NU = NPolU - 1;
84 Standard_Real NV = NPolV - 1;
85 myPoles = new TColgp_HArray2OfPnt( 1, NPolU, 1, NPolV);
86
87 // The boundaries are not modified
88 Standard_Integer i,j,k;
89 for ( i=1; i<=NPolU; i++) {
90 myPoles->SetValue( i, 1 , P1(i));
91 myPoles->SetValue( i, NPolV, P3(i));
92 }
93 Standard_Real PU,PU1,PV,PV1;
94
95 for ( j=2; j<=NPolV-1; j++) {
96 PV = (j-1)/NV;
97 PV1 = 1 - PV;
98 myPoles->SetValue( 1 , j, P4(j));
99 myPoles->SetValue( NPolU, j, P2(j));
100
101 for ( i=2; i<=NPolU-1; i++) {
102 PU = (i-1)/NU;
103 PU1 = 1 - PU;
104
105 gp_Pnt P;
106 for (k=1; k<=3; k++) {
107 P.SetCoord(k,
108 PV1 * P1(i).Coord(k) + PV * P3(i).Coord(k) +
109 PU * P2(j).Coord(k) + PU1 * P4(j).Coord(k) -
110 ( PU1 * PV1 * P1(1).Coord(k) +
111 PU * PV1 * P2(1).Coord(k) +
112 PU * PV * P3(NPolU).Coord(k) +
113 PU1 * PV * P4(NPolV).Coord(k) ) );
114 }
115 myPoles->SetValue(i,j,P);
116 }
117 }
118 }
119
120
121 //=======================================================================
122 //function : Init
123 //purpose :
124 //=======================================================================
125
Init(const TColgp_Array1OfPnt & P1,const TColgp_Array1OfPnt & P2,const TColgp_Array1OfPnt & P3,const TColgp_Array1OfPnt & P4,const TColStd_Array1OfReal & W1,const TColStd_Array1OfReal & W2,const TColStd_Array1OfReal & W3,const TColStd_Array1OfReal & W4)126 void GeomFill_Stretch::Init(const TColgp_Array1OfPnt& P1,
127 const TColgp_Array1OfPnt& P2,
128 const TColgp_Array1OfPnt& P3,
129 const TColgp_Array1OfPnt& P4,
130 const TColStd_Array1OfReal& W1,
131 const TColStd_Array1OfReal& W2,
132 const TColStd_Array1OfReal& W3,
133 const TColStd_Array1OfReal& W4)
134 {
135 Standard_DomainError_Raise_if
136 ( W1.Length() != W3.Length() || W2.Length() != W4.Length()," ");
137 Standard_DomainError_Raise_if
138 ( W1.Length() != P1.Length() ||
139 W2.Length() != P2.Length() ||
140 W3.Length() != P3.Length() ||
141 W4.Length() != P4.Length() , " ");
142
143 Init(P1,P2,P3,P4);
144 IsRational = Standard_True;
145
146 Standard_Integer NPolU = W1.Length();
147 Standard_Integer NPolV = W2.Length();
148
149 Standard_Real NU = NPolU - 1;
150 Standard_Real NV = NPolV - 1;
151 myWeights = new TColStd_HArray2OfReal( 1, NPolU, 1, NPolV);
152
153 // The boundaries are not modified
154 Standard_Integer i,j;
155 for ( i=1; i<=NPolU; i++) {
156 myWeights->SetValue( i, 1 , W1(i));
157 myWeights->SetValue( i, NPolV, W3(i));
158 }
159 Standard_Real PU,PU1,PV,PV1;
160
161 for ( j=2; j<=NPolV-1; j++) {
162 PV = (j-1)/NV;
163 PV1 = 1 - PV;
164 myWeights->SetValue( 1 , j, W4(j));
165 myWeights->SetValue( NPolU, j, W2(j));
166
167 for ( i=2; i<=NPolU-1; i++) {
168 PU = (i-1)/NU;
169 PU1 = 1 - PU;
170
171 Standard_Real W = 0.5 * ( PV1 * W1(i) + PV * W3(i) +
172 PU * W2(j) + PU1 * W4(j) );
173
174 // Standard_Real W = PV1 * W1(i) + PV * W3(i) +
175 // PU * W2(j) + PU1 * W4(j) -
176 // ( PU1 * PV1 * W1(1) +
177 // PU * PV1 * W2(1) +
178 // PU * PV * W3(NPolU) +
179 // PU1 * PV * W4(NPolV) );
180 myWeights->SetValue(i,j,W);
181 }
182 }
183 }
184
185
186