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