summaryrefslogtreecommitdiff
path: root/src/AdvApp2Var/AdvApp2Var_Framework.cxx
blob: f07fd399256469afd7c145328059528299a74b93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
// File:	AdvApp2Var_Framework.cxx
// Created:	Tue Jul  2 12:12:24 1996
// Author:	Joelle CHAUVET
//		<jct@sgi38>
// Modified:	Mon Dec  9 11:39:13 1996
//   by:	Joelle CHAUVET
//		G1135 : empty constructor


#include <AdvApp2Var_Framework.hxx>
#include <AdvApp2Var_Iso.hxx>
#include <AdvApp2Var_Strip.hxx>
#include <AdvApp2Var_SequenceOfStrip.hxx>
#include <AdvApp2Var_Node.hxx>
#include <AdvApp2Var_SequenceOfNode.hxx>
#include <TColStd_HArray1OfReal.hxx>
#include <gp_XY.hxx>

//==========================================================================================
//function : AdvApp2Var_Framework
//purpose  :
//==========================================================================================

AdvApp2Var_Framework::AdvApp2Var_Framework()
{
}


//==========================================================================================
//function : AdvApp2Var_Framework
//purpose  :
//==========================================================================================

AdvApp2Var_Framework::AdvApp2Var_Framework(const AdvApp2Var_SequenceOfNode& Frame,
					   const AdvApp2Var_SequenceOfStrip& UFrontier,
					   const AdvApp2Var_SequenceOfStrip& VFrontier)
{
  myNodeConstraints = Frame;
  myUConstraints = UFrontier;
  myVConstraints = VFrontier;
}

//==========================================================================================
//function : FirstNotApprox
//purpose  : return the first Iso not approximated
//==========================================================================================

Standard_Boolean  AdvApp2Var_Framework::FirstNotApprox(Standard_Integer& IndexIso,
                                                       Standard_Integer& IndexStrip,
						       AdvApp2Var_Iso& anIso) const
{
  Standard_Boolean good = Standard_True;
  Standard_Integer i,j;
  AdvApp2Var_Strip S;

  for (i = 1; i <= myUConstraints.Length() && good ; i++) {
    S = myUConstraints.Value(i);
    for (j = 1; j <= S.Length() && good ; j++) {
      good = (S.Value(j)).IsApproximated();
      if (!good) {
	IndexIso = j;
	IndexStrip = i;
	anIso = S.Value(j);
      }
    }
  }
  if (!good)  {
    goto FINISH;
  }

  for (i = 1; i <= myVConstraints.Length() && good; i++) {
    S = myVConstraints.Value(i);
    for (j = 1; j <= S.Length() && good ; j++) {
      good = (S.Value(j)).IsApproximated();
      if (!good) {
	IndexIso = j;
	IndexStrip = i;
	anIso = S.Value(j);
      }
    }
  }

  FINISH:
  return !good;
}

//==========================================================================================
//function : FirstNode 
//purpose  : return the first node of an iso
//==========================================================================================

Standard_Integer AdvApp2Var_Framework::FirstNode(const GeomAbs_IsoType Type,
						 const Standard_Integer IndexIso,
						 const Standard_Integer IndexStrip) const 
{
  Standard_Integer NbIso,Index;
  NbIso = myUConstraints.Length()+1;
  if (Type==GeomAbs_IsoU) {
    Index = NbIso * (IndexStrip-1) + IndexIso;
    return Index;
  }
  else {
    Index = NbIso * (IndexIso-1) + IndexStrip;
    return Index;
  }
}

//==========================================================================================
//function : LastNode 
//purpose  : return the last node of an iso
//==========================================================================================

Standard_Integer AdvApp2Var_Framework::LastNode(const GeomAbs_IsoType Type,
					       const Standard_Integer IndexIso,
					       const Standard_Integer IndexStrip) const 
{
  Standard_Integer NbIso,Index;
  NbIso = myUConstraints.Length()+1;
  if (Type==GeomAbs_IsoU) {
    Index = NbIso * IndexStrip + IndexIso;
    return Index;
  }
  else {
    Index = NbIso * (IndexIso-1) + IndexStrip + 1;
    return Index;
  }
}

//==========================================================================================
//function : ChangeIso
//purpose  : replace the iso IndexIso of the strip IndexStrip by anIso
//==========================================================================================

void AdvApp2Var_Framework::ChangeIso(const Standard_Integer IndexIso,
				     const Standard_Integer IndexStrip,
				     const AdvApp2Var_Iso& anIso)
{
  AdvApp2Var_Strip S0;
  if (anIso.Type()==GeomAbs_IsoV) {
    S0 = myUConstraints.Value(IndexStrip); 
    S0.SetValue(IndexIso,anIso);
    myUConstraints.SetValue(IndexStrip,S0);
  }
  else {
    S0 = myVConstraints.Value(IndexStrip);
    S0.SetValue(IndexIso,anIso);
    myVConstraints.SetValue(IndexStrip,S0);
  }
}

//==========================================================================================
//function : Node
//purpose  : return the node of coordinates (U,V)
//==========================================================================================

const AdvApp2Var_Node& AdvApp2Var_Framework::Node(const Standard_Real U,
						  const Standard_Real V) const
{
  Standard_Integer Index=1;
  while ( ( ((myNodeConstraints.Value(Index)).Coord()).X() != U
	 || ((myNodeConstraints.Value(Index)).Coord()).Y() != V )
         && (Index<myNodeConstraints.Length()) ) {
    Index++;
  }
  return myNodeConstraints.Value(Index);
}

//==========================================================================================
//function : IsoU
//purpose  : return the Iso U=U with V0<=V<=V1
//==========================================================================================

const AdvApp2Var_Iso& 
AdvApp2Var_Framework::IsoU(const Standard_Real U,
			      const Standard_Real V0,
			      const Standard_Real V1) const 
{
  Standard_Integer IndexStrip=1,IndexIso=1;
  while ( ( ((myVConstraints.Value(IndexStrip)).Value(1)).T0() != V0
	 || ((myVConstraints.Value(IndexStrip)).Value(1)).T1() != V1 )
         && (IndexStrip<myVConstraints.Length()) ) {
    IndexStrip++;
  }
  while ( ( ((myVConstraints.Value(IndexStrip)).Value(IndexIso)).Constante() != U)
         && (IndexIso<=myUConstraints.Length()) ) {
    IndexIso++;
  }
  return (myVConstraints.Value(IndexStrip)).Value(IndexIso);
}

//==========================================================================================
//function : IsoV
//purpose  : return the Iso V=V with U0<=U<=U1
//==========================================================================================

const AdvApp2Var_Iso& 
AdvApp2Var_Framework::IsoV(const Standard_Real U0,
			      const Standard_Real U1,
			      const Standard_Real V) const
{
  Standard_Integer IndexStrip=1,IndexIso=1;
  while ( ( ((myUConstraints.Value(IndexStrip)).Value(1)).T0() != U0
	 || ((myUConstraints.Value(IndexStrip)).Value(1)).T1() != U1 )
         && (IndexStrip<myUConstraints.Length()) ) {
    IndexStrip++;
  }
  while ( ( ((myUConstraints.Value(IndexStrip)).Value(IndexIso)).Constante() != V)
         && (IndexIso<=myVConstraints.Length()) ) {
    IndexIso++;
  }
  return (myUConstraints.Value(IndexStrip)).Value(IndexIso);
}

//==========================================================================================
//function : UpdateInU
//purpose  : modification and insertion of nodes and isos
//==========================================================================================

void AdvApp2Var_Framework::UpdateInU(const Standard_Real CuttingValue)
{
  Standard_Integer i=1,j;
  while (((myUConstraints.Value(i)).Value(1)).U0()>CuttingValue
	 || ((myUConstraints.Value(i)).Value(1)).U1()<CuttingValue) {
    i++;
  }
  AdvApp2Var_Strip S0;
  AdvApp2Var_Iso Is;
  S0 = myUConstraints.Value(i);
  Standard_Real Udeb = (S0.Value(1)).U0(), Ufin = (S0.Value(1)).U1(); 

//  modification des Isos V de la bande en U d'indice i
  for (j=1;j<=S0.Length();j++) {
    Is = S0.Value(j);
    Is.ChangeDomain(Udeb,CuttingValue);
    Is.ResetApprox();
    S0.SetValue(j,Is);
  }
  myUConstraints.SetValue(i,S0);

//  insertion d'une nouvelle bande en U apres l'indice i
  AdvApp2Var_Strip NewStrip;
  for (j=1;j<=S0.Length();j++) {
    AdvApp2Var_Iso NewIso((S0.Value(j)).Type(),(S0.Value(j)).Constante(),
                          CuttingValue,Ufin,(S0.Value(j)).V0(),(S0.Value(j)).V1(),
			  0,(S0.Value(j)).UOrder(),(S0.Value(j)).VOrder());
    NewIso.ResetApprox();
    NewStrip.Append(NewIso);
  }
  myUConstraints.InsertAfter(i,NewStrip);

//  insertion d'une nouvelle Iso U=U* dans chaque bande en V apres l'indice i
//  et restriction des paves des Isos adjacentes
  for (j=1;j<=myVConstraints.Length();j++) {
    S0 = myVConstraints.Value(j);
    Is = S0.Value(i);
    Is.ChangeDomain(Is.U0(),CuttingValue,Is.V0(),Is.V1());
    S0.SetValue(i,Is);
    AdvApp2Var_Iso NewIso(Is.Type(),CuttingValue,Is.U0(),CuttingValue,Is.V0(),Is.V1(),
			  0,Is.UOrder(),Is.VOrder());
    NewIso.ResetApprox();
    S0.InsertAfter(i,NewIso);
    Is = S0.Value(i+2);
    Is.ChangeDomain(CuttingValue,Is.U1(),Is.V0(),Is.V1());
    S0.SetValue(i+2,Is);
    myVConstraints.SetValue(j,S0);
  }

//  insertion des nouveaux noeuds (U*,Vj)
  AdvApp2Var_Node Prev, Next;
  Prev=myNodeConstraints.Value(1);
  for (j=1;j<myNodeConstraints.Length();j++) {
    Next=myNodeConstraints.Value(j+1);
    if ((Prev.Coord()).X()<CuttingValue && ((Next.Coord()).X()>CuttingValue)
	&& ((Prev.Coord()).Y()==(Next.Coord()).Y())) {
      gp_XY NewUV(CuttingValue,(Prev.Coord()).Y());
      AdvApp2Var_Node NewNode(NewUV,Prev.UOrder(),Prev.VOrder());
      myNodeConstraints.InsertAfter(j,NewNode);
    }
    Prev=Next;
  }
}

