#include "view.h"

#define MAXSHADOW 2000

typedef struct{
	int n;
	int faceIndex[MAXSHADOW];
} FaceIndex;

#define AT(x,i)		((x).faceIndex[i])
#define PUT(x,v)	{\
	if((x).n==MAXSHADOW){ \
printf("(x).n = %d\n",(x).n);\
		printf("Exceeded MAXSHADOW in DrawListOnView\n");	\
		EXIT;	\
	}	\
	else	(x).faceIndex[(x).n++] = (v);	\
}


static void DrawListOnView(view,facelist,plist)
View *view;
FaceList *facelist;
FaceIndex *plist;
{
	FaceIndex p,g;
	register int i,j;
	Face *face;
	Index *indShadow;
	
	p = *plist;
	
	while(p.n != 0){
		g.n = 0;
		for(i=0;i<p.n;++i){
			if((face = atFaceList(facelist,AT(p,i)))->noOfShadows > 0){ printf("entered here\n");
				indShadow = face->shadow;
				while(indShadow != NOINDEX){
					PUT(g,INDEX(indShadow));
					indShadow = NEXT(indShadow);
				}
			}
			displayClipFaceOnView(view,face);
		}
		p = g;
	}
}
					

void displayFaceSetOnView(view,facelist,faceset)
View *view;
FaceList *facelist;
Index *faceset;
{
	Index *ind;
	Face *face;
	FaceIndex plist;
	
	ind = faceset;
	while(ind != NOINDEX){
		plist.n = 0;
		PUT(plist,INDEX(ind));
		ind = NEXT(ind);
		DrawListOnView(view,facelist,&plist);
	}
}
