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.

217 lines
6.1 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. * mapdescv.c++ - $Revision: 1.1 $
  14. * Derrick Burns - 1991
  15. */
  16. #include "glimport.h"
  17. #include "mystdio.h"
  18. #include "myassert.h"
  19. #include "mystring.h"
  20. #include "mymath.h"
  21. #include "nurbscon.h"
  22. #include "mapdesc.h"
  23. /*--------------------------------------------------------------------------
  24. * calcPartialVelocity - calculate maximum magnitude of a given partial
  25. * derivative
  26. *--------------------------------------------------------------------------
  27. */
  28. REAL
  29. Mapdesc::calcPartialVelocity (
  30. REAL *p,
  31. int stride,
  32. int ncols,
  33. int partial,
  34. REAL range )
  35. {
  36. REAL tmp[MAXORDER][MAXCOORDS];
  37. REAL mag[MAXORDER];
  38. assert( ncols <= MAXORDER );
  39. int j, k, t;
  40. // copy inhomogeneous control points into temporary array
  41. for( j=0; j != ncols; j++ )
  42. for( k=0; k != inhcoords; k++ )
  43. tmp[j][k] = p[j*stride + k];
  44. for( t=0; t != partial; t++ )
  45. for( j=0; j != ncols-t-1; j++ )
  46. for( k=0; k != inhcoords; k++ )
  47. tmp[j][k] = tmp[j+1][k] - tmp[j][k];
  48. // compute magnitude and store in mag array
  49. for( j=0; j != ncols-partial; j++ ) {
  50. mag[j] = 0.0;
  51. for( k=0; k != inhcoords; k++ )
  52. mag[j] += tmp[j][k] * tmp[j][k];
  53. }
  54. // compute scale factor
  55. REAL fac = 1;
  56. REAL invt = 1.0 / range;
  57. for( t = ncols-1; t != ncols-1-partial; t-- )
  58. fac *= t * invt;
  59. // compute max magnitude of all entries in array
  60. REAL max = 0.0;
  61. for( j=0; j != ncols-partial; j++ )
  62. if( mag[j] > max ) max = mag[j];
  63. max = fac * ::sqrtf( (float) max );
  64. return max;
  65. }
  66. /*--------------------------------------------------------------------------
  67. * calcPartialVelocity - calculate maximum magnitude of a given partial
  68. * derivative
  69. *--------------------------------------------------------------------------
  70. */
  71. REAL
  72. Mapdesc::calcPartialVelocity (
  73. REAL *dist,
  74. REAL *p,
  75. int rstride,
  76. int cstride,
  77. int nrows,
  78. int ncols,
  79. int spartial,
  80. int tpartial,
  81. REAL srange,
  82. REAL trange,
  83. int side )
  84. {
  85. REAL tmp[MAXORDER][MAXORDER][MAXCOORDS];
  86. REAL mag[MAXORDER][MAXORDER];
  87. assert( nrows <= MAXORDER );
  88. assert( ncols <= MAXORDER );
  89. REAL *tp = &tmp[0][0][0];
  90. REAL *mp = &mag[0][0];
  91. const int istride = sizeof( tmp[0]) / sizeof( tmp[0][0][0] );
  92. const int jstride = sizeof( tmp[0][0]) / sizeof( tmp[0][0][0] );
  93. const int kstride = sizeof( tmp[0][0][0]) / sizeof( tmp[0][0][0] );
  94. const int mistride = sizeof( mag[0]) / sizeof( mag[0][0] );
  95. const int mjstride = sizeof( mag[0][0]) / sizeof( mag[0][0] );
  96. const int idist = nrows * istride;
  97. const int jdist = ncols * jstride;
  98. const int kdist = inhcoords * kstride;
  99. const int id = idist - spartial * istride;
  100. const int jd = jdist - tpartial * jstride;
  101. {
  102. // copy control points
  103. REAL *ti = tp;
  104. REAL *qi = p;
  105. REAL *til = tp + idist;
  106. for( ; ti != til; ) {
  107. REAL *tj = ti;
  108. REAL *qj = qi;
  109. REAL *tjl = ti + jdist;
  110. for( ; tj != tjl; ) {
  111. for( int k=0; k != inhcoords; k++ ) {
  112. tj[k] = qj[k];
  113. }
  114. tj += jstride;
  115. qj += cstride;
  116. }
  117. ti += istride;
  118. qi += rstride;
  119. }
  120. }
  121. {
  122. // compute (s)-partial derivative control points
  123. REAL *til = tp + idist - istride;
  124. const REAL *till = til - ( spartial * istride );
  125. for( ; til != till; til -= istride )
  126. for( REAL *ti = tp; ti != til; ti += istride )
  127. for( REAL *tj = ti, *tjl = tj + jdist; tj != tjl; tj += jstride )
  128. for( int k=0; k != inhcoords; k++ )
  129. tj[k] = tj[k+istride] - tj[k];
  130. }
  131. {
  132. // compute (s,t)-partial derivative control points
  133. REAL *tjl = tp + jdist - jstride;
  134. const REAL *tjll = tjl - ( tpartial * jstride );
  135. for( ; tjl != tjll; tjl -= jstride )
  136. for( REAL *tj = tp; tj != tjl; tj += jstride )
  137. for( REAL *ti = tj, *til = ti + id; ti != til; ti += istride )
  138. for( int k=0; k != inhcoords; k++ )
  139. ti[k] = ti[k+jstride] - ti[k];
  140. }
  141. REAL max = 0.0;
  142. {
  143. // compute magnitude and store in mag array
  144. memset( (void *) mp, 0, sizeof( mag ) );
  145. for( REAL *ti = tp, *mi = mp, *til = tp + id; ti != til; ti += istride, mi += mistride )
  146. for( REAL *tj = ti, *mj = mi, *tjl = ti + jd; tj != tjl; tj += jstride, mj += mjstride ) {
  147. for( int k=0; k != inhcoords; k++ )
  148. *mj += tj[k] * tj[k];
  149. if( *mj > max ) max = *mj;
  150. }
  151. }
  152. int i, j;
  153. // compute scale factor
  154. REAL fac = 1.0;
  155. {
  156. REAL invs = 1.0 / srange;
  157. REAL invt = 1.0 / trange;
  158. for( int s = nrows-1, slast = s-spartial; s != slast; s-- )
  159. fac *= s * invs;
  160. for( int t = ncols-1, tlast = t-tpartial; t != tlast; t-- )
  161. fac *= t * invt;
  162. }
  163. if( side == 0 ) {
  164. // compute max magnitude of first and last column
  165. dist[0] = 0.0;
  166. dist[1] = 0.0;
  167. for( i=0; i != nrows-spartial; i++ ) {
  168. j = 0;
  169. if( mag[i][j] > dist[0] ) dist[0] = mag[i][j];
  170. j = ncols-tpartial-1;
  171. if( mag[i][j] > dist[1] ) dist[1] = mag[i][j];
  172. }
  173. dist[0] = fac * ::sqrtf( dist[0] );
  174. dist[1] = fac * ::sqrtf( dist[1] );
  175. } else if( side == 1 ) {
  176. // compute max magnitude of first and last row
  177. dist[0] = 0.0;
  178. dist[1] = 0.0;
  179. for( j=0; j != ncols-tpartial; j++ ) {
  180. i = 0;
  181. if( mag[i][j] > dist[0] ) dist[0] = mag[i][j];
  182. i = nrows-spartial-1;
  183. if( mag[i][j] > dist[1] ) dist[1] = mag[i][j];
  184. }
  185. dist[0] = fac * ::sqrtf( dist[0] );
  186. dist[1] = fac * ::sqrtf( dist[1] );
  187. }
  188. max = fac * ::sqrtf( (float) max );
  189. return max;
  190. }