/*
	Test program for C code from An Introduction to NURBS
	by David F. Rogers. Copyright (C) 2000 David F. Rogers,
	All rights reserved.
	
	Name: tdbsurf.c
	Purpose: Test B-spline surface generator
	Language: C
	Subroutines called: dbsurf.c
	Book reference: Chapter 6, Alg. p. 306
*/

	#include <stdio.h>

	main(){

	int i;
	int npts,mpts;
	int k,l;
	int p1,p2;
   	int hdrlen;
	int ch;

   	char header[80];

	float b[61];
	float q[301];
	float qu[301];
	float qw[301];
	float quw[301];
	float quu[301];
	float qww[301];


/*
	Data for the standard test control net.
	Comment out to use file input.
*/

	npts = 4;
	mpts = 4;
	k = 4;
	l = 3;

	p1 = 5;
	p2 = 5;

/*	printf("k,l,npts,mpts,p1,p2 = %d %d %d %d %d %d \n",k,l,npts,mpts,p1,p2); */

	for (i = 1; i <= 3*npts; i++){
		b[i] = 0.;
	}

	for (i = 1; i <= 3*p1*p2; i++){
		q[i] = 0.;
	}

/*
	This is a standard test control polygon from Ex. 6.1, p. 184
	Comment out to use file input <filename>.pnp
*/

	b[1] = -15.;
	b[2] = 0.;
	b[3] = 15.;
	b[4] = -15.;
	b[5] = 5.;
	b[6] = 5.;
	b[7] = -15.;
	b[8] = 5.;
	b[9] = -5.;
	b[10] = -15.;
	b[11] = 0.;
	b[12] = -15.;

	b[13] = -5.;
	b[14] = 5.;
	b[15] = 15.;
	b[16] = -5.;
	b[17] = 10.;
	b[18] = 5.;
	b[19] = -5.;
	b[20] = 10.;
	b[21] = -5.;
	b[22] = -5.;
	b[23] = 5.;
	b[24] = -15.;

	b[25] = 5.;
	b[26] = 5.;
	b[27] = 15.;
	b[28] = 5.;
	b[29] = 10.;
	b[30] = 5.;
	b[31] = 5.;
	b[32] = 10.;
	b[33] = -5.;
	b[34] = 5.;
	b[35] = 5.;
	b[36] = -15.;

	b[37] = 15.;
	b[38] = 0.;
	b[39] = 15.;
	b[40] = 15.;
	b[41] = 5.;
	b[42] = 5.;
	b[43] = 15.;
	b[44] = 5.;
	b[45] = -5.;
	b[46] = 15.;
	b[47] = 0.;
	b[48] = -15.;

   	hdrlen = 80;

/*
	Uncomment the file input statement below and comment out the standard
    control net data above to use file input.
*/

/*  get polygon netpoint file */

/* 	rdpnp(header,&hdrlen,&k,&l,&npts,&mpts,b); */
 
	dbsurf(b,k,l,npts,mpts,p1,p2,q,qu,qw,quw,quu,qww);

/*	Use the next two lines for getting performance timings
    and comment out the line above.
*/

/*	for (i=1; i <=1000; i++){
	dbsurf(b,k,l,npts,mpts,p1,p2,q);}
*/
	ch = getchar();

	printf("\nPolygon points\n\n");

	for (i = 1; i <= 3*npts*mpts; i=i+3){
		printf(" %f %f %f \n",b[i],b[i+1],b[i+2]);
	}

	ch = getchar();

	printf("\nSurface points\n\n");

	for (i = 1; i <= 3*p1*p2; i=i+3){
		printf(" %f %f %f \n",q[i],q[i+1],q[i+2]);
	}

	ch = getchar();
	
	printf("\nQu on Surface\n\n");

	for (i = 1; i <= 3*p1*p2; i=i+3){
		printf(" %f %f %f \n",qu[i],qu[i+1],qu[i+2]);
	}

	ch = getchar();
	
	printf("\nQw on Surface\n\n");

	for (i = 1; i <= 3*p1*p2; i=i+3){
		printf(" %f %f %f \n",qw[i],qw[i+1],qw[i+2]);
	}

	ch = getchar();
	
	printf("\nQuw on Surface\n\n");

	for (i = 1; i <= 3*p1*p2; i=i+3){
		printf(" %f %f %f \n",quw[i],quw[i+1],quw[i+2]);
	}

	ch = getchar();
	
	printf("\nQuu on Surface\n\n");

	for (i = 1; i <= 3*p1*p2; i=i+3){
		printf(" %f %f %f \n",quu[i],quu[i+1],quu[i+2]);
	}
	
	ch = getchar();
	
	printf("\nQww on Surface\n\n");

	for (i = 1; i <= 3*p1*p2; i=i+3){
		printf(" %f %f %f \n",qww[i],qww[i+1],qww[i+2]);
	}
}
