home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Graphics / graphics-16000.iso / general / raytrace / renaisnc / delaunay.lha / Delaunay / null.c < prev    next >
C/C++ Source or Header  |  1992-01-04  |  4KB  |  183 lines

  1. /*
  2.  *  Null device for animation.  Provides stubs but does nothing.
  3.  */
  4.  
  5. #include "k-Dtree.h"
  6. #include "Delaunay.h"
  7.  
  8. #ifndef FALSE
  9. #  define FALSE 0
  10. #endif
  11. #ifndef TRUE
  12. #  define TRUE 1
  13. #endif
  14.  
  15.             /* Options that can be changed by the user */
  16. static int ShowTriangles = 1;
  17. static int ShowCells = 0;
  18.  
  19.  
  20. AnimateInitialize( XL,YL,XH,YH) 
  21.      double XL, XH, YL, YH;
  22. {
  23.   /* Set up the user coordinate system.
  24.    *  XL is the x minimum
  25.    *  XH is the x maximum
  26.    *  ...
  27.    *
  28.    *  These are in the range [-1,1] as I recall (don't quote me)
  29.    */
  30.  
  31. }
  32.  
  33.  
  34. AnimateShadeTriangle( i, j, k )
  35.      register i,j,k;
  36. {
  37.   /* Shade a single triangle
  38.   ** i,j,k are vertex indicies.
  39.   **   Points[ i|j|k ] contains the vertex coordinates
  40.   **   PointData[ i|j|k ] contains the colors
  41.   */
  42.  
  43. }
  44.  
  45.  
  46. AnimateShadeCell( Boundary, Sample )
  47.      RectType *Boundary;
  48.      SampleData *Sample;
  49. {
  50.  
  51.   /* Fill a rectangular cell with a single color value */
  52.   /* PointData[ Sample->index ] contains the color. */
  53.   /* Boundary->{xL,yL,xH,yH} contain the rectangle bounds. */
  54.  
  55. }
  56.  
  57. void Animate (Animation)
  58.      char *Animation;
  59. {
  60.   ANIMATING = true;
  61.  
  62.   /* Initialize the graphics hardware */
  63.  
  64.  
  65.  
  66. static void TrianglesReDraw()
  67. {
  68.   register TrianglePointer T;
  69.  
  70.   /* Step through all the triangles calling Animate Shade Triangle
  71.    * for each one.  These gives us a way to redraw on an expose event.
  72.    */
  73.   T = Triangles;
  74.   do
  75.     {
  76.       AnimateShadeTriangle( T->P1, T->P2, T->P3 );
  77.       T = T->Next;
  78.     }  
  79.   while (T != Triangles);
  80. }
  81.  
  82.  
  83. static void CellsReDraw()
  84. {
  85.   /*
  86.    *  Step through the kD-tree redrawing all leaf cells.
  87.    */
  88.   extern HierarchicalRegion Root;
  89.   extern RectType RootBoundary;
  90.   register HierarchicalRegion *Node;
  91.   RectType LeftBoundary, RightBoundary, Boundary, Overlap;
  92.  
  93.   /* This stack is used to avoid the expense of recursion */
  94.   HierarchicalRegion *NodeStack[MAX_DEPTH];
  95.   RectType BoundaryStack[MAX_DEPTH];
  96.   int levelStack[MAX_DEPTH];
  97.   int nStack, level;
  98.  
  99.   /* Start with the root node on the stack */
  100.   nStack = 0;
  101.   NodeStack[nStack] = &Root;
  102.   BoundaryStack[nStack] = RootBoundary;
  103.   levelStack[nStack++] = 0;
  104.  
  105.   while (nStack > 0) {
  106.  
  107.     /* Get the next node to process from the stack */
  108.     Node = NodeStack[--nStack];
  109.     Boundary = BoundaryStack[nStack];
  110.     level    = levelStack[nStack];
  111.     
  112.     /* Follow the tree down a leaf, pushing the side branches.
  113.      */
  114.     while (! IsLeaf(Node)) {
  115.  
  116.       SplitBoundary( TRUE, Node->splitDirection, Node->splitValue,
  117.             &Boundary, &LeftBoundary );
  118.       if (Node->Left) {
  119.     NodeStack[nStack] = Node->Left;
  120.     BoundaryStack[nStack] = LeftBoundary;
  121.     levelStack[nStack++] = level+1;
  122.       }
  123.       SplitBoundary( FALSE, Node->splitDirection, Node->splitValue, 
  124.             &Boundary, &RightBoundary );
  125.       if (Node->Right) {
  126.     if (nStack >= MAX_DEPTH) {
  127.       fprintf( stderr, "Filter stack overflow!\n"  );
  128.       abort();
  129.     }
  130.     NodeStack[nStack] = Node->Right;
  131.     BoundaryStack[nStack] = RightBoundary;
  132.     levelStack[nStack++] = level+1;
  133.       }
  134.  
  135.       /* Get the next node to process from the stack */
  136.       Node = NodeStack[--nStack];
  137.       Boundary = BoundaryStack[nStack];
  138.       level    = levelStack[nStack];
  139.     }
  140.   
  141.     if (Node == NULL)
  142.       continue;        /* Dead end, go back to the stack loop */
  143.   
  144.     AnimateShadeCell( &Boundary, Node->Sample );
  145.   }
  146. }
  147.  
  148.  
  149. static void AnimateReDraw()
  150. {
  151.   
  152.   /* Force a redraw */
  153.   if (ShowTriangles)    TrianglesReDraw();
  154.   if (ShowCells)        CellsReDraw();
  155. }
  156.  
  157.  
  158. AnimateDoEvent()
  159. {
  160.   double range;
  161.  
  162.   if (!ANIMATING) return;
  163.  
  164.   /* Respond to input events  */
  165.  
  166. }
  167.  
  168.  
  169. int AnimateCheckInput()
  170. {
  171.   /* Poll event queue and call AnimateDo Event if one is pending */
  172. }
  173.  
  174.  
  175. AnimateExit()
  176. {
  177.   /* Call AnimateDoEvent until the user chooses to stop by ^C or picking
  178.      QUIT from the menu.
  179.   */
  180. }
  181.  
  182.