gekvec.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2015 Autodesk, Inc. All rights reserved.
  4. //
  5. // Use of this software is subject to the terms of the Autodesk license
  6. // agreement provided at the time of installation or download, or which
  7. // otherwise accompanies this software in either electronic or hard copy form.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. //
  11. //
  12. // DESCRIPTION:
  13. //
  14. // This file contains the class AcGeKnotVector - a dynamic array used
  15. // to represent the knot sequence of a spline. Refer to
  16. // AcGeDoubleArray for details concerning the dynamic array
  17. // behavior.
  18. #ifndef AC_GEKVEC_H
  19. #define AC_GEKVEC_H
  20. #include "gegbl.h"
  21. #include "gedblar.h"
  22. #pragma pack (push, 8)
  23. class AcGeInterval;
  24. class
  25. GE_DLLEXPIMPORT
  26. AcGeKnotVector
  27. {
  28. public:
  29. // By default it is 1.0e-9. It could be changed by API user.
  30. static double globalKnotTolerance;
  31. AcGeKnotVector(double eps = globalKnotTolerance);
  32. AcGeKnotVector(int size, int growSize, double eps = globalKnotTolerance);
  33. AcGeKnotVector(int size, const double [], double eps = globalKnotTolerance);
  34. // Elevates multiplicity of each DISTINCT knot by plusMult;
  35. // Contract: plusMul >= 0;
  36. AcGeKnotVector(int plusMult, const AcGeKnotVector& src);
  37. AcGeKnotVector(const AcGeKnotVector& src);
  38. AcGeKnotVector(const AcGeDoubleArray& src, double eps = globalKnotTolerance);
  39. ~AcGeKnotVector();
  40. // Copy operator.
  41. //
  42. AcGeKnotVector& operator = (const AcGeKnotVector& src);
  43. AcGeKnotVector& operator = (const AcGeDoubleArray& src);
  44. // Indexing into the knot vector.
  45. //
  46. double& operator [] (int);
  47. const double operator [] (int) const;
  48. // Equality test
  49. //
  50. Adesk::Boolean isEqualTo (const AcGeKnotVector& other) const;
  51. // Inquiry functions
  52. //
  53. double startParam () const;
  54. double endParam () const;
  55. int multiplicityAt (int i) const;
  56. int multiplicityAt (double param) const;
  57. int numIntervals () const;
  58. // Evaluate funtions
  59. //
  60. int getInterval (int ord, double par,
  61. AcGeInterval& interval ) const;
  62. void getDistinctKnots (AcGeDoubleArray& knots) const;
  63. Adesk::Boolean contains (double param) const;
  64. Adesk::Boolean isOn (double knot) const;
  65. // Edit function
  66. //
  67. AcGeKnotVector& reverse ();
  68. AcGeKnotVector& removeAt (int);
  69. AcGeKnotVector& removeSubVector (int startIndex, int endIndex);
  70. AcGeKnotVector& insertAt (int indx, double u,
  71. int multiplicity = 1);
  72. AcGeKnotVector& insert (double u);
  73. int append (double val);
  74. AcGeKnotVector& append (AcGeKnotVector& tail,
  75. double knotRatio = 0.);
  76. int split (double par,
  77. AcGeKnotVector* pKnot1,
  78. int multLast,
  79. AcGeKnotVector* pKnot2,
  80. int multFirst ) const;
  81. AcGeKnotVector& setRange (double lower, double upper);
  82. double tolerance () const;
  83. AcGeKnotVector& setTolerance (double tol);
  84. // Array length.
  85. //
  86. int length () const; // Logical length.
  87. Adesk::Boolean isEmpty () const;
  88. int logicalLength () const;
  89. AcGeKnotVector& setLogicalLength (int);
  90. int physicalLength () const;
  91. AcGeKnotVector& setPhysicalLength (int);
  92. // Automatic resizing.
  93. //
  94. int growLength () const;
  95. AcGeKnotVector& setGrowLength(int);
  96. // Treat as simple array of double.
  97. //
  98. const double* asArrayPtr () const;
  99. double* asArrayPtr ();
  100. AcGeKnotVector& set (int size, const double [], double eps = globalKnotTolerance);
  101. protected:
  102. AcGeDoubleArray mData;
  103. double mTolerance;
  104. Adesk::Boolean isValid (int) const;
  105. };
  106. // Inline methods.
  107. //
  108. inline double
  109. AcGeKnotVector::tolerance() const
  110. { return mTolerance;}
  111. inline AcGeKnotVector&
  112. AcGeKnotVector::setTolerance(double eps)
  113. { mTolerance = eps; return *this;}
  114. inline Adesk::Boolean
  115. AcGeKnotVector::isValid(int i) const
  116. { return i >= 0 && i < mData.logicalLength(); }
  117. inline double&
  118. AcGeKnotVector::operator [] (int i)
  119. { assert(isValid(i)); return mData[i]; }
  120. inline const double
  121. AcGeKnotVector::operator [] (int i) const
  122. { assert(isValid(i)); return mData[i]; }
  123. inline const double*
  124. AcGeKnotVector::asArrayPtr() const
  125. { return mData.asArrayPtr(); }
  126. inline double*
  127. AcGeKnotVector::asArrayPtr()
  128. { return mData.asArrayPtr(); }
  129. #pragma pack (pop)
  130. #endif