/* * $Id: bench.c,v 1.1.1.1 2005/09/18 22:04:22 dhmunro Exp $ * Exercise GIST graphics */ /* Copyright (c) 2005, The Regents of the University of California. * All rights reserved. * This file is part of yorick (http://yorick.sourceforge.net). * Read the accompanying LICENSE file for details. */ #include "pstdlib.h" #include "pstdio.h" #include "hlevel.h" #include #include #include #ifndef NO_XLIB #include "xfancy.h" #else #include "play.h" /* Animated versions of low level tests use these directly-- ordinarily they are used indirectly via hlevel.h, as in the animate command in on_stdin. */ static int GxAnimate(Engine *engine, GpBox *viewport); static int GxStrobe(Engine *engine, int clear); static int GxDirect(Engine *engine); static int GxAnimate(Engine *engine, GpBox *viewport) { return 0; } static int GxStrobe(Engine *engine, int clear) { return 0; } static int GxDirect(Engine *engine) { return 0; } #endif #define PRINTF p_stdout #define PRINTF1(f,x) sprintf(p_wkspc.c,f,x);p_stdout(p_wkspc.c) #define PRINTF2(f,x,y) sprintf(p_wkspc.c,f,x,y);p_stdout(p_wkspc.c) #define PRINTF3(f,x,y,z) sprintf(p_wkspc.c,f,x,y,z);p_stdout(p_wkspc.c) #define DPI 75 #define PI 3.14159265359 /* Mesh for benchmarks 0-4 */ #define NCOLORS 240 #define NFRAMES 50 #define AMPLITUDE 0.5 #define NMID 25 #define N (2*NMID+1) #define DPHI (2.0*PI/8.3) GpReal cosine[N], amplitude[NFRAMES]; GaQuadMesh mesh; GpReal *xmesh=0, *ymesh=0; int *ireg=0; GpColor *cmesh=0; int meshReg= 0; int meshBnd= 0; #define PALETTE_FILE "earth.gp" int actualColors; GpColorCell *palette; /* Level function and vector function */ GpReal *z=0, *u=0, *v=0; GpReal zLevels[10]= { -.9, -.7, -.5, -.3, -.1, .1, .3, .5, .7, .9 }; /* Lissajous test */ #define LISSPTS 400 GpReal xliss[LISSPTS], yliss[LISSPTS]; int animate= 0, markers= 0, markType= M_POINT; #define LISSFRAMES 50 #define LISSSIZE 40.0 #define NA1 1 #define NB1 5 #define NA2 2 #define NB2 7 #define RC1 40.0 #define RC2 160.0 #define DPHASE (2*PI/(LISSFRAMES-1)) #define DTHETA (PI/(LISSFRAMES-1)) #define DELPHI (2*PI/(LISSPTS-1)) GpReal xSmall[7]= { 1.1, 1.2, 9.1, 9.5, 11.5, 12.5, 13.6 }; GpReal ySmall[7]= { 1.0, 10., 5.0, 9.0, 8.0, 5.0, 4.0 }; GpReal xqSmall[7]; GpReal yqSmall[7]; static void GenerateLiss(int i, GpReal rc, GpReal size, int na, int nb); static void GenerateLiss(int i, GpReal rc, GpReal size, int na, int nb) { double theta= i*DTHETA; double phase= i*DPHASE; double xoff= rc*cos(theta), yoff= rc*sin(theta); int j; for (j=0 ; j1.0) { gistA.l.width= 1.0; PRINTF(" Toggle wide lines (now off)\n"); } else { gistA.l.width= 8.0; PRINTF(" Toggle wide lines (now on)\n"); } GhSetLines(); } else if (strcmp(token, "linetype")==0) { GhGetLines(); gistA.l.type++; if (gistA.l.type>L_DASHDOTDOT) gistA.l.type= L_SOLID; if (gistA.l.type==L_SOLID) PRINTF(" Toggle line type (now solid)\n"); else if (gistA.l.type==L_DASH) PRINTF(" Toggle line type (now dashed)\n"); else if (gistA.l.type==L_DOT) PRINTF(" Toggle line type (now dotted)\n"); else if (gistA.l.type==L_DASHDOT) PRINTF(" Toggle line type (now dash-dot)\n"); else if (gistA.l.type==L_DASHDOTDOT) PRINTF(" Toggle line type (now dash-dot-dot)\n"); else PRINTF(" Toggle line type (now bad type?)\n"); GhSetLines(); } else if (strcmp(token, "closed")==0) { GhGetLines(); if (gistA.dl.closed) { gistA.dl.closed= 0; PRINTF(" Toggle closed lines (now off)\n"); } else { gistA.dl.closed= 1; PRINTF(" Toggle closed lines (now on)\n"); } GhSetLines(); } else if (strcmp(token, "smooth")==0) { GhGetLines(); if (gistA.dl.smooth==4) { gistA.dl.smooth= 0; PRINTF(" Toggle smooth lines (now off)\n"); } else if (gistA.dl.smooth==1) { gistA.dl.smooth= 4; PRINTF(" Toggle smooth lines (now max)\n"); } else { gistA.dl.smooth= 1; PRINTF(" Toggle smooth lines (now min)\n"); } GhSetLines(); } else if (strcmp(token, "rays")==0) { GhGetLines(); if (gistA.dl.rays) { gistA.dl.rays= 0; PRINTF(" Toggle rays (now off)\n"); } else { gistA.dl.rays= 1; PRINTF(" Toggle rays (now on)\n"); } GhSetLines(); } else if (strcmp(token, "edges")==0) { GhGetFill(); if (gistA.e.type!=L_NONE) { gistA.e.type= L_NONE; PRINTF(" Toggle edges on plf (now off)\n"); } else { gistA.e.type= L_SOLID; PRINTF(" Toggle edges on plf (now on)\n"); } GhSetFill(); } else if (strcmp(token, "limits")==0) { char *suffix; GpReal limits[4], value; int i= 0; if (GdGetLimits()) { PRINTF("****** No drawing yet\n"); return; } PRINTF(" Setting limits\n"); limits[0]= gistD.limits.xmin; limits[1]= gistD.limits.xmax; limits[2]= gistD.limits.ymin; limits[3]= gistD.limits.ymax; while ((token= strtok(0, "=, \t\n"))) { if (strcmp(token, "nice")==0) { token= strtok(0, "= \t\n"); if (!token) break; if (strcmp(token, "0")==0) gistD.flags&= ~D_NICE; else gistD.flags|= D_NICE; } else if (strcmp(token, "square")==0) { token= strtok(0, "= \t\n"); if (!token) break; if (strcmp(token, "0")==0) gistD.flags&= ~D_SQUARE; else gistD.flags|= D_SQUARE; } else if (strcmp(token, "restrict")==0) { token= strtok(0, "= \t\n"); if (!token) break; if (strcmp(token, "0")==0) gistD.flags&= ~D_RESTRICT; else gistD.flags|= D_RESTRICT; } else if (i<4) { if (strcmp(token, "e")==0) { gistD.flags|= (D_XMIN<M_CROSS) { if (markType>='C') markType= M_POINT; else if (markType<'A') markType= 'A'; } GdLines(7, xSmall, ySmall); /* change curve for next pass */ for (i=0 ; i<7 ; i++) ySmall[i]+= 1.0; GhBeforeWait(); } else if (strcmp(token, "pldj")==0) { int i; PRINTF(" Plot disjoint lines.\n"); GhGetLines(); gistD.legend= "7 point disjoint"; for (i=0 ; i<7 ; i++) { xqSmall[i]= xSmall[i]+1.5; yqSmall[i]= ySmall[i]+0.3; } GdDisjoint(7, xSmall, ySmall, xqSmall, yqSmall); /* change curve for next pass */ for (i=0 ; i<7 ; i++) ySmall[i]+= 1.0; GhBeforeWait(); } else if (strcmp(token, "plc1")==0) { PRINTF(" Plot contours.\n"); GenerateMesh(1, amplitude[NFRAMES-2]); GhGetLines(); gistD.legend= "Contours"; gistA.dl.marks= markers; GdContours(noCopy, &mesh, meshReg, z, zLevels, 10); GhBeforeWait(); } else if (strcmp(token, "animate")==0) { if (animate) { animate= 0; GhFMAMode(2, 0); PRINTF(" Toggle animation mode (now off)\n"); } else { animate= 1; GhFMAMode(2, 1); PRINTF(" Toggle animation mode (now on)\n"); } GhBeforeWait(); } else if (strcmp(token, "marks")==0) { if (markers) { markers= 0; PRINTF(" Toggle markers (now off)\n"); } else { markers= 1; PRINTF(" Toggle markers (now on)\n"); } } else if (strcmp(token, "legends")==0) { if (ghDevices[0].doLegends) { ghDevices[0].doLegends= 0; PRINTF(" Toggle hcp legends (now off)\n"); } else { ghDevices[0].doLegends= 1; PRINTF(" Toggle hcp legends (now on)\n"); } } else if (strcmp(token, "plm1")==0) { PRINTF(" GdMesh test\n"); gistA.l.color= FG_COLOR; GhGetLines(); GenerateMesh(1, amplitude[NFRAMES-2]); gistD.legend= "Test mesh"; GdMesh(noCopy, &mesh, meshReg, meshBnd, 0); GhBeforeWait(); } else if (strcmp(token, "plf1")==0) { PRINTF(" GdFillMesh test\n"); GenerateMesh(1, amplitude[NFRAMES-2]); GenerateColors(); gistD.legend= "Test filled mesh"; GdFillMesh(noCopy, &mesh, meshReg, cmesh+N+1, N); GhBeforeWait(); } else if (strcmp(token, "txout")==0) { PRINTF(" Exterior text\n"); GhGetText(); gistA.t.color= MAGENTA_COLOR; gistA.t.font= T_NEWCENTURY; gistA.t.height= 24.*ONE_POINT; gistA.t.opaque= 1; gistD.legend= 0; GdText(0.2, 0.5, "Outside", 0); GhBeforeWait(); } else if (strcmp(token, "txin")==0) { PRINTF(" Interior text\n"); GhGetText(); gistA.t.color= GREEN_COLOR; gistA.t.font= T_NEWCENTURY; gistA.t.height= 10.*ONE_POINT; gistA.t.opaque= 1; gistD.legend= 0; GdText(0.5, 0.5, "Inside", 1); GhBeforeWait(); } else if (strcmp(token, "calib")==0) { GpReal y0= 0.85; GpReal x[2], y[2], x2[2]; PRINTF(" Text calibration frame\n"); GhGetText(); gistA.t.font= calibFont; gistA.t.height= 14.*ONE_POINT; gistA.t.alignH= TH_NORMAL; gistA.t.alignV= TV_NORMAL; gistA.t.opaque= 0; gistD.legend= 0; GdText(0.15, y0-0.0*gistA.t.height, "Times 14 pt gjpqy", 0); GdText(0.15, y0-1.0*gistA.t.height, "Times 14 pt EFTZB", 0); GdText(0.15, y0-2.0*gistA.t.height, "Third line, 14 pt", 0); GdSetSystem(-1); x[0]= x[1]= .30; y[0]= y0= 0.75; y[1]= y[0]+gistA.t.height; GhGetLines(); GdLines(2, x, y); gistA.t.alignH= TH_LEFT; GdText(0.30, y0-1.0*gistA.t.height, "Horizontal (lf)", 0); gistA.t.alignH= TH_CENTER; GdText(0.30, y0-2.5*gistA.t.height, "Horizontal (cn)", 0); gistA.t.alignH= TH_RIGHT; GdText(0.30, y0-4.0*gistA.t.height, "Horizontal (rt)", 0); y[0]= y0-4.5*gistA.t.height; y[1]= y0-5.5*gistA.t.height; GdLines(2, x, y); gistA.t.alignH= TH_NORMAL; x[0]= 0.50; x[1]= 0.50-gistA.t.height; x2[0]= 0.60; x2[1]= 0.60+gistA.t.height; y[0]= y[1]= y0= .85; GdLines(2, x, y); GdLines(2, x2, y); gistA.t.alignV= TV_TOP; GdText(0.50, y0-0.0*gistA.t.height, "Vertical (tp)", 0); y[0]= y[1]= y0-2.0*gistA.t.height; GdLines(2, x, y); GdLines(2, x2, y); gistA.t.alignV= TV_CAP; GdText(0.50, y0-2.0*gistA.t.height, "Vertical (cp)", 0); y[0]= y[1]= y0-4.0*gistA.t.height; GdLines(2, x, y); GdLines(2, x2, y); gistA.t.alignV= TV_HALF; GdText(0.50, y0-4.0*gistA.t.height, "Vertical (hf)", 0); y[0]= y[1]= y0-6.0*gistA.t.height; GdLines(2, x, y); GdLines(2, x2, y); gistA.t.alignV= TV_BASE; GdText(0.50, y0-6.0*gistA.t.height, "Vertical (ba)", 0); y[0]= y[1]= y0-8.0*gistA.t.height; GdLines(2, x, y); GdLines(2, x2, y); gistA.t.alignV= TV_BOTTOM; GdText(0.50, y0-8.0*gistA.t.height, "Vertical (bt)", 0); GdSetSystem(0); GhBeforeWait(); } else if (strcmp(token, "cfont")==0) { if (calibFont!=T_TIMES) { calibFont= T_TIMES; PRINTF(" Toggle calib font (now Times)\n"); } else { calibFont= T_HELVETICA; PRINTF(" Toggle calib font (now Helvetica)\n"); } } else if (strcmp(token, "fma")==0) { PRINTF(" Frame advance\n"); GhFMA(); } else if (strcmp(token, "hcp")==0) { PRINTF(" Sent frame to hcp\n"); GhHCP(); } else if (strcmp(token, "hcpon")==0) { PRINTF(" hcp on fma\n"); GhFMAMode(1, 2); } else if (strcmp(token, "hcpoff")==0) { PRINTF(" NO hcp on fma\n"); GhFMAMode(0, 2); } else if (strcmp(token, "redraw")==0) { PRINTF(" Redraw\n"); GhRedraw(); } else if (strcmp(token, "plt")==0) { /* Test text primitive */ GpReal ynow= 0.90; PRINTF(" Text test\n"); GhGetText(); gistA.t.color= FG_COLOR; gistA.t.font= T_HELVETICA; gistA.t.height= ONE_POINT*12.0; GdText(0.25, ynow, "Helvetica 12 pt?", 0); ynow-= gistA.t.height; GdText(0.25, ynow, "Helvetica 12 pt, second line", 0); gistA.t.height= ONE_POINT*18.0; ynow-= gistA.t.height; GdText(0.25, ynow, "Helvetica 18 pt?", 0); gistA.t.font= T_NEWCENTURY; gistA.t.height= ONE_POINT*12.0; ynow-= gistA.t.height; GdText(0.25, ynow, "New Century 12 pt, first line", 0); ynow-= gistA.t.height; gistA.t.font|= T_BOLD | T_ITALIC; GdText(0.25, ynow, "New Century 12 pt, bold italic", 0); gistA.t.font= T_NEWCENTURY; gistA.t.height= ONE_POINT*14.0; gistA.t.alignH= TH_RIGHT; ynow-= gistA.t.height; GdText(0.65, ynow, "New Century 14 pt,\nthree lines\nright justified", 0); ynow-= 3*gistA.t.height; gistA.t.alignH= TH_NORMAL; gistA.t.orient= TX_DOWN; GdText(0.25, ynow, "Path down", 0); GhBeforeWait(); } else if (strcmp(token, "help")==0 || strcmp(token, "?")==0) { PRINTF("\n This is the GIST benchmark/test program, commands are:\n"); PRINTF("\n Movies to test low level Gist functions--\n"); PRINTF("0 - raw performance test GaMesh (direct)\n"); PRINTF("1 - raw performance test GaMesh (animated)\n"); PRINTF("2 - raw performance test GaFillMesh (direct)\n"); PRINTF("3 - raw performance test GaFillMesh (animated)\n"); PRINTF("clr - toggle interframe clear for tests 0-3\n"); PRINTF("c - clear screen\n"); PRINTF("im - raw performance test GpCells\n"); PRINTF("clip - toggle floating point clip\n"); PRINTF("zoom - toggle zoom for 0-3, im, pli\n"); PRINTF("\n Property toggles for high level tests--\n"); PRINTF("bnd - mesh boundary odd0 - mesh region to 0\n"); PRINTF("odd2 - mesh region to 2 reg0 - plot region to 0\n"); PRINTF("reg1 - plot region to 1 reg2 - plot region to 2\n"); PRINTF("nocopy - toggle noCopy mode for mesh-based tests\n"); PRINTF("cmode - toggle dumping of colormap in hcp file\n"); PRINTF("earth - use earthtones palette (default). Others are:\n"); PRINTF(" stern rainbow heat gray yarg\n"); PRINTF("work - use work stylesheet (default). Others are:\n"); PRINTF(" boxed axes\n"); PRINTF("wide - toggle wide lines in all line drawings\n"); PRINTF("linetype - cycle through 5 line types in all line drawings\n"); PRINTF("closed - toggle closed lines in plg tests\n"); PRINTF("rays - toggle ray arrows in plg tests\n"); PRINTF("smooth - cycle through 3 hcp smoothnesses in plg tests\n"); PRINTF("limits, xmin, xmax, ymin, ymax, nice=1/0, square=1/0,\n"); PRINTF(" restrict=1/0 - set limits (default limits,e,e,e,e)\n"); PRINTF("logxy, 1/0, 1/0 - set/reset log scaling for x,y axes\n"); PRINTF("animate - toggle animation mode\n"); PRINTF("marks - toggle occasional curve markers for line drawings\n"); PRINTF("legends - toggle dumping of legends into hcp file\n"); PRINTF("\n Movies to test high level Gist functions--\n"); PRINTF("plg - test GdLines\n"); PRINTF("plm - test GdMesh\n"); PRINTF("plf - test GdFillMesh\n"); PRINTF("plv - test GdVectors\n"); PRINTF("plc - test GdContours\n"); PRINTF("\n Single frame tests of high level Gist functions--\n"); PRINTF("plg1 - test GdLines\n"); PRINTF("plm1 - test GdMesh\n"); PRINTF("plf1 - test GdFillMesh\n"); PRINTF("plc1 - test GdContours\n"); PRINTF("pli - test GdCells\n"); PRINTF("plt - test GdText\n"); PRINTF("pls - test GdLines in polymarker mode\n"); PRINTF("pldj - test GdDisjoint\n"); PRINTF("txin - test GdText txout - 2nd test of GdText\n"); PRINTF("calib - text calibration frame\n"); PRINTF("cfont - toggle font for calibration frame\n"); PRINTF("\n Tests of high level Gist control functions--\n"); PRINTF("fma - frame advance\n"); PRINTF("hcp - send current frame to hardcopy file\n"); PRINTF("hcpon - send every frame to hardcopy file\n"); PRINTF("hcpoff - stop sending every frame to hardcopy file\n"); PRINTF("redraw - redraw the X window\n"); PRINTF("\nquit - exit bench program (just q works too)\n"); } else { PRINTF(" NO ACTION TAKEN -- type help for (long) list of commands\n"); } return; } static int waitTest= 0; static void window_exposed(void); static int no_key = 0; int on_idle(void) { if (noKeyboard) { if (noKeyTest[no_key]) { char line[24]; strcpy(line, noKeyTest[no_key++]); on_stdin(line); } else { p_quit(); } return 1; } if (waitTest || !prompt_issued) { GhBeforeWait(); p_stdout("bench> "); prompt_issued = 1; } return 0; } static char *default_path = "~/gist:~/Gist:../g"; int on_launch(int argc, char *argv[]) { int i, j; int usePS= (argc>1 && argv[1][0]!='0'); GpReal ypage= 1.033461; /* 11.0 inches in NDC */ GpReal xpage= 0.798584; /* 8.5 inches in NDC */ GpReal meshSize; noKeyboard = waitTest = (argc>1 && argv[1][0]=='-'); gistPathDefault = default_path; p_stdinit(&on_stdin); p_idler(&on_idle); p_handler(&on_exception); p_quitter(&on_quit); #ifndef NO_XLIB g_initializer(&argc, argv); engine= GpFXEngine("Gist bench test", 0, DPI, argc>2? argv[2] : 0); hcpDefault= usePS? GpPSEngine("Gist bench test", 0, 0, "bench.ps") : GpCGMEngine("Gist bench test", 0, 0, "bench.cgm"); #else engine= GpCGMEngine("Gist bench test", 0, 0, "bench.cgm"); hcpDefault= GpPSEngine("Gist bench test", 0, 0, "bench.ps"); #endif ghDevices[0].drawing= GdNewDrawing("work.gs"); ghDevices[0].display= engine; ghDevices[0].hcp= 0; ghDevices[0].doLegends= 0; actualColors= GpReadPalette(engine, PALETTE_FILE, &palette, 240); GpSetPalette(hcpDefault, palette, actualColors); /* GpActivate(engine); */ GhSetPlotter(0); meshTrans.window= unitBox; /* Set up viewport to be 512-by-512 pixels at 100 dpi, centered for portrait mode. */ meshSize= ONE_INCH*5.125; meshTrans.viewport.xmin= 0.5*(xpage-meshSize); meshTrans.viewport.xmax= 0.5*(xpage+meshSize); meshTrans.viewport.ymin= ypage-0.5*(xpage+meshSize); meshTrans.viewport.ymax= ypage-0.5*(xpage-meshSize); /* Initialize mesh arrays */ mesh.iMax= N; mesh.jMax= N; mesh.x= xmesh= (GpReal *)p_malloc(sizeof(GpReal)*N*N); mesh.y= ymesh= (GpReal *)p_malloc(sizeof(GpReal)*N*N); mesh.reg= ireg= (int *)p_malloc(sizeof(int)*(N*N+N+1)); mesh.triangle= 0; cmesh= (GpColor *)p_malloc(sizeof(GpColor)*N*N); z= (GpReal *)p_malloc(sizeof(GpReal)*N*N); u= (GpReal *)p_malloc(sizeof(GpReal)*N*N); v= (GpReal *)p_malloc(sizeof(GpReal)*N*N); j= 0; for (i=0 ; i=N*N) ireg[i]= 0; else ireg[i]= 1; j++; if (j==N) j= 0; } /* Initialize cosines and sines for perturbation amplitude */ for (i=0 ; i"); p_quit(); }