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.

253 lines
7.3 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. * quilt.c++ - $Revision: 1.2 $
  14. * Derrick Burns - 1991
  15. */
  16. #include "glimport.h"
  17. #include "mystdio.h"
  18. #include "myassert.h"
  19. #include "quilt.h"
  20. #include "backend.h"
  21. #include "mapdesc.h"
  22. #include "flist.h"
  23. #include "knotvect.h"
  24. #include "patchlis.h"
  25. #include "math.h" //fabs()
  26. #define _abs_defined
  27. #include "simplema.h" //min()
  28. /* local preprocessor definitions */
  29. #define DEF_PATCH_STEPSIZE .2
  30. #define fsizeof(x) (sizeof(x)/sizeof(REAL))
  31. Quilt::Quilt( Mapdesc *_mapdesc )
  32. {
  33. mapdesc = _mapdesc;
  34. }
  35. void
  36. Quilt::deleteMe( Pool& p )
  37. {
  38. for( Quiltspec *q=qspec; q != eqspec; q++ ) {
  39. #if 1
  40. if( q->breakpoints) delete[] q->breakpoints; q->breakpoints = 0;
  41. #else
  42. if( q->breakpoints) {
  43. delete[] q->breakpoints;
  44. q->breakpoints = 0;
  45. printf("in here\n");
  46. }
  47. #endif
  48. }
  49. if( cpts ) delete[] cpts;
  50. cpts = 0;
  51. PooledObj::deleteMe( p );
  52. }
  53. void
  54. Quilt::show( void )
  55. {
  56. #ifndef NDEBUG
  57. int nc = mapdesc->getNcoords();
  58. REAL *ps = cpts;
  59. ps += qspec[0].offset;
  60. ps += qspec[1].offset;
  61. for( int i=0; i!= qspec[0].order * qspec[0].width; i++ ) {
  62. for( int j = 0; j!= qspec[1].order * qspec[1].width; j++ ) {
  63. for( int k=0; k < nc; k++ )
  64. dprintf( "%g ", ps[i*qspec[0].stride + j*qspec[1].stride + k] );
  65. dprintf( "\n" );
  66. }
  67. dprintf( "\n" );
  68. }
  69. dprintf( "\n" );
  70. #endif
  71. }
  72. /*--------------------------------------------------------------------------
  73. * Quilt::select - find which map in each quilt contains the points
  74. * pta and ptb with pta[i] < ptb[i]
  75. *--------------------------------------------------------------------------
  76. */
  77. void
  78. Quilt::select( REAL *pta, REAL *ptb )
  79. {
  80. int dim = eqspec - qspec;
  81. for( int i=0; i<dim; i++) {
  82. for( int j=qspec[i].width-1; j>=0; j-- )
  83. if( (qspec[i].breakpoints[j] <= pta[i] ) &&
  84. (ptb[i] <= qspec[i].breakpoints[j+1] ) )
  85. break;
  86. assert( j != -1 );
  87. qspec[i].index = j;
  88. }
  89. }
  90. void
  91. Quilt::download( Backend &backend )
  92. {
  93. if( getDimension() == 2 ) {
  94. REAL *ps = cpts;
  95. ps += qspec[0].offset;
  96. ps += qspec[1].offset;
  97. ps += qspec[0].index * qspec[0].order * qspec[0].stride;
  98. ps += qspec[1].index * qspec[1].order * qspec[1].stride;
  99. backend.surfpts( mapdesc->getType(), ps,
  100. qspec[0].stride,
  101. qspec[1].stride,
  102. qspec[0].order,
  103. qspec[1].order,
  104. qspec[0].breakpoints[qspec[0].index],
  105. qspec[0].breakpoints[qspec[0].index+1],
  106. qspec[1].breakpoints[qspec[1].index],
  107. qspec[1].breakpoints[qspec[1].index+1] );
  108. } else {
  109. REAL *ps = cpts;
  110. ps += qspec[0].offset;
  111. ps += qspec[0].index * qspec[0].order * qspec[0].stride;
  112. backend.curvpts( mapdesc->getType(), ps,
  113. qspec[0].stride,
  114. qspec[0].order,
  115. qspec[0].breakpoints[qspec[0].index],
  116. qspec[0].breakpoints[qspec[0].index+1] );
  117. }
  118. }
  119. /*--------------------------------------------------------------------------
  120. * Quilt::downloadAll - download each map that contains the current patch
  121. *--------------------------------------------------------------------------
  122. */
  123. void
  124. Quilt::downloadAll( REAL *pta, REAL *ptb, Backend &backend )
  125. {
  126. for( Quilt *m = this; m; m=m->next ) {
  127. m->select( pta, ptb );
  128. m->download( backend );
  129. }
  130. }
  131. /*--------------------------------------------------------------------------
  132. * Quilt::isCulled - determine if an entire quilt is trivially rejected.
  133. *--------------------------------------------------------------------------
  134. */
  135. int
  136. Quilt::isCulled( void )
  137. {
  138. if( mapdesc->isCulling() )
  139. return mapdesc->xformAndCullCheck( cpts + qspec[0].offset + qspec[1].offset,
  140. qspec[0].order * qspec[0].width, qspec[0].stride,
  141. qspec[1].order * qspec[1].width, qspec[1].stride );
  142. else
  143. return CULL_ACCEPT;
  144. }
  145. /*---------------------------------------------------------------------------
  146. * Quilt::getRange - retrieve the valid paramater range of a set of quilts
  147. *---------------------------------------------------------------------------
  148. */
  149. void
  150. Quilt::getRange( REAL *from, REAL *to, Flist& slist, Flist &tlist )
  151. {
  152. getRange( from, to, 0, slist );
  153. getRange( from, to, 1, tlist );
  154. }
  155. /*---------------------------------------------------------------------------
  156. * Quilt::getRange - retrieve the valid paramater range of a set of quilts
  157. *---------------------------------------------------------------------------
  158. */
  159. void
  160. Quilt::getRange( REAL *from, REAL *to, int i, Flist &list )
  161. {
  162. Quilt *maps = this;
  163. from[i] = maps->qspec[i].breakpoints[0];
  164. to[i] = maps->qspec[i].breakpoints[maps->qspec[i].width];
  165. int maxpts = 0;
  166. for( Quilt_ptr m=maps; m; m=m->next ) {
  167. if( m->qspec[i].breakpoints[0] > from[i] )
  168. from[i] = m->qspec[i].breakpoints[0];
  169. if( m->qspec[i].breakpoints[m->qspec[i].width] < to[i] )
  170. to[i] = m->qspec[i].breakpoints[m->qspec[i].width];
  171. maxpts += m->qspec[i].width + 1;
  172. }
  173. list.grow( maxpts );
  174. for( m=maps; m; m=m->next )
  175. for( int j=0; j<=m->qspec[i].width; j++ ) {
  176. list.add( m->qspec[i].breakpoints[j] );
  177. }
  178. list.filter( );
  179. list.taper( from[i], to[i] );
  180. }
  181. void
  182. Quilt::getRange( REAL *from, REAL *to, Flist& slist )
  183. {
  184. getRange( from, to, 0, slist );
  185. }
  186. void
  187. Quilt::findRates( Flist& slist, Flist& tlist, REAL rate[2] )
  188. {
  189. findSampleRates( slist, tlist );
  190. rate[0] = qspec[0].step_size;
  191. rate[1] = qspec[1].step_size;
  192. for( Quilt *q = next; q; q = q->next ) {
  193. q->findSampleRates( slist, tlist );
  194. if( q->qspec[0].step_size < rate[0] )
  195. rate[0] = q->qspec[0].step_size;
  196. if( q->qspec[1].step_size < rate[1] )
  197. rate[1] = q->qspec[1].step_size;
  198. }
  199. }
  200. void
  201. Quilt::findSampleRates( Flist& slist, Flist& tlist )
  202. {
  203. qspec[0].step_size = DEF_PATCH_STEPSIZE *
  204. (qspec[0].breakpoints[qspec[0].width] - qspec[0].breakpoints[0]);
  205. qspec[1].step_size = DEF_PATCH_STEPSIZE *
  206. (qspec[1].breakpoints[qspec[1].width] - qspec[1].breakpoints[0]);
  207. for( int i = slist.start; i < slist.end-1; i++ ) {
  208. for( int j = tlist.start; j < tlist.end-1; j++ ) {
  209. REAL pta[2], ptb[2];
  210. pta[0] = slist.pts[i];
  211. ptb[0] = slist.pts[i+1];
  212. pta[1] = tlist.pts[j];
  213. ptb[1] = tlist.pts[j+1];
  214. Patchlist patchlist( this, pta, ptb );
  215. patchlist.getstepsize();
  216. {
  217. float edge_len_s = min(fabs(ptb[0]-pta[0]),1.0);
  218. float edge_len_t = min(fabs(ptb[1]-pta[1]),1.0);
  219. if( patchlist.getStepsize(0)/edge_len_s < qspec[0].step_size )
  220. qspec[0].step_size = patchlist.getStepsize(0)/edge_len_s;
  221. if( patchlist.getStepsize(1)/edge_len_t < qspec[1].step_size )
  222. qspec[1].step_size = patchlist.getStepsize(1)/edge_len_t;
  223. }
  224. }
  225. }
  226. }