1 // Copyright (c) 2018 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _BSplCLib_CacheParams_Headerfile
15 #define _BSplCLib_CacheParams_Headerfile
17 #include <Standard_Real.hxx>
18 #include <TColStd_Array1OfReal.hxx>
20 #include <BSplCLib.hxx>
22 //! Simple structure containing parameters describing parameterization
23 //! of a B-spline curve or a surface in one direction (U or V),
24 //! and data of the current span for its caching
25 struct BSplCLib_CacheParams
27 const Standard_Integer Degree; ///< degree of Bezier/B-spline
28 const Standard_Boolean IsPeriodic; ///< true of the B-spline is periodic
29 const Standard_Real FirstParameter; ///< first valid parameter
30 const Standard_Real LastParameter; ///< last valid parameter
32 const Standard_Integer SpanIndexMin; ///< minimal index of span
33 const Standard_Integer SpanIndexMax; ///< maximal index of span
35 Standard_Real SpanStart; ///< parameter for the frst point of the span
36 Standard_Real SpanLength; ///< length of the span
37 Standard_Integer SpanIndex; ///< index of the span
39 //! Constructor, prepares data structures for caching.
40 //! \param theDegree degree of the B-spline (or Bezier)
41 //! \param thePeriodic identify whether the B-spline is periodic
42 //! \param theFlatKnots knots of Bezier / B-spline parameterization
43 BSplCLib_CacheParams (Standard_Integer theDegree, Standard_Boolean thePeriodic,
44 const TColStd_Array1OfReal& theFlatKnots)
46 IsPeriodic(thePeriodic),
47 FirstParameter(theFlatKnots.Value(theFlatKnots.Lower() + theDegree)),
48 LastParameter(theFlatKnots.Value(theFlatKnots.Upper() - theDegree)),
49 SpanIndexMin(theFlatKnots.Lower() + theDegree),
50 SpanIndexMax(theFlatKnots.Upper() - theDegree - 1),
56 //! Normalizes the parameter for periodic B-splines
57 //! \param theParameter the value to be normalized into the knots array
58 Standard_Real PeriodicNormalization (Standard_Real theParameter) const
62 if (theParameter < FirstParameter)
64 Standard_Real aPeriod = LastParameter - FirstParameter;
65 Standard_Real aScale = IntegerPart ((FirstParameter - theParameter) / aPeriod);
66 return theParameter + aPeriod * (aScale + 1.0);
68 if (theParameter > LastParameter)
70 Standard_Real aPeriod = LastParameter - FirstParameter;
71 Standard_Real aScale = IntegerPart ((theParameter - LastParameter) / aPeriod);
72 return theParameter - aPeriod * (aScale + 1.0);
78 //! Verifies validity of the cache using flat parameter of the point
79 //! \param theParameter parameter of the point placed in the span
80 Standard_Boolean IsCacheValid (Standard_Real theParameter) const
82 Standard_Real aNewParam = PeriodicNormalization (theParameter);
83 Standard_Real aDelta = aNewParam - SpanStart;
84 return ((aDelta >= 0.0 || SpanIndex == SpanIndexMin) &&
85 (aDelta < SpanLength || SpanIndex == SpanIndexMax));
88 //! Computes span for the specified parameter
89 //! \param theParameter parameter of the point placed in the span
90 //! \param theFlatKnots knots of Bezier / B-spline parameterization
91 void LocateParameter (Standard_Real& theParameter, const TColStd_Array1OfReal& theFlatKnots)
94 BSplCLib::LocateParameter (Degree, theFlatKnots, BSplCLib::NoMults(),
95 theParameter, IsPeriodic, SpanIndex, theParameter);
96 SpanStart = theFlatKnots.Value(SpanIndex);
97 SpanLength = theFlatKnots.Value(SpanIndex + 1) - SpanStart;
101 // copying is prohibited
102 BSplCLib_CacheParams (const BSplCLib_CacheParams&);
103 void operator = (const BSplCLib_CacheParams&);