/***********************************************************/ /** **/ /** **/ /** Bezier subdivision based 3D -> Image rendering **/ /** **/ /** (C) Theo Verelst theover@tiscali.nl **/ /** http://theover.tripod.com **/ /** **/ /** Non-commercial use of the code is permitted **/ /** under the condition that a pointer to me is **/ /** included in every copy or derivative. **/ /** **/ /** Commercial rights reserved, mail me. **/ /** **/ /** This is a prototype I made in one night, **/ /** so don't expect it to be all to tested or **/ /** refined, it is a brute force approach I redid **/ /** from software I made in the time of my masters' **/ /** thesis, which started with reading an article **/ /** Pulleyblank and Kapenga about the feasibility **/ /** for such an approach as a on-chip algorithm. **/ /** **/ /** For this version 0.1, you need a file test.cb **/ /** with the Bezier Surface definition(s) **/ /** **/ /** **/ /***********************************************************/ #include #include #include #include #include #include unsigned char *im; int *zbuf; int w,h; #define MAXBEZ (256*256*4*4*3) int b1[MAXBEZ], b2[MAXBEZ], b3[MAXBEZ]; int b1max=0, b2max=0, b3max=0; int premul=500; unsigned char rc = 255; #define PI 3.1415926535 unsigned char * createim(w,h) int w,h; { unsigned char *d; int x,y; d = (unsigned char *) malloc(3*w*h); for (x=0; x 0) i++; } for (j=0; j *xma) *xma = b[i]; } if (b[i+1] < *ymi) { *ymi = b[i+1]; } else { if (b[i+1] > *yma) *yma = b[i+1]; } if (b[i+2] < *zmi) { *zmi = b[i+2]; } else { if (b[i+2] > *zma) *zma = b[i+2]; } } } int subdiv_rbc(in,out) int in[][4][4][3], out[][4][4][3]; { int i,j,k; int t[2][4][4][3]; int a , b , c; int d , e ; int f ; for (i=0; i<4; i++) { for (j=0; j<3; j++) { a = (in[0][i][0][j] + in[0][i][1][j])/2 ; b = (in[0][i][1][j] + in[0][i][2][j])/2 ; c = (in[0][i][2][j] + in[0][i][3][j])/2 ; d = (a+b)/2; e = (b+c)/2; f = (d+e)/2; t[0][i][0][j] = in[0][i][0][j]; t[0][i][1][j] = a; t[0][i][2][j] = d; t[0][i][3][j] = f; t[1][i][0][j] = f; t[1][i][1][j] = e; t[1][i][2][j] = c; t[1][i][3][j] = in[0][i][3][j]; } } for (i=0; i<4; i++) { for (j=0; j<3; j++) { a = (t[0][0][i][j] + t[0][1][i][j])/2 ; b = (t[0][1][i][j] + t[0][2][i][j])/2 ; c = (t[0][2][i][j] + t[0][3][i][j])/2 ; d = (a+b)/2; e = (b+c)/2; f = (d+e)/2; out[0][0][i][j] = t[0][0][i][j]; out[0][1][i][j] = a; out[0][2][i][j] = d; out[0][3][i][j] = f; out[1][0][i][j] = f; out[1][1][i][j] = e; out[1][2][i][j] = c; out[1][3][i][j] = t[0][3][i][j]; } } for (i=0; i<4; i++) { for (j=0; j<3; j++) { a = (t[1][0][i][j] + t[1][1][i][j])/2 ; b = (t[1][1][i][j] + t[1][2][i][j])/2 ; c = (t[1][2][i][j] + t[1][3][i][j])/2 ; d = (a+b)/2; e = (b+c)/2; f = (d+e)/2; out[2][0][i][j] = t[1][0][i][j]; out[2][1][i][j] = a; out[2][2][i][j] = d; out[2][3][i][j] = f; out[3][0][i][j] = f; out[3][1][i][j] = e; out[3][2][i][j] = c; out[3][3][i][j] = t[1][3][i][j]; } } /* print_rbc2(out,(4*48)); flatproject_rbc(out[0],im,w,h); flatproject_rbc(out[1],im,w,h); flatproject_rbc(out[2],im,w,h); flatproject_rbc(out[3],im,w,h); */ } subdivn(b1,b2,b1m,b2m,n,res) int b1[][48], b2[][48], *b1m, *b2m, n,*res; { int i,j; for (i=0; i 250) intens = 250; intens = 250-intens; x1/=premul; x2/=premul; y1/=premul; y2/=premul; if (x1<0) { x1=0; } else if (x1>(width-1)) x1=width-1; if (x2<0) { x2=0; } else if (x2>(width-1)) x2=width-1; if (y1<0) { y1=0; } else if (y1>(height-1)) y1=height-1; if (y2<0) { y2=0; } else if (y2>(height-1)) y2=height-1; rectangle(x1,y1,x2,y2,(unsigned char) intens, z1/premul); }