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

📄 mipick.c

📁 seismic software,very useful
💻 C
📖 第 1 页 / 共 2 页
字号:
					}								/* make new bytes in zoombox */					if (czb!=cz) free1(czb);					czb = ealloc1(nxb*nyb,						sizeof(signed char));					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);			} else if (event.xbutton.button==Button3) {                                pkey = 0;				xMousePicks(dpy,win,event,style,					topmutecolor,bottommutecolor,					mpicksfp, x,y,width,height,					x1begb,x1endb,x2begb,x2endb,					xtp,tp,&ntp,xbt,bt,&nbt,pkey,tkey,gci,					&savebg);			} 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);		/* 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);}/* return pointer to new interpolated array of bytes */static unsigned char *newInterpBytes (int n1in, int n2in, unsigned char *bin,	int n1out, int n2out){	unsigned char *bout;	float d1in,d2in,d1out,d2out,f1in,f2in,f1out,f2out;		f1in = f2in = f1out = f2out = 0.0;	d1in = d2in = 1.0;	d1out = d1in*(float)(n1in-1)/(float)(n1out-1);	d2out = d2in*(float)(n2in-1)/(float)(n2out-1);	bout = ealloc1(n1out*n2out,sizeof(unsigned char));	intl2b(n1in,d1in,f1in,n2in,d2in,f2in,bin,		n1out,d1out,f1out,n2out,d2out,f2out,bout);	return bout;}	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){	XGCValues values;	static XFontStruct *fs=NULL;	static XCharStruct overall;	static GC gc;	int dummy,xoffset=10,yoffset=10;	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,&values);		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 = x2endb+(x2begb-x2endb)*(event.xmotion.y-y)/height;	} else {		x1 = x1begb+(x1endb-x1begb)*(event.xmotion.y-y)/height;		x2 = x2begb+(x2endb-x2begb)*(event.xmotion.x-x)/width;	}	/* draw string indicating mouse location */	sprintf(string,"(%0.4g,%0.4g)",x1,x2);	XTextExtents(fs,string,strlen(string),&dummy,&dummy,&dummy,&overall);	XDrawImageString(dpy,win,gc,xoffset,yoffset+overall.ascent,		string,strlen(string));}void xMousePrint(Display *dpy, Window win, XEvent event, int style,	FILE *mpicksfp, int x, int y, int width, int height,	float x1begb, float x1endb, float x2begb, float x2endb,	char *pcard, int ppos, 	float *xtp, float *tp, int ntp, float *xbt, float *bt, int nbt, int fex){	int ic,ip,np,npout,np2; 	int p1,p2,p3;	float *xpout, *tpout, *btout, res;	int *indx;	static int first=1;	/* output picks */	if(first==1 && fex==0 ) {	first = 999;	fprintf(mpicksfp,"1---5---10---15----21----27----33----39----45----51----57----63----69----75\n");	fprintf(mpicksfp,"NAME  ppos        px1   tp1   bp1   px2   tp2   bt2   px3   tp3   bp3\n");		fprintf(mpicksfp,"\n");	}	/* find output pick x positions */	np2 = ntp + nbt; 	xpout = (float*) malloc(np2*sizeof(float)); 	tpout = (float*) malloc(np2*sizeof(float)); 	btout = (float*) malloc(np2*sizeof(float)); 	indx = (int*) malloc(np2*sizeof(int)); 	for(ip=0;ip<ntp;ip++) xpout[ip]=xtp[ip];	for(ip=ntp;ip<np2;ip++) xpout[ip]=xbt[ip-ntp];	/* sort x position in increasing order */ 	qksort(np2,xpout);	/* delete x positions that are too close together */	tpout[0]=xpout[0];	npout = 0;	for(ip=1;ip<np2;ip++) {		if(fabs(xpout[ip]-tpout[npout])>1.) {			npout = npout + 1; 			tpout[npout] = xpout[ip];		}	}	npout=npout+1;	for(ip=0;ip<npout;ip++) xpout[ip] = tpout[ip]; 	/* interpolate tp and bt at output x locations */	if ( ntp > 0 ) {		bisear_(&ntp,&npout,xtp,xpout,indx);		for(ip=0;ip<npout;ip++) {			np = indx[ip] - 1;			if(xpout[ip] < xtp[0]) {				tpout[ip] = tp[0];			} else if ((xpout[ip] > xtp[ntp-1]) || np >= ntp-1) {				tpout[ip] = tp[ntp-1];			} else {				res = (xpout[ip]-xtp[np])/(xtp[np+1]-xtp[np]);				tpout[ip] = tp[np]+res*(tp[np+1]-tp[np]);			} 		}	}	if ( nbt > 0 ) {			bisear_(&nbt,&npout,xbt,xpout,indx);		for(ip=0;ip<npout;ip++) {			np = indx[ip] - 1;			if(xpout[ip] < xbt[0]) {				btout[ip] = bt[0];			} else if ((xpout[ip] > xbt[nbt-1]) || np >= nbt-1) {				btout[ip] = bt[nbt-1];			} else {				res = (xpout[ip]-xbt[np])/(xbt[np+1]-xbt[np]);				btout[ip] = bt[np]+res*(bt[np+1]-bt[np]);			} 		}	}	for (ic=0;ic<(npout+2)/3;ic++) {	   if( (ic+1)*3 < npout ) {	      np = 3;  	   }	   else { 	      np = npout - ic*3;	   }	   fprintf(mpicksfp, "%-5s%5d     ",pcard,ppos);	   for(ip=0;ip<np;ip++) {	         p1 = xpout[ic*3+ip];		         p2 = tpout[ic*3+ip];		         p3 = btout[ic*3+ip];			 if ( ntp > 0 && nbt >> 0 ) { 	         	fprintf(mpicksfp,"%6d%6d%6d",p1,p2,p3);		 } else if ( ntp > 0 && nbt <= 0 ) {	         	fprintf(mpicksfp,"%6d%6d      ",p1,p2);		 } else if ( ntp <= 0 && nbt > 0 ) {	         	fprintf(mpicksfp,"%6d      %6d",p1,p3);		 }	   }	   fprintf(mpicksfp,"\n");	}	fflush(mpicksfp);	free(xpout);	free(tpout);	free(btout);	free(indx);}void xMousePicks(Display *dpy, Window win, XEvent event, int style,	char *topmutecolor, char *bottommutecolor,	FILE *mpicksfp, int x, int y, int width, int height,	float x1begb, float x1endb, float x2begb, float x2endb,	float *xtp, float *tp, int *ntp, float *xbt, float *bt, int *nbt, 	int pkey, int tkey, GC gc, int *savebg){	float x1,x2;	int ipicks;	int xx1,yy1,xx2,yy2,temp,ip;	int dismin,dis;	int ipmin, ipins;		GC gctop, gcbot;        XGCValues *values;        XColor scolor,ecolor;        XWindowAttributes wa;        Colormap cmap;        int scr;		/* first time, save bitmap of window to background for retrival */ 	if(*savebg) {		fg2bg(dpy,win);		*savebg = 0;	}	/* convert mouse location to (x1,x2) coordinates */	if (style==NORMAL) {		x1 = x1begb+(x1endb-x1begb)*(event.xmotion.x-x)/width;		x2 = x2endb+(x2begb-x2endb)*(event.xmotion.y-y)/height;	} else {		x1 = x1begb+(x1endb-x1begb)*(event.xmotion.y-y)/height;		x2 = x2begb+(x2endb-x2begb)*(event.xmotion.x-x)/width;	}	/* save x1 and x2 */	if( pkey == 0 ) {		if(tkey==0) {			ipicks = *ntp;			tp[ipicks] = x1;			xtp[ipicks] = x2;			*ntp = *ntp + 1;		} else if (tkey==1) {			ipicks = *nbt;			bt[ipicks] = x1;			xbt[ipicks] = x2;			*nbt = *nbt + 1;		}	/* delete nearest picks from x1 and x2 picks*/	} else if ( pkey==1 ) {		if( tkey==0 && *ntp > 0 ) {			ipicks = *ntp;				dismin = (x1-tp[0])*(x1-tp[0])+		       	         (x2-xtp[0])*(x2-xtp[0]);			ipmin = 0;			for(ip=1;ip<ipicks;ip++) {		   		dis=(x1-tp[ip])*(x1-tp[ip])+		       		    (x2-xtp[ip])*(x2-xtp[ip]);				if(dis<dismin) {					dismin = dis;					ipmin = ip;				}			}			ipicks = ipicks - 1;			for(ip=ipmin;ip<ipicks;ip++) {				tp[ip] = tp[ip+1];				xtp[ip] = xtp[ip+1];			}			*ntp = ipicks;		} else if(tkey==1 && *nbt > 0 ) {			ipicks = *nbt;				dismin = (x1-bt[0])*(x1-bt[0])+		       	         (x2-xbt[0])*(x2-xbt[0]);			ipmin = 0;			for(ip=1;ip<ipicks;ip++) {		   		dis=(x1-bt[ip])*(x1-bt[ip])+		       		    (x2-xbt[ip])*(x2-xbt[ip]);				if(dis<dismin) {					dismin = dis;					ipmin = ip;				}			}			ipicks = ipicks - 1;			for(ip=ipmin;ip<ipicks;ip++) {				bt[ip] = bt[ip+1];				xbt[ip] = xbt[ip+1];			}			*nbt = ipicks;		}	/* insert the pick into x1 and x2 picks */	} else if ( pkey==2 ) {		if ( tkey == 0 ) {			ipicks = *ntp;				dismin=(x2-xtp[0])*(x2-xtp[0]);			ipmin = 0;			for(ip=1;ip<ipicks;ip++) {		   		dis=(x2-xtp[ip])*(x2-xtp[ip]);				if(dis<dismin) {					dismin = dis;					ipmin = ip;				}			}			if(x2>xtp[ipmin]) { 				ipins = ipmin+1;				ipicks +=1;				for(ip=ipicks;ip>ipins;ip--) {					xtp[ip] = xtp[ip-1];					tp[ip] = tp[ip-1];				}				tp[ipins] = x1;				xtp[ipins] = x2;			} else if(x2<xtp[ipmin]) {				ipins = ipmin;				ipicks +=1;				for(ip=ipicks;ip>ipins;ip--) {					xtp[ip] = xtp[ip-1];					tp[ip] = tp[ip-1];				}				xtp[ipins] = x2;				tp[ipins] = x1;			}			*ntp = ipicks;		}		if ( tkey == 1 ) {			ipicks = *nbt;				dismin=(x2-xbt[0])*(x2-xbt[0]);			ipmin = 0;			for(ip=1;ip<ipicks;ip++) {		   		dis=(x2-xbt[ip])*(x2-xbt[ip]);				if(dis<dismin) {					dismin = dis;					ipmin = ip;				}			}			if(x2>xbt[ipmin]) { 				ipins = ipmin+1;				ipicks +=1;				for(ip=ipicks;ip>ipins;ip--) {					xbt[ip] = xbt[ip-1];					bt[ip] = bt[ip-1];				}				xbt[ipins] = x2;				bt[ipins] = x1;			} else if(x2<xbt[ipmin]) {				ipins = ipmin;				ipicks +=1;				for(ip=ipicks;ip>ipins;ip--) {					xbt[ip] = xbt[ip-1];					bt[ip] = bt[ip-1];				}				xbt[ipins] = x2;				bt[ipins] = x1;			}			*nbt = ipicks;		}	}	/* draw lines between picks */       	XClearWindow(dpy, win);	if (*ntp > 1 || *nbt > 1 ) {                /* get screen */                scr = DefaultScreen(dpy);                /* determine window's current colormap */                XGetWindowAttributes(dpy,win,&wa);                cmap = wa.colormap;        }	if(*ntp>1) {		/* create graphics contexts */                gctop = XCreateGC(dpy,win,0,values);                if (XAllocNamedColor(dpy,cmap,topmutecolor,&scolor,&ecolor))                        XSetForeground(dpy,gctop,ecolor.pixel);                else                        XSetForeground(dpy,gctop,1L);                XSetLineAttributes(dpy,gctop,2,LineSolid,CapButt,JoinMiter);		for(ip=1;ip<*ntp;ip++) {			yy1=(tp[ip-1]-x1begb)/(x1endb-x1begb)*height+y;			xx1=(xtp[ip-1]-x2begb)/(x2endb-x2begb)*width+x;			yy2=(tp[ip]-x1begb)/(x1endb-x1begb)*height+y;			xx2=(xtp[ip]-x2begb)/(x2endb-x2begb)*width+x;			XDrawLine(dpy,win,gctop,xx1,yy1,xx2,yy2);		}		/* free resources before returning */                XFreeGC(dpy,gctop);	}	if(*nbt>1) {		/* create graphics contexts */                gcbot = XCreateGC(dpy,win,0,values);                if (XAllocNamedColor(dpy,cmap,bottommutecolor,&scolor,&ecolor))                        XSetForeground(dpy,gcbot,ecolor.pixel);                else                        XSetForeground(dpy,gcbot,1L);                XSetLineAttributes(dpy,gcbot,2,LineSolid,CapButt,JoinMiter);		for(ip=1;ip<*nbt;ip++) {			yy1=(bt[ip-1]-x1begb)/(x1endb-x1begb)*height+y;			xx1=(xbt[ip-1]-x2begb)/(x2endb-x2begb)*width+x;			yy2=(bt[ip]-x1begb)/(x1endb-x1begb)*height+y;			xx2=(xbt[ip]-x2begb)/(x2endb-x2begb)*width+x;			XDrawLine(dpy,win,gcbot,xx1,yy1,xx2,yy2);		}		/* free resources before returning */                XFreeGC(dpy,gcbot);	}}

⌨️ 快捷键说明

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