/////////////////////////////////////////////////////////////////////////// // // NAME // main.cpp -- entry point for mondrian motion code // // USAGE // Mondrian ... // // DESCRIPTION // // SEE ALSO // // Copyright © Timothy Bahls, Daniel Scharstein, 2003. // /////////////////////////////////////////////////////////////////////////// #include #include #include #include "Image.h" #include "ImageIO.h" #include "Error.h" #include "Scene.h" #include "Utils.h" #include "Deductor.h" #include "Approximator.h" #include "Rasterizor.h" #include "Approx2D.h" int main(int argc, const char *argv[]) { if(argc>2){ printf("argc=%d\n",argc); fprintf(stderr, "usage1: Mondrian\nusage2: Mondrian output"); exit(1); } bool dataSet=false; bool approx=false;//float values on or off? bool multi=false;//compare deductor with rasterizor? bool verbose=true; bool random=false;//randomly created set? bool twoD=false; bool stereo=true;//Mondrian Stereo? CByteImage* imgs; int s=-1; int iters=1; int nFrames=10; int nregions = 10; if (iters>1){ verbose=false; } if(twoD){ multi=false; } int times=0; int maxtimes=-10000;//arbitrary very low number int maxSeed=-10000;//arbitrary very low number if(s==-1&&iters==1) random=true; if(s==-1&&iters!=0){ s=0; } int stop=iters+s;//stop running trials when this number is reached const char *outname="testout"; if(argc==2){ outname = argv[1]; dataSet=true; multi=false; verbose=false; } for(;s!=stop;s++){ int seed; if(random&&iters==1){ seed = time(NULL) % 1000; }else{ seed=s%1000; } srand(seed); try { int imsize = 256; CDeductor deductor(nFrames,verbose); CApproximator approximator(nFrames,verbose); CRasterizor rasterizor(nFrames,verbose,imsize); CApprox2D approxTwoD(nFrames,verbose); CScene scene; imgs=new CByteImage[nFrames]; if(twoD){ if(!stereo){ scene.makeTwoDScene(nregions, imsize); }else{ scene.makeStereoScene(nregions, imsize); } }else{ if(approx){ scene.makeApproximateScene(nregions, imsize, !twoD, false); }else{ scene.makeRandomScene(nregions, imsize, !twoD, false); } } for (int f = 0; f < nFrames; f++) { CShape sh(imsize, !twoD ? 50 : imsize, 4); CByteImage im(sh); float time = (float)f; imgs[f]=scene.drawScene(im, time); if(iters==1){ char fname[200]; if(dataSet){ sprintf(fname, "../../data/%s%02d.ppm",outname, f); }else{ sprintf(fname, "../images/%s%02d.ppm",outname, f); } WriteImage(im, fname); if(verbose) printf("."); } if(twoD){ //do nothing }else{ if(approx){ approximator.readFrame(im,f); }else{ rasterizor.readFrame(im,f); //deductor.readFrame(im,f); } if(multi){ deductor.readFrame(im,f); } } } if(dataSet){ scene.sortByDepth();//shouldn't be necesary for(int i=0; icolor; printf("[%d,%d,%d] ",c.R,c.G,c.B); justify(ptr->vel.x); printf("\n"); } continue; } if(twoD){ int t; if(stereo){ t=approxTwoD.goGoGo(imgs, stereo,1.0f,7.0f); }else{ t=approxTwoD.goGoGo(imgs, stereo,-5.0f,5.0f); } times+=t; if(t>maxtimes){ maxtimes=t; maxSeed=seed; } if(verbose) scene.printDescription(true); if(verbose){ printf("\n seed=%d \n times=%d\n", seed,t); }else{ printf("seed %d %d\n", seed,t); } approxTwoD.checkAccuracy(scene); }else{ if(verbose){ printf("\n"); if(approx){ approximator.printData(); }else{ rasterizor.printData(); //deductor.printData(); } } int d=0; int t=0; if(multi){ d=deductor.goGoGo(); } if(approx){ t=approximator.goGoGo(); }else{ t=rasterizor.goGoGo(false); //t=deductor.goGoGo(); } if(verbose){ printf("\n seed=%d \n times=%d\n", seed,t); }else{ if(!dataSet){ printf("seed %d %d\n", seed,t); } } times+=t; if(t>maxtimes){ maxtimes=t; maxSeed=seed; } if(multi&&verbose){ printf("\n Results:\n\n"); deductor.reportResults(); printf("Times: %d",d); rasterizor.reportResults(); printf("Times: %d",t); } if(verbose){ scene.printDescription(approx); } if(approx){ approximator.checkAccuracy(scene); }else{ rasterizor.checkAccuracy(scene); deductor.checkAccuracy(scene); } } } catch (CError &err) { fprintf(stderr, err.message); fprintf(stderr, "\n"); return -1; } } if(!dataSet){ printf("Times: %d Max Times: %d Max Seed: %d",times,maxtimes,maxSeed); } return 0; }