/************************************************ || moveRay() || Purpose: takes a ray and applies the matrix to || it. ************************************************/ Ray moveRay(Ray tempRay, Matrix inverse) { tempRay.u = matrixTimesVector(inverse, tempRay.u); tempRay.v = matrixTimesVector(inverse, tempRay.v); return tempRay; }
/************************************************ || reflection() || Purpose: this is supposed to calculate reflections || but it does not. this is never called || in the current version ************************************************/ Ray reflection(ObjectAttributes obj, Ray ray) { Vector n,L,R; Matrix temp; int iNum; Ray newRay; iNum = obj.objNumber; obj.objPoint.w = 0; temp = (objects[iNum].transform.transformation); //Intersection point in world space newRay.u = obj.worldPoint; //Direction v-2n(n.v) n = matrixTimesVector(temp, obj.objPoint); newRay.v = vector_subtract(ray.v ,vector_X_n(vector_X_n(n, dot_product(n,ray.v)),2)); return newRay; }
/************************************************ || Shade() || Purpose: checks for shadow and actually calculates || the color of the pixel. || ************************************************/ RGBColor Shade(ObjectAttributes obj, Ray ray) { RGBColor color, spec; int iNum; Vector n,L,R; Matrix temp; int notInShadow; GLdouble dotOfR; //store the object number iNum = obj.objNumber; //find normal obj.objPoint.w = 0; temp = (objects[iNum].transform.transformation); //Move normal to world space and normalize n = unit_vector(matrixTimesVector(temp, obj.objPoint)); //Color = black color.red = (ambient_light.red * objects[iNum].material.diffuse.red); color.green = (ambient_light.green * objects[iNum].material.diffuse.green); color.blue = (ambient_light.blue * objects[iNum].material.diffuse.blue); //color.red = ambient_light.red; //color.green = ambient_light.green; //color.blue = ambient_light.blue; int i; for(i =0; i < numLights; i++) { //find if object is in shdaow notInShadow = shadow(obj, i); if(notInShadow) { //printf("Adding stuff\n"); //Find L L = unit_vector(vector_subtract(lightSources[i].position, obj.worldPoint)); //Find R R = vector_subtract(L ,vector_X_n(vector_X_n(n, dot_product(n,L)),2)); dotOfR = dot_product(R,ray.v); //Add in lights color.red += lightSources[i].color.red * (objects[iNum].material.diffuse.red * dot_product(L, n)); color.green += lightSources[i].color.green * (objects[iNum].material.diffuse.green * dot_product(L, n)); color.blue += lightSources[i].color.blue * (objects[iNum].material.diffuse.blue * dot_product(L, n)); if(dotOfR > 0) //checks for negative light { color.red += lightSources[i].color.red * (objects[iNum].material.specular.red * pow(dotOfR,objects[iNum].material.shininess)) ; color.green += lightSources[i].color.green * (objects[iNum].material.specular.green * pow(dotOfR,objects[iNum].material.shininess)) ; color.blue += lightSources[i].color.blue * (objects[iNum].material.specular.blue * pow(dotOfR,objects[iNum].material.shininess)) ; } //Reflections if(objects[iNum].material.specular.red > 0 || objects[iNum].material.specular.green > 0 || objects[iNum].material.specular.blue > 0) { //spec = trace(reflection(obj, ray)); //color.red += spec.red * objects[iNum].material.specular.red; //color.green += spec.green * objects[iNum].material.specular.green; //color.blue += spec.blue * objects[iNum].material.specular.blue; } } } if(color.red > 1) color.red = 1; if(color.green > 1) color.green = 1; if(color.blue > 1) color.blue = 1; if(color.red < 0) color.red = 0; if(color.green < 0) color.green = 0; if(color.blue < 0) color.blue = 0; return color; }
/* ----------------------------------------------------------------- */ int output_main(int argc, char *argv[]) { int i,j,x,y,z,numOfVars,numOfRows,numOfFixPoints,numOfLabels,infoLevel, degree,lowdegree,highdegree,coord,sizeOfLayer,val; char *s; char fileName[127],outFileName[127],domFileName[127],symFileName[127], varFileName[127],groFileName[127],costFileName[127]; char **labels; vector v,w,fixpoints; listVector *A, *B, *C, *basis, *domBasis, *tmp, *tmpV, *symmGroup, *weights; FILE *in; infoLevel=standardInfoLevel; for (i=1;i<argc-1;i++) { if (strncmp(argv[i],"--",2)==0) { if (strncmp(argv[i],"--qui",5)==0) { infoLevel=-1; } } } if (infoLevel>-1) { printVersionInfo(); } for (i=1; i<argc; i++) { if (strncmp(argv[i],"--pos",5)==0) { strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); basis=extractPositivePartsOfVectors(basis,numOfVars); strcpy(outFileName,fileName); strcat(outFileName,".pos"); printListVectorToFile(outFileName,basis,numOfVars); } if (strncmp(argv[i],"--rep",5)==0) { strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); strcpy(symFileName,fileName); strcat(symFileName,".sym.full"); symmGroup=readListVector(&numOfVars,symFileName); if (symmGroup==0) { strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); strcpy(symFileName,fileName); strcat(symFileName,".sym"); symmGroup=readListVector(&numOfVars,symFileName); tmpV=symmGroup; while (tmpV) { int i; v=tmpV->first; for (i=0; i<numOfVars; i++) v[i]=v[i]-1; tmpV->first=v; tmpV=tmpV->rest; } symmGroup=generateSymmetryGroup(symmGroup,numOfVars); strcat(symFileName,".full"); printListVectorToFile(symFileName, symmGroup, numOfVars); } basis=extractSymmetryRepresentatives(basis,symmGroup,numOfVars); strcpy(outFileName,fileName); strcat(outFileName,".rep"); printListVectorToFile(outFileName,basis,numOfVars); printf("%d representatives found.\n",lengthListVector(basis)); } if (strncmp(argv[i],"--dom",5)==0) { strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); strcpy(domFileName,argv[argc-2]); domBasis=readListVector(&numOfVars,domFileName); basis=extractNonDominatedVectors(basis,domBasis,numOfVars); strcpy(outFileName,fileName); strcat(outFileName,".nondom"); printListVectorToFile(outFileName,basis,numOfVars); printf("%d non-dominated vectors found.\n", lengthListVector(basis)); } if (strncmp(argv[i],"--max",5)==0) { strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); strcpy(symFileName,fileName); strcat(symFileName,".sym.full"); symmGroup=readListVector(&numOfVars,symFileName); if (symmGroup==0) { strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); strcpy(symFileName,fileName); strcat(symFileName,".sym"); symmGroup=readListVector(&numOfVars,symFileName); tmpV=symmGroup; while (tmpV) { int i; v=tmpV->first; for (i=0; i<numOfVars; i++) v[i]=v[i]-1; tmpV->first=v; tmpV=tmpV->rest; } symmGroup=generateSymmetryGroup(symmGroup,numOfVars); strcat(symFileName,".full"); printListVectorToFile(symFileName, symmGroup, numOfVars); } basis=extractMaximalNonDominatedVectors(basis,symmGroup,numOfVars); strcpy(outFileName,fileName); strcat(outFileName,".maxnondom"); printListVectorToFile(outFileName,basis,numOfVars); printf("%d maximal non-dominated vectors found.\n", lengthListVector(basis)); } if (strncmp(argv[i],"--exp",5)==0) { strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); strcpy(symFileName,fileName); strcat(symFileName,".sym.full"); symmGroup=readListVector(&numOfVars,symFileName); if (symmGroup==0) { strcpy(symFileName,fileName); strcat(symFileName,".sym"); symmGroup=readListVector(&numOfVars,symFileName); tmpV=symmGroup; while (tmpV) { int i; v=tmpV->first; for (i=0; i<numOfVars; i++) v[i]=v[i]-1; tmpV->first=v; tmpV=tmpV->rest; } symmGroup=generateSymmetryGroup(symmGroup,numOfVars); } basis=expandRepresentativeIntoFullOrbits(basis,symmGroup,numOfVars,10); strcpy(outFileName,fileName); strcat(outFileName,".exp"); printListVectorToFile(outFileName,basis,numOfVars); } if (strncmp(argv[i],"--deg",5)==0) { strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); if (argc==3) { printL1NormOfListVector(basis,numOfVars); } else { if (argc==4) { degree=atoi(argv[i+1]); printf("degree = %d\n",degree); strcpy(outFileName,fileName); strcat(outFileName,".deg."); strcat(outFileName,argv[i+1]); printListVectorWithGivenDegreesToFile(outFileName,basis,numOfVars, degree,degree); } else { lowdegree=atoi(argv[i+1]); highdegree=atoi(argv[i+2]); printf("degrees %d..%d\n",lowdegree,highdegree); strcpy(outFileName,fileName); strcat(outFileName,".deg."); strcat(outFileName,argv[i+1]); strcat(outFileName,"-"); strcat(outFileName,argv[i+2]); printListVectorWithGivenDegreesToFile(outFileName,basis,numOfVars, lowdegree,highdegree); } } return(0); } if (strncmp(argv[i],"--sup",5)==0) { strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); if (argc==3) { printSupportsOfListVector(basis,numOfVars); } else { if (argc==4) { degree=atoi(argv[i+1]); printf("size of support = %d\n",degree); strcpy(outFileName,fileName); strcat(outFileName,".supp."); strcat(outFileName,argv[i+1]); printListVectorWithGivenSupportsToFile(outFileName,basis,numOfVars, degree,degree); } else { lowdegree=atoi(argv[i+1]); highdegree=atoi(argv[i+2]); printf("sizes of support %d..%d\n",lowdegree,highdegree); strcpy(outFileName,fileName); strcat(outFileName,".supp."); strcat(outFileName,argv[i+1]); strcat(outFileName,"-"); strcat(outFileName,argv[i+2]); printListVectorWithGivenSupportsToFile(outFileName,basis,numOfVars, lowdegree,highdegree); } } return(0); } if (strncmp(argv[i],"--typ",5)==0) { strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); sizeOfLayer=atoi(argv[i+1]); printTypesOfListVector(basis,sizeOfLayer,numOfVars); return(0); } if (strncmp(argv[i],"--non",5)==0) { strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); if (argc==3) { printf("You need to specify a coordinate!\n"); return(0); } else { coord=atoi(argv[i+1]); strcpy(outFileName,fileName); strcat(outFileName,".nonzero."); strcat(outFileName,argv[i+1]); printListVectorWithGivenNonzeroEntryToFile(outFileName,basis, numOfVars,coord); } return(0); } if (strncmp(argv[i],"--AxB",5)==0) { strcpy(fileName,argv[argc-3]); A=readListVector(&numOfVars,fileName); strcpy(fileName,argv[argc-2]); B=readListVector(&numOfVars,fileName); v=matrixTimesVector(A,B->first,lengthListVector(A),numOfVars); C=createListVector(v); strcpy(fileName,argv[argc-1]); printListVectorToFile(fileName,C,lengthListVector(A)); } if (strncmp(argv[i],"--0-1",5)==0) { strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); basis=extractZeroOneVectors(basis,numOfVars); strcpy(outFileName,fileName); strcat(outFileName,".0-1"); printListVectorToFile(outFileName,basis,numOfVars); } if (strncmp(argv[i],"--3wa",5)==0) { strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); x=atoi(argv[i+1]); y=atoi(argv[i+2]); z=atoi(argv[i+3]); strcpy(outFileName,fileName); strcat(outFileName,".3way"); print3wayTables(outFileName,basis,x,y,z,numOfVars); } if (strncmp(argv[i],"--tra",5)==0) { strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); strcpy(outFileName,fileName); strcat(outFileName,".tra"); printTransposedListVectorToFile(outFileName,basis,numOfVars); } if (strncmp(argv[i],"--map",5)==0) { strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); strcpy(outFileName,fileName); strcat(outFileName,".maple"); printListVectorMaple(outFileName,basis,numOfVars); } if (strncmp(argv[i],"--mac",5)==0) { strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); strcpy(outFileName,fileName); strcat(outFileName,".macaulay2"); printListVectorMacaulay2(outFileName,basis,numOfVars); } if (strncmp(argv[i],"--mat",5)==0) { strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); strcpy(outFileName,fileName); strcat(outFileName,".mathematica"); printListVectorMaple(outFileName,basis,numOfVars); } if (strncmp(argv[i],"--coc",5)==0) { strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); strcpy(outFileName,fileName); strcat(outFileName,".cocoa"); printListVectorMaple(outFileName,basis,numOfVars); } if (strncmp(argv[i],"--bin",5)==0) { strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); strcpy(outFileName,fileName); strcat(outFileName,".bin"); labels=0; strcpy(varFileName,fileName); strcat(varFileName,".vars"); if ((in = fopen(varFileName,"r"))) { int i; printf("File \"%s\" found. 4ti2 will use it.\n\n",varFileName); if (fscanf(in,"%d %d",&numOfRows, &numOfLabels)!=2 || numOfRows!=1) { printf("ERROR: Unrecognised file format for \"%s\".\n", varFileName); exit(1); } if (numOfLabels != numOfVars) { printf("ERROR: Incorrect number of variable names in \"%s\".\n", varFileName); exit(1); } labels = (char **)malloc(sizeof(char*)*(numOfVars)); for (i=0; i<numOfVars; i++) { s=(char *)malloc(sizeof(char)*127); if (fscanf(in,"%s",s) != 1) { printf("ERROR: Unrecognised file format for \"%s\".\n", varFileName); exit(1); } labels[i]=s; } fclose(in); } printListBinomialsToFile(outFileName,basis,numOfVars,labels); } if (strncmp(argv[i],"--sum",5)==0) { strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); v=createVector(numOfVars); for (i=0; i<numOfVars; i++) v[i]=0; while (basis) { for (i=0; i<numOfVars; i++) v[i]=v[i]+(basis->first)[i]; basis=basis->rest; } printVector(v,numOfVars); } if (strncmp(argv[i],"--sub",5)==0) { strcpy(fileName,argv[argc-2]); basis=readListVector(&numOfVars,fileName); v=basis->first; strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); strcpy(outFileName,fileName); strcat(outFileName,".submat"); printSubsetOfListVectorToFile(outFileName,basis,v,numOfVars); } if (strncmp(argv[i],"--rem",5)==0) { if (strncmp(argv[i],"--remcol",8)==0) { /* Remove column. */ strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); coord=atoi(argv[argc-2]); strcpy(outFileName,fileName); strcat(outFileName,".remcol"); printListVectorWithoutColumnToFile(outFileName,basis,coord,numOfVars); } } if (strncmp(argv[i],"--sta",5)==0) { /* Extracting those symmetries from a list of given symmetries that keep a given list of vectors fixed. */ strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); strcpy(symFileName,argv[argc-2]); symmGroup=readListVector(&numOfVars,symFileName); symmGroup=extractStabilizer(basis,symmGroup,numOfVars); strcpy(outFileName,symFileName); strcat(outFileName,".stab"); printListVectorToFile(outFileName,symmGroup,numOfVars); } if (strncmp(argv[i],"--fil",5)==0) { /* Fill specified column with specified value. */ strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); coord=atoi(argv[argc-3]); val=atoi(argv[argc-2]); tmp=basis; while (tmp) { (tmp->first)[coord-1]=val; tmp=tmp->rest; } strcpy(outFileName,fileName); strcat(outFileName,".fil"); printListVectorToFile(outFileName,basis,numOfVars); } if (strncmp(argv[i],"--add",5)==0) { /* Add column with specified value. */ strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); coord=atoi(argv[argc-3]); val=atoi(argv[argc-2]); strcpy(outFileName,fileName); strcat(outFileName,".addcol"); printListVectorWithAdditionalColumnToFile(outFileName,basis, coord,val,numOfVars); } if (strncmp(argv[i],"--fix",5)==0) { /* Extracting those vectors that have given coordinates x[i]=i. */ numOfFixPoints=argc-3; fixpoints=createVector(numOfFixPoints); for (j=2;j<argc-1;j++) fixpoints[j-2]=atoi(argv[j]); strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); basis=extractFixedVectors(basis,fixpoints,numOfFixPoints); strcpy(outFileName,fileName); strcat(outFileName,".fix"); printListVectorToFile(outFileName,basis,numOfVars); } if (strncmp(argv[i],"--fox",5)==0) { /* Extracting those vectors that have given coordinates x[i]=i. */ numOfFixPoints=argc-3; fixpoints=createVector(numOfFixPoints); for (j=2;j<argc-1;j++) fixpoints[j-2]=atoi(argv[j]); strcpy(fileName,argv[argc-1]); basis=readListVector(&numOfVars,fileName); basis=extractRelaxedFixedVectors(basis,fixpoints,numOfFixPoints); strcpy(outFileName,fileName); strcat(outFileName,".fox"); printListVectorToFile(outFileName,basis,numOfVars); } if (strncmp(argv[i],"--ini",5)==0) { strcpy(fileName,argv[argc-1]); strcpy(groFileName,fileName); strcat(groFileName,".gro"); basis=readListVector(&numOfVars,groFileName); strcpy(costFileName,argv[argc-1]); strcat(costFileName,".cost"); weights=readListVector(&numOfVars,costFileName); if (weights!=0) { w=weights->first; } else { int i; w=createVector(numOfVars); for (i=0;i<numOfVars;i++) w[i]=1; } basis=extractInitialForms(basis,w,numOfVars); strcpy(outFileName,fileName); strcat(outFileName,".ini"); printListVectorToFile(outFileName,basis,numOfVars); labels=0; strcpy(varFileName,fileName); strcat(varFileName,".vars"); if ((in = fopen(varFileName,"r"))) { int i; printf("File \"%s\" found. 4ti2 will use it.\n\n",varFileName); fscanf(in,"%d %d",&numOfRows, &numOfLabels); labels = (char **)malloc(sizeof(char*)*(numOfVars)); if (fscanf(in,"%d %d",&numOfRows, &numOfLabels)!=2 || numOfRows!=1) { printf("ERROR: Unrecognised file format for \"%s\".\n", varFileName); exit(1); } if (numOfLabels != numOfVars) { printf("ERROR: Incorrect number of variable names in \"%s\".\n", varFileName); exit(1); } for (i=0; i<numOfVars; i++) { s=(char *)malloc(sizeof(char)*127); if (fscanf(in,"%s",s) != 1) { printf("ERROR: Unrecognised file format for \"%s\".\n", varFileName); exit(1); } labels[i]=s; } fclose(in); } strcpy(outFileName,fileName); strcat(outFileName,".ini.bin"); printListMonomialsAndBinomialsToFile(outFileName,basis,numOfVars,labels); } } return (0); }