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

📄 wview.c

📁 mit数据库ecg波形观察软件
💻 C
📖 第 1 页 / 共 4 页
字号:
			    vv0[s] = vmn[s] = vmx[s];
			else
			    vv0[s] = vmx[s] = vmn[s];
			if ((vp[s] = vv0[s]) > vmax[s]) vmax[s] = vp[s];
			else if (vp[s] < vmin[s]) vmin[s] = vp[s];
		    }
		}
		else {
		    for (s = 0; s < nsig; s++) {
			if (vv[s] > vmx[s]) vmx[s] = vv[s];
			else if (vv[s] < vmn[s]) vmn[s] = vv[s];
		    }
		}
	    }
	    i = (vp - v)/nsig;
	}
	else {
	    for (i = 0, vp = v; i < trlen; i++, vp += nsig) {
		if (getvec(vp) < nsig) break;
		for (s = 0; s < nsig; s++) {
		    if (vp[s] < vmin[s]) vmin[s] = vp[s];
		    else if (vp[s] > vmax[s]) vmax[s] = vp[s];
		}
	    }
	}
	
	SelectObject(hDC, signal_pen);
	for (s = 0; s < nsig; s++) {
	    yb = base[s];
	    v0 = (vmax[s] + vmin[s])/2;
	    ysc = yppadu[s];
	    if (nflag)
                TextOut(hDC, xtr(1.), (int)(yb - yppmm*10), si[s].desc,
			strlen(si[s].desc));
	    vp = v+s;
	    MoveTo(hDC, 0, yt(*vp - v0));
	    vp += nsig;
	    if (compress)
		for (j = 1; j < i; j++, vp += nsig)
		    LineTo(hDC, j, yt(*vp - v0));
	    else
		for (j = 1; j < i; j++, vp += nsig)
		    LineTo(hDC, xt(j), yt(*vp - v0));
	    vmax[s] = -9999; vmin[s] = 9999;
	}
	
	/* Free the signal buffer.  (This is not strictly necessary for a large
	   memory model Windows program, since the version of malloc used in
	   this case allocates memory from the automatic data segment.) */
	free(v);
    }
    
    if (nann > 0) {     /* Show annotations. */
	WFDB_Annotation annot;
	
	iannsettime(t0);
	if (t0 == 0L) {         /* skip modification labels */
	    int i;
	    
	    while ((i = getann(0, &annot)) == 0 &&
		   annot.time == 0L && annot.anntyp == NOTE)
		;
	    if (i == 0) ungetann(0, &annot);
	}
	if (mflag) SelectObject(hDC, marker_pen);
	SetTextColor(hDC, MARKER_COLOR);
	tbhigh = tbmid - cheight;
	tblow = tbmid + cheight;
	do {
	    if (getann(0, &annot) < 0) break;
	    switch (annot.anntyp) {
	      case RHYTHM:
		y = tblow;
		if (annot.aux && !show_aux)
		    p = annot.aux+1;
		else
		    p = annstr(annot.anntyp);
		break;
	      case STCH:
	      case TCH:
	      case NOTE:
		y = tbhigh;
		if (annot.aux && !show_aux)
		    p = annot.aux+1;
		else
		    p = annstr(annot.anntyp);
		break;
              case LINK:
                y = tbhigh;
                if (annot.aux && !show_aux) {
                    char *p1 = annot.aux+1, *p2 = p1 + *(p1-1);
                    p = p1;
                    while (p1 < p2) {
                        if (*p1 == ' ' || *p1 == '\t') {
                             p = p1 + 1;
                             break;
                        }
                        p1++;
                    }
                    SetTextColor(hDC, SIGNAL_COLOR);
                }
                break;
	      case NOISE:
		y = tbhigh;
		if (annot.subtyp == -1) { p = "U"; break; }
		/* The existing scheme is good for up to 4 signals;  it can
		   be easily extended to 8 or 12 signals using the chan and
		   num fields, or to an arbitrary number of signals using
		   `aux'. */
		for (s = 0; s < nsig && s < 4; s++) {
		    if (annot.subtyp & (0x10 << s))
			ts[s] = 'u';    /* signal s is unreadable */
		    else if (annot.subtyp & (0x01 << s))
			ts[s] = 'n';    /* signal s is noisy */
		    else
			ts[s] = 'c';    /* signal s is clean */
		}
		ts[s] = '\0';
		p = ts; break;
	      default:
		y = tbmid; p = annstr(annot.anntyp); break;
	    }
	    x = (int)((annot.time - t0) * xppsi);
	    if (mflag) {
		MoveTo(hDC, x, 0);
		LineTo(hDC, x, y - tm.tmExternalLeading);
	    }
	    TextOut(hDC, x, y, p, strlen(p));
	    if (show_subtyp) {
		y += cheight;
		sprintf(ts, "%d", annot.subtyp);
		TextOut(hDC, x, y, ts, strlen(ts));
	    }
	    if (show_chan) {
		y += cheight;
		sprintf(ts, "%d", annot.chan);
		TextOut(hDC, x, y, ts, strlen(ts));
	    }
	    if (show_num) {
		y += cheight;
		sprintf(ts, "%d", annot.num);
		TextOut(hDC, x, y, ts, strlen(ts));
	    }
	    if (show_aux && annot.aux) {
		y += cheight;
		p = annot.aux+1;
		TextOut(hDC, x, y, p, strlen(p));
	    }
	    if (mflag) {
		MoveTo(hDC, x, y + cheight);
		LineTo(hDC, x, wheight);
	    }
            if (annot.anntyp == LINK)
                SetTextColor(hDC, MARKER_COLOR);
	} while (annot.time < t1);
    }
    SelectObject(hDC, hOldPen);
    EndPaint (hWnd,  &ps);
}

