📄 mwpick.c
字号:
} /* 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 box limits */ *x1b = x1+(xb-x)*(x2-x1)/w; *x2b = x1+(xb+wb-x)*(x2-x1)/w; *y1b = y1+(yb-y)*(y2-y1)/h; *y2b = y1+(yb+hb-y)*(y2-y1)/h;}/* return pointer to new image bitmap of rasterized wiggles */static XImage *newBitmap (Display *dpy, int width, int height, int n1, float d1, float f1, int n2, float *x2, float *z, float x1beg, float x1end, float x2beg, float x2end, float xcur, float clip, int wt, int va, float *p2begp, float *p2endp){ int widthpad,nbpr,i1beg,i1end,if1r,n1r,b1fz,b1lz,i2,i,n2in; float x2min,x2max,p2beg,p2end,bscale,boffset,bxcur,bx2; unsigned char *bits; int scr=DefaultScreen(dpy); /* determine bitmap dimensions and allocate space for bitmap */ widthpad = (1+(width-1)/(BitmapPad(dpy)/8))*BitmapPad(dpy)/8; nbpr = 1+(widthpad-1)/8; bits = ealloc1(nbpr*height,sizeof(unsigned char)); for (i=0; i<nbpr*height; ++i) bits[i] = 0; /* determine number of traces that fall within axis 2 bounds */ x2min = MIN(x2beg,x2end); x2max = MAX(x2beg,x2end); for (i2=0,n2in=0; i2<n2; i2++) if (x2[i2]>=x2min && x2[i2]<=x2max) n2in++; /* determine pads for wiggle excursion along axis 2 */ xcur = fabs(xcur); if (n2in>1) xcur *= (x2max-x2min)/(n2in-1); p2beg = (x2end>x2beg)?-xcur:xcur; p2end = (x2end>x2beg)?xcur:-xcur; /* determine scale and offset to map x2 units to bitmap units */ bscale = (width-1)/(x2end+p2end-x2beg-p2beg); boffset = -(x2beg+p2beg)*bscale; bxcur = xcur*bscale; /* adjust x1beg and x1end to fall on sampled values */ i1beg = NINT((x1beg-f1)/d1); i1beg = MAX(0,MIN(n1-1,i1beg)); x1beg = f1+i1beg*d1; i1end = NINT((x1end-f1)/d1); i1end = MAX(0,MIN(n1-1,i1end)); x1end = f1+i1end*d1; /* determine first sample and number of samples to rasterize */ if1r = MIN(i1beg,i1end); n1r = MAX(i1beg,i1end)-if1r+1; /* determine bits corresponding to first and last samples */ b1fz = (x1end>x1beg)?0:height-1; b1lz = (x1end>x1beg)?height-1:0; /* rasterize traces */ for (i2=0; i2<n2; i2++,z+=n1) { /* skip traces not in bounds */ if (x2[i2]<x2min || x2[i2]>x2max) continue; /* determine bitmap coordinate of trace */ bx2 = boffset+x2[i2]*bscale; /* rasterize one trace */ rfwtva(n1r,&z[if1r],-clip,clip,va?0:clip, (int)(bx2-bxcur),(int)(bx2+bxcur),b1fz,b1lz, wt,nbpr,bits); }/* !!! inserted by Z. Li to fix problem of SUN's display colormap different from rs-6000's colormap !!! */ for (i=0; i<nbpr*height; ++i) bits[i] = 255 - bits[i]; /* return axis 2 pads */ *p2begp = p2beg; *p2endp = p2end; /* return pointer to image */ return XCreateImage(dpy,DefaultVisual(dpy,scr), 1,XYBitmap,0,bits,widthpad,height,BitmapPad(dpy),nbpr);} 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){ 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 = 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,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 p2beg, float p2end){ float x1,x2; int ipicks; int xx1,yy1,xx2,yy2,temp,ip; int dismin,dis; int ipmin, ipins; static int fs=1; GC gctop, gcbot; XGCValues *values; XColor scolor,ecolor; XWindowAttributes wa; Colormap cmap; int scr; /* if needed, 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 = 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; } /* 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); x2 = p2end+x2endb+(p2beg+x2begb-x2endb-p2end)* (event.xmotion.y-y)/height; for(ip=1;ip<*ntp;ip++) { yy1=(tp[ip-1]-x1begb)/(x1endb-x1begb)*height+y; xx1=(xtp[ip-1]-x2begb-p2beg)/ (x2endb+p2end-x2begb-p2beg)*width+x; yy2=(tp[ip]-x1begb)/(x1endb-x1begb)*height+y; xx2=(xtp[ip]-x2begb-p2beg)/ (x2endb+p2end-x2begb-p2beg)*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-p2beg)/ (x2endb+p2end-x2begb-p2beg)*width+x; yy2=(bt[ip]-x1begb)/(x1endb-x1begb)*height+y; xx2=(xbt[ip]-x2begb-p2beg)/ (x2endb+p2end-x2begb-p2beg)*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 + -