b311480e |
1 | // Created on: 1998-04-09 |
2 | // Created by: Andre LIEUTIER |
3 | // Copyright (c) 1998-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
42cf5bc1 |
17 | |
18 | #include <Geom_Surface.hxx> |
19 | #include <gp_Pnt.hxx> |
20 | #include <gp_Vec.hxx> |
21 | #include <gp_XY.hxx> |
22 | #include <gp_XYZ.hxx> |
23 | #include <math_Gauss.hxx> |
7fd59977 |
24 | #include <math_Matrix.hxx> |
25 | #include <math_Vector.hxx> |
42cf5bc1 |
26 | #include <NLPlate_HGPPConstraint.hxx> |
27 | #include <NLPlate_ListIteratorOfStackOfPlate.hxx> |
28 | #include <NLPlate_NLPlate.hxx> |
7fd59977 |
29 | #include <Plate_D1.hxx> |
30 | #include <Plate_D2.hxx> |
31 | #include <Plate_D3.hxx> |
7fd59977 |
32 | #include <Plate_FreeGtoCConstraint.hxx> |
42cf5bc1 |
33 | #include <Plate_PinpointConstraint.hxx> |
34 | #include <Plate_Plate.hxx> |
7fd59977 |
35 | |
36 | NLPlate_NLPlate::NLPlate_NLPlate(const Handle(Geom_Surface)& InitialSurface) : |
37 | myInitialSurface(InitialSurface),OK(Standard_False) {} |
38 | //======================================================================= |
39 | |
40 | void NLPlate_NLPlate::Load(const Handle(NLPlate_HGPPConstraint)& GConst) |
41 | { |
42 | if(!GConst.IsNull()) myHGPPConstraints.Append(GConst); |
43 | OK = Standard_False; |
44 | } |
45 | |
46 | //======================================================================= |
47 | //function : Solve |
48 | //purpose : |
49 | //======================================================================= |
50 | void NLPlate_NLPlate::Solve(const Standard_Integer ord, const Standard_Integer InitialConsraintOrder) |
51 | { |
52 | Standard_Integer maxOrder = MaxActiveConstraintOrder(); |
53 | Standard_Integer ordre = ord; |
54 | if(ordre<maxOrder+2) ordre = maxOrder+2; |
55 | |
56 | for(Standard_Integer iterOrder=InitialConsraintOrder;iterOrder<=maxOrder;iterOrder++) |
57 | { |
58 | if(!Iterate(iterOrder,ordre+iterOrder-maxOrder)) |
59 | { |
60 | OK = Standard_False; |
61 | break; |
62 | } |
63 | } |
64 | OK = Standard_True; |
65 | } |
66 | //======================================================================= |
67 | //function : Solve2 |
68 | //purpose : |
69 | //======================================================================= |
70 | void NLPlate_NLPlate::Solve2(const Standard_Integer ord, const Standard_Integer InitialConsraintOrder) |
71 | { |
72 | Standard_Integer maxOrder = MaxActiveConstraintOrder(); |
73 | Standard_Integer ordre = ord; |
74 | if(ordre<maxOrder+2) ordre = maxOrder+2; |
75 | if(Iterate(0,ord)) |
76 | { |
6af4fe1c |
77 | mySOP.First().SetPolynomialPartOnly(Standard_True); |
7fd59977 |
78 | ConstraintsSliding(); |
79 | } |
80 | |
81 | |
82 | for(Standard_Integer iterOrder=InitialConsraintOrder;iterOrder<=maxOrder;iterOrder++) |
83 | { |
84 | if(!Iterate(iterOrder,ordre+iterOrder-maxOrder)) |
85 | { |
86 | OK = Standard_False; |
87 | break; |
88 | } |
89 | } |
90 | OK = Standard_True; |
91 | } |
92 | |
93 | //======================================================================= |
94 | //function : IncrementalSolve |
95 | //purpose : |
96 | //======================================================================= |
35e08fe8 |
97 | void NLPlate_NLPlate::IncrementalSolve(const Standard_Integer ord, const Standard_Integer /*InitialConsraintOrder*/, |
7fd59977 |
98 | const Standard_Integer NbIncrements, const Standard_Boolean UVSliding) |
99 | { |
100 | Standard_Integer maxOrder = MaxActiveConstraintOrder(); |
101 | Standard_Integer ordre = ord; |
102 | if(ordre<maxOrder+2) ordre = maxOrder+2; |
103 | Standard_Real IncrementalLoad = 1.; |
104 | |
105 | for(Standard_Integer increment=0;increment < NbIncrements;increment++) |
106 | { |
107 | IncrementalLoad = 1./Standard_Real(NbIncrements-increment); |
108 | // for(Standard_Integer iterOrder=InitialConsraintOrder;iterOrder<=maxOrder;iterOrder++) |
109 | Standard_Integer iterOrder=maxOrder; |
110 | { |
111 | if(!Iterate(iterOrder,ordre+iterOrder-maxOrder,IncrementalLoad)) |
112 | { |
113 | OK = Standard_False; |
114 | return; |
115 | } |
116 | } |
117 | if(UVSliding) ConstraintsSliding(); |
118 | } |
119 | OK = Standard_True; |
120 | } |
121 | |
122 | //======================================================================= |
123 | Standard_Boolean NLPlate_NLPlate::IsDone() const |
124 | { |
125 | return OK; |
126 | } |
127 | //======================================================================= |
128 | |
129 | void NLPlate_NLPlate::destroy() |
130 | { |
131 | Init(); |
132 | } |
133 | //======================================================================= |
134 | |
135 | void NLPlate_NLPlate::Init() |
136 | { |
137 | mySOP.Clear(); |
138 | myHGPPConstraints.Clear(); |
139 | } |
140 | //======================================================================= |
141 | |
142 | gp_XYZ NLPlate_NLPlate::Evaluate(const gp_XY& point2d) const |
143 | { |
144 | return EvaluateDerivative(point2d,0,0); |
145 | } |
146 | //======================================================================= |
147 | |
148 | gp_XYZ NLPlate_NLPlate::EvaluateDerivative(const gp_XY& point2d,const Standard_Integer iu,const Standard_Integer iv) const |
149 | { |
150 | gp_XYZ Value(0.,0.,0.); |
151 | if((iu==0)&&(iv==0)) |
152 | Value = myInitialSurface->Value(point2d.X(),point2d.Y()).XYZ(); |
153 | else |
154 | Value = myInitialSurface->DN(point2d.X(),point2d.Y(),iu,iv).XYZ(); |
155 | |
6af4fe1c |
156 | for(NLPlate_ListIteratorOfStackOfPlate SI(mySOP);SI.More();SI.Next()) |
7fd59977 |
157 | { |
158 | if(SI.Value().IsDone()) |
159 | Value += SI.Value().EvaluateDerivative(point2d,iu,iv); |
160 | } |
161 | return Value; |
162 | } |
163 | //======================================================================= |
164 | |
165 | Standard_Integer NLPlate_NLPlate::Continuity() const |
166 | { |
167 | Standard_Integer cont ; |
168 | for( cont=-1; cont<10;cont++) |
169 | { |
170 | if(!(myInitialSurface->IsCNu(cont+1)&&myInitialSurface->IsCNv(cont+1)))break; |
171 | } |
6af4fe1c |
172 | for(NLPlate_ListIteratorOfStackOfPlate SI(mySOP);SI.More();SI.Next()) |
7fd59977 |
173 | { |
174 | if((SI.Value().IsDone())&&(cont > SI.Value().Continuity())) cont = SI.Value().Continuity(); |
175 | } |
176 | return cont; |
177 | } |
178 | //======================================================================= |
179 | |
180 | Standard_Boolean NLPlate_NLPlate::Iterate(const Standard_Integer ConstraintOrder, |
181 | const Standard_Integer ResolutionOrder, |
182 | const Standard_Real IncrementalLoading) |
183 | { |
184 | Plate_Plate EmptyPlate; |
6af4fe1c |
185 | mySOP.Prepend(EmptyPlate); |
186 | Plate_Plate &TopP = mySOP.First(); |
7fd59977 |
187 | for(Standard_Integer index =1; index <= myHGPPConstraints.Length(); index++) |
188 | { |
189 | const Handle(NLPlate_HGPPConstraint) &HGPP = myHGPPConstraints(index); |
190 | Standard_Integer Order = HGPP->ActiveOrder(); |
191 | if(ConstraintOrder<Order) Order = ConstraintOrder; |
192 | const gp_XY &UV = HGPP->UV(); |
193 | |
194 | if((Order >=0)&& HGPP->IsG0()) |
195 | { |
196 | if(HGPP->IncrementalLoadAllowed()) |
197 | TopP.Load(Plate_PinpointConstraint(UV, (HGPP->G0Target()-Evaluate(UV))*IncrementalLoading)); |
198 | else |
199 | TopP.Load(Plate_PinpointConstraint(UV, HGPP->G0Target()-Evaluate(UV))); |
200 | } |
201 | |
202 | if((IncrementalLoading != 1.) && HGPP->IncrementalLoadAllowed() && (Order>=1)) |
203 | { |
204 | switch(Order) |
205 | { |
206 | case 1: |
207 | { |
208 | Plate_D1 D1S(EvaluateDerivative(UV,1,0),EvaluateDerivative(UV,0,1)); |
209 | TopP.Load(Plate_FreeGtoCConstraint(UV,D1S,HGPP->G1Target(),IncrementalLoading,HGPP->Orientation())); |
210 | } |
211 | break; |
212 | case 2: |
213 | { |
214 | Plate_D1 D1S(EvaluateDerivative(UV,1,0),EvaluateDerivative(UV,0,1)); |
215 | Plate_D2 D2S(EvaluateDerivative(UV,2,0),EvaluateDerivative(UV,1,1),EvaluateDerivative(UV,0,2)); |
216 | TopP.Load(Plate_FreeGtoCConstraint(UV,D1S,HGPP->G1Target(),D2S,HGPP->G2Target(), |
217 | IncrementalLoading,HGPP->Orientation())); |
218 | } |
219 | break; |
220 | case 3: |
221 | { |
222 | Plate_D1 D1S(EvaluateDerivative(UV,1,0),EvaluateDerivative(UV,0,1)); |
223 | Plate_D2 D2S(EvaluateDerivative(UV,2,0),EvaluateDerivative(UV,1,1),EvaluateDerivative(UV,0,2)); |
224 | Plate_D3 D3S(EvaluateDerivative(UV,3,0),EvaluateDerivative(UV,2,1), |
225 | EvaluateDerivative(UV,1,2),EvaluateDerivative(UV,0,3)); |
226 | TopP.Load(Plate_FreeGtoCConstraint(UV,D1S,HGPP->G1Target(),D2S,HGPP->G2Target(),D3S,HGPP->G3Target(), |
227 | IncrementalLoading,HGPP->Orientation())); |
228 | } |
229 | break; |
230 | default: |
231 | break; |
232 | } |
233 | } |
234 | else |
235 | { |
236 | switch(Order) |
237 | { |
238 | case 1: |
239 | { |
240 | Plate_D1 D1S(EvaluateDerivative(UV,1,0),EvaluateDerivative(UV,0,1)); |
241 | TopP.Load(Plate_FreeGtoCConstraint(UV,D1S,HGPP->G1Target())); |
242 | } |
243 | break; |
244 | case 2: |
245 | { |
246 | Plate_D1 D1S(EvaluateDerivative(UV,1,0),EvaluateDerivative(UV,0,1)); |
247 | Plate_D2 D2S(EvaluateDerivative(UV,2,0),EvaluateDerivative(UV,1,1),EvaluateDerivative(UV,0,2)); |
248 | TopP.Load(Plate_FreeGtoCConstraint(UV,D1S,HGPP->G1Target(),D2S,HGPP->G2Target())); |
249 | } |
250 | break; |
251 | case 3: |
252 | { |
253 | Plate_D1 D1S(EvaluateDerivative(UV,1,0),EvaluateDerivative(UV,0,1)); |
254 | Plate_D2 D2S(EvaluateDerivative(UV,2,0),EvaluateDerivative(UV,1,1),EvaluateDerivative(UV,0,2)); |
255 | Plate_D3 D3S(EvaluateDerivative(UV,3,0),EvaluateDerivative(UV,2,1), |
256 | EvaluateDerivative(UV,1,2),EvaluateDerivative(UV,0,3)); |
257 | TopP.Load(Plate_FreeGtoCConstraint(UV,D1S,HGPP->G1Target(),D2S,HGPP->G2Target(),D3S,HGPP->G3Target())); |
258 | } |
259 | break; |
260 | default: |
261 | break; |
262 | } |
263 | } |
264 | } |
265 | |
266 | TopP.SolveTI(ResolutionOrder); |
267 | if(!TopP.IsDone()) |
268 | { |
6af4fe1c |
269 | mySOP.RemoveFirst(); |
7fd59977 |
270 | return Standard_False; |
271 | } |
272 | else |
273 | return Standard_True; |
274 | } |
275 | //======================================================================= |
276 | |
277 | void NLPlate_NLPlate::ConstraintsSliding(const Standard_Integer NbIterations) |
278 | { |
279 | for(Standard_Integer index =1; index <= myHGPPConstraints.Length(); index++) |
280 | { |
281 | const Handle(NLPlate_HGPPConstraint) &HGPP = myHGPPConstraints(index); |
282 | if(HGPP->UVFreeSliding() && HGPP->IsG0()) |
283 | { |
284 | gp_XY UV = HGPP->UV(); |
285 | gp_XYZ P0 = Evaluate(UV); |
286 | const gp_XYZ P1 = HGPP->G0Target(); |
287 | for(Standard_Integer iter=1;iter<=NbIterations;iter++) |
288 | { |
289 | // on itere au premier ordre, ce qui suffit si on est assez pres de la surface ?? |
290 | gp_XYZ DP = P1 - P0; |
291 | gp_XYZ Du = EvaluateDerivative(UV,1,0); |
292 | gp_XYZ Dv = EvaluateDerivative(UV,0,1); |
293 | math_Matrix mat(0,1,0,1); |
294 | mat(0,0) = Du*Du; |
295 | mat(0,1) = Du*Dv; |
296 | mat(1,0) = Du*Dv; |
297 | mat(1,1) = Dv*Dv; |
298 | math_Gauss gauss(mat); |
299 | if(!gauss.IsDone()) break; |
300 | |
301 | math_Vector vec(0,1); |
302 | vec(0) = Du*DP; |
303 | vec(1) = Dv*DP; |
304 | math_Vector sol(0,1); |
305 | gauss.Solve(vec,sol); |
306 | UV.SetX(UV.X()+sol(0)); |
307 | UV.SetY(UV.Y()+sol(1)); |
308 | P0 = Evaluate(UV); |
309 | } |
310 | HGPP->SetUV(UV); |
311 | } |
312 | } |
313 | } |
314 | |
315 | //======================================================================= |
316 | |
317 | Standard_Integer NLPlate_NLPlate::MaxActiveConstraintOrder() const |
318 | { |
319 | Standard_Integer MaxOrder = -1; |
320 | for(Standard_Integer index =1; index <= myHGPPConstraints.Length(); index++) |
321 | { |
322 | Standard_Integer CAOrder = myHGPPConstraints(index)->ActiveOrder(); |
323 | if(CAOrder > MaxOrder) MaxOrder = CAOrder; |
324 | } |
325 | return MaxOrder; |
326 | } |