Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:18

0001 // Copyright (c) 2018 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _BSplCLib_CacheParams_Headerfile
0015 #define _BSplCLib_CacheParams_Headerfile
0016 
0017 #include <BSplCLib.hxx>
0018 
0019 //! Simple structure containing parameters describing parameterization
0020 //! of a B-spline curve or a surface in one direction (U or V),
0021 //! and data of the current span for its caching
0022 struct BSplCLib_CacheParams
0023 {
0024   const Standard_Integer Degree;      ///< degree of Bezier/B-spline
0025   const Standard_Boolean IsPeriodic;  ///< true of the B-spline is periodic
0026   const Standard_Real FirstParameter; ///< first valid parameter
0027   const Standard_Real LastParameter;  ///< last valid parameter
0028 
0029   const Standard_Integer SpanIndexMin; ///< minimal index of span
0030   const Standard_Integer SpanIndexMax; ///< maximal index of span
0031 
0032   Standard_Real    SpanStart;    ///< parameter for the frst point of the span
0033   Standard_Real    SpanLength;   ///< length of the span
0034   Standard_Integer SpanIndex;    ///< index of the span
0035 
0036   //! Constructor, prepares data structures for caching.
0037   //! \param theDegree     degree of the B-spline (or Bezier)
0038   //! \param thePeriodic   identify whether the B-spline is periodic
0039   //! \param theFlatKnots  knots of Bezier / B-spline parameterization
0040   BSplCLib_CacheParams (Standard_Integer theDegree, Standard_Boolean thePeriodic,
0041                         const TColStd_Array1OfReal& theFlatKnots)
0042   : Degree(theDegree),
0043     IsPeriodic(thePeriodic),
0044     FirstParameter(theFlatKnots.Value(theFlatKnots.Lower() + theDegree)),
0045     LastParameter(theFlatKnots.Value(theFlatKnots.Upper() - theDegree)),
0046     SpanIndexMin(theFlatKnots.Lower() + theDegree),
0047     SpanIndexMax(theFlatKnots.Upper() - theDegree - 1),
0048     SpanStart(0.),
0049     SpanLength(0.),
0050     SpanIndex(0)
0051   {}
0052 
0053   //! Normalizes the parameter for periodic B-splines
0054   //! \param theParameter the value to be normalized into the knots array
0055   Standard_Real PeriodicNormalization (Standard_Real theParameter) const
0056   {
0057     if (IsPeriodic)
0058     {
0059       if (theParameter < FirstParameter)
0060       {
0061         Standard_Real aPeriod = LastParameter - FirstParameter;
0062         Standard_Real aScale = IntegerPart ((FirstParameter - theParameter) / aPeriod);
0063         return theParameter + aPeriod * (aScale + 1.0);
0064       }
0065       if (theParameter > LastParameter)
0066       {
0067         Standard_Real aPeriod = LastParameter - FirstParameter;
0068         Standard_Real aScale = IntegerPart ((theParameter - LastParameter) / aPeriod);
0069         return theParameter - aPeriod * (aScale + 1.0);
0070       }
0071     }
0072     return theParameter;
0073   }
0074 
0075   //! Verifies validity of the cache using flat parameter of the point
0076   //! \param theParameter parameter of the point placed in the span
0077   Standard_Boolean IsCacheValid (Standard_Real theParameter) const
0078   {
0079     Standard_Real aNewParam = PeriodicNormalization  (theParameter);
0080     Standard_Real aDelta = aNewParam - SpanStart;
0081     return ((aDelta >= 0.0 || SpanIndex == SpanIndexMin) &&
0082             (aDelta < SpanLength || SpanIndex == SpanIndexMax));
0083   }
0084 
0085   //! Computes span for the specified parameter
0086   //! \param theParameter parameter of the point placed in the span
0087   //! \param theFlatKnots  knots of Bezier / B-spline parameterization
0088   void LocateParameter (Standard_Real& theParameter, const TColStd_Array1OfReal& theFlatKnots)
0089   {
0090     SpanIndex = 0;
0091     BSplCLib::LocateParameter (Degree, theFlatKnots, BSplCLib::NoMults(), 
0092                                theParameter, IsPeriodic, SpanIndex, theParameter);
0093     SpanStart  = theFlatKnots.Value(SpanIndex);
0094     SpanLength = theFlatKnots.Value(SpanIndex + 1) - SpanStart;
0095   }
0096 
0097 private:
0098   // copying is prohibited
0099   BSplCLib_CacheParams (const BSplCLib_CacheParams&);
0100   void operator = (const BSplCLib_CacheParams&);
0101 };
0102 
0103 #endif