home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Resource Library: Graphics
/
graphics-16000.iso
/
general
/
raytrace
/
renaisnc
/
delaunay.lha
/
Delaunay
/
null.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-01-04
|
4KB
|
183 lines
/*
* Null device for animation. Provides stubs but does nothing.
*/
#include "k-Dtree.h"
#include "Delaunay.h"
#ifndef FALSE
# define FALSE 0
#endif
#ifndef TRUE
# define TRUE 1
#endif
/* Options that can be changed by the user */
static int ShowTriangles = 1;
static int ShowCells = 0;
AnimateInitialize( XL,YL,XH,YH)
double XL, XH, YL, YH;
{
/* Set up the user coordinate system.
* XL is the x minimum
* XH is the x maximum
* ...
*
* These are in the range [-1,1] as I recall (don't quote me)
*/
}
AnimateShadeTriangle( i, j, k )
register i,j,k;
{
/* Shade a single triangle
** i,j,k are vertex indicies.
** Points[ i|j|k ] contains the vertex coordinates
** PointData[ i|j|k ] contains the colors
*/
}
AnimateShadeCell( Boundary, Sample )
RectType *Boundary;
SampleData *Sample;
{
/* Fill a rectangular cell with a single color value */
/* PointData[ Sample->index ] contains the color. */
/* Boundary->{xL,yL,xH,yH} contain the rectangle bounds. */
}
void Animate (Animation)
char *Animation;
{
ANIMATING = true;
/* Initialize the graphics hardware */
}
static void TrianglesReDraw()
{
register TrianglePointer T;
/* Step through all the triangles calling Animate Shade Triangle
* for each one. These gives us a way to redraw on an expose event.
*/
T = Triangles;
do
{
AnimateShadeTriangle( T->P1, T->P2, T->P3 );
T = T->Next;
}
while (T != Triangles);
}
static void CellsReDraw()
{
/*
* Step through the kD-tree redrawing all leaf cells.
*/
extern HierarchicalRegion Root;
extern RectType RootBoundary;
register HierarchicalRegion *Node;
RectType LeftBoundary, RightBoundary, Boundary, Overlap;
/* This stack is used to avoid the expense of recursion */
HierarchicalRegion *NodeStack[MAX_DEPTH];
RectType BoundaryStack[MAX_DEPTH];
int levelStack[MAX_DEPTH];
int nStack, level;
/* Start with the root node on the stack */
nStack = 0;
NodeStack[nStack] = &Root;
BoundaryStack[nStack] = RootBoundary;
levelStack[nStack++] = 0;
while (nStack > 0) {
/* Get the next node to process from the stack */
Node = NodeStack[--nStack];
Boundary = BoundaryStack[nStack];
level = levelStack[nStack];
/* Follow the tree down a leaf, pushing the side branches.
*/
while (! IsLeaf(Node)) {
SplitBoundary( TRUE, Node->splitDirection, Node->splitValue,
&Boundary, &LeftBoundary );
if (Node->Left) {
NodeStack[nStack] = Node->Left;
BoundaryStack[nStack] = LeftBoundary;
levelStack[nStack++] = level+1;
}
SplitBoundary( FALSE, Node->splitDirection, Node->splitValue,
&Boundary, &RightBoundary );
if (Node->Right) {
if (nStack >= MAX_DEPTH) {
fprintf( stderr, "Filter stack overflow!\n" );
abort();
}
NodeStack[nStack] = Node->Right;
BoundaryStack[nStack] = RightBoundary;
levelStack[nStack++] = level+1;
}
/* Get the next node to process from the stack */
Node = NodeStack[--nStack];
Boundary = BoundaryStack[nStack];
level = levelStack[nStack];
}
if (Node == NULL)
continue; /* Dead end, go back to the stack loop */
AnimateShadeCell( &Boundary, Node->Sample );
}
}
static void AnimateReDraw()
{
/* Force a redraw */
if (ShowTriangles) TrianglesReDraw();
if (ShowCells) CellsReDraw();
}
AnimateDoEvent()
{
double range;
if (!ANIMATING) return;
/* Respond to input events */
}
int AnimateCheckInput()
{
/* Poll event queue and call AnimateDo Event if one is pending */
}
AnimateExit()
{
/* Call AnimateDoEvent until the user chooses to stop by ^C or picking
QUIT from the menu.
*/
}