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