////////////////////////////////////////////////////////////////////// // // Pixie // // Copyright © 1999 - 2003, Okan Arikan // // Contact: okan@cs.berkeley.edu // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public // License as published by the Free Software Foundation; either // version 2 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// // // File : ribOut.cpp // Classes : CRibOut // Description : // //////////////////////////////////////////////////////////////////////// #include #include #include #include "ribOut.h" #include "common/os.h" #include "ri.h" #include "renderer.h" #include "error.h" static char *getFilter(float (*function)(float,float,float,float)) { if (function == RiGaussianFilter) { return RI_GAUSSIANFILTER; } else if (function == RiBoxFilter) { return RI_BOXFILTER; } else if (function == RiTriangleFilter) { return RI_TRIANGLEFILTER; } else if (function == RiCatmullRomFilter) { return RI_CATMULLROMFILTER; } else if (function == RiSincFilter) { return RI_SINCFILTER; } else { return RI_GAUSSIANFILTER; } } CRibOut::CRibAttributes::CRibAttributes() { uStep = 3; vStep = 3; next = NULL; } CRibOut::CRibAttributes::CRibAttributes(CRibAttributes *a) { this[0] = a[0]; this->next = a; } CRibOut::CRibAttributes::~CRibAttributes() { } CRibOut::CRibOut(const char *n) : CRiInterface() { struct tm *newtime; time_t aclock; time( &aclock ); newtime = localtime( &aclock ); outName = strdup(n); if (*outName == '|') { outFile = popen(outName+1,"w"); outputIsPipe = TRUE; } else { outFile = fopen(outName,"w"); outputIsPipe = FALSE; } declaredVariables = new CTrie; numLightSources = 1; numObjects = 1; attributes = new CRibAttributes; // Write a header fprintf(outFile,"## Pixie %d.%d.%d\n",VERSION_RELEASE,VERSION_BETA,VERSION_ALPHA); fprintf(outFile,"## Generated %s \n",asctime(newtime)); declareDefaultVariables(); } CRibOut::CRibOut(FILE *o) : CRiInterface() { struct tm *newtime; time_t aclock; time( &aclock ); newtime = localtime( &aclock ); outName = NULL; outFile = o; outputIsPipe = FALSE; declaredVariables = new CTrie; numLightSources = 1; numObjects = 1; attributes = new CRibAttributes; // Write a header fprintf(outFile,"## Pixie %d.%d.%d\n",VERSION_RELEASE,VERSION_BETA,VERSION_ALPHA); fprintf(outFile,"## Generated %s \n",asctime(newtime)); declareDefaultVariables(); } CRibOut::~CRibOut() { if (outName != NULL) { if (outputIsPipe) { pclose(outFile); } else { fclose(outFile); } free((void *) outName); } declaredVariables->destroy(); } void CRibOut::RiDeclare(char *name,char *type) { fprintf(outFile,"Declare \"%s\" \"%s\"\n",name,type); declareVariable(name,type); } void CRibOut::RiFrameBegin(int number) { fprintf(outFile,"FrameBegin %d\n",number); } void CRibOut::RiFrameEnd(void) { fprintf(outFile,"FrameEnd\n"); } void CRibOut::RiWorldBegin(void) { fprintf(outFile,"WorldBegin\n"); } void CRibOut::RiWorldEnd(void) { fprintf(outFile,"WorldEnd\n"); } void CRibOut::RiFormat(int xres,int yres,float aspect) { fprintf(outFile,"Format %d %d %g\n",xres,yres,aspect); } void CRibOut::RiFrameAspectRatio(float aspect) { fprintf(outFile,"FrameAspectRatio %g\n",aspect); } void CRibOut::RiScreenWindow(float left,float right,float bot,float top) { fprintf(outFile,"ScreenWindow %g %g %g %g\n",left,right,bot,top); } void CRibOut::RiCropWindow(float xmin,float xmax,float ymin,float ymax) { fprintf(outFile,"CropWindow %g %g %g %g\n",xmin,xmax,ymin,ymax); } void CRibOut::RiProjectionV(char *name,int n,char *tokens[],char *params[]) { fprintf(outFile,"Projection \"%s\" ",name); writePL(n,tokens,params); } void CRibOut::RiClipping(float hither,float yon) { fprintf(outFile,"Clipping %g %g\n",hither,yon); } void CRibOut::RiClippingPlane(float x,float y,float z,float nx,float ny,float nz) { fprintf(outFile,"ClippingPlane %g %g %g %g %g %g\n",x,y,z,nx,ny,nz); } void CRibOut::RiDepthOfField(float fstop,float focallength,float focaldistance) { fprintf(outFile,"DepthOfField %g %g %g\n",fstop,focallength,focaldistance); } void CRibOut::RiShutter(float smin,float smax) { fprintf(outFile,"Shutter %g %g\n",smin,smax); } void CRibOut::RiPixelVariance(float variance) { fprintf(outFile,"PixelVariance %g\n",variance); } void CRibOut::RiPixelSamples(float xsamples,float ysamples) { fprintf(outFile,"PixelSamples %g %g\n",xsamples,ysamples); } void CRibOut::RiPixelFilter(float (*function)(float,float,float,float),float xwidth,float ywidth) { if (function == RiGaussianFilter) { fprintf(outFile,"PixelFilter \"%s\" %g %g\n",RI_GAUSSIANFILTER,xwidth,ywidth); } else if (function == RiBoxFilter) { fprintf(outFile,"PixelFilter \"%s\" %g %g\n",RI_BOXFILTER,xwidth,ywidth); } else if (function == RiTriangleFilter) { fprintf(outFile,"PixelFilter \"%s\" %g %g\n",RI_TRIANGLEFILTER,xwidth,ywidth); } else if (function == RiCatmullRomFilter) { fprintf(outFile,"PixelFilter \"%s\" %g %g\n",RI_CATMULLROMFILTER,xwidth,ywidth); } else if (function == RiSincFilter) { fprintf(outFile,"PixelFilter \"%s\" %g %g\n",RI_SINCFILTER,xwidth,ywidth); } else { errorHandler(RIE_BADHANDLE,RIE_ERROR,"Unable to write custom filter function\n"); } } void CRibOut::RiExposure(float gain,float gamma) { fprintf(outFile,"Exposure %g %g\n",gain,gamma); } void CRibOut::RiImagerV(char *name,int n,char *tokens[],char *params[]) { fprintf(outFile,"Imager \"%s\" ",name); writePL(n,tokens,params); } void CRibOut::RiQuantize(char * type,int one,int qmin,int qmax,float ampl) { fprintf(outFile,"Quantize \"%s\" %d %d %d %g\n",type,one,qmin,qmax,ampl); } void CRibOut::RiDisplayV(char *name,char * type,char * mode,int n,char *tokens[],char *params[]) { fprintf(outFile,"Display \"%s\" \"%s\" \"%s\" ",name,type,mode); writePL(n,tokens,params); } void CRibOut::RiDisplayChannelV(char *channel,int n,char *tokens[],char *params[]) { fprintf(outFile,"Display \"%s\" ",channel); writePL(n,tokens,params); } void CRibOut::RiHiderV(char * type,int n,char *tokens[],char *params[]) { fprintf(outFile,"Hider \"%s\" ",type); writePL(n,tokens,params); } void CRibOut::RiColorSamples(int N,float *nRGB,float *RGBn) { int i; fprintf(outFile,"ColorSamples [ "); for (i=0;inext; delete old; } void CRibOut::RiColor(float *Cs) { fprintf(outFile,"Color [%g %g %g]\n",Cs[0],Cs[1],Cs[2]); } void CRibOut::RiOpacity(float *Cs) { fprintf(outFile,"Opacity [%g %g %g]\n",Cs[0],Cs[1],Cs[2]); } void CRibOut::RiTextureCoordinates(float s1,float t1,float s2,float t2,float s3,float t3,float s4,float t4) { fprintf(outFile,"TextureCoordinates [%g %g %g %g %g %g %g %g]\n",s1,t1,s2,t2,s3,t3,s4,t4); } void *CRibOut::RiLightSourceV(char *name,int n,char *tokens[],char *params[]) { fprintf(outFile,"LightSource \"%s\" %d ",name,numLightSources); writePL(n,tokens,params); return (void *) numLightSources++; } void *CRibOut::RiAreaLightSourceV(char *name,int n,char *tokens[],char *params[]) { fprintf(outFile,"AreaLightSource \"%s\" %d ",name,numLightSources); writePL(n,tokens,params); return (void *) numLightSources++; } void CRibOut::RiIlluminate(void *light,int onoff) { fprintf(outFile,"Illuminate %d %d\n",light,onoff); } void CRibOut::RiSurfaceV(char *name,int n,char *tokens[],char *params[]) { fprintf(outFile,"Surface \"%s\" ",name); writePL(n,tokens,params); } void CRibOut::RiAtmosphereV(char *name,int n,char *tokens[],char *params[]) { fprintf(outFile,"Atmosphere \"%s\" ",name); writePL(n,tokens,params); } void CRibOut::RiInteriorV(char *name,int n,char *tokens[],char *params[]) { fprintf(outFile,"Interior \"%s\" ",name); writePL(n,tokens,params); } void CRibOut::RiExteriorV(char *name,int n,char *tokens[],char *params[]) { fprintf(outFile,"Exterior \"%s\" ",name); writePL(n,tokens,params); } void CRibOut::RiShadingRate(float size) { fprintf(outFile,"ShadingRate %g\n",size); } void CRibOut::RiShadingInterpolation(char * type) { fprintf(outFile,"ShadingInterpolation \"%s\"\n",type); } void CRibOut::RiMatte(int onoff) { fprintf(outFile,"Matte %d\n",onoff); } void CRibOut::RiBound(float *bound) { fprintf(outFile,"Bound [%g %g %g %g %g %g]\n",bound[0],bound[1],bound[2],bound[3],bound[4],bound[5]); } void CRibOut::RiDetail(float *bound) { fprintf(outFile,"Detail [%g %g %g %g %g %g]\n",bound[0],bound[1],bound[2],bound[3],bound[4],bound[5]); } void CRibOut::RiDetailRange(float minvis,float lowtran,float uptran,float maxvis) { fprintf(outFile,"DetailRange %g %g %g %g\n",minvis,lowtran,uptran,maxvis); } void CRibOut::RiGeometricApproximation(char * type,float value) { fprintf(outFile,"GeometricApproximation \"%s\" %g\n",type,value); } void CRibOut::RiGeometricRepresentation(char * type) { fprintf(outFile,"GeometricRepresentation \"%s\"\n",type); } void CRibOut::RiOrientation(char * orientation) { fprintf(outFile,"Orientation \"%s\"\n",orientation); } void CRibOut::RiReverseOrientation(void) { fprintf(outFile,"ReverseOrientation\n"); } void CRibOut::RiSides(int nsides) { fprintf(outFile,"Sides %d\n",nsides); } void CRibOut::RiIdentity(void) { fprintf(outFile,"Identity\n"); } void CRibOut::RiTransform(float transform[][4]) { fprintf(outFile,"Transform [%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g]\n",transform[0][0],transform[0][1],transform[0][2],transform[0][3] ,transform[1][0],transform[1][1],transform[1][2],transform[1][3] ,transform[2][0],transform[2][1],transform[2][2],transform[2][3] ,transform[3][0],transform[3][1],transform[3][2],transform[3][3]); } void CRibOut::RiConcatTransform(float transform[][4]) { fprintf(outFile,"ConcatTransform [%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g]\n",transform[0][0],transform[0][1],transform[0][2],transform[0][3] ,transform[1][0],transform[1][1],transform[1][2],transform[1][3] ,transform[2][0],transform[2][1],transform[2][2],transform[2][3] ,transform[3][0],transform[3][1],transform[3][2],transform[3][3]); } void CRibOut::RiPerspective(float fov) { fprintf(outFile,"Perspective %g\n",fov); } void CRibOut::RiTranslate(float dx,float dy,float dz) { fprintf(outFile,"Translate %g %g %g\n",dx,dy,dz); } void CRibOut::RiRotate(float angle,float dx,float dy,float dz) { fprintf(outFile,"Rotate %g %g %g %g\n",angle,dx,dy,dz); } void CRibOut::RiScale(float dx,float dy,float dz) { fprintf(outFile,"Scale %g %g %g\n",dx,dy,dz); } void CRibOut::RiSkew(float angle,float dx1,float dy1,float dz1,float dx2,float dy2,float dz2) { fprintf(outFile,"Skew %g %g %g %g %g %g %g\n",angle,dx1,dy1,dz1,dx2,dy2,dz2); } void CRibOut::RiDeformationV(char *name,int n,char *tokens[],char *params[]) { fprintf(outFile,"Deformation \"%s\" ",name); writePL(n,tokens,params); } void CRibOut::RiDisplacementV(char *name,int n,char *tokens[],char *params[]) { fprintf(outFile,"Displacement \"%s\" ",name); writePL(n,tokens,params); } void CRibOut::RiCoordinateSystem(char * space) { fprintf(outFile,"CoordinateSystem \"%s\"\n",space); } void CRibOut::RiCoordSysTransform(char * space) { fprintf(outFile,"CoordSysTransform \"%s\"\n",space); } void CRibOut::RiTransformPoints(char * fromspace,char * tospace,int npoints,float points[][3]) { errorHandler(RIE_SYSTEM,RIE_ERROR,"Unable to output TransformPoints\n"); } void CRibOut::RiTransformBegin(void) { fprintf(outFile,"TransformBegin\n"); } void CRibOut::RiTransformEnd(void) { fprintf(outFile,"TransformEnd\n"); } #define attributeCheckInt(__name,__num) \ } else if (strcmp(tokens[i],__name) == 0) { \ int *val = (int *) params[i]; \ int k; \ fprintf(outFile,"Attribute \"%s\" \"%s\" [%i",name,tokens[i],val[0]); \ for (k=1;k<__num;k++) { \ fprintf(outFile," %i",val[k]); \ } \ fprintf(outFile,"]\n"); #define attributeCheckFloat(__name,__num) \ } else if (strcmp(tokens[i],__name) == 0) { \ float *val = (float *) params[i]; \ int k; \ fprintf(outFile,"Attribute \"%s\" \"%s\" [%g",name,tokens[i],val[0]); \ for (k=1;k<__num;k++) { \ fprintf(outFile," %g",val[k]); \ } \ fprintf(outFile,"]\n"); #define attributeCheckString(__name) \ } else if (strcmp(tokens[i],__name) == 0) { \ char *val = ((char **) params[i])[0]; \ fprintf(outFile,"Attribute \"%s\" \"%s\" \"%s\"\n",name,tokens[i],val); #define attributeEndCheck \ } else { \ CVariable var; \ if (parseVariable(&var,NULL,tokens[i]) == TRUE) { \ RiAttribute(name,var.name,params[i],RI_NULL); \ } else { \ error(CODE_BADTOKEN,"Unknown %s option: \"%s\"\n",name,tokens[i]); \ } \ } void CRibOut::RiAttributeV(char *name,int n,char *tokens[],char *params[]) { int i; if (strcmp(name,RI_DICE) == 0) { for (i=0;iuStep = ustep; attributes->vStep = vstep; } void CRibOut::RiPatchV(char * type,int n,char *tokens[],char *params[]) { int uver,vver; if (strcmp(type,RI_BILINEAR) == 0) { uver = 2; vver = 2; } else if (strcmp(type,RI_BICUBIC) == 0) { uver = 4; vver = 4; } else { char tmp[512]; sprintf(tmp,"Unknown patch type: \"%s\"\n",type); errorHandler(RIE_BADTOKEN,RIE_ERROR,tmp); return; } fprintf(outFile,"Patch \"%s\" ",type); writePL(uver*vver,4,4,1,n,tokens,params); } void CRibOut::RiPatchMeshV(char *type,int nu,char * uwrap,int nv,char * vwrap,int n,char *tokens[],char *params[]) { int uw,vw; int uver,vver; int upatches,vpatches; if (strcmp(uwrap,RI_PERIODIC) == 0) { uw = TRUE; } else if ((strcmp(uwrap,RI_NONPERIODIC) == 0) || (strcmp(uwrap,RI_NOWRAP) == 0)) { uw = FALSE; } else { errorHandler(RIE_BADTOKEN,RIE_ERROR,"Wrapping mode unrecognised \n"); return; } if (strcmp(vwrap,RI_PERIODIC) == 0) { vw = TRUE; } else if ((strcmp(vwrap,RI_NONPERIODIC) == 0) || (strcmp(vwrap,RI_NOWRAP) == 0)) { vw = FALSE; } else { errorHandler(RIE_BADTOKEN,RIE_ERROR,"Wrapping mode unrecognised \n"); return; } uver = nu; vver = nv; if (strcmp(type,RI_BICUBIC) == 0) { if (uw) { if ((uver % attributes->uStep) != 0) { errorHandler(RIE_CONSISTENCY,RIE_ERROR,"Unexpected number of u vertices \n"); return; } upatches = (uver ) / attributes->uStep; } else { if (((uver - 4) % attributes->uStep) != 0) { errorHandler(RIE_CONSISTENCY,RIE_ERROR,"Unexpected number of u vertices \n"); return; } upatches = ((uver - 4) / attributes->uStep)+1; } if (vw) { if ((vver % attributes->vStep) != 0) { errorHandler(RIE_CONSISTENCY,RIE_ERROR,"Unexpected number of v vertices \n"); return; } vpatches = (vver) / attributes->vStep; } else { if (((vver - 4) % attributes->vStep) != 0) { errorHandler(RIE_CONSISTENCY,RIE_ERROR,"Unexpected number of v vertices \n"); return; } vpatches = ((vver - 4) / attributes->vStep)+1; } } else { if (uw) upatches = uver; else upatches = uver-1; if (vw) vpatches = vver; else vpatches = vver-1; } fprintf(outFile,"PatchMesh \"%s\" %i \"%s\" %i \"%s\" ",type,nu,uwrap,nv,vwrap); writePL(uver*vver,uver*vver,uver*vver,upatches*vpatches,n,tokens,params); } void CRibOut::RiNuPatchV(int nu,int uorder,float *uknot,float umin,float umax,int nv,int vorder,float *vknot,float vmin,float vmax,int n,char *tokens[],char *params[]) { int upatches = nu - uorder + 1; int vpatches = nv - vorder + 1; int i,uk,vk; fprintf(outFile,"NuPatch "); // Print the knot sequence uk = nu + uorder; vk = nv + vorder; fprintf(outFile,"%i %i [%g",nu,uorder,uknot[0]); for (i=1;i0;j--,k++) { if (k == 0) { fprintf(outFile,"%g",knot[k]); } else { fprintf(outFile," %g",knot[k]); } } } // Print the parametric range for each curve fprintf(outFile,"] [%g",amin[0]); for (i=1;i0;j--,k++) { if (k == 0) { fprintf(outFile,"%g",u[k]); } else { fprintf(outFile," %g",u[k]); } } } fprintf(outFile,"] ["); for (k=0,i=0;i0;j--,k++) { if (k == 0) { fprintf(outFile,"%g",v[k]); } else { fprintf(outFile," %g",v[k]); } } } fprintf(outFile,"] ["); for (k=0,i=0;i0;j--,k++) { if (k == 0) { fprintf(outFile,"%g",w[k]); } else { fprintf(outFile," %g",w[k]); } } } fprintf(outFile,"]\n"); } void CRibOut::RiSphereV(float radius,float zmin,float zmax,float thetamax,int n,char *tokens[],char *params[]) { fprintf(outFile,"Sphere %g %g %g %g ",radius,zmin,zmax,thetamax); writePL(4,4,4,1,n,tokens,params); } void CRibOut::RiConeV(float height,float radius,float thetamax,int n,char *tokens[],char *params[]) { fprintf(outFile,"Cone %g %g %g ",height,radius,thetamax); writePL(4,4,4,1,n,tokens,params); } void CRibOut::RiCylinderV(float radius,float zmin,float zmax,float thetamax,int n,char *tokens[],char *params[]) { fprintf(outFile,"Cylinder %g %g %g %g ",radius,zmin,zmax,thetamax); writePL(4,4,4,1,n,tokens,params); } void CRibOut::RiHyperboloidV(float *point1,float *point2,float thetamax,int n,char *tokens[],char *params[]) { fprintf(outFile,"Hyperboloid %g %g %g %g %g %g %g ",point1[0],point1[1],point1[2],point2[0],point2[1],point2[2],thetamax); writePL(4,4,4,1,n,tokens,params); } void CRibOut::RiParaboloidV(float rmax,float zmin,float zmax,float thetamax,int n,char *tokens[],char *params[]) { fprintf(outFile,"Paraboloid %g %g %g %g ",rmax,zmin,zmax,thetamax); writePL(4,4,4,1,n,tokens,params); } void CRibOut::RiDiskV(float height,float radius,float thetamax,int n,char *tokens[],char *params[]) { fprintf(outFile,"Disk %g %g %g ",height,radius,thetamax); writePL(4,4,4,1,n,tokens,params); } void CRibOut::RiTorusV(float majorrad,float minorrad,float phimin,float phimax,float thetamax,int n,char *tokens[],char *params[]) { fprintf(outFile,"Torus %g %g %g %g %g",majorrad,minorrad,phimin,phimax,thetamax); writePL(4,4,4,1,n,tokens,params); } void CRibOut::RiProcedural(char * data,float *bound,void (*subdivfunc)(char *,float),void (*freefunc)(char *)) { errorHandler(RIE_UNIMPLEMENT,RIE_ERROR,"Unable to output procedural geometry\n"); } void CRibOut::RiGeometryV(char * type,int n,char *tokens[],char *params[]) { errorHandler(RIE_UNIMPLEMENT,RIE_ERROR,"Unable to output optional geometry\n"); } void CRibOut::RiCurvesV(char * degree,int ncurves,int nverts[],char * wrap,int n,char *tokens[],char *params[]) { int i; int nvertices = 0; int nvaryings = 0; fprintf(outFile,"Curves \"%s\" [",degree); for (i=0;i numVertices) numVertices = vertices[i]; } numVertices++; fprintf(outFile,"SubdivisionMesh \"%s\" [ ",scheme); for (i=0;ifind(tokens[i],variable) == TRUE) { retry:; fprintf(outFile," \"%s\" [",tokens[i]); switch(variable->type) { case TYPE_FLOAT: f = (float *) vals[i]; for (j=variable->numItems;j>0;j--,f++) { fprintf(outFile,"%g ",f[0]); } break; case TYPE_COLOR: case TYPE_VECTOR: case TYPE_NORMAL: case TYPE_POINT: f = (float *) vals[i]; for (j=variable->numItems;j>0;j--,f+=3) { fprintf(outFile,"%g %g %g ",f[0],f[1],f[2]); } break; case TYPE_MATRIX: f = (float *) vals[i]; for (j=variable->numItems;j>0;j--,f+=16) { fprintf(outFile,"%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g ",f[0],f[1],f[2],f[3],f[4],f[5],f[6],f[7],f[8],f[9],f[10],f[11],f[12],f[13],f[14],f[15]); } break; case TYPE_QUAD: f = (float *) vals[i]; for (j=variable->numItems;j>0;j--,f+=4) { fprintf(outFile,"%g %g %g %g ",f[0],f[1],f[2],f[3]); } break; case TYPE_DOUBLE: f = (float *) vals[i]; for (j=variable->numItems;j>0;j--,f+=2) { fprintf(outFile,"%g %g ",f[0],f[1]); } break; case TYPE_STRING: s = (char **) vals[i]; for (j=variable->numItems;j>0;j--,s++) { fprintf(outFile,"\"%s\" ",s[0]); } break; case TYPE_INTEGER: iv = (int *) vals[i]; for (j=variable->numItems;j>0;j--,iv++) { fprintf(outFile,"%d ",iv[0]); } break; case TYPE_BOOLEAN: break; default: break; } fprintf(outFile,"] "); } else { if (parseVariable(&tmpVar,NULL,tokens[i])) { variable = &tmpVar; goto retry; } else { char tmp[512]; sprintf(tmp,"Parameter \"%s\" not found\n",tokens[i]); errorHandler(RIE_BADTOKEN,RIE_ERROR,tmp); } } } fprintf(outFile,"\n"); } void CRibOut::writePL(int numVertex,int numVarying,int numFaceVarying,int numUniform,int numParameters,char *tokens[],char *vals[]) { int i,j; float *f; char **s; #define numItems(__dest,__var) \ switch(variable->container) { \ case CONTAINER_UNIFORM: \ __dest = __var->numItems*numUniform; \ break; \ case CONTAINER_VERTEX: \ __dest = __var->numItems*numVertex; \ break; \ case CONTAINER_VARYING: \ __dest = __var->numItems*numVarying; \ break; \ case CONTAINER_FACEVARYING: \ __dest = __var->numItems*numFaceVarying; \ break; \ case CONTAINER_CONSTANT: \ __dest = 1; \ break; \ } for (i=0;ifind(tokens[i],variable) == TRUE) { retry:; fprintf(outFile," \"%s\" [",tokens[i]); switch(variable->type) { case TYPE_FLOAT: f = (float *) vals[i]; numItems(j,variable); for (;j>0;j--,f++) { fprintf(outFile,"%g ",f[0]); } break; case TYPE_COLOR: case TYPE_VECTOR: case TYPE_NORMAL: case TYPE_POINT: f = (float *) vals[i]; numItems(j,variable); for (;j>0;j--,f+=3) { fprintf(outFile,"%g %g %g ",f[0],f[1],f[2]); } break; case TYPE_MATRIX: f = (float *) vals[i]; numItems(j,variable); for (;j>0;j--,f+=16) { fprintf(outFile,"%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g ",f[0],f[1],f[2],f[3],f[4],f[5],f[6],f[7],f[8],f[9],f[10],f[11],f[12],f[13],f[14],f[15]); } break; case TYPE_QUAD: f = (float *) vals[i]; numItems(j,variable); for (;j>0;j--,f+=4) { fprintf(outFile,"%g %g %g %g ",f[0],f[1],f[2],f[3]); } break; case TYPE_DOUBLE: f = (float *) vals[i]; numItems(j,variable); for (;j>0;j--,f+=2) { fprintf(outFile,"%g %g ",f[0],f[1]); } break; case TYPE_STRING: s = (char **) vals[i]; for (j=variable->numItems;j>0;j--,s++) { fprintf(outFile,"\"%s\" ",s[0]); } break; case TYPE_INTEGER: break; case TYPE_BOOLEAN: break; default: break; } fprintf(outFile,"] "); } else { if (parseVariable(&tmpVar,NULL,tokens[i])) { variable = &tmpVar; goto retry; } else { char tmp[512]; sprintf(tmp,"Parameter \"%s\" not found\n",tokens[i]); errorHandler(RIE_BADTOKEN,RIE_ERROR,tmp); } } } fprintf(outFile,"\n"); #undef numItems } void CRibOut::declareVariable(char *name,char *decl) { CVariable cVariable,*nVariable; assert(declaredVariables != NULL); if (parseVariable(&cVariable,name,decl) == TRUE) { // Parse successful, insert the variable into the dictionary CVariable *oVariable; if (declaredVariables->erase(cVariable.name,oVariable)) { delete oVariable; }; // Add the new variable into the variables list nVariable = new CVariable; nVariable[0] = cVariable; // Insert the variable into the variables trie declaredVariables->insert(nVariable->name,nVariable); } } void CRibOut::declareDefaultVariables() { // Define the options declareVariable(RI_ARCHIVE, "string"); declareVariable(RI_PROCEDURAL, "string"); declareVariable(RI_TEXTURE, "string"); declareVariable(RI_SHADER, "string"); declareVariable(RI_DISPLAY, "string"); declareVariable(RI_RESOURCE, "string"); declareVariable(RI_BUCKETSIZE, "int[2]"); declareVariable(RI_INHERITATTRIBUTES, "int"); declareVariable(RI_GRIDSIZE, "int"); declareVariable(RI_HIERARCHYDEPTH, "int"); declareVariable(RI_HIERARCHYOBJECTS, "int"); declareVariable(RI_EYESPLITS, "int"); declareVariable(RI_TEXTUREMEMORY, "int"); declareVariable(RI_SHADERCACHE, "int"); declareVariable(RI_RADIANCECACHE, "int"); declareVariable(RI_JITTER, "float"); declareVariable(RI_FALSECOLOR, "int"); declareVariable(RI_EMIT, "int"); declareVariable(RI_DEPTHFILTER, "string"); declareVariable(RI_MAXDEPTH, "int"); declareVariable(RI_ENDOFFRAME, "int"); declareVariable(RI_FILELOG, "string"); declareVariable(RI_PROGRESS, "int"); // Define the attributes declareVariable(RI_NUMPROBES, "int[2]"); declareVariable(RI_MINSUBDIVISION, "int"); declareVariable(RI_MAXSUBDIVISION, "int"); declareVariable(RI_MINSPLITS, "int"); declareVariable(RI_BOUNDEXPAND, "float"); declareVariable(RI_BINARY, "int"); declareVariable(RI_RASTERORIENT, "int"); declareVariable(RI_SPHERE, "float"); declareVariable(RI_COORDINATESYSYTEM, "string"); declareVariable(RI_DISPLACEMENTS, "int"); declareVariable(RI_BIAS, "float"); declareVariable(RI_MAXDIFFUSEDEPTH, "int"); declareVariable(RI_MAXSPECULARDEPTH, "int"); declareVariable(RI_HANDLE, "string"); declareVariable(RI_FILEMODE, "string"); declareVariable(RI_MAXERROR, "float"); declareVariable(RI_GLOBALMAP, "string"); declareVariable(RI_CAUSTICMAP, "string"); declareVariable(RI_SHADINGMODEL, "string"); declareVariable(RI_ESTIMATOR, "int"); declareVariable(RI_ILLUMINATEFRONT, "int"); declareVariable(RI_TRANSMISSION, "string"); declareVariable(RI_CAMERA, "int"); declareVariable(RI_TRACE, "int"); declareVariable(RI_PHOTON, "int"); declareVariable(RI_NAME, "string"); declareVariable(RI_HIDDEN, "int"); declareVariable(RI_BACKFACING, "backfacing"); // File display variables declareVariable("quantize", "float[4]"); declareVariable("dither", "float"); declareVariable("gamma", "float"); declareVariable("gain", "float"); declareVariable("near", "float"); declareVariable("far", "float"); declareVariable("Software", "string"); declareVariable("compression", "string"); declareVariable("NP", "float[16]"); declareVariable("Nl", "float[16]"); // Declare the rest declareVariable("P", "global vertex point"); declareVariable("Ps", "global vertex point"); declareVariable("N", "global varying normal"); declareVariable("Ng", "global varying normal"); declareVariable("dPdu", "global vertex vector"); declareVariable("dPdv", "global vertex vector"); declareVariable("L", "global varying vector"); declareVariable("Cs", "global varying color"); declareVariable("Os", "global varying color"); declareVariable("Cl", "global varying color"); declareVariable("Ol", "global varying color"); declareVariable("Ci", "global varying color"); declareVariable("Oi", "global varying color"); declareVariable("s", "global varying float"); declareVariable("t", "global varying float"); declareVariable("st", "varying float[2]"); declareVariable("du", "global varying float"); declareVariable("dv", "global varying float"); declareVariable("u", "global varying float"); declareVariable("v", "global varying float"); declareVariable("I", "global varying vector"); declareVariable("E", "global varying point"); declareVariable("alpha","global varying float"); declareVariable("time", "global varying float"); declareVariable("Pw", "global vertex htpoint"); declareVariable("__sru","global varying float"); declareVariable("__srv","global varying float"); declareVariable("Pz", "vertex float"); declareVariable("width","vertex float"); declareVariable("constantwidth","uniform float"); // Define uniform variables declareVariable("ncomps","global uniform float"); declareVariable("dtime","global uniform float"); declareVariable("Np","uniform normal"); // Misc. variables declareVariable("fov", "float"); // Standard RI variables declareVariable("Ka", "float"); declareVariable("Kd", "float"); declareVariable("Kr", "float"); declareVariable("Ks", "float"); declareVariable("amplitude", "float"); declareVariable("background", "color"); declareVariable("beamdistribution", "float"); declareVariable("coneangle", "float"); declareVariable("conedeltangle", "float"); declareVariable("distance", "float"); declareVariable("from", "point"); declareVariable("intensity", "float"); declareVariable("lightcolor", "color"); declareVariable("maxdistance", "float"); declareVariable("mindistance", "float"); declareVariable("roughness", "float"); declareVariable("specularcolor", "color"); declareVariable("texturename", "string"); declareVariable("to", "point"); }