void print_window(hWnd, printer)
HWND hWnd;
char *printer;
{
    char *p, ts[80], *jobname = "WVIEW";
    double pwsec, phmv, pxppmm, pyppmm, pxppsi, pyppadu[WFDB_MAXSIG], pysc;
    DWORD dwextent;
    HDC hDC;
    HPEN hOldPen;
    int base[WFDB_MAXSIG], compress = 0, j, s, slen, tbhigh, tblow, tbmid,
        *v, *vp, vmax[WFDB_MAXSIG], vmin[WFDB_MAXSIG], v0, x, y, yb, pwidth,
        pheight, pcheight;
    long i, trlen;
    TEXTMETRIC ptm;
    
    /* Set up a device context for printing. */
    if ((hDC = GetPrinterDC(printer)) == NULL) return;
    if (Escape(hDC, STARTDOC, strlen(jobname), jobname, NULL) <= 0) {
	DeleteDC(hDC);
	return;
    }
    /* Determine the printer resolution and paper size in sec and mV. */
    pwidth = GetDeviceCaps(hDC,HORZRES);
    pheight = GetDeviceCaps(hDC,VERTRES);
    pxppmm = pwidth/(double)GetDeviceCaps(hDC,HORZSIZE);
    pyppmm = pheight/(double)GetDeviceCaps(hDC,VERTSIZE);
    pwsec = pwidth/(ptscale*pxppmm);
    phmv = pheight/(pvscale*pyppmm);
    
    GetTextMetrics(hDC, &ptm);
    pcheight = ptm.tmExternalLeading + ptm.tmHeight;
    
    /* Calculate the time scale in pixels per sample interval. */
    pxppsi = pxppmm * ptscale / sps;
    
    /* Draw in transparent mode (do not clear spaces around letters,
       etc., to white). */
    SetBkMode(hDC, TRANSPARENT);
    
    /* Draw the grid, if requested. */
    hOldPen = SelectObject(hDC, pgrid_pen);
    if (pgtflag) {
	double gdx = pxppmm*ptscale/GTICKSPERSEC;
	int i;
	
	for (i = 1, x = (int)gdx; x < pwidth; i++, x = (int)(i*gdx)) {
	    MoveTo(hDC, x, 0);
	    LineTo(hDC, x, pheight - 1);
	}
    }
    if (pgvflag) {
	double gdy = pyppmm*pvscale/GTICKSPERMV;
	int i;
	
	for (i = 1, y = (int)gdy; y < pheight; i++, y = (int)(i*gdy)){
	    MoveTo(hDC, 0, y);
	    LineTo(hDC, pwidth - 1, y);
	}
    }
    
    if (nsig > 0 || nann > 0) {
	/* Set color for time stamps and signal names. */
	SetTextColor(hDC, SIGNAL_COLOR);
	
	/* Show the starting time in the lower left corner. */
        slen = sprintf(ts, "%s", timstr(ptmode ? -pt0 : pt0));
	for (p = ts; *p == ' '; p++, slen--)
	    ;   /* discard initial spaces, if any */
	x = pxtr(2.);
	y = pytr(7.5) - ptm.tmExternalLeading;
	TextOut(hDC, x, y, p, slen);
	
	/* Determine the ending time. */
	pt1 = pt0 + (WFDB_Time)(sps*(int)pwsec);
	
	/* Show the ending time in the lower right corner. */
        slen = sprintf(ts, "%s", timstr(ptmode ? -pt1 : pt1));
	for (p = ts; *p == ' '; p++, slen--)
	    ;   /* discard initial spaces, if any */
	dwextent = GetTextExtent(hDC, p, slen);
	x = pxt(sps*(int)pwsec) - LOWORD(dwextent) - pxtr(2.);
	TextOut(hDC, x, y, p, slen);
    }
    
    /* Show the record and annotator names centered at the top. */
    if (*record && nann > 0) 
	slen = sprintf(ts, "Record %s, Annotator %s", record, annotator);
    else if (*record)
	slen = sprintf(ts, "Record %s", record);
    else
	slen = 0;
    if (slen > 0) {
	dwextent = GetTextExtent(hDC, ts, slen);
	x = pxt(sps*0.5*(int)pwsec) - LOWORD(dwextent)/2;
	TextOut(hDC, x, pcheight, ts, slen);
    }
    
    /* Show scales centered at the bottom. */
    slen = sprintf(ts, "%s  %s", tst[ptsi], vst[pvsi]);
    dwextent = GetTextExtent(hDC, ts, slen);
    x = pxt(sps*0.5*(int)pwsec) - LOWORD(dwextent)/2;
    TextOut(hDC, x, y - pcheight, ts, slen);
    
    /* Show the copyright notice centered at the bottom. */
    slen = sprintf(ts, "Printed by WVIEW %s  Copyright \251 MIT 1997",
		   VERSION);
    dwextent = GetTextExtent(hDC, ts, slen);
    x = pxt(sps*0.5*(int)pwsec) - LOWORD(dwextent)/2;
    TextOut(hDC, x, y, ts, slen);
    
    if (nsig < 1)
	tbmid = pheight/2;      /* Set standard ordinate for annotations. */
    else {      /* Draw signals. */
	/* Determine signal amplitude scales and baselines. */
	for (s = 0; s < nsig; s++) {
	    pyppadu[s] = (pyppmm * pvscale) / sg[s];
	    base[s] = ((2*s+1)*pheight)/(2*nsig);
	    vmin[s] = 9999; vmax[s] = -9999;
	}
	tbmid = (nsig==1)?(int)(0.75*pheight):(base[nsig/2-1]+base[nsig/2])/2;
	
	/* Allocate the signal buffer. */
	trlen = (long)(pwsec * sps);
	if (pxppsi < 0.75) {
	    compress = 1;
	    while ((v=malloc((unsigned)(1.5*pwidth*nsig*sizeof(int))))==NULL)
		pwidth /= 2;
	}
	else while ((v = malloc((unsigned)(trlen*nsig*sizeof(int)))) == NULL)
	    trlen -= (long)(sps/5.);
	
	/* Skip to the starting time. */
	isigsettime(pt0);
	
	if (compress) {
	    static int x0, vv0[WFDB_MAXSIG], vmn[WFDB_MAXSIG],
	               vmx[WFDB_MAXSIG], vv[WFDB_MAXSIG];
	    
	    getvec(vp = v);
	    for (s = 0; s < nsig; s++)
		vmax[s] = vmin[s] = vmn[s] = vmx[s] = vv0[s] = vp[s];
	    for (i = 1, x0 = 0; i < trlen && getvec(vv) > 0; i++) {
		int xx;
		if ((xx = (int)(i*pxppsi)) > x0) {
		    x0 = xx;
		    vp += nsig;
		    for (s = 0; s < nsig; s++) {
			if (vv[s] > vmx[s]) vmx[s] = vv[s];
			else if (vv[s] < vmn[s]) vmn[s] = vv[s];
			if (vmx[s] - vv0[s] > vv0[s] - vmn[s])
			    vv0[s] = vmn[s] = vmx[s];
			else
			    vv0[s] = vmx[s] = vmn[s];
			if ((vp[s] = vv0[s]) > vmax[s]) vmax[s] = vp[s];
			else if (vp[s] < vmin[s]) vmin[s] = vp[s];
		    }
		}
		else {
		    for (s = 0; s < nsig; s++) {
			if (vv[s] > vmx[s]) vmx[s] = vv[s];
			else if (vv[s] < vmn[s]) vmn[s] = vv[s];
		    }
		}
	    }
	    i = (vp - v)/nsig;
	}
	else {
	    for (i = 0, vp = v; i < trlen; i++, vp += nsig) {
		if (getvec(vp) < nsig) break;
		for (s = 0; s < nsig; s++) {
		    if (vp[s] < vmin[s]) vmin[s] = vp[s];
		    else if (vp[s] > vmax[s]) vmax[s] = vp[s];
		}
	    }
	}
	
	SelectObject(hDC, signal_pen);
	for (s = 0; s < nsig; s++) {
	    yb = base[s];
	    v0 = (vmax[s] + vmin[s])/2;
	    pysc = pyppadu[s];
	    if (nflag)
		TextOut(hDC, pxtr(1.), (int)(yb + pyppmm*2), si[s].desc,
			strlen(si[s].desc));
	    vp = v+s;
	    MoveTo(hDC, 0, pyt(*vp - v0));
	    vp += nsig;
	    if (compress)
		for (j = 1; j < i; j++, vp += nsig)
		    LineTo(hDC, j, pyt(*vp - v0));
	    else
		for (j = 1; j < i; j++, vp += nsig)
		    LineTo(hDC, pxt(j), pyt(*vp - v0));
	    vmax[s] = -9999; vmin[s] = 9999;
	}
	
	/* Free the signal buffer.  (This is not strictly necessary for a large
	   memory model Windows program, since the version of malloc used in
	   this case allocates memory from the automatic data segment.) */
	free(v);
    }
    
    if (nann > 0) {     /* Show annotations. */
	WFDB_Annotation annot;
	
	iannsettime(pt0);
	if (pt0 == 0L) {                /* skip modification labels */
	    int i;
	    
	    while ((i = getann(0, &annot)) == 0 &&
		   annot.time == 0L && annot.anntyp == NOTE)
		;
	    if (i == 0) ungetann(0, &annot);
	}
	if (pmflag) SelectObject(hDC, marker_pen);
	SetTextColor(hDC, MARKER_COLOR);
	tbhigh = tbmid - pcheight;
	tblow = tbmid + pcheight;
	do {
	    if (getann(0, &annot) < 0) break;
	    switch (annot.anntyp) {
	      case RHYTHM:
		y = tblow;
		if (annot.aux && !pshow_aux)
		    p = annot.aux+1;
		else
		    p = annstr(annot.anntyp);
		break;
	      case STCH:
	      case TCH:
	      case NOTE:
		y = tbhigh;
		if (annot.aux && !pshow_aux)
		    p = annot.aux+1;
		else
		    p = annstr(annot.anntyp);
		break;
	      case NOISE:
		y = tbhigh;
		if (annot.subtyp == -1) { p = "U"; break; }
		/* The existing scheme is good for up to 4 signals;  it can
		   be easily extended to 8 or 12 signals using the chan and
		   num fields, or to an arbitrary number of signals using
		   `aux'. */
		for (s = 0; s < nsig && s < 4; s++) {
		    if (annot.subtyp & (0x10 << s))
			ts[s] = 'u';    /* signal s is unreadable */
		    else if (annot.subtyp & (0x01 << s))
			ts[s] = 'n';    /* signal s is noisy */
		    else
			ts[s] = 'c';    /* signal s is clean */
		}
		ts[s] = '\0';
		p = ts; break;
	      default:
		y = tbmid; p = annstr(annot.anntyp); break;
	    }
	    x = (int)((annot.time - pt0) * pxppsi);
	    if (pmflag) {
		MoveTo(hDC, x, 0);
		LineTo(hDC, x, y - ptm.tmExternalLeading);
	    }
	    TextOut(hDC, x, y, p, strlen(p));
	    if (pshow_subtyp) {
		y += pcheight;
		sprintf(ts, "%d", annot.subtyp);
		TextOut(hDC, x, y, ts, strlen(ts));
	    }
	    if (pshow_chan) {
		y += cheight;
		sprintf(ts, "%d", annot.chan);
		TextOut(hDC, x, y, ts, strlen(ts));
	    }
	    if (pshow_num) {
		y += pcheight;
		sprintf(ts, "%d", annot.num);
		TextOut(hDC, x, y, ts, strlen(ts));
	    }
	    if (pshow_aux && annot.aux) {
		y += pcheight;
		p = annot.aux+1;
		TextOut(hDC, x, y, p, strlen(p));
	    }
	    if (pmflag) {
		MoveTo(hDC, x, y + pcheight);
		LineTo(hDC, x, pheight);
	    }
	} while (annot.time < pt1);
    }
    SelectObject(hDC, hOldPen);
    if (Escape(hDC, NEWFRAME, 0, NULL, NULL) > 0)
	Escape(hDC, ENDDOC, 0, NULL, NULL);
    DeleteDC(hDC);
}

⌨️ 快捷键说明

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