Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
2.9 KiB

  1. /**************************************************************************
  2. * *
  3. * Copyright (C) 1992, Silicon Graphics, Inc. *
  4. * *
  5. * These coded instructions, statements, and computer programs contain *
  6. * unpublished proprietary information of Silicon Graphics, Inc., and *
  7. * are protected by Federal copyright law. They may not be disclosed *
  8. * to third parties or copied or duplicated in any form, in whole or *
  9. * in part, without the prior written consent of Silicon Graphics, Inc. *
  10. * *
  11. **************************************************************************/
  12. /*
  13. * knotvector.c++ - $Revision: 1.5 $
  14. * Derrick Burns - 1991
  15. */
  16. #include "glimport.h"
  17. #include "mystdio.h"
  18. #include "myassert.h"
  19. #include "knotvect.h"
  20. #include "defines.h"
  21. void Knotvector::init( long _knotcount, long _stride, long _order, INREAL *_knotlist )
  22. {
  23. knotcount = _knotcount;
  24. stride = _stride;
  25. order = _order;
  26. knotlist = new Knot[_knotcount];
  27. assert( knotlist != 0 );
  28. for( int i = 0; i != _knotcount; i++ )
  29. knotlist[i] = (Knot) _knotlist[i];
  30. }
  31. Knotvector::Knotvector( void )
  32. {
  33. knotlist = 0;
  34. }
  35. Knotvector::~Knotvector( void )
  36. {
  37. if( knotlist ) delete[] knotlist;
  38. }
  39. int Knotvector::validate( void )
  40. {
  41. /* kindex is used as an array index so subtract one first,
  42. * this propagates throughout the code so study carefully */
  43. long kindex = knotcount-1;
  44. if( order < 1 || order > MAXORDER ) {
  45. // spline order un-supported
  46. return( 1 );
  47. }
  48. if( knotcount < (2 * order) ) {
  49. // too few knots
  50. return( 2 );
  51. }
  52. if( identical( knotlist[kindex-(order-1)], knotlist[order-1]) ) {
  53. // valid knot range is empty
  54. return( 3 );
  55. }
  56. for( long i = 0; i < kindex; i++)
  57. if( knotlist[i] > knotlist[i+1] ) {
  58. // decreasing knot sequence
  59. return( 4 );
  60. }
  61. /* check for valid multiplicity */
  62. /* kindex is currently the index of the last knot.
  63. * In the next loop it is decremented to ignore the last knot
  64. * and the loop stops when kindex is 2 so as to ignore the first
  65. * knot as well. These knots are not used in computing
  66. * knot multiplicities.
  67. */
  68. long multi = 1;
  69. for( ; kindex >= 1; kindex-- ) {
  70. if( knotlist[kindex] - knotlist[kindex-1] < TOLERANCE ) {
  71. multi++;
  72. continue;
  73. }
  74. if ( multi > order ) {
  75. // knot multiplicity greater than order of spline
  76. return( 5 );
  77. }
  78. multi = 1;
  79. }
  80. if ( multi > order ) {
  81. // knot multiplicity greater than order of spline
  82. return( 5 );
  83. }
  84. return 0;
  85. }
  86. void Knotvector::show( char *msg )
  87. {
  88. #ifndef NDEBUG
  89. dprintf( "%s\n", msg );
  90. dprintf( "order = %ld, count = %ld\n", order, knotcount );
  91. for( int i=0; i<knotcount; i++ )
  92. dprintf( "knot[%d] = %g\n", i, knotlist[i] );
  93. #endif
  94. }