Beispiel #1
0
int
main (int argc, char **argv)
{
	int n1,n2,nz,iz,verbose,looping,nTic1,nTic2,width,height,interp;
	float d1,f1,d2,f2,*z,
		clip,bclip,wclip,white,wfrac,
		perc,bperc,wperc,*temp,
		bhue,whue,sat,bright,
		x1beg,x2beg,x1end,x2end,
		x1min,x1max,x2min,x2max,
		fframe,dframe;
	char *label1="",*label2="",*format="",*windowtitle="",
		*labelFont="",*titleFont="",
		*axesColor="",*gridColor="",*titleColor="",
		*style="normal",*grid1="none",*grid2="none",
		*cmap;
	ClientData cd;
	XrmValue from,to;
	Widget toplevel,axes;
	XtAppContext ac;
	Display *dpy;
	Window win;
	Arg args[98];
	int nargs;
	int scr;
	unsigned int depth;

	/* initialize getpar */
	initargs(argc,argv);
	requestdoc(1);

	/* get parameters describing colormaps */
	cmap = "gray";  getparstring("cmap",&cmap);
	if (STREQ("saturation",cmap)) cmap = "sat";
	bhue = 0;  getparfloat("bhue",&bhue);  bhue /= 360.0;
	whue = 240;  getparfloat("whue",&whue); whue /= 360.0;
	sat = 1.0; getparfloat("sat",&sat);
	if (sat<0.0 || sat>1.0) err("sat must be in range [0,1]!\n");
	bright = 1.0; getparfloat("bright",&bright);
	if (bright<0.0 || bright>1.0) err("bright must be in range [0,1]!\n");

	/* get parameters describing 1st dimension sampling */
	if (!getparint("n1",&n1))
		err("Must specify number of samples in 1st dimension!\n");
	if (!getparfloat("d1",&d1)) d1 = 1.0;
	if (!getparfloat("f1",&f1)) f1 = 0.0;
	x1min = (d1>0.0)?f1:f1+(n1-1)*d1;
	x1max = (d1<0.0)?f1:f1+(n1-1)*d1;
	if (!getparfloat("x1beg",&x1beg)) x1beg = x1min;
	if (!getparfloat("x1end",&x1end)) x1end = x1max;

	/* get parameters describing 2nd dimension sampling */
	if (!getparint("n2",&n2))
		err("Must specify number of samples in 2nd dimension!\n");
	if (!getparfloat("d2",&d2)) d2 = 1.0;
	if (!getparfloat("f2",&f2)) f2 = 0.0;
	x2min = (d2>0.0)?f2:f2+(n2-1)*d2;
	x2max = (d2<0.0)?f2:f2+(n2-1)*d2;
	if (!getparfloat("x2beg",&x2beg)) x2beg = x2min;
	if (!getparfloat("x2end",&x2end)) x2end = x2max;

	/* read first frame of float data */
	nz = n1*n2;
	z = ealloc1float(nz);
	if (fread(z,sizeof(float),nz,stdin)!=nz)
		err("error reading input file");

	/* if necessary, determine clips from percentiles */
	if (getparfloat("clip",&clip)) {
		bclip = clip;
		wclip = -clip;
	}
	if ((!getparfloat("bclip",&bclip) || !getparfloat("wclip",&wclip)) &&
		!getparfloat("clip",&clip)) {
		perc = 100.0;  getparfloat("perc",&perc);
		temp = ealloc1float(nz);
		for (iz=0; iz<nz; iz++)
			temp[iz] = z[iz];
		if (!getparfloat("bclip",&bclip)) {
			bperc = perc;	getparfloat("bperc",&bperc);
			iz = (nz*bperc/100.0);
			if (iz<0) iz = 0;
			if (iz>nz-1) iz = nz-1;
			qkfind(iz,nz,temp);
			bclip = temp[iz];
		}
		if (!getparfloat("wclip",&wclip)) {
			wperc = 100.0-perc;  getparfloat("wperc",&wperc);
			iz = (nz*wperc/100.0);
			if (iz<0) iz = 0;
			if (iz>nz-1) iz = nz-1;
			qkfind(iz,nz,temp);
			wclip = temp[iz];
		}
		free1float(temp);
	}
	if (!getparfloat("white",&white)) white = (bclip+wclip)/2.0;
	if (!getparint("verbose",&verbose)) verbose = 1;
	if (!getparint("sleep",&cd.sleep)) cd.sleep=0 ;
	if (!getparint("loop",&looping)) looping = 0;
	if (verbose) {
		if(STREQ(cmap,"sat") || STREQ(cmap,"customsat")) {
			warn("bclip=%g wclip=%g white=%g",bclip,wclip,white);
		} else {
			warn("bclip=%g wclip=%g",bclip,wclip);
		}
	}
	wfrac = (bclip!=wclip) ? (bclip-white)/(bclip-wclip) : 1.0;

	/* initialize toolkit and set toplevel parameters */
 	toplevel = XtAppInitialize(&ac,"XMovie_XAPP_DEF",NULL,0,&argc,argv,NULL,NULL,0);
	dpy = XtDisplay(toplevel);
	nargs = 0;
	if (getparstring("windowtitle",&windowtitle))
		{XtSetArg(args[nargs],XtNtitle,windowtitle); nargs++;}
	if (getparstring("windowtitle",&windowtitle))
		{XtSetArg(args[nargs],XtNiconName,windowtitle); nargs++;}
	if (getparint("width",&width))
		{XtSetArg(args[nargs],XtNwidth,width); nargs++;}
	if (getparint("height",&height))
		{XtSetArg(args[nargs],XtNheight,height); nargs++;}
	XtSetArg(args[nargs],XtNinput,TRUE);nargs++; 
	XtSetValues(toplevel,args,nargs);

	/* if necessary, make private colormap */
	win = XRootWindowOfScreen(XtScreen(toplevel));
	nargs = 0;

	scr=DefaultScreen(dpy);
	depth=(unsigned int)DefaultDepth(dpy,scr);

	if (depth<=8) {
	  if (STREQ(cmap,"gray")) {
	    Colormap cm=XtcwpCreateGrayColormap(dpy,win);
	    XtSetArg(args[nargs],XtNcolormap,cm); nargs++;
	  } else if (STREQ(cmap,"hue")) {
	    Colormap cm=XtcwpCreateHueColormap(dpy,win,
					       bhue,whue,sat,bright);
	    XtSetArg(args[nargs],XtNcolormap,cm); nargs++;
	  } else if (STREQ(cmap,"sat")) {
	    Colormap cm=XtcwpCreateSatColormap(dpy,win,
					       bhue,whue,wfrac,bright);

	    XtSetArg(args[nargs],XtNcolormap,cm); nargs++;
	  }
	  XtSetValues(toplevel,args,nargs);
	}

	/* create axes and set axes parameters */
	axes = XtCreateManagedWidget("axes",xtcwpAxesWidgetClass, 
		toplevel,NULL,0);
		
	nargs = 0;

	if (getparstring("grid1",&grid1)) {
		from.addr = (char *)grid1;
		XtConvertAndStore(axes,XtRString,&from,XtcwpRAxesGrid,&to);
		if (to.addr) XtSetArg(args[nargs],XtNgrid1,*((int*)to.addr));
		nargs++;
	}
	if (getparstring("grid2",&grid2)) {
		from.addr = (char *)grid2;
		XtConvertAndStore(axes,XtRString,&from,XtcwpRAxesGrid,&to);
		if (to.addr) XtSetArg(args[nargs],XtNgrid2,*((int*)to.addr));
		nargs++;
	}

	if (getparint("nTic1",&nTic1))
		{XtSetArg(args[nargs],XtNnTic1,nTic1); nargs++;}
	if (getparint("nTic2",&nTic2))
		{XtSetArg(args[nargs],XtNnTic2,nTic2); nargs++;}
	if (getparstring("label1",&label1))
		{XtSetArg(args[nargs],XtNlabel1,label1); nargs++;}
	if (getparstring("label2",&label2))
		{XtSetArg(args[nargs],XtNlabel2,label2); nargs++;}
	if (getparstring("title",&format))
		{XtSetArg(args[nargs],XtNtitle,format); nargs++;}
	if (getparstring("style",&style)) {
		from.size = (unsigned int) strlen(style);  from.addr = (char *)style;
		XtConvertAndStore(axes,XtRString,&from,XtcwpRAxesStyle,&to);
		if (to.addr) XtSetArg(args[nargs],XtNstyle,*((int*)to.addr));
		nargs++;
	}
	if (getparstring("axesColor",&axesColor)) {
		from.addr = (char *)axesColor;
		XtConvertAndStore(axes,XtRString,&from,XtRPixel,&to);
		if (to.addr) XtSetArg(args[nargs],XtNaxesColor,
			*((unsigned long*)to.addr));
		nargs++;
	}
	if (getparstring("gridColor",&gridColor)) {
		from.addr = (char *)gridColor;
		XtConvertAndStore(axes,XtRString,&from,XtRPixel,&to);
		if (to.addr) XtSetArg(args[nargs],XtNgridColor,
			*((unsigned long*)to.addr));
		nargs++;
	}
	if (getparstring("titleColor",&titleColor)) {
		from.addr = (char *)titleColor;
		XtConvertAndStore(axes,XtRString,&from,XtRPixel,&to);
		if (to.addr) XtSetArg(args[nargs],XtNtitleColor,
			*((unsigned long*)to.addr));
		nargs++;
	}
	if (getparstring("labelFont",&labelFont)) {
		from.addr = (char *)labelFont;
		XtConvertAndStore(axes,XtRString,&from,XtRFont,&to);
		if (to.addr) XtSetArg(args[nargs],XtNlabelFont,
			*((Font*)to.addr));
		nargs++;
	}
	if (getparstring("titleFont",&titleFont)) {
		from.addr = (char *)titleFont;
		XtConvertAndStore(axes,XtRString,&from,XtRFont,&to);
		if (to.addr) XtSetArg(args[nargs],XtNtitleFont,
			*((Font*)to.addr));
		nargs++;
	}
	XtSetValues(axes,args,nargs);
	x1beg = x1min; getparfloat("x1beg",&x1beg);
	x1end = x1max; getparfloat("x1end",&x1end);
	x2beg = x2min; getparfloat("x2beg",&x2beg);
	x2end = x2max; getparfloat("x2end",&x2end);
	adjustAxesValues(n1,d1,f1,n2,d2,f2,&x1beg,&x1end,&x2beg,&x2end);
	XtcwpSetAxesValues(axes,x1beg,x1end,x2beg,x2end);

	/* frame sampling */
	if (!getparfloat("fframe",&fframe)) fframe = 1.0;
	if (!getparfloat("dframe",&dframe)) dframe = 1.0;

	/* interpolation */
	if (!getparint("interp",&interp)) interp = 1;

	/* initial display mode: cont or step */
	if (!getparint("idm", &displayMode)) displayMode = DM_CONT;

	checkpars();

	/* initialize client data */
	cd.n1 = n1;  cd.d1 = d1;  cd.f1 = f1;
	cd.n2 = n2;  cd.d2 = d2;  cd.f2 = f2;
	cd.floats = z;
	cd.fmin = bclip;
	cd.fmax = wclip;
	cd.bmin = (unsigned char) (XtcwpGetFirstPixel(dpy));
	cd.bmax = (unsigned char) (XtcwpGetLastPixel(dpy));
	if(cd.bmax==0)cd.bmax=255;
	warn("bmin=%d bmax=%d",cd.bmin,cd.bmax);
	cd.x1bega = x1beg;
	cd.x1enda = x1end;
	cd.x2bega = x2beg;
	cd.x2enda = x2end;
	cd.abytes = NULL;
	cd.bbytes = NULL;
	cd.image = NULL;
	cd.exposed = 0;
	cd.noframes = 1;
	cd.axes = axes;
	cd.looping = looping;
	cd.frame = NULL;
	cd.format = format;
	cd.iframe = 0;
	cd.fframe = fframe;
	cd.dframe = dframe;
	cd.interp = interp;
	cd.forward = 1;
	cd.ac = ac;

	/* adjust axes title if formatted */
	if (strchr(cd.format,'%') && !strstr(cd.format,"%%")) {
		sprintf(cd.title,cd.format,cd.fframe+cd.iframe*cd.dframe);
		XtVaSetValues(cd.axes,XtNtitle,cd.title,NULL);
	}

	/* add work procedure */
	cd.wpid = XtAppAddWorkProc(ac,(XtWorkProc) readFrame,&cd);

	/* add callbacks to axes widget */
	XtAddCallback(axes,XtNresizeCallback,(XtCallbackProc) resizeCB,&cd);
	XtAddCallback(axes,XtNexposeCallback,(XtCallbackProc) exposeCB,&cd);
	XtAddCallback(axes,XtNinputCallback,(XtCallbackProc) inputCB,&cd);

	/* add Button2 translation for reversing the movie */
	XtOverrideTranslations(axes,
		XtParseTranslationTable("<Btn2Up>: input()"));

	/* add Button3 translation for pausing the movie */
	XtOverrideTranslations(axes,
		XtParseTranslationTable("<Btn3Up>: input()"));

	/* set up keypress */
	XtAddEventHandler(axes, KeyPress, FALSE,
			  (XtEventHandler) key_pressed, &cd);

	/* realize everything */
	XtRealizeWidget(toplevel);

	/* go */
	XtAppMainLoop(ac);

	return EXIT_SUCCESS;
}
Beispiel #2
0
int main (int argc, char **argv)
{
	int nTic1,nTic2,width,height;
	float smin,smax,bclip,wclip,x1beg,x1end,x2beg,x2end;
	char *edgecolor="cyan",*tricolor="yellow",*cmap="gray",
		*label1="",*label2="",*title="",
		*labelFont="",*titleFont="",
		*axesColor="",*gridColor="",*titleColor="",
		*style="seismic",*grid1="none",*grid2="none";
	Model *model;
	XrmValue from,to;
	ExposeCD exposeCD;
	Widget toplevel,axes;
	Display *dpy;
	Window win;
	Arg args[100];
	int nargs;
	float bhue=0,whue=240,sat=1,bright=1;

	/* initialize getpar */
	initargs(argc,argv);
        requestdoc(0);

	
	/* read model */
	model = readModel(stdin);
	
	/* determine minimum and maximum s(x,y) */
	minmax(model,&smin,&smax);
	
	/* get optional parameters */
	getparstring("edgecolor",&edgecolor);
	getparstring("tricolor",&tricolor);
	bclip = smin; getparfloat("bclip",&bclip);
	wclip = smax; getparfloat("wclip",&wclip);
        getparstring("cmap",&cmap);   

	/* initialize toolkit intrinsics and set toplevel parameters */
	toplevel = XtInitialize(argv[0],"Sxplot",NULL,0,&argc,argv);
	nargs = 0;
	if (getparint("width",&width))
		{XtSetArg(args[nargs],XtNwidth,width); nargs++;}
	if (getparint("height",&height))
		{XtSetArg(args[nargs],XtNheight,height); nargs++;}
	XtSetValues(toplevel,args,nargs);

	/* create axes and set axes parameters */
	axes = XtCreateManagedWidget("axes",xtcwpAxesWidgetClass,
		toplevel,NULL,0);


	nargs = 0;
	if (getparstring("grid1",&grid1)) {
		from.addr = (char *)grid1;
		XtConvertAndStore(axes,XtRString,&from,XtcwpRAxesGrid,&to);
		if (to.addr) XtSetArg(args[nargs],XtNgrid1,*((int*)to.addr));
		nargs++;
	}
	if (getparstring("grid2",&grid2)) {
		from.addr = (char *)grid2;
		XtConvertAndStore(axes,XtRString,&from,XtcwpRAxesGrid,&to);
		if (to.addr) XtSetArg(args[nargs],XtNgrid2,*((int*)to.addr));
		nargs++;
	}
	if (getparint("nTic1",&nTic1))
		{XtSetArg(args[nargs],XtNnTic1,nTic1); nargs++;}
	if (getparint("nTic2",&nTic2))
		{XtSetArg(args[nargs],XtNnTic2,nTic2); nargs++;}
	if (getparstring("label1",&label1))
		{XtSetArg(args[nargs],XtNlabel1,label1); nargs++;}
	if (getparstring("label2",&label2))
		{XtSetArg(args[nargs],XtNlabel2,label2); nargs++;}
	if (getparstring("title",&title))
		{XtSetArg(args[nargs],XtNtitle,title); nargs++;}
	if (getparstring("style",&style)) {
		from.size = (unsigned int) strlen(style);  from.addr = (char *)style;
		XtConvertAndStore(axes,XtRString,&from,XtcwpRAxesStyle,&to);
		if (to.addr) XtSetArg(args[nargs],XtNstyle,*((int*)to.addr));
		nargs++;
	}
	if (getparstring("axesColor",&axesColor)) {
		from.addr = (char *)axesColor;
		XtConvertAndStore(axes,XtRString,&from,XtRPixel,&to);
		if (to.addr) XtSetArg(args[nargs],XtNaxesColor,
			*((unsigned long*)to.addr));
		nargs++;
	}
	if (getparstring("gridColor",&gridColor)) {
		from.addr = (char *)gridColor;
		XtConvertAndStore(axes,XtRString,&from,XtRPixel,&to);
		if (to.addr) XtSetArg(args[nargs],XtNgridColor,
			*((unsigned long*)to.addr));
		nargs++;
	}
	if (getparstring("titleColor",&titleColor)) {
		from.addr = (char *)titleColor;
		XtConvertAndStore(axes,XtRString,&from,XtRPixel,&to);
		if (to.addr) XtSetArg(args[nargs],XtNtitleColor,
			*((unsigned long*)to.addr));
		nargs++;
	}
	if (getparstring("labelFont",&labelFont)) {
		from.addr = (char *)labelFont;
		XtConvertAndStore(axes,XtRString,&from,XtRFont,&to);
		if (to.addr) XtSetArg(args[nargs],XtNlabelFont,
			*((Font*)to.addr));
		nargs++;
	}
	if (getparstring("titleFont",&titleFont)) {
		from.addr = (char *)titleFont;
		XtConvertAndStore(axes,XtRString,&from,XtRFont,&to);
		if (to.addr) XtSetArg(args[nargs],XtNtitleFont,
			*((Font*)to.addr));
		nargs++;
	}
	XtSetValues(axes,args,nargs);
	x1beg = model->xmin; getparfloat("x1beg",&x1beg);
	x1end = model->xmax; getparfloat("x1end",&x1end);
	x2beg = model->ymin; getparfloat("x2beg",&x2beg);
	x2end = model->ymax; getparfloat("x2end",&x2end);
	XtcwpSetAxesValues(axes,x1beg,x1end,x2beg,x2end);

	/* add callbacks to axes widget */
	XtAddCallback(axes,XtNresizeCallback,(XtCallbackProc) resizeCB,NULL);
	exposeCD.model = model;
	exposeCD.edgecolor = edgecolor;
	exposeCD.tricolor = tricolor;
	exposeCD.bclip = bclip;
	exposeCD.wclip = wclip;
	XtAddCallback(axes,XtNexposeCallback,(XtCallbackProc) exposeCB,&exposeCD);
	XtAddCallback(axes,XtNinputCallback,(XtCallbackProc) inputCB,NULL);

	/* realize widgets */
	XtRealizeWidget(toplevel);

	/* if necessary, create private colormap */
	dpy = XtDisplay(toplevel);
	win = XtWindow(toplevel);

	if (STREQ(cmap,"gray")) {
	  XSetWindowColormap(dpy,win,XtcwpCreateGrayColormap(dpy,win));
	} else if (STREQ(cmap,"hue")) {
	  XSetWindowColormap(dpy,win,XtcwpCreateHueColormap(dpy,win,
														bhue,whue,sat,bright)); /* see Note below */
	}
	
	/* go */
	XtMainLoop();

	return EXIT_SUCCESS;
}
Beispiel #3
0
main()
{
	Display *dpy;
	Window root,win;
	Colormap cmap;
	XStandardColormap scmap;
	XColor color,junk;
	XImage *image;
	XEvent event;
	GC gc;
	int scr,i;
	unsigned long black,white,pmin,pmax;
	char *data;
	
	/* connect to X server */
	dpy = XOpenDisplay(NULL);
	if ((dpy=XOpenDisplay(NULL))==NULL) {
		fprintf(stderr,"Cannot open display!\n");
		exit(-1);
	}
	scr = DefaultScreen(dpy);
	root = RootWindow(dpy,scr);
	black = BlackPixel(dpy,scr);
	white = WhitePixel(dpy,scr);
	
	/* create and map window */
	win = XCreateSimpleWindow(dpy,root,X,Y,WIDTH,HEIGHT,4,black,white);
	cmap = XtcwpCreateGrayColormap(dpy,win);
	XSetWindowColormap(dpy,win,cmap);
	XMapWindow(dpy,win);
	
	/* determine range of contiguous pixels from standard colormap */
	if (!XtcwpCreateRGBDefaultMap(dpy,&scmap)) {
		fprintf(stderr,"Cannot create standard colormap!\n");
		exit(-1);
	}
	pmin = XtcwpGetFirstPixel(dpy);
	pmax = XtcwpGetLastPixel(dpy);
	
	/* create image */
	data = (char*)malloc(WIDTH*HEIGHT);
	for (i=0; i<WIDTH*HEIGHT; ++i)
		data[i] = pmin+(pmax-pmin)*(i%WIDTH)/WIDTH;
	image = XCreateImage(dpy,DefaultVisual(dpy,scr),
		DefaultDepth(dpy,scr),ZPixmap,
		0,data,WIDTH,HEIGHT,BitmapPad(dpy),WIDTH);
	gc = XCreateGC(dpy,win,0,NULL);
	XAllocNamedColor(dpy,cmap,"red",&color,&junk);
	XSetForeground(dpy,gc,color.pixel);
	
	/* set event mask */
	XSelectInput(dpy,win,ExposureMask);

	/* loop forever */
	XPutImage(dpy,win,gc,image,0,0,0,0,WIDTH,HEIGHT);
	while(True) {
		XNextEvent(dpy,&event);
		while (XCheckTypedEvent(dpy,Expose,&event));
		XPutImage(dpy,win,gc,image,0,0,0,0,WIDTH,HEIGHT);
		XDrawLine(dpy,win,gc,0,0,WIDTH,HEIGHT);
	}

	/* close display */
	XCloseDisplay(dpy);
}