//==========================================================================================
//function : UpdateInV
//purpose  : modification and insertion of nodes and isos
//==========================================================================================

void AdvApp2Var_Framework::UpdateInV(const Standard_Real CuttingValue)
{
  Standard_Integer i,j=1;
  while (((myVConstraints.Value(j)).Value(1)).V0()>CuttingValue
	 || ((myVConstraints.Value(j)).Value(1)).V1()<CuttingValue) {
    j++;
  }
  AdvApp2Var_Strip S0;
  AdvApp2Var_Iso Is;
  S0 = myVConstraints.Value(j);
  Standard_Real Vdeb = (S0.Value(1)).V0(), Vfin = (S0.Value(1)).V1(); 

//  modification des Isos U de la bande en V d'indice j
  for (i=1;i<=S0.Length();i++) {
    Is = S0.Value(i);
    Is.ChangeDomain(Vdeb,CuttingValue);
    Is.ResetApprox();
    S0.SetValue(i,Is);
  }
  myVConstraints.SetValue(j,S0);

//  insertion d'une nouvelle bande en V apres l'indice j
  AdvApp2Var_Strip NewStrip;
  for (i=1;i<=S0.Length();i++) {
    AdvApp2Var_Iso NewIso((S0.Value(i)).Type(),(S0.Value(i)).Constante(),
                          (S0.Value(i)).U0(),(S0.Value(i)).U1(),CuttingValue,Vfin,
			  0,(S0.Value(i)).UOrder(),(S0.Value(i)).VOrder());
    NewIso.ResetApprox();
    NewStrip.Append(NewIso);
  }
  myVConstraints.InsertAfter(j,NewStrip);

//  insertion d'une nouvelle Iso V=V* dans chaque bande en U apres l'indice j
//  et restriction des paves des Isos adjacentes
  for (i=1;i<=myUConstraints.Length();i++) {
    S0 = myUConstraints.Value(i);
    Is = S0.Value(j);
    Is.ChangeDomain(Is.U0(),Is.U1(),Is.V0(),CuttingValue);
    S0.SetValue(j,Is);
    AdvApp2Var_Iso NewIso(Is.Type(),CuttingValue,Is.U0(),Is.U1(),Is.V0(),CuttingValue,
			  0,Is.UOrder(),Is.VOrder());
    NewIso.ResetApprox();
    S0.InsertAfter(j,NewIso);
    Is = S0.Value(j+2);
    Is.ChangeDomain(Is.U0(),Is.U1(),CuttingValue,Is.V1());
    S0.SetValue(j+2,Is);
    myUConstraints.SetValue(i,S0);
  }

//  insertion des nouveaux noeuds (Ui,V*)
  i = 1;
  while ( i<=myNodeConstraints.Length() 
	 && ( ((myNodeConstraints.Value(i)).Coord()).Y()) < CuttingValue) {
    i+=myUConstraints.Length()+1;
  }
  for (j=1;j<=myUConstraints.Length()+1;j++) {
    gp_XY NewUV(((myNodeConstraints.Value(j)).Coord()).X(),CuttingValue);
    AdvApp2Var_Node NewNode(NewUV,
			    (myNodeConstraints.Value(j)).UOrder(),
			    (myNodeConstraints.Value(j)).VOrder());
    myNodeConstraints.InsertAfter(i+j-2,NewNode);
  }
}

//==========================================================================================
//function : UEquation
//purpose  : return the coefficients of the polynomial equation which approximates an iso U
//==========================================================================================

const Handle(TColStd_HArray1OfReal)& 
AdvApp2Var_Framework::UEquation(const Standard_Integer IndexIso,
				const Standard_Integer IndexStrip) const
{
  return ((myVConstraints.Value(IndexStrip)).Value(IndexIso)).Polynom();
}

//==========================================================================================
//function : VEquation
//purpose  : return the coefficients of the polynomial equation which approximates an iso V
//==========================================================================================

const Handle(TColStd_HArray1OfReal)& 
AdvApp2Var_Framework::VEquation(const Standard_Integer IndexIso,
				const Standard_Integer IndexStrip) const
{  
  return myUConstraints.Value(IndexStrip).Value(IndexIso).Polynom();
}