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.

177 lines
5.5 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. * curve.c++ - $Revision: 1.1 $
  14. * Derrick Burns - 1991
  15. */
  16. #include "glimport.h"
  17. #include "myassert.h"
  18. #include "mystdio.h"
  19. #include "mymath.h"
  20. #include "curve.h"
  21. #include "mapdesc.h"
  22. #include "types.h"
  23. #include "quilt.h"
  24. #include "nurbscon.h"
  25. /*--------------------------------------------------------------------------
  26. * Curve::Curve - copy curve from quilt and transform control points
  27. *--------------------------------------------------------------------------
  28. */
  29. Curve::Curve( Quilt_ptr geo, REAL pta, REAL ptb, Curve *c )
  30. {
  31. mapdesc = geo->mapdesc;
  32. next = c;
  33. needsSampling = mapdesc->isRangeSampling() ? 1 : 0;
  34. cullval = mapdesc->isCulling() ? CULL_ACCEPT : CULL_TRIVIAL_ACCEPT;
  35. order = geo->qspec[0].order;
  36. stride = MAXCOORDS;
  37. REAL *ps = geo->cpts;
  38. Quiltspec_ptr qs = geo->qspec;
  39. ps += qs->offset;
  40. ps += qs->index * qs->order * qs->stride;
  41. REAL *pend = ps + qs->order * qs->stride;
  42. if( needsSampling )
  43. mapdesc->xformSampling( ps, qs->order, qs->stride, spts, stride );
  44. if( cullval == CULL_ACCEPT )
  45. mapdesc->xformCulling( ps, qs->order, qs->stride, cpts, stride );
  46. /* set untrimmed curve range */
  47. range[0] = qs->breakpoints[qs->index];
  48. range[1] = qs->breakpoints[qs->index+1];
  49. range[2] = range[1] - range[0];
  50. if( range[0] != pta ) {
  51. Curve lower( *this, pta, 0 );
  52. lower.next = next;
  53. *this = lower;
  54. }
  55. if( range[1] != ptb ) {
  56. Curve lower( *this, ptb, 0 );
  57. }
  58. }
  59. /*--------------------------------------------------------------------------
  60. * Curve::Curve - subdivide a curve along an isoparametric line
  61. *--------------------------------------------------------------------------
  62. */
  63. Curve::Curve( Curve& upper, REAL value, Curve *c )
  64. {
  65. Curve &lower = *this;
  66. lower.next = c;
  67. lower.mapdesc = upper.mapdesc;
  68. lower.needsSampling = upper.needsSampling;
  69. lower.order = upper.order;
  70. lower.stride = upper.stride;
  71. lower.cullval = upper.cullval;
  72. REAL d = (value - upper.range[0]) / upper.range[2];
  73. if( needsSampling )
  74. mapdesc->subdivide( upper.spts, lower.spts, d, upper.stride, upper.order );
  75. if( cullval == CULL_ACCEPT )
  76. mapdesc->subdivide( upper.cpts, lower.cpts, d, upper.stride, upper.order );
  77. lower.range[0] = upper.range[0];
  78. lower.range[1] = value;
  79. lower.range[2] = value - upper.range[0];
  80. upper.range[0] = value;
  81. upper.range[2] = upper.range[1] - value;
  82. }
  83. /*--------------------------------------------------------------------------
  84. * Curve::clamp - clamp the sampling rate to a given maximum
  85. *--------------------------------------------------------------------------
  86. */
  87. void
  88. Curve::clamp( void )
  89. {
  90. if( stepsize < minstepsize )
  91. stepsize = mapdesc->clampfactor * minstepsize;
  92. }
  93. void
  94. Curve::setstepsize( REAL max )
  95. {
  96. stepsize = ( max >= 1.0 ) ? (range[2] / max) : range[2];
  97. minstepsize = stepsize;
  98. }
  99. void
  100. Curve::getstepsize( void )
  101. {
  102. minstepsize= 0;
  103. if( mapdesc->isConstantSampling() ) {
  104. // fixed number of samples per patch in each direction
  105. // maxrate is number of s samples per patch
  106. setstepsize( mapdesc->maxrate );
  107. } else if( mapdesc->isDomainSampling() ) {
  108. // maxrate is number of s samples per unit s length of domain
  109. setstepsize( mapdesc->maxrate * range[2] );
  110. } else {
  111. // upper bound on path length between sample points
  112. assert( order <= MAXORDER );
  113. /* points have been transformed, therefore they are homogeneous */
  114. REAL tmp[MAXORDER][MAXCOORDS];
  115. const int tstride = sizeof(tmp[0]) / sizeof(REAL);
  116. int val = mapdesc->project( spts, stride, &tmp[0][0], tstride, order );
  117. if( val == 0 ) {
  118. // control points cross infinity, therefore derivatives are undefined
  119. setstepsize( mapdesc->maxrate );
  120. } else {
  121. REAL t = mapdesc->getProperty( N_PIXEL_TOLERANCE );
  122. if( mapdesc->isParametricDistanceSampling() ) {
  123. REAL d = mapdesc->calcPartialVelocity( &tmp[0][0], tstride, order, 2, range[2] );
  124. stepsize = (d > 0.0) ? ::sqrtf( 8.0 * t / d ) : range[2];
  125. minstepsize = ( mapdesc->maxrate > 0.0 ) ? (range[2] / mapdesc->maxrate) : 0.0;
  126. } else if( mapdesc->isPathLengthSampling() ) {
  127. // t is upper bound on path (arc) length
  128. REAL d = mapdesc->calcPartialVelocity( &tmp[0][0], tstride, order, 1, range[2] );
  129. stepsize = ( d > 0.0 ) ? (t / d) : range[2];
  130. minstepsize = ( mapdesc->maxrate > 0.0 ) ? (range[2] / mapdesc->maxrate) : 0.0;
  131. } else {
  132. // control points cross infinity, therefore partials are undefined
  133. setstepsize( mapdesc->maxrate );
  134. }
  135. }
  136. }
  137. }
  138. int
  139. Curve::needsSamplingSubdivision( void )
  140. {
  141. return ( stepsize < minstepsize ) ? 1 : 0;
  142. }
  143. int
  144. Curve::cullCheck( void )
  145. {
  146. if( cullval == CULL_ACCEPT )
  147. cullval = mapdesc->cullCheck( cpts, order, stride );
  148. return cullval;
  149. }