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