⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xcontour.c

📁 su 的源代码库
💻 C
📖 第 1 页 / 共 2 页
字号:
	/* set normal event mask */	XSelectInput(dpy,win,		StructureNotifyMask |		ExposureMask |		KeyPressMask |		PointerMotionMask |		ButtonPressMask |		ButtonReleaseMask |		Button1MotionMask |		Button2MotionMask);		/* map window */	XMapWindow(dpy,win);		/* clear the window */	XClearWindow(dpy,win);	/* Set Backing store so we don't need to update the plot unless we	   need it... Check if it's work in IRIX*/	set_window_attributes.backing_store = Always;	XChangeWindowAttributes (dpy,win, CWBackingStore, &set_window_attributes);	/* determine good size for axes box */	xSizeAxesBox(dpy,win,		labelfont,titlefont,style,		&x,&y,&width,&height);		/* note that image is out of date */	imageOutOfDate = 1;	/* main event loop */	while((imageOutOfDate)|(~imageOutOfDate)/*True*/) {		XNextEvent(dpy,&event);		/* if window was resized */		if (event.type==ConfigureNotify &&			(event.xconfigure.width!=winwidth ||			 event.xconfigure.height!=winheight)) {			winwidth = event.xconfigure.width;			winheight = event.xconfigure.height;										/* determine good size for axes box */			xSizeAxesBox(dpy,win,				labelfont,titlefont,style,				&x,&y,&width,&height);						/* clear the window *//*			XClearWindow(dpy,win);*/						/* note that image is out of date */			imageOutOfDate = 1;		/* else if window exposed */		} else if (event.type==Expose) {		        /* clear all expose events from queue */		        while (XCheckTypedEvent(dpy,Expose,&event));		        if(imageOutOfDate){			  float *ixX,*iyX,yscale,xscale;			  /* I only clear the window when I need to*/			  /* For a static image I just let backingstore 			     handle it*/			  XClearWindow(dpy,win);			  ixX=ealloc1float(nxb);			  iyX=ealloc1float(nyb);			  /* map x1 and x2 units to bitmap units */			  xscale = (width-1)/(ix[ixb+nxb-1]-ix[ixb]);			  yscale = (height-1)/(iy[iyb+nyb-1]-iy[iyb]);			  			  for (i1=0; i1<nxb; i1++) 			    ixX[i1]=(ix[ixb+i1]-ix[ixb])*xscale;			  for (i2=0; i2<nyb; i2++) 			    iyX[i2]=(iy[iyb+i2]-iy[iyb])*yscale;						  newContour(dpy, win,gci,				     x,y,nxb,&ixX[0],nyb,				     &iyX[0],czb,				     nc,c,cwidth,ccolor,cdash,labelcf,labelcper,nlabelc,labelcfont,labelccolor,nplaces);			free1float(ixX);			free1float(iyX);			}						/* draw axes on top of image */			xDrawAxesBox(dpy,win,				x,y,width,height,				x1begb,x1endb,0.0,0.0,				d1num,f1num,n1tic,grid1,label1,				x2begb,x2endb,0.0,0.0,				d2num,f2num,n2tic,grid2,label2,				labelfont,title,titlefont,				labelcolor,titlecolor,gridcolor,				style);		/* else if key down */		} else if (event.type==KeyPress) {			XLookupString(&(event.xkey),keybuf,0,&keysym,&keystat);			if (keysym==XK_s) {				xMousePrint(event,style, mpicksfp,					    x,y,width,height,					    x1begb,x1endb,x2begb,x2endb,					    p2beg, p2end);			} else if (keysym==XK_q || keysym==XK_Q) {			/* This is the exit from the event loop */				break;			} else if (keysym==XK_p || keysym==XK_P) {			/* invoke pscontour with appropriate data */				char cmdline[1024], cmdtemp[256];				float cmdfloat;				int iargc;				int nbpi;				efseeko(infp,(off_t) 0,SEEK_SET);				strcpy(cmdline,"pscontour ");				for (iargc = 1; iargc < argc; iargc++ ) {					strcat(cmdline," ");					strcat(cmdline,argv[iargc]);					}				/* override incompatible args */				sprintf(cmdtemp," axescolor=%s",labelcolor);				strcat(cmdline,cmdtemp);				nbpi = 300; getparint("nbpi", &nbpi);				sprintf(cmdtemp," nbpi=%d",nbpi);				strcat(cmdline,cmdtemp);				cmdfloat = DisplayWidthMM(dpy,scr)/25.4;				cmdfloat /= DisplayWidth(dpy,scr);				sprintf(cmdtemp," wbox=%g", cmdfloat*width);				strcat(cmdline,cmdtemp);				sprintf(cmdtemp," xbox=%g", 0.5+cmdfloat*xbox);				strcat(cmdline,cmdtemp);				cmdfloat = DisplayHeightMM(dpy,scr)/25.4;				cmdfloat /= DisplayHeight(dpy,scr);				sprintf(cmdtemp," hbox=%g", cmdfloat*height);				strcat(cmdline,cmdtemp);				sprintf(cmdtemp," ybox=%g", 0.5+cmdfloat*ybox);				strcat(cmdline,cmdtemp);				sprintf(cmdtemp," x1beg=%g", x1begb);				strcat(cmdline,cmdtemp);				sprintf(cmdtemp," x1end=%g", x1endb);				strcat(cmdline,cmdtemp);				sprintf(cmdtemp," x2beg=%g", x2begb);				strcat(cmdline,cmdtemp);				sprintf(cmdtemp," x2end=%g", x2endb);				strcat(cmdline,cmdtemp);				strcat(cmdline," title=\"");				strcat(cmdline,title); strcat(cmdline,"\"");				strcat(cmdline," label1=\"");				strcat(cmdline,label1); strcat(cmdline,"\"");				strcat(cmdline," label2=\"");				strcat(cmdline,label2); strcat(cmdline,"\"");				fprintf(stderr,"%s\n",cmdline);				system(cmdline);			} else {				continue;			}		/* else if button down (1 == zoom, 2 == mouse tracking */		} else if (event.type==ButtonPress) {			/* if 1st button: zoom */			if (event.xbutton.button==Button1) {				/* track pointer and get new box */				xRubberBox(dpy,win,event,&xb,&yb,&wb,&hb);							/* if new box has tiny width or height */				if (wb<4 || hb<4) {									/* reset box to initial values */					x1begb = x1beg;					x1endb = x1end;					x2begb = x2beg;					x2endb = x2end;					nxb = nx;					nyb = ny;					ixb = iyb = 0;					if (czb!=cz) free1(czb);					czb = cz;				/* else, if new box has non-zero width */				} else {								/* calculate new box parameters */					if (style==NORMAL) {					    zoomBox(x,y,width,height,						    xb,yb,wb,hb,						    nxb,ixb,x1begb,x1endb,						    nyb,iyb,x2endb,x2begb,						    &nxb,&ixb,&x1begb,&x1endb,						    &nyb,&iyb,&x2endb,&x2begb);					} else {					    zoomBox(x,y,width,height,						    xb,yb,wb,hb,						    nxb,ixb,x2begb,x2endb,						    nyb,iyb,x1begb,x1endb,						    &nxb,&ixb,&x2begb,&x2endb,						    &nyb,&iyb,&x1begb,&x1endb);					}					/* make new bytes in zoombox */					if (czb!=cz) free1(czb);					czb = ealloc1float(nxb*nyb);					for (i=0,czbp=czb; i<nyb; i++) {					    czp = cz+(iyb+i)*nx+ixb;					    for (j=0; j<nxb; j++)						    *czbp++ = *czp++; 					}				}				/* clear area and force an expose event */				XClearArea(dpy,win,0,0,0,0,True);				/* note that image is out of date */				imageOutOfDate = 1;						/* else if 2nd button down: display mouse coords */			} else if (event.xbutton.button==Button2) {				showloc = 1;				xMouseLoc(dpy,win,event,style,showloc,					  x,y,width,height,x1begb,x1endb,					  x2begb,x2endb,p2beg,p2end);			} else {				continue;			}		/* else if pointer has moved */		} else if (event.type==MotionNotify) {						/* if button2 down, show mouse location */			if (showloc)				xMouseLoc(dpy,win,event,style,True,					x,y,width,height,x1begb,x1endb,					x2begb,x2endb,p2beg,p2end);		/* else if button2 released, stop tracking */		} else if (event.type==ButtonRelease &&			   event.xbutton.button==Button2) {			showloc = 0;		}	} /* end of event loop */	/* close connection to X server */	XCloseDisplay(dpy);	return EXIT_SUCCESS;}			/* update parameters associated with zoom box */static void zoomBox (int x, int y, int w, int h, 	int xb, int yb, int wb, int hb,	int nx, int ix, float x1, float x2,	int ny, int iy, float y1, float y2,	int *nxb, int *ixb, float *x1b, float *x2b,	int *nyb, int *iyb, float *y1b, float *y2b){	/* if width and/or height of box are zero, just copy values */	if (wb==0 || hb==0) {		*nxb = nx; *ixb = ix; *x1b = x1; *x2b = x2;		*nyb = ny; *iyb = iy; *y1b = y1; *y2b = y2;		return;			} 		/* clip box */	if (xb<x) {		wb -= x-xb;		xb = x;	}	if (yb<y) {		hb -= y-yb;		yb = y;	}	if (xb+wb>x+w) wb = x-xb+w;	if (yb+hb>y+h) hb = y-yb+h;		/* determine number of samples in rubber box (at least 2) */	*nxb = MAX(nx*wb/w,2);	*nyb = MAX(ny*hb/h,2);		/* determine indices of first samples in box */	*ixb = ix+(xb-x)*(nx-1)/w;	*ixb = MIN(*ixb,ix+nx-*nxb);	*iyb = iy+(yb-y)*(ny-1)/h;	*iyb = MIN(*iyb,iy+ny-*nyb);			/* determine box limits to nearest samples */	*x1b = x1+(*ixb-ix)*(x2-x1)/(nx-1);	*x2b = x1+(*ixb+*nxb-1-ix)*(x2-x1)/(nx-1);	*y1b = y1+(*iyb-iy)*(y2-y1)/(ny-1);	*y2b = y1+(*iyb+*nyb-1-iy)*(y2-y1)/(ny-1);}/* Plots a new set of contours with the right apperance */static void newContour (Display *dpy, Window win,GC gci,	int xbase, int ybase, int nx, float x[], int ny, float y[], float *z,	int nc, float c[],float cwidth[], char *ccolor[],float cdash[],int labelcf,int labelcper,int nlabelc,char *labelcfont,char *labelccolor, int nplaces){        float *w;	int ic,linewidth=0;	XColor scolor,ecolor;	char dash[2];	char lcflag=0;	XGCValues *values=NULL;	GC gcc;	GC gcl;	XWindowAttributes wa;	Colormap cmap;	XFontStruct *fs;	int scr=DefaultScreen(dpy);	int i;	/* zero w array for contour labeling*/	w = ealloc1float(nx*ny);	for(i=0; i<nx*ny; i++) {	  w[i] = 0.;	}		/* shift the axes due to xbase and ybase */	for(i=0;i<nx;i++)	  x[i]=x[i]+xbase;	for(i=0;i<ny;i++)	  y[i]=y[i]+ybase;	  /* determine window's current colormap */	  XGetWindowAttributes(dpy,win,&wa);	  cmap = wa.colormap;	/* Generate at local GC used for the contour lines */ 	gcc=gci;	gcc=XCreateGC(dpy,win,0,values);	/* Generate at local GC used for the contour labels */ 	gcl=XCreateGC(dpy,win,0,NULL);	/*Set the color of the contour labels */	if(strcmp(labelccolor,"none")){	  if (!XAllocNamedColor(dpy,cmap,labelccolor,&scolor,&ecolor))	    XSetForeground(dpy,gcl,BlackPixel(dpy,scr));	  else	    XSetForeground(dpy,gcl,ecolor.pixel);	} else {	  XSetForeground(dpy,gcl,BlackPixel(dpy,scr));	}	  XSetBackground(dpy,gcl,WhitePixel(dpy,scr));	/* Set the labeling font */	fs = XLoadQueryFont(dpy,labelcfont);	if (fs==NULL) fs = XLoadQueryFont(dpy,"fixed");	XSetFont(dpy,gcl,fs->fid);	/*loop over contours*/	for (ic=0;ic<nc;ic++){	  /*Set the linestyle */	  if (nlabelc>0) {	    if((ic-labelcf+1)%labelcper==0 && ic>=labelcf-1  			   && ic<labelcf-1+labelcper*nlabelc) {			  linewidth=cwidth[ic];			  lcflag=1;			}			else { 			  linewidth=0.25*cwidth[ic];			  lcflag=0;				}	  }				/*	(note that small line segments will mask the dash settings) */	  if(cdash[ic]!=0.0){	    XSetLineAttributes(dpy,gcc,linewidth,LineOnOffDash,CapButt,JoinMiter);	    dash[0] = cdash[ic];  dash[1] = cdash[ic];	    XSetDashes(dpy,gcc,0,dash,2);	  } else {	    XSetLineAttributes(dpy,gcc,linewidth,LineSolid,CapButt,JoinMiter);	  }	  	  /*Set the color of the contour lines */	  if(strcmp(ccolor[ic],"none")){	    if (!XAllocNamedColor(dpy,cmap,ccolor[ic],&scolor,&ecolor))	      XSetForeground(dpy,gcc,BlackPixel(dpy,scr));	    else	      XSetForeground(dpy,gcc,ecolor.pixel);	  }else{	    XSetForeground(dpy,gcc,BlackPixel(dpy,scr));	  }	  /* Let xContour draw the contours */	  xContour(dpy,win,gcc,gcl,&c[ic],nx,x,ny,y,z,lcflag,labelcfont,labelccolor,w,nplaces);	  }	free1float(w);}void xMouseLoc(Display *dpy, Window win, XEvent event, int style, Bool show,	int x, int y, int width, int height,	float x1begb, float x1endb, float x2begb, float x2endb,	float p2beg, float p2end){	static XFontStruct *fs=NULL;	static XCharStruct overall;	static GC gc;	int dummy,xoffset=5,yoffset=5;	float x1,x2;	char string[256];	/* if first time, get font attributes and make gc */	if (fs==NULL) {		fs = XLoadQueryFont(dpy,"fixed");		gc = XCreateGC(dpy,win,0,NULL);		/* make sure foreground/background are black/white */		XSetForeground(dpy,gc,BlackPixel(dpy,DefaultScreen(dpy)));		XSetBackground(dpy,gc,WhitePixel(dpy,DefaultScreen(dpy)));		XSetFont(dpy,gc,fs->fid);		overall.width = 1;		overall.ascent = 1;		overall.descent = 1;	}	/* erase previous string */	XClearArea(dpy,win,xoffset,yoffset,		overall.width,overall.ascent+overall.descent,False);	/* if not showing, then return */	if (!show) return;	/* convert mouse location to (x1,x2) coordinates */	if (style==NORMAL) {		x1 = x1begb+(x1endb-x1begb)*(event.xmotion.x-x)/width;		x2 = p2end+x2endb+(p2beg+x2begb-x2endb-p2end)*			(event.xmotion.y-y)/height;	} else {		x1 = x1begb+(x1endb-x1begb)*(event.xmotion.y-y)/height;		x2 = p2beg+x2begb+(p2end+x2endb-x2begb-p2beg)*			(event.xmotion.x-x)/width;	}	/* draw string indicating mouse location */	sprintf(string,"(%0.3g,%0.3g)",x1,x2);	XTextExtents(fs,string,(int) strlen(string),&dummy,&dummy,&dummy,&overall);	XDrawString(dpy,win,gc,xoffset,yoffset+overall.ascent,		string,(int) strlen(string));}void xMousePrint(XEvent event, int style, FILE *mpicksfp,		 int x, int y, int width, int height,		 float x1begb, float x1endb, float x2begb, float x2endb,		 float p2beg, float p2end){	float x1,x2;	/* convert mouse location to (x1,x2) coordinates */	if (style==NORMAL) {		x1 = x1begb+(x1endb-x1begb)*(event.xmotion.x-x)/width;		x2 = p2end+x2endb+(p2beg+x2begb-x2endb-p2end)*			(event.xmotion.y-y)/height;	} else {		x1 = x1begb+(x1endb-x1begb)*(event.xmotion.y-y)/height;		x2 = p2beg+x2begb+(p2end+x2endb-x2begb-p2beg)*			(event.xmotion.x-x)/width;	}	/* write string indicating mouse location */	fprintf(mpicksfp, "%0.4g  %0.4g\n", x1, x2);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -