0030480: Visualization - Clear of Select3D_SensitiveGroup does not update internal...
[occt.git] / src / GeomFill / GeomFill_Curved.cxx
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_Curved.hxx>
19 #include <gp_Pnt.hxx>
20 #include <gp_Vec.hxx>
21 #include <Standard_NotImplemented.hxx>
22 #include <TColgp_HArray2OfPnt.hxx>
23 #include <TColStd_Array1OfReal.hxx>
24 #include <TColStd_HArray2OfReal.hxx>
25
26 //=======================================================================
27 //function : GeomFill_Curved
28 //purpose  : 
29 //=======================================================================
30 GeomFill_Curved::GeomFill_Curved()
31 {
32 }
33
34
35 //=======================================================================
36 //function : GeomFill_Curved
37 //purpose  : 
38 //=======================================================================
39
40 GeomFill_Curved::GeomFill_Curved(const TColgp_Array1OfPnt& P1, 
41                            const TColgp_Array1OfPnt& P2, 
42                            const TColgp_Array1OfPnt& P3, 
43                            const TColgp_Array1OfPnt& P4)
44 {
45   Init(P1, P2, P3, P4);
46 }
47
48
49 //=======================================================================
50 //function : GeomFill_Curved
51 //purpose  : 
52 //=======================================================================
53
54 GeomFill_Curved::GeomFill_Curved(const TColgp_Array1OfPnt&   P1, 
55                            const TColgp_Array1OfPnt&   P2, 
56                            const TColgp_Array1OfPnt&   P3, 
57                            const TColgp_Array1OfPnt&   P4,
58                            const TColStd_Array1OfReal& W1,
59                            const TColStd_Array1OfReal& W2,
60                            const TColStd_Array1OfReal& W3,
61                            const TColStd_Array1OfReal& W4)
62 {
63   Init(P1, P2, P3, P4, W1, W2, W3, W4);
64 }
65
66 //=======================================================================
67 //function : GeomFill_Curved
68 //purpose  : 
69 //=======================================================================
70
71 GeomFill_Curved::GeomFill_Curved(const TColgp_Array1OfPnt& P1, 
72                            const TColgp_Array1OfPnt& P2)
73 {
74   Init(P1, P2);
75 }
76
77
78 //=======================================================================
79 //function : GeomFill_Curved
80 //purpose  : 
81 //=======================================================================
82
83 GeomFill_Curved::GeomFill_Curved(const TColgp_Array1OfPnt&   P1, 
84                            const TColgp_Array1OfPnt&   P2, 
85                            const TColStd_Array1OfReal& W1, 
86                            const TColStd_Array1OfReal& W2)
87 {
88   Init(P1, P2, W1, W2);
89 }
90
91
92 //=======================================================================
93 //function : Init
94 //purpose  : 
95 //=======================================================================
96
97 void  GeomFill_Curved::Init(const TColgp_Array1OfPnt& P1, 
98                          const TColgp_Array1OfPnt& P2, 
99                          const TColgp_Array1OfPnt& P3, 
100                          const TColgp_Array1OfPnt& P4)
101 {
102   Standard_DomainError_Raise_if
103     ( P1.Length() != P3.Length() || P2.Length() != P4.Length()," ");
104
105   Standard_Integer NPolU = P1.Length();
106   Standard_Integer NPolV = P2.Length();
107   
108   IsRational = Standard_False;
109   
110   Standard_Real NU = NPolU - 1;
111   Standard_Real NV = NPolV - 1;
112   myPoles = new TColgp_HArray2OfPnt( 1, NPolU, 1, NPolV);
113   
114   // The boundaries are not modified
115   Standard_Integer i,j,k;
116   for ( i=1; i<=NPolU; i++) {
117     myPoles->SetValue( i, 1    , P1(i));
118     myPoles->SetValue( i, NPolV, P3(i));
119   }
120   Standard_Real PU,PU1,PV,PV1;
121   
122   for ( j=2; j<=NPolV-1; j++) {
123     PV  = (j-1)/NV;
124     PV1 = 1 - PV;
125     PV /= 2.;
126     PV1 /= 2.;
127     myPoles->SetValue( 1    , j, P4(j));
128     myPoles->SetValue( NPolU, j, P2(j));
129
130     for ( i=2; i<=NPolU-1; i++) {
131       PU  = (i-1)/NU;
132       PU1 = 1 - PU;
133       PU /= 2.;
134       PU1 /= 2.;
135       gp_Pnt P;
136       for (k=1; k<=3; k++) {
137         P.SetCoord(k, 
138                    PV1 * P1(i).Coord(k) + PV  * P3(i).Coord(k) +
139                    PU  * P2(j).Coord(k) + PU1 * P4(j).Coord(k)  );
140       }
141       myPoles->SetValue(i,j,P);
142     }
143   }
144 }
145
146
147 //=======================================================================
148 //function : Init
149 //purpose  : 
150 //=======================================================================
151
152 void  GeomFill_Curved::Init(const TColgp_Array1OfPnt&   P1, 
153                          const TColgp_Array1OfPnt&   P2, 
154                          const TColgp_Array1OfPnt&   P3, 
155                          const TColgp_Array1OfPnt&   P4,
156                          const TColStd_Array1OfReal& W1,
157                          const TColStd_Array1OfReal& W2,
158                          const TColStd_Array1OfReal& W3,
159                          const TColStd_Array1OfReal& W4)
160 {
161   Standard_DomainError_Raise_if
162     ( W1.Length() != W3.Length() || W2.Length() != W4.Length()," ");
163   Standard_DomainError_Raise_if
164     ( W1.Length() != P1.Length() || 
165       W2.Length() != P2.Length() || 
166       W3.Length() != P3.Length() || 
167       W4.Length() != P4.Length()   , " ");
168
169   Init(P1,P2,P3,P4);
170   IsRational = Standard_True;
171
172   Standard_Integer NPolU = W1.Length();
173   Standard_Integer NPolV = W2.Length();
174
175   Standard_Real NU = NPolU - 1;
176   Standard_Real NV = NPolV - 1;
177   myWeights = new TColStd_HArray2OfReal( 1, NPolU, 1, NPolV);
178   
179   // The boundaries are not modified
180   Standard_Integer i,j;
181   for ( i=1; i<=NPolU; i++) {
182     myWeights->SetValue( i, 1    , W1(i));
183     myWeights->SetValue( i, NPolV, W3(i));
184   }
185   Standard_Real PU,PU1,PV,PV1;
186   
187   for ( j=2; j<=NPolV-1; j++) {
188     PV  = (j-1)/NV;
189     PV1 = 1 - PV;
190     PV /= 2.;
191     PV1 /= 2.;
192     myWeights->SetValue( 1    , j, W4(j));
193     myWeights->SetValue( NPolU, j, W2(j));
194
195     for ( i=2; i<=NPolU-1; i++) {
196       PU  = (i-1)/NU;
197       PU1 = 1 - PU;
198       PU /= 2.;
199       PU1 /= 2.;
200       Standard_Real W = PV1 * W1(i) + PV  * W3(i) +
201                         PU  * W2(j) + PU1 * W4(j)  ;
202       myWeights->SetValue(i,j,W);
203     }
204   }
205 }
206
207
208 //=======================================================================
209 //function : Init
210 //purpose  : 
211 //=======================================================================
212
213 void  GeomFill_Curved::Init(const TColgp_Array1OfPnt& P1,
214                          const TColgp_Array1OfPnt& P2)
215 {
216   Standard_Integer NPolU = P1.Length();
217   Standard_Integer NPolV = P2.Length();
218   
219   IsRational = Standard_False;
220   
221   myPoles = new TColgp_HArray2OfPnt( 1, NPolU, 1, NPolV);
222   
223   Standard_Integer i,j;
224   
225   for ( j=1; j<=NPolV; j++) {
226     gp_Vec Tra(P2(1),P2(j));
227     for ( i=1; i<=NPolU; i++) {
228       myPoles->SetValue( i, j, P1(i).Translated(Tra));
229     }
230   }
231 }
232
233
234 //=======================================================================
235 //function : Init
236 //purpose  : 
237 //=======================================================================
238
239 void  GeomFill_Curved::Init(const TColgp_Array1OfPnt&   P1, 
240                          const TColgp_Array1OfPnt&   P2, 
241                          const TColStd_Array1OfReal& W1, 
242                          const TColStd_Array1OfReal& W2)
243 {
244   Init(P1,P2);
245   IsRational = Standard_True;
246   
247   //Initialisation des poids.
248   Standard_Integer NPolU = W1.Length();
249   Standard_Integer NPolV = W2.Length();
250
251   myWeights = new TColStd_HArray2OfReal( 1, NPolU, 1, NPolV);
252   for (Standard_Integer j=1; j<=NPolV; j++) {
253     Standard_Real Factor = W2(j)/W1(1);
254     for (Standard_Integer i=1; i<=NPolU; i++) {
255       myWeights->SetValue(i,j,W1(i)*Factor);
256     }
257   }
258 }