0026042: OCCT won't work with the latest Xcode
[occt.git] / src / Geom / Geom_OsculatingSurface.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
42cf5bc1 14
15#include <BSplSLib.hxx>
16#include <Convert_GridPolynomialToPoles.hxx>
7fd59977 17#include <Geom_BezierSurface.hxx>
42cf5bc1 18#include <Geom_BSplineSurface.hxx>
19#include <Geom_OsculatingSurface.hxx>
20#include <Geom_Surface.hxx>
21#include <PLib.hxx>
22#include <Precision.hxx>
23#include <TColgp_Array1OfPnt.hxx>
7fd59977 24#include <TColgp_Array2OfPnt.hxx>
42cf5bc1 25#include <TColgp_Array2OfVec.hxx>
7fd59977 26#include <TColgp_HArray2OfPnt.hxx>
7fd59977 27#include <TColStd_Array1OfInteger.hxx>
42cf5bc1 28#include <TColStd_Array1OfReal.hxx>
7fd59977 29#include <TColStd_HArray1OfInteger.hxx>
42cf5bc1 30#include <TColStd_HArray1OfReal.hxx>
31#include <TColStd_HArray2OfInteger.hxx>
7fd59977 32
33//=======================================================================
34//function : Geom_OffsetOsculatingSurface
35//purpose :
36//=======================================================================
7fd59977 37Geom_OsculatingSurface::Geom_OsculatingSurface()
3d58dc49 38 : myAlong(1,4)
7fd59977 39{
40}
41//=======================================================================
42//function : Geom_OffsetOsculatingSurface
43//purpose :
44//=======================================================================
45
46Geom_OsculatingSurface::Geom_OsculatingSurface(const Handle(Geom_Surface)& BS,
3d58dc49 47 const Standard_Real Tol)
48 : myAlong(1,4)
7fd59977 49{
50 Init(BS,Tol);
51}
52
53//=======================================================================
54//function : Init
55//purpose :
56//=======================================================================
57
58void Geom_OsculatingSurface::Init(const Handle(Geom_Surface)& BS,
3d58dc49 59 const Standard_Real Tol)
7fd59977 60{
61 ClearOsculFlags();
62 myTol=Tol;
c15398ab 63 Standard_Real TolMin=0.;//consider all singularities below Tol, not just above 1.e-12 (id23943)
7fd59977 64 Standard_Boolean OsculSurf = Standard_True;
65 myBasisSurf = Handle(Geom_Surface)::DownCast(BS->Copy());
66 myOsculSurf1 = new Geom_HSequenceOfBSplineSurface();
67 myOsculSurf2 = new Geom_HSequenceOfBSplineSurface();
68 if ((BS->IsKind(STANDARD_TYPE(Geom_BSplineSurface))) ||
3d58dc49 69 (BS->IsKind(STANDARD_TYPE(Geom_BezierSurface))))
70 {
71 Standard_Real U1=0,U2=0,V1=0,V2=0;
72
73 Standard_Integer i = 1;
74 BS->Bounds(U1,U2,V1,V2);
75 myAlong.SetValue(1,IsQPunctual(BS,V1,GeomAbs_IsoV,TolMin,Tol));
76 myAlong.SetValue(2,IsQPunctual(BS,V2,GeomAbs_IsoV,TolMin,Tol));
77 myAlong.SetValue(3,IsQPunctual(BS,U1,GeomAbs_IsoU,TolMin,Tol));
78 myAlong.SetValue(4,IsQPunctual(BS,U2,GeomAbs_IsoU,TolMin,Tol));
0797d9d3 79#ifdef OCCT_DEBUG
3d58dc49 80 cout<<myAlong(1)<<endl<<myAlong(2)<<endl<<myAlong(3)<<endl<<myAlong(4)<<endl;
7fd59977 81#endif
3d58dc49 82 if (myAlong(1) || myAlong(2) || myAlong(3) || myAlong(4))
83 {
84 Handle(Geom_BSplineSurface) InitSurf, L,S;
85 if (BS->IsKind(STANDARD_TYPE(Geom_BezierSurface)))
86 {
87 Handle(Geom_BezierSurface) BzS = Handle(Geom_BezierSurface)::DownCast(BS);
88 TColgp_Array2OfPnt P(1,BzS->NbUPoles(),1,BzS->NbVPoles());
89 TColStd_Array1OfReal UKnots(1,2);
90 TColStd_Array1OfReal VKnots(1,2);
91 TColStd_Array1OfInteger UMults(1,2);
92 TColStd_Array1OfInteger VMults(1,2);
93 for (i=1;i<=2;i++)
94 {
95 UKnots.SetValue(i,(i-1));
96 VKnots.SetValue(i,(i-1));
97 UMults.SetValue(i,BzS->UDegree()+1);
98 VMults.SetValue(i,BzS->VDegree()+1);
99 }
100 BzS->Poles(P);
101 InitSurf = new Geom_BSplineSurface(P,UKnots,VKnots,
102 UMults,VMults,
103 BzS->UDegree(),
104 BzS->VDegree(),
105 BzS->IsUPeriodic(),
106 BzS->IsVPeriodic());
107 }
108 else
109 {
110 InitSurf = Handle(Geom_BSplineSurface)::DownCast(myBasisSurf);
111 }
0797d9d3 112#ifdef OCCT_DEBUG
3d58dc49 113 cout<<"UDEG: "<<InitSurf->UDegree()<<endl;
114 cout<<"VDEG: "<<InitSurf->VDegree()<<endl;
7fd59977 115#endif
3d58dc49 116
117 if(IsAlongU() && IsAlongV()) ClearOsculFlags();
118 // Standard_ConstructionError_Raise_if((IsAlongU() && IsAlongV()),"Geom_OsculatingSurface");
119 if ((IsAlongU() && InitSurf->VDegree()>1) ||
120 (IsAlongV() && InitSurf->UDegree()>1))
121 {
122 myKdeg = new TColStd_HSequenceOfInteger();
123 Standard_Integer k=0;
124 Standard_Boolean IsQPunc;
125 Standard_Integer UKnot,VKnot;
126 if (myAlong(1) || myAlong(2))
127 {
128 for (i=1;i<InitSurf->NbUKnots();i++)
129 {
130 if (myAlong(1))
131 {
132 S = InitSurf; k=0; IsQPunc=Standard_True;
133 UKnot=i;
134 VKnot=1;
135 while(IsQPunc)
136 {
137 OsculSurf = BuildOsculatingSurface(V1,UKnot,VKnot,S,L);
138 if(!OsculSurf) break;
139 k++;
0797d9d3 140#ifdef OCCT_DEBUG
3d58dc49 141 cout<<"1.k = "<<k<<endl;
7fd59977 142#endif
3d58dc49 143 IsQPunc=IsQPunctual(L,V1,GeomAbs_IsoV,0.,Tol);
144 UKnot=1;
145 VKnot=1;
146 S=L;
147
148 }
149 if (OsculSurf)
150 myOsculSurf1->Append(L);
151 else
152 ClearOsculFlags(); //myAlong.SetValue(1,Standard_False);
153 if (myAlong(2) && OsculSurf)
154 {
155 S = InitSurf; k=0; IsQPunc=Standard_True;
156 UKnot=i;
157 VKnot=InitSurf->NbVKnots()-1;
158
159 while(IsQPunc)
160 {
161 OsculSurf = BuildOsculatingSurface(V2,UKnot,VKnot,S,L);
162 if(!OsculSurf) break;
163 k++;
0797d9d3 164#ifdef OCCT_DEBUG
3d58dc49 165 cout<<"2.k = "<<k<<endl;
7fd59977 166#endif
3d58dc49 167 IsQPunc=IsQPunctual(L,V2,GeomAbs_IsoV,0.,Tol);
168 UKnot=1;
169 VKnot=1;
170 S=L;
171 }
172 if(OsculSurf)
173 {
174 myOsculSurf2->Append(L);
175 myKdeg->Append(k);
176 }
177 }
178 }
179 else
180 //if (myAlong(2))
181 {
182 S = InitSurf; k=0; IsQPunc=Standard_True;
183 UKnot=i;
184 VKnot=InitSurf->NbVKnots()-1;
185 while(IsQPunc)
186 {
187 OsculSurf = BuildOsculatingSurface(V2,UKnot,VKnot,S,L);
188 if(!OsculSurf) break;
189 k++;
0797d9d3 190#ifdef OCCT_DEBUG
3d58dc49 191 cout<<"2.k = "<<k<<endl;
7fd59977 192#endif
3d58dc49 193 IsQPunc=IsQPunctual(L,V2,GeomAbs_IsoV,0.,Tol);
194 UKnot=1;
195 VKnot=1;
196 S=L;
197
198 }
199 if(OsculSurf)
200 {
201 myOsculSurf2->Append(L);
202 myKdeg->Append(k);
203 }
204 else
205 ClearOsculFlags(); //myAlong.SetValue(2,Standard_False);
206 }
207 }
208 }
209 if (myAlong(3) || myAlong(4))
210 {
211 for (i=1;i<InitSurf->NbVKnots();i++)
212 {
213 if (myAlong(3))
214 {
215 S = InitSurf; k=0; IsQPunc=Standard_True;
216 UKnot=1;
217 VKnot=i;
218 while(IsQPunc)
219 {
220 OsculSurf = BuildOsculatingSurface(U1,UKnot,VKnot,S,L);
221 if(!OsculSurf) break;
222 k++;
0797d9d3 223#ifdef OCCT_DEBUG
3d58dc49 224 cout<<"1.k = "<<k<<endl;
7fd59977 225#endif
3d58dc49 226 IsQPunc=IsQPunctual(L,U1,GeomAbs_IsoU,0.,Tol);
227 UKnot=1;
228 VKnot=1;
229 S=L;
230 }
231 if(OsculSurf)
232 myOsculSurf1->Append(L);
233 else
234 ClearOsculFlags(); //myAlong.SetValue(3,Standard_False);
235 if (myAlong(4) && OsculSurf )
236 {
237 S = InitSurf; k=0; IsQPunc=Standard_True;
238 UKnot=InitSurf->NbUKnots()-1;
239 VKnot=i;
240 while(IsQPunc)
241 {
242 OsculSurf = BuildOsculatingSurface(U2,UKnot,VKnot,S,L);
243 if(!OsculSurf) break;
244 k++;
0797d9d3 245#ifdef OCCT_DEBUG
3d58dc49 246 cout<<"2.k = "<<k<<endl;
7fd59977 247#endif
3d58dc49 248 IsQPunc=IsQPunctual(L,U2,GeomAbs_IsoU,0.,Tol);
249 UKnot=1;
250 VKnot=1;
251 S=L;
252 }
253 if(OsculSurf)
254 {
255 myOsculSurf2->Append(L);
256 myKdeg->Append(k);
257 }
258 }
259 }
260 else
261 {
262 S = InitSurf; k=0; IsQPunc=Standard_True;
263 UKnot=InitSurf->NbUKnots()-1;
264 VKnot=i;
265 while(IsQPunc)
266 {
267 OsculSurf = BuildOsculatingSurface(U2,UKnot,VKnot,S,L);
268 if(!OsculSurf) break;
269 k++;
0797d9d3 270#ifdef OCCT_DEBUG
3d58dc49 271 cout<<"2.k = "<<k<<endl;
7fd59977 272#endif
3d58dc49 273 IsQPunc=IsQPunctual(L,U2,GeomAbs_IsoU,0.,Tol);
274 UKnot=1;
275 VKnot=1;
276 S=L;
277 }
278 if(OsculSurf)
279 {
280 myOsculSurf2->Append(L);
281 myKdeg->Append(k);
282 }
283 else
284 ClearOsculFlags(); //myAlong.SetValue(4,Standard_False);
285 }
286 }
287 }
288 }
289 else
290 {
291 ClearOsculFlags();
292 }
7fd59977 293 }
3d58dc49 294 }
7fd59977 295 else
296 ClearOsculFlags();
297}
298
299//=======================================================================
300//function : BasisSurface
301//purpose :
302//=======================================================================
303
3d58dc49 304Handle(Geom_Surface) Geom_OsculatingSurface::BasisSurface() const
7fd59977 305{
306 return myBasisSurf;
307}
308
309//=======================================================================
310//function : Tolerance
311//purpose :
312//=======================================================================
313
314Standard_Real Geom_OsculatingSurface::Tolerance() const
315{
316 return myTol;
317}
318
319//=======================================================================
320//function : UOscSurf
321//purpose :
322//=======================================================================
323
324Standard_Boolean Geom_OsculatingSurface::UOscSurf
3d58dc49 325 (const Standard_Real U,
326 const Standard_Real V,
327 Standard_Boolean& t,
328 Handle(Geom_BSplineSurface)& L) const
7fd59977 329{
330 Standard_Boolean along = Standard_False;
331 if (myAlong(1) || myAlong(2))
332 {
333 Standard_Integer NU = 1, NV = 1;
334 Standard_Real u1,u2,v1,v2;
335 t = Standard_False;
336 myBasisSurf->Bounds(u1,u2,v1,v2);
337 Standard_Integer NbUK,NbVK;
338 Standard_Boolean isToSkipSecond = Standard_False;
339 if (myBasisSurf->IsKind(STANDARD_TYPE(Geom_BSplineSurface)))
340 {
341 Handle(Geom_BSplineSurface) BSur =
c5f3a425 342 Handle(Geom_BSplineSurface)::DownCast (myBasisSurf);
7fd59977 343 NbUK = BSur->NbUKnots();
344 NbVK = BSur->NbVKnots();
345 TColStd_Array1OfReal UKnots(1,NbUK);
346 TColStd_Array1OfReal VKnots(1,NbVK);
347 BSur->UKnots(UKnots);
348 BSur->VKnots(VKnots);
349 BSplCLib::Hunt(UKnots,U,NU);
350 BSplCLib::Hunt(VKnots,V,NV);
351 if (NU < 1) NU=1;
352 if (NU >= NbUK) NU=NbUK-1;
353 if (NbVK==2 && NV==1)
3d58dc49 354 // Need to find the closest end
355 if (VKnots(NbVK)-V > V-VKnots(1))
356 isToSkipSecond = Standard_True;
7fd59977 357 }
358 else {NU = 1; NV = 1 ; NbVK = 2 ;}
359
360 if (myAlong(1) && NV == 1)
361 {
362 L = *((Handle(Geom_BSplineSurface)*)& myOsculSurf1->Value(NU));
363 along = Standard_True;
364 }
365 if (myAlong(2) && (NV == NbVK-1) && !isToSkipSecond)
366 {
367 // t means that derivative vector of osculating surface is opposite
368 // to the original. This happens when (v-t)^k is negative, i.e.
369 // difference between degrees (k) is odd and t is the last parameter
370 if (myKdeg->Value(NU)%2) t = Standard_True;
371 L = *((Handle(Geom_BSplineSurface)*)& myOsculSurf2->Value(NU));
372 along = Standard_True;
373 }
374 }
375 return along;
376}
377
378//=======================================================================
379//function : VOscSurf
380//purpose :
381//=======================================================================
382
383Standard_Boolean Geom_OsculatingSurface::VOscSurf
3d58dc49 384 (const Standard_Real U,
385 const Standard_Real V,
386 Standard_Boolean& t,
387 Handle(Geom_BSplineSurface)& L) const
7fd59977 388{
389 Standard_Boolean along = Standard_False;
390 if (myAlong(3) || myAlong(4))
391 {
392 Standard_Integer NU = 1, NV = 1;
393 Standard_Real u1,u2,v1,v2;
394 t = Standard_False;
395 myBasisSurf->Bounds(u1,u2,v1,v2);
396 Standard_Integer NbUK,NbVK;
397 Standard_Boolean isToSkipSecond = Standard_False;
398 if (myBasisSurf->IsKind(STANDARD_TYPE(Geom_BSplineSurface)))
399 {
400 Handle(Geom_BSplineSurface) BSur =
c5f3a425 401 Handle(Geom_BSplineSurface)::DownCast (myBasisSurf);
7fd59977 402 NbUK = BSur->NbUKnots();
403 NbVK = BSur->NbVKnots();
404 TColStd_Array1OfReal UKnots(1,NbUK);
405 TColStd_Array1OfReal VKnots(1,NbVK);
406 BSur->UKnots(UKnots);
407 BSur->VKnots(VKnots);
408 BSplCLib::Hunt(UKnots,U,NU);
409 BSplCLib::Hunt(VKnots,V,NV);
410 if (NV < 1) NV=1;
411 if (NV >= NbVK) NV=NbVK-1;
412 if (NbUK==2 && NU==1)
3d58dc49 413 // Need to find the closest end
414 if (UKnots(NbUK)-U > U-UKnots(1))
415 isToSkipSecond = Standard_True;
7fd59977 416 }
417 else {NU = 1; NV = 1 ; NbUK = 2;}
418
419 if (myAlong(3) && NU == 1)
420 {
421 L = *((Handle(Geom_BSplineSurface)*)& myOsculSurf1->Value(NV));
422 along = Standard_True;
423 }
424 if (myAlong(4) && (NU == NbUK-1) && !isToSkipSecond)
425 {
426 if (myKdeg->Value(NV)%2) t = Standard_True;
427 L = *((Handle(Geom_BSplineSurface)*)& myOsculSurf2->Value(NV));
428 along = Standard_True;
429 }
430 }
431 return along;
432}
433
434//=======================================================================
435//function : BuildOsculatingSurface
436//purpose :
437//=======================================================================
438
439Standard_Boolean Geom_OsculatingSurface::BuildOsculatingSurface
3d58dc49 440 (const Standard_Real Param,
441 const Standard_Integer SUKnot,
442 const Standard_Integer SVKnot,
443 const Handle(Geom_BSplineSurface)& BS,
444 Handle(Geom_BSplineSurface)& BSpl) const
7fd59977 445{
446 Standard_Integer i, j;
447 Standard_Boolean OsculSurf=Standard_True;
0797d9d3 448#ifdef OCCT_DEBUG
7fd59977 449 cout<<"t = "<<Param<<endl;
450 cout<<"======================================"<<endl<<endl;
451#endif
452
3d58dc49 453 // for cache
7fd59977 454 Standard_Integer MinDegree,
3d58dc49 455 MaxDegree ;
7fd59977 456 Standard_Real udeg, vdeg;
457 udeg = BS->UDegree();
458 vdeg = BS->VDegree();
459 if( (IsAlongU() && vdeg <=1) || (IsAlongV() && udeg <=1))
460 {
0797d9d3 461#ifdef OCCT_DEBUG
3d58dc49 462 cout<<" surface osculatrice nulle "<<endl;
7fd59977 463#endif
3d58dc49 464 //Standard_ConstructionError::Raise("Geom_OsculatingSurface");
465 OsculSurf=Standard_False;
7fd59977 466 }
467 else
468 {
3d58dc49 469 MinDegree = (Standard_Integer ) Min(udeg,vdeg) ;
470 MaxDegree = (Standard_Integer ) Max(udeg,vdeg) ;
471
472 TColgp_Array2OfPnt cachepoles(1, MaxDegree + 1, 1, MinDegree + 1);
473 // end for cache
474
475 // for polynomial grid
476 Standard_Integer MaxUDegree, MaxVDegree;
477 Standard_Integer UContinuity, VContinuity;
478
479 Handle(TColStd_HArray2OfInteger) NumCoeffPerSurface =
480 new TColStd_HArray2OfInteger(1, 1, 1, 2);
481 Handle(TColStd_HArray1OfReal) PolynomialUIntervals =
482 new TColStd_HArray1OfReal(1, 2);
483 Handle(TColStd_HArray1OfReal) PolynomialVIntervals =
484 new TColStd_HArray1OfReal(1, 2);
485 Handle(TColStd_HArray1OfReal) TrueUIntervals =
486 new TColStd_HArray1OfReal(1, 2);
487 Handle(TColStd_HArray1OfReal) TrueVIntervals =
488 new TColStd_HArray1OfReal(1, 2);
489 MaxUDegree = (Standard_Integer ) udeg;
490 MaxVDegree = (Standard_Integer ) vdeg;
491
492 for (i=1;i<=2;i++)
493 {
494 PolynomialUIntervals->ChangeValue(i) = i-1;
495 PolynomialVIntervals->ChangeValue(i) = i-1;
496 TrueUIntervals->ChangeValue(i) = BS->UKnot(SUKnot+i-1);
497 TrueVIntervals->ChangeValue(i) = BS->VKnot(SVKnot+i-1);
498 }
7fd59977 499
500
3d58dc49 501 Standard_Integer OscUNumCoeff=0, OscVNumCoeff=0;
502 if (IsAlongU())
503 {
0797d9d3 504#ifdef OCCT_DEBUG
3d58dc49 505 cout<<">>>>>>>>>>> AlongU"<<endl;
7fd59977 506#endif
3d58dc49 507 OscUNumCoeff = (Standard_Integer ) udeg + 1;
508 OscVNumCoeff = (Standard_Integer ) vdeg;
509 }
510 if (IsAlongV())
511 {
0797d9d3 512#ifdef OCCT_DEBUG
3d58dc49 513 cout<<">>>>>>>>>>> AlongV"<<endl;
7fd59977 514#endif
3d58dc49 515 OscUNumCoeff = (Standard_Integer ) udeg;
516 OscVNumCoeff = (Standard_Integer ) vdeg + 1;
517 }
518 NumCoeffPerSurface->ChangeValue(1,1) = OscUNumCoeff;
519 NumCoeffPerSurface->ChangeValue(1,2) = OscVNumCoeff;
520 Standard_Integer nbc = NumCoeffPerSurface->Value(1,1)*NumCoeffPerSurface->Value(1,2)*3;
521 //
522 if(nbc == 0)
523 {
524 return Standard_False;
525 }
526 //
527 Handle(TColStd_HArray1OfReal) Coefficients = new TColStd_HArray1OfReal(1, nbc);
528 // end for polynomial grid
529
530 // building the cache
531 Standard_Integer ULocalIndex, VLocalIndex;
532 Standard_Real ucacheparameter, vcacheparameter,uspanlength, vspanlength;
533 TColgp_Array2OfPnt NewPoles(1, BS->NbUPoles(), 1, BS->NbVPoles());
534
535 Standard_Integer aUfKnotsLength = BS->NbUPoles() + BS->UDegree() + 1;
536 Standard_Integer aVfKnotsLength = BS->NbVPoles() + BS->VDegree() + 1;
537
538 if(BS->IsUPeriodic())
539 {
540 TColStd_Array1OfInteger aMults(1, BS->NbUKnots());
541 BS->UMultiplicities(aMults);
542 aUfKnotsLength = BSplCLib::KnotSequenceLength(aMults, BS->UDegree(), Standard_True);
543 }
544
545 if(BS->IsVPeriodic())
546 {
547 TColStd_Array1OfInteger aMults(1, BS->NbVKnots());
548 BS->VMultiplicities(aMults);
549 aVfKnotsLength = BSplCLib::KnotSequenceLength(aMults, BS->VDegree(), Standard_True);
550 }
551
552 TColStd_Array1OfReal UFlatKnots(1, aUfKnotsLength);
553 TColStd_Array1OfReal VFlatKnots(1, aVfKnotsLength);
554 BS->Poles(NewPoles);
555 BS->UKnotSequence(UFlatKnots);
556 BS->VKnotSequence(VFlatKnots);
557
558 VLocalIndex = 0;
559 ULocalIndex = 0;
560 for(j = 1; j <= SVKnot; j++) VLocalIndex += BS->VMultiplicity(j);
561 for(i = 1; i <= SUKnot; i++) ULocalIndex += BS->UMultiplicity(i);
562 ucacheparameter = BS->UKnot(SUKnot);
563 vcacheparameter = BS->VKnot(SVKnot);
564 vspanlength = BS->VKnot(SVKnot + 1) - BS->VKnot(SVKnot);
565 uspanlength = BS->UKnot(SUKnot + 1) - BS->UKnot(SUKnot);
566
567 // On se ramene toujours a un parametrage tel que localement ce soit l'iso
568 // u=0 ou v=0 qui soit degeneree
569
570 Standard_Boolean IsVNegative = Param > vcacheparameter + vspanlength/2;
571 Standard_Boolean IsUNegative = Param > ucacheparameter + uspanlength/2;
572
573 if (IsAlongU() && (Param > vcacheparameter + vspanlength/2))
574 vcacheparameter = vcacheparameter + vspanlength;
575 if (IsAlongV() && (Param > ucacheparameter + uspanlength/2))
576 ucacheparameter = ucacheparameter + uspanlength;
577
578 BSplSLib::BuildCache(ucacheparameter,
579 vcacheparameter,
580 uspanlength,
581 vspanlength,
582 BS->IsUPeriodic(),
583 BS->IsVPeriodic(),
584 BS->UDegree(),
585 BS->VDegree(),
586 ULocalIndex,
587 VLocalIndex,
588 UFlatKnots,
589 VFlatKnots,
590 NewPoles,
591 BSplSLib::NoWeights(),
592 cachepoles,
593 BSplSLib::NoWeights());
594 Standard_Integer m, n, index;
595 TColgp_Array2OfPnt OscCoeff(1,OscUNumCoeff , 1, OscVNumCoeff);
596
597 if (IsAlongU())
598 {
599 if (udeg > vdeg)
600 {
601 for(n = 1; n <= udeg + 1; n++)
602 for(m = 1; m <= vdeg; m++)
603 OscCoeff(n,m) = cachepoles(n,m+1) ;
604 }
605 else
606 {
607 for(n = 1; n <= udeg + 1; n++)
608 for(m = 1; m <= vdeg; m++)
609 OscCoeff(n,m) = cachepoles(m+1,n) ;
7fd59977 610 }
3d58dc49 611 if (IsVNegative) PLib::VTrimming(-1,0,OscCoeff,PLib::NoWeights2());
612
613 index=1;
614 for(n = 1; n <= udeg + 1; n++)
615 for(m = 1; m <= vdeg; m++)
616 {
617 Coefficients->ChangeValue(index++) = OscCoeff(n,m).X();
618 Coefficients->ChangeValue(index++) = OscCoeff(n,m).Y();
619 Coefficients->ChangeValue(index++) = OscCoeff(n,m).Z();
620 }
621 }
622
623 if (IsAlongV())
624 {
625 if (udeg > vdeg)
626 {
627 for(n = 1; n <= udeg; n++)
628 for(m = 1; m <= vdeg + 1; m++)
629 OscCoeff(n,m) = cachepoles(n+1,m);
630 }
631 else
632 {
633 for(n = 1; n <= udeg; n++)
634 for(m = 1; m <= vdeg + 1; m++)
635 OscCoeff(n,m) = cachepoles(m,n+1);
636 }
637 if (IsUNegative) PLib::UTrimming(-1,0,OscCoeff,PLib::NoWeights2());
638 index=1;
639 for(n = 1; n <= udeg; n++)
640 for(m = 1; m <= vdeg + 1; m++)
641 {
642 Coefficients->ChangeValue(index++) = OscCoeff(n,m).X();
643 Coefficients->ChangeValue(index++) = OscCoeff(n,m).Y();
644 Coefficients->ChangeValue(index++) = OscCoeff(n,m).Z();
645 }
646 }
647
648 if (IsAlongU()) MaxVDegree--;
649 if (IsAlongV()) MaxUDegree--;
650 UContinuity = - 1;
651 VContinuity = - 1;
652
653 Convert_GridPolynomialToPoles Data(1,1,
654 UContinuity,
655 VContinuity,
656 MaxUDegree,
657 MaxVDegree,
658 NumCoeffPerSurface,
659 Coefficients,
660 PolynomialUIntervals,
661 PolynomialVIntervals,
662 TrueUIntervals,
663 TrueVIntervals);
664
665 // Handle(Geom_BSplineSurface) BSpl =
666 BSpl =new Geom_BSplineSurface(Data.Poles()->Array2(),
667 Data.UKnots()->Array1(),
668 Data.VKnots()->Array1(),
669 Data.UMultiplicities()->Array1(),
670 Data.VMultiplicities()->Array1(),
671 Data.UDegree(),
672 Data.VDegree(),
673 0, 0);
0797d9d3 674#ifdef OCCT_DEBUG
3d58dc49 675 cout<<"^====================================^"<<endl<<endl;
7fd59977 676#endif
677
3d58dc49 678 // L=BSpl;
679 }
7fd59977 680 return OsculSurf;
681}
682
683//=======================================================================
684//function : IsQPunctual
685//purpose :
686//=======================================================================
687
688Standard_Boolean Geom_OsculatingSurface::IsQPunctual
3d58dc49 689 (const Handle(Geom_Surface)& S,
690 const Standard_Real Param,
691 const GeomAbs_IsoType IT,
692 const Standard_Real TolMin,
693 const Standard_Real TolMax) const
7fd59977 694{
3d58dc49 695 Standard_Real U1=0,U2=0,V1=0,V2=0,T;
696 Standard_Boolean Along = Standard_True;
697 S->Bounds(U1,U2,V1,V2);
698 gp_Vec D1U,D1V;
699 gp_Pnt P;
700 Standard_Real Step,D1NormMax;
701 if (IT == GeomAbs_IsoV)
702 {
703 Step = (U2 - U1)/10;
704 D1NormMax=0.;
705 for (T=U1;T<=U2;T=T+Step)
7fd59977 706 {
3d58dc49 707 S->D1(T,Param,P,D1U,D1V);
708 D1NormMax=Max(D1NormMax,D1U.Magnitude());
709 }
7fd59977 710
0797d9d3 711#ifdef OCCT_DEBUG
3d58dc49 712 cout << " D1NormMax = " << D1NormMax << endl;
7fd59977 713#endif
3d58dc49 714 if (D1NormMax >TolMax || D1NormMax < TolMin )
715 Along = Standard_False;
716 }
717 else
718 {
719 Step = (V2 - V1)/10;
720 D1NormMax=0.;
721 for (T=V1;T<=V2;T=T+Step)
7fd59977 722 {
3d58dc49 723 S->D1(Param,T,P,D1U,D1V);
724 D1NormMax=Max(D1NormMax,D1V.Magnitude());
725 }
0797d9d3 726#ifdef OCCT_DEBUG
3d58dc49 727 cout << " D1NormMax = " << D1NormMax << endl;
7fd59977 728#endif
3d58dc49 729 if (D1NormMax >TolMax || D1NormMax < TolMin )
730 Along = Standard_False;
7fd59977 731
732
3d58dc49 733 }
734 return Along;
7fd59977 735}
736
737//=======================================================================
738//function : HasOscSurf
739//purpose :
740//=======================================================================
741
3d58dc49 742Standard_Boolean Geom_OsculatingSurface::HasOscSurf() const
7fd59977 743{
744 return (myAlong(1) || myAlong(2) || myAlong(3) || myAlong(4));
745}
746
747//=======================================================================
748//function : IsAlongU
749//purpose :
750//=======================================================================
751
752Standard_Boolean Geom_OsculatingSurface::IsAlongU() const
753{
754 return (myAlong(1) || myAlong(2));
755}
756//=======================================================================
757//function : IsAlongV
758//purpose :
759//=======================================================================
760
761Standard_Boolean Geom_OsculatingSurface::IsAlongV() const
762{
763 return (myAlong(3) || myAlong(4));
764}
765
766
767//=======================================================================
768//function : IsGetSeqOfL1
769//purpose :
770//=======================================================================
771
772const Geom_SequenceOfBSplineSurface& Geom_OsculatingSurface::GetSeqOfL1() const
773{
774 return myOsculSurf1->Sequence();
775}
776//=======================================================================
777//function : IsGetSeqOfL2
778//purpose :
779//=======================================================================
780
781const Geom_SequenceOfBSplineSurface& Geom_OsculatingSurface::GetSeqOfL2() const
782{
783 return myOsculSurf2->Sequence();
784}
785//=======================================================================
786//function : ClearOsculFlags
787//purpose :
788//=======================================================================
789
790void Geom_OsculatingSurface::ClearOsculFlags()
791{
3d58dc49 792 myAlong.SetValue(1,Standard_False);
793 myAlong.SetValue(2,Standard_False);
794 myAlong.SetValue(3,Standard_False);
795 myAlong.SetValue(4,Standard_False);
7fd59977 796
797}
798
799
800