0023024: Update headers of OCCT files
[occt.git] / src / AdvApp2Var / AdvApp2Var_Framework.cxx
CommitLineData
b311480e 1// Created on: 1996-07-02
2// Created by: Joelle CHAUVET
3// Copyright (c) 1996-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21// Modified: Mon Dec 9 11:39:13 1996
22// by: Joelle CHAUVET
23// G1135 : empty constructor
24
25
26#include <AdvApp2Var_Framework.hxx>
27#include <AdvApp2Var_Iso.hxx>
28#include <AdvApp2Var_Strip.hxx>
29#include <AdvApp2Var_SequenceOfStrip.hxx>
30#include <AdvApp2Var_Node.hxx>
31#include <AdvApp2Var_SequenceOfNode.hxx>
32#include <TColStd_HArray1OfReal.hxx>
33#include <gp_XY.hxx>
34
35//==========================================================================================
36//function : AdvApp2Var_Framework
37//purpose :
38//==========================================================================================
39
40AdvApp2Var_Framework::AdvApp2Var_Framework()
41{
42}
43
44
45//==========================================================================================
46//function : AdvApp2Var_Framework
47//purpose :
48//==========================================================================================
49
50AdvApp2Var_Framework::AdvApp2Var_Framework(const AdvApp2Var_SequenceOfNode& Frame,
51 const AdvApp2Var_SequenceOfStrip& UFrontier,
52 const AdvApp2Var_SequenceOfStrip& VFrontier)
53{
54 myNodeConstraints = Frame;
55 myUConstraints = UFrontier;
56 myVConstraints = VFrontier;
57}
58
59//==========================================================================================
60//function : FirstNotApprox
61//purpose : return the first Iso not approximated
62//==========================================================================================
63
64Standard_Boolean AdvApp2Var_Framework::FirstNotApprox(Standard_Integer& IndexIso,
65 Standard_Integer& IndexStrip,
66 AdvApp2Var_Iso& anIso) const
67{
68 Standard_Boolean good = Standard_True;
69 Standard_Integer i,j;
70 AdvApp2Var_Strip S;
71
72 for (i = 1; i <= myUConstraints.Length() && good ; i++) {
73 S = myUConstraints.Value(i);
74 for (j = 1; j <= S.Length() && good ; j++) {
75 good = (S.Value(j)).IsApproximated();
76 if (!good) {
77 IndexIso = j;
78 IndexStrip = i;
79 anIso = S.Value(j);
80 }
81 }
82 }
83 if (!good) {
84 goto FINISH;
85 }
86
87 for (i = 1; i <= myVConstraints.Length() && good; i++) {
88 S = myVConstraints.Value(i);
89 for (j = 1; j <= S.Length() && good ; j++) {
90 good = (S.Value(j)).IsApproximated();
91 if (!good) {
92 IndexIso = j;
93 IndexStrip = i;
94 anIso = S.Value(j);
95 }
96 }
97 }
98
99 FINISH:
100 return !good;
101}
102
103//==========================================================================================
104//function : FirstNode
105//purpose : return the first node of an iso
106//==========================================================================================
107
108Standard_Integer AdvApp2Var_Framework::FirstNode(const GeomAbs_IsoType Type,
109 const Standard_Integer IndexIso,
110 const Standard_Integer IndexStrip) const
111{
112 Standard_Integer NbIso,Index;
113 NbIso = myUConstraints.Length()+1;
114 if (Type==GeomAbs_IsoU) {
115 Index = NbIso * (IndexStrip-1) + IndexIso;
116 return Index;
117 }
118 else {
119 Index = NbIso * (IndexIso-1) + IndexStrip;
120 return Index;
121 }
122}
123
124//==========================================================================================
125//function : LastNode
126//purpose : return the last node of an iso
127//==========================================================================================
128
129Standard_Integer AdvApp2Var_Framework::LastNode(const GeomAbs_IsoType Type,
130 const Standard_Integer IndexIso,
131 const Standard_Integer IndexStrip) const
132{
133 Standard_Integer NbIso,Index;
134 NbIso = myUConstraints.Length()+1;
135 if (Type==GeomAbs_IsoU) {
136 Index = NbIso * IndexStrip + IndexIso;
137 return Index;
138 }
139 else {
140 Index = NbIso * (IndexIso-1) + IndexStrip + 1;
141 return Index;
142 }
143}
144
145//==========================================================================================
146//function : ChangeIso
147//purpose : replace the iso IndexIso of the strip IndexStrip by anIso
148//==========================================================================================
149
150void AdvApp2Var_Framework::ChangeIso(const Standard_Integer IndexIso,
151 const Standard_Integer IndexStrip,
152 const AdvApp2Var_Iso& anIso)
153{
154 AdvApp2Var_Strip S0;
155 if (anIso.Type()==GeomAbs_IsoV) {
156 S0 = myUConstraints.Value(IndexStrip);
157 S0.SetValue(IndexIso,anIso);
158 myUConstraints.SetValue(IndexStrip,S0);
159 }
160 else {
161 S0 = myVConstraints.Value(IndexStrip);
162 S0.SetValue(IndexIso,anIso);
163 myVConstraints.SetValue(IndexStrip,S0);
164 }
165}
166
167//==========================================================================================
168//function : Node
169//purpose : return the node of coordinates (U,V)
170//==========================================================================================
171
172const AdvApp2Var_Node& AdvApp2Var_Framework::Node(const Standard_Real U,
173 const Standard_Real V) const
174{
175 Standard_Integer Index=1;
176 while ( ( ((myNodeConstraints.Value(Index)).Coord()).X() != U
177 || ((myNodeConstraints.Value(Index)).Coord()).Y() != V )
178 && (Index<myNodeConstraints.Length()) ) {
179 Index++;
180 }
181 return myNodeConstraints.Value(Index);
182}
183
184//==========================================================================================
185//function : IsoU
186//purpose : return the Iso U=U with V0<=V<=V1
187//==========================================================================================
188
189const AdvApp2Var_Iso&
190AdvApp2Var_Framework::IsoU(const Standard_Real U,
191 const Standard_Real V0,
192 const Standard_Real V1) const
193{
194 Standard_Integer IndexStrip=1,IndexIso=1;
195 while ( ( ((myVConstraints.Value(IndexStrip)).Value(1)).T0() != V0
196 || ((myVConstraints.Value(IndexStrip)).Value(1)).T1() != V1 )
197 && (IndexStrip<myVConstraints.Length()) ) {
198 IndexStrip++;
199 }
200 while ( ( ((myVConstraints.Value(IndexStrip)).Value(IndexIso)).Constante() != U)
201 && (IndexIso<=myUConstraints.Length()) ) {
202 IndexIso++;
203 }
204 return (myVConstraints.Value(IndexStrip)).Value(IndexIso);
205}
206
207//==========================================================================================
208//function : IsoV
209//purpose : return the Iso V=V with U0<=U<=U1
210//==========================================================================================
211
212const AdvApp2Var_Iso&
213AdvApp2Var_Framework::IsoV(const Standard_Real U0,
214 const Standard_Real U1,
215 const Standard_Real V) const
216{
217 Standard_Integer IndexStrip=1,IndexIso=1;
218 while ( ( ((myUConstraints.Value(IndexStrip)).Value(1)).T0() != U0
219 || ((myUConstraints.Value(IndexStrip)).Value(1)).T1() != U1 )
220 && (IndexStrip<myUConstraints.Length()) ) {
221 IndexStrip++;
222 }
223 while ( ( ((myUConstraints.Value(IndexStrip)).Value(IndexIso)).Constante() != V)
224 && (IndexIso<=myVConstraints.Length()) ) {
225 IndexIso++;
226 }
227 return (myUConstraints.Value(IndexStrip)).Value(IndexIso);
228}
229
230//==========================================================================================
231//function : UpdateInU
232//purpose : modification and insertion of nodes and isos
233//==========================================================================================
234
235void AdvApp2Var_Framework::UpdateInU(const Standard_Real CuttingValue)
236{
237 Standard_Integer i=1,j;
238 while (((myUConstraints.Value(i)).Value(1)).U0()>CuttingValue
239 || ((myUConstraints.Value(i)).Value(1)).U1()<CuttingValue) {
240 i++;
241 }
242 AdvApp2Var_Strip S0;
243 AdvApp2Var_Iso Is;
244 S0 = myUConstraints.Value(i);
245 Standard_Real Udeb = (S0.Value(1)).U0(), Ufin = (S0.Value(1)).U1();
246
247// modification des Isos V de la bande en U d'indice i
248 for (j=1;j<=S0.Length();j++) {
249 Is = S0.Value(j);
250 Is.ChangeDomain(Udeb,CuttingValue);
251 Is.ResetApprox();
252 S0.SetValue(j,Is);
253 }
254 myUConstraints.SetValue(i,S0);
255
256// insertion d'une nouvelle bande en U apres l'indice i
257 AdvApp2Var_Strip NewStrip;
258 for (j=1;j<=S0.Length();j++) {
259 AdvApp2Var_Iso NewIso((S0.Value(j)).Type(),(S0.Value(j)).Constante(),
260 CuttingValue,Ufin,(S0.Value(j)).V0(),(S0.Value(j)).V1(),
261 0,(S0.Value(j)).UOrder(),(S0.Value(j)).VOrder());
262 NewIso.ResetApprox();
263 NewStrip.Append(NewIso);
264 }
265 myUConstraints.InsertAfter(i,NewStrip);
266
267// insertion d'une nouvelle Iso U=U* dans chaque bande en V apres l'indice i
268// et restriction des paves des Isos adjacentes
269 for (j=1;j<=myVConstraints.Length();j++) {
270 S0 = myVConstraints.Value(j);
271 Is = S0.Value(i);
272 Is.ChangeDomain(Is.U0(),CuttingValue,Is.V0(),Is.V1());
273 S0.SetValue(i,Is);
274 AdvApp2Var_Iso NewIso(Is.Type(),CuttingValue,Is.U0(),CuttingValue,Is.V0(),Is.V1(),
275 0,Is.UOrder(),Is.VOrder());
276 NewIso.ResetApprox();
277 S0.InsertAfter(i,NewIso);
278 Is = S0.Value(i+2);
279 Is.ChangeDomain(CuttingValue,Is.U1(),Is.V0(),Is.V1());
280 S0.SetValue(i+2,Is);
281 myVConstraints.SetValue(j,S0);
282 }
283
284// insertion des nouveaux noeuds (U*,Vj)
285 AdvApp2Var_Node Prev, Next;
286 Prev=myNodeConstraints.Value(1);
287 for (j=1;j<myNodeConstraints.Length();j++) {
288 Next=myNodeConstraints.Value(j+1);
289 if ((Prev.Coord()).X()<CuttingValue && ((Next.Coord()).X()>CuttingValue)
290 && ((Prev.Coord()).Y()==(Next.Coord()).Y())) {
291 gp_XY NewUV(CuttingValue,(Prev.Coord()).Y());
292 AdvApp2Var_Node NewNode(NewUV,Prev.UOrder(),Prev.VOrder());
293 myNodeConstraints.InsertAfter(j,NewNode);
294 }
295 Prev=Next;
296 }
297}
298
299//==========================================================================================
300//function : UpdateInV
301//purpose : modification and insertion of nodes and isos
302//==========================================================================================
303
304void AdvApp2Var_Framework::UpdateInV(const Standard_Real CuttingValue)
305{
306 Standard_Integer i,j=1;
307 while (((myVConstraints.Value(j)).Value(1)).V0()>CuttingValue
308 || ((myVConstraints.Value(j)).Value(1)).V1()<CuttingValue) {
309 j++;
310 }
311 AdvApp2Var_Strip S0;
312 AdvApp2Var_Iso Is;
313 S0 = myVConstraints.Value(j);
314 Standard_Real Vdeb = (S0.Value(1)).V0(), Vfin = (S0.Value(1)).V1();
315
316// modification des Isos U de la bande en V d'indice j
317 for (i=1;i<=S0.Length();i++) {
318 Is = S0.Value(i);
319 Is.ChangeDomain(Vdeb,CuttingValue);
320 Is.ResetApprox();
321 S0.SetValue(i,Is);
322 }
323 myVConstraints.SetValue(j,S0);
324
325// insertion d'une nouvelle bande en V apres l'indice j
326 AdvApp2Var_Strip NewStrip;
327 for (i=1;i<=S0.Length();i++) {
328 AdvApp2Var_Iso NewIso((S0.Value(i)).Type(),(S0.Value(i)).Constante(),
329 (S0.Value(i)).U0(),(S0.Value(i)).U1(),CuttingValue,Vfin,
330 0,(S0.Value(i)).UOrder(),(S0.Value(i)).VOrder());
331 NewIso.ResetApprox();
332 NewStrip.Append(NewIso);
333 }
334 myVConstraints.InsertAfter(j,NewStrip);
335
336// insertion d'une nouvelle Iso V=V* dans chaque bande en U apres l'indice j
337// et restriction des paves des Isos adjacentes
338 for (i=1;i<=myUConstraints.Length();i++) {
339 S0 = myUConstraints.Value(i);
340 Is = S0.Value(j);
341 Is.ChangeDomain(Is.U0(),Is.U1(),Is.V0(),CuttingValue);
342 S0.SetValue(j,Is);
343 AdvApp2Var_Iso NewIso(Is.Type(),CuttingValue,Is.U0(),Is.U1(),Is.V0(),CuttingValue,
344 0,Is.UOrder(),Is.VOrder());
345 NewIso.ResetApprox();
346 S0.InsertAfter(j,NewIso);
347 Is = S0.Value(j+2);
348 Is.ChangeDomain(Is.U0(),Is.U1(),CuttingValue,Is.V1());
349 S0.SetValue(j+2,Is);
350 myUConstraints.SetValue(i,S0);
351 }
352
353// insertion des nouveaux noeuds (Ui,V*)
354 i = 1;
355 while ( i<=myNodeConstraints.Length()
356 && ( ((myNodeConstraints.Value(i)).Coord()).Y()) < CuttingValue) {
357 i+=myUConstraints.Length()+1;
358 }
359 for (j=1;j<=myUConstraints.Length()+1;j++) {
360 gp_XY NewUV(((myNodeConstraints.Value(j)).Coord()).X(),CuttingValue);
361 AdvApp2Var_Node NewNode(NewUV,
362 (myNodeConstraints.Value(j)).UOrder(),
363 (myNodeConstraints.Value(j)).VOrder());
364 myNodeConstraints.InsertAfter(i+j-2,NewNode);
365 }
366}
367
368//==========================================================================================
369//function : UEquation
370//purpose : return the coefficients of the polynomial equation which approximates an iso U
371//==========================================================================================
372
373const Handle(TColStd_HArray1OfReal)&
374AdvApp2Var_Framework::UEquation(const Standard_Integer IndexIso,
375 const Standard_Integer IndexStrip) const
376{
377 return ((myVConstraints.Value(IndexStrip)).Value(IndexIso)).Polynom();
378}
379
380//==========================================================================================
381//function : VEquation
382//purpose : return the coefficients of the polynomial equation which approximates an iso V
383//==========================================================================================
384
385const Handle(TColStd_HArray1OfReal)&
386AdvApp2Var_Framework::VEquation(const Standard_Integer IndexIso,
387 const Standard_Integer IndexStrip) const
388{
389 return myUConstraints.Value(IndexStrip).Value(IndexIso).Polynom();
390}
391