home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / gfx / 3d / irit / contrib / scripts / animbevl.irt < prev    next >
Encoding:
Text File  |  1995-02-04  |  5.2 KB  |  176 lines

  1. # ListCopy - deep copy of the lists
  2. # BsplineShowEval - returns list of polylines showing steps of the algorithm
  3. #                   at particular point
  4. # BsplineFindInterval - returns J such that t in [T_j, T_j+1)    
  5. # BsplineShowIntervals - returns list of curve pieces connection points
  6. # BsplineShowWithPolygon - returns list of objects: curve, control polygon,
  7. #                    control points and BsplineShowIntervals
  8. # BsplineShowAll - returns complete list of objects demonstrating algorithm
  9. #                  steps at specific parameter value t and views it
  10. # BsplineAnimateEval - animates BsplineShowAll at  parameter value samples
  11. #
  12. #                    Michael Plavnik 
  13. #
  14. iritState("EchoSource", false);
  15.  
  16. ListCopy = FUNCTION( argList) : len  : i :
  17.   len = sizeof( argList ) :
  18.   return = NIL() :
  19.   FOR (i = 1, 1, len, snoc( nth( argList, i ), return ) );
  20.  
  21. BsplineShowEval = FUNCTION(k, polyList, knotList, J, t) 
  22. # returns list of polylines demonstrating steps of the algorithm at parameter t
  23.   : pList : pl : t_kpi : t_i : t_0 : t_1 : i : ii : p : colorValue  :
  24.   pList = NIL() :
  25.   return = NIL() :
  26.   colorValue = 3 :
  27.   FOR(ii = J-k+1, 1, J, snoc( nth( polyList, ii+1 ), pList ) ) :
  28.   FOR(p = 1, 1, k-1,
  29.     pl = NIL() :
  30.     FOR(i = J-k+1+p, 1, J,
  31.       t_kpi = nth(knotList, i+k-p+1) :
  32.       t_i = nth(knotList, i+1) :
  33.       td = t_kpi -  t_i :
  34.       t_0 = (t - t_i) / ( t_kpi - t_i ) :
  35.       t_1 = 1 - t_0 :
  36.       index = i-J+k-p :
  37.       ptnew = coerce(
  38.               t_0 * coerce(nth(pList, index+1), VECTOR_TYPE) + 
  39.               t_1 * coerce(nth(pList, index), VECTOR_TYPE),
  40.               E2) :
  41.       snoc(ptnew, pl) 
  42.     ) :
  43.     color( pl, colorValue ) :
  44.     snoc(pl, return) :
  45.     IF (sizeof(pl) > 1,
  46.       poly_curve = cbspline(2, pl, list(KV_OPEN)) :
  47.       color( poly_curve, colorValue ) :
  48.       colorValue = colorValue + 1 :
  49.       snoc( poly_curve, return )
  50.     ) :
  51.     pList = ListCopy( pl )
  52.   );
  53.  
  54. BsplineFindInterval = FUNCTION(order, knotList, t)
  55. # returns J such that t in [T_j, T_j+1), where T_j stands for knotList[j]
  56.   : i : len :
  57.   return = 0 :
  58.   len = sizeof(knotList) - order - 1 :
  59.   FOR (i = order-1, 1, len,
  60.     IF (t >= nth(knotList, i+1),
  61.     return = i) );
  62.  
  63. BsplineShowIntervals = FUNCTION(order, polyList, knotList, splineCurve)
  64. # return list of connection points between pieces
  65.   : piece_list : i :
  66.   piece_list = NIL() :
  67.   FOR(i = 1, 1, sizeof(polyList)-1,
  68.     snoc( ceval(splineCurve, nth(knotList, i+order-1)), piece_list ) 
  69.   ) :
  70.   color(piece_list, 10) :
  71.   return = piece_list ;
  72.  
  73. BsplineShowWithPolygon = FUNCTION(k, polyList, knotList)
  74. # returns list of curve, its polygon and polygon points visualy
  75.   : spline_curve : polygon_curve :
  76.   spline_curve = cbspline(k, polyList, knotList ) :
  77.   polygon_curve = cbspline(2, polyList, list( KV_OPEN ) ) :
  78.   color( spline_curve, YELLOW ) :
  79.   color( polygon_curve, MAGENTA ) :
  80.   color( polyList, MAGENTA ) :
  81.   return = list( spline_curve, polygon_curve, polyList ) +
  82.        BsplineShowIntervals(k, polyList, knotList, spline_curve);
  83.  
  84. BsplineShowAll = FUNCTION(k, polyList, knotList, t)
  85.   : J :
  86.   J = BsplineFindInterval(k, knotList, t) :
  87.   return = list(
  88.          BsplineShowWithPolygon(order, polygon_list, knot_list),
  89.              BsplineShowEval(order, polygon_list, knot_list, J, t)
  90.            ) : 
  91.   view( return, TRUE );
  92.  
  93. BsplineAnimateEval = PROCEDURE(resolution, k, polyList, knotList)
  94.   : i : step : t : J :
  95.   FOR (J = order-1, 1, sizeof(polyList)-1,
  96.     t = nth(knotList, J+1) :
  97.     step = (nth(knotList, J+2) - t) / resolution : 
  98.     FOR (i = 1, 1, resolution,
  99.       view( list( BsplineShowWithPolygon(order, polyList, knotList),
  100.                 BsplineShowEval(order, polyList, knotList, J, t)
  101.                 ), 
  102.             TRUE 
  103.       ) :
  104.       printf("J = %g t = %f\\n", list( J, t) ) :
  105.       t = t + step  
  106.    ) 
  107.   );
  108.  
  109. iritState("EchoSource", true);
  110.  
  111. #
  112. # Set the view state
  113. #
  114. view_mat = sc( 0.4 );
  115. viewobj( list( view_mat ) );
  116. viewstate( "WiderLns" );
  117.  
  118. #
  119. # example 8.1
  120. #
  121. order = 4;
  122. knot_list = list( 0, 0, 0, 0, 1, 4, 5, 5, 5, 5 );
  123. polygon_list = list( ctlpt( E2, -1, -2),
  124.              ctlpt( E2, -2, -1),
  125.              ctlpt( E2, -1,  1),
  126.              ctlpt( E2,  1,  1),
  127.              ctlpt( E2,  2, -1), 
  128.              ctlpt( E2,  2,  0) );
  129.  
  130. BsplineShowAll(order, polygon_list, knot_list, 2);
  131. pause();
  132.  
  133. BsplineAnimateEval( 40, order, polygon_list, knot_list );
  134. BsplineAnimateEval( 40, order, polygon_list, knot_list );
  135. pause();
  136.  
  137. #
  138. # example 8.2
  139. #
  140. order = 3;
  141. knot_list = list( 0, 0, 0, 1, 3, 4, 4, 4 );
  142. polygon_list = list( ctlpt( E2, -1, -2),
  143.              ctlpt( E2, -2, -1),
  144.              ctlpt( E2, -1,  1),
  145.              ctlpt( E2,  1,  1),
  146.              ctlpt( E2,  2,  0) );
  147.  
  148.  
  149. BsplineShowAll( order, polygon_list, knot_list, 0.7);
  150. pause();
  151.  
  152. BsplineShowAll( order, polygon_list, knot_list, 1.7);
  153. pause();
  154.  
  155. BsplineAnimateEval( 40, order, polygon_list, knot_list );
  156. BsplineAnimateEval( 40, order, polygon_list, knot_list );
  157. pause();
  158.  
  159. #
  160. # Bezier case
  161. #
  162. order = 5;
  163. knot_list = list( 0, 0, 0, 0, 0, 1, 1, 1, 1, 1 );
  164. polygon_list = list( ctlpt( E2, -1, -2),
  165.              ctlpt( E2, -2, -1),
  166.              ctlpt( E2, -1,  1),
  167.              ctlpt( E2,  1,  1),
  168.              ctlpt( E2,  2,  0) );
  169.  
  170. BsplineShowAll( order, polygon_list, knot_list, 0.35 );
  171. pause();
  172.  
  173. BsplineAnimateEval( 70, order, polygon_list, knot_list );
  174. BsplineAnimateEval( 70, order, polygon_list, knot_list );
  175. pause();
  176.