📄 xbcview.c
字号:
xscl = (ranges[attinfo.h_att].max -xoff) /(wd -1); yscl = (yoff -ranges[attinfo.v_att].min) /(ht -1); a = 1.0/clscnt; /* compute transformation constants */ b = (clscnt > 1) ? clscnt/(clscnt-1.0) : 1; colcnt = shd_colcnt(shades); /* get the number of colors */ shdcnt = shd_shdcnt(shades); /* and the number of shades */ pxl_prev = shd_pixel(shades, 0, 0); for (y = rc.y; y < rc.y +rc.height; y++) { for (x = x_prev = rc.x +rc.width; --x >= rc.x; ) { rx = xoff +x *xscl; /* traverse the pixels in the rect. */ ry = yoff -y *yscl; /* and compute their real coordinates */ max = sum = 0; col = 0; /* traverse the classes/clusters */ if (colinfo.dist >= DT_FUZZY) { /* if fuzzy memberships */ for (i = clscnt; --i >= 0; ) { val = bvn_dist(bvnorm +i, rx, ry); sum += val = (val > 0) ? 1/val : 1e12; if (val > max) { max = val; col = i; } } /* compute Mahalanobis distance */ if (colinfo.dist == DT_POSS) { /* if possibilistic coloring */ val = max /(1 +max);} /* compute relative intensity */ else { /* if probabilistic fuzzy coloring */ val = (sum > 0) ? (colinfo.ndwgt *(max/sum) + colinfo.cowgt *(max/sum -a) *b) : 0; } } /* compute relative intensity */ else { /* if probabilistic coloring */ for (i = clscnt; --i >= 0; ) { sum += val = bvn_eval(bvnorm +i, rx, ry); if (val > max) { max = val; col = i; } } /* compute class probabilities */ val = (sum > 0) ? (colinfo.ndwgt *(max/bvn_max(bvnorm +col)) + colinfo.cowgt *(max/sum -a) *b) : 0; } /* compute the relative intensity */ shd = (int)(shdcnt *val); /* and from it the color shade */ if (shd >= shdcnt) shd = shdcnt-1; if (shd < 0) shd = 0; if (colcnt <= 0) col = 0; pxl = shd_pixel(shades, col, shd); if (pxl == pxl_prev) continue; XSetForeground(display, gc, pxl_prev); XDrawLine(display, window, gc, x_prev, y, x, y); x_prev = x; /* draw a line segment and note */ pxl_prev = pxl; /* the end of the line segment */ } /* and the new pixel value */ XSetForeground(display, gc, pxl_prev); XDrawLine(display, window, gc, x_prev, y, x, y); } /* draw last line segment */ /* --- draw markers --- */ mrk = ((colcnt > 0) && (shd_shdbase(shades) == SHD_BLACK)) ? white : black; /* get the default marker color */ if (mrkflgs & (MRK_CENTER|MRK_ELL1S|MRK_ELL2S|MRK_ELL3S)) { if (colcnt > 0) /* black/white markers on color */ XSetForeground(display, gc, mrk); for (i = clscnt; --i >= 0; ) { /* traverse the classes */ if (colcnt <= 0) /* on grey use the class color */ XSetForeground(display, gc, shd_pixel(datcols, i, 0)); rx = bvn_ex(bvnorm +i); /* get the expected values */ ry = bvn_ey(bvnorm +i); /* (coordinates of the center) */ if (mrkflgs & MRK_CENTER){/* if to mark the centers */ x = (int)((rx -xoff) /xscl +0.5) -1; y = (int)((yoff -ry) /yscl +0.5) -1; XDrawRectangle(display, window, gc, x, y, 2, 2); } /* draw a 3x3 pixel rectangle */ dx = bvn_dx(bvnorm +i); /* get the standard deviations */ dy = bvn_dy(bvnorm +i); /* (extensions of the ellipse) */ for (k = 1; k <= 3; k++){ /* traverse the ellipses */ if (!(mrkflgs & (MRK_ELL1S << (k-1)))) continue; /* skip unselected ellipses */ cmin = (int)((rx -k*dx -xoff) /xscl +0.5); cmax = (int)((rx +k*dx -xoff) /xscl +0.5); for (x = cmin; x <= cmax; x++) { t0 = xoff +x *xscl; bvn_ellx2y(bvnorm +i, k, t0, &t1, &t2); y = (int)((yoff -t1) /yscl +0.5); XDrawPoint(display, window, gc, x, y); y = (int)((yoff -t2) /yscl +0.5); XDrawPoint(display, window, gc, x, y); } cmin = (int)((yoff -ry -k*dy) /yscl +0.5); cmax = (int)((yoff -ry +k*dy) /yscl +0.5); for (y = cmin; y <= cmax; y++) { t0 = yoff -y *yscl; bvn_elly2x(bvnorm +i, k, t0, &t1, &t2); x = (int)((t1 -xoff) /xscl +0.5); XDrawPoint(display, window, gc, x, y); x = (int)((t2 -xoff) /xscl +0.5); XDrawPoint(display, window, gc, x, y); } /* for each k sigma ellipse: */ } /* draw the ellipse twice, */ } /* once traversing the x-coordinates */ } /* if (mrkflgs .. */ /* and once the y-coordinates */ /* --- draw data --- */ if (table /* if a data table has been loaded */ && (mrkflgs & MRK_DATA)) { /* and the marker flag is set */ if (nbc) clsid = nbc_clsid(nbc); else if (fbc) clsid = fbc_clsid(fbc); else clsid = -1; /* get the class attribute id. */ xid = attmap[attinfo.h_att]; /* get other attribute ids. */ yid = attmap[attinfo.v_att]; /* and attribute types */ xtype = att_type(as_att(attset, xid)); ytype = att_type(as_att(attset, yid)); pxl = grey; /* set default marker color */ for (k = tab_tplcnt(table); --k >= 0; ) { tpl = tab_tpl(table, k); /* traverse the tuples */ col = (clsid >= 0) ? tpl_colval(tpl, clsid)->i : UV_SYM; if (xtype == AT_INT) { /* if x-coordinate is integer valued */ i = tpl_colval(tpl, xid)->i; if (i <= UV_INT) continue; rx = (double)i; } /* get and check the attribute value */ else { /* if x-coordinate is real valued */ f = tpl_colval(tpl, xid)->f; if (f <= UV_FLT) continue; rx = (double)f; /* get and check the attribute value */ } if (ytype == AT_INT) { /* if y-coordinate is integer valued */ i = tpl_colval(tpl, yid)->i; if (i <= UV_INT) continue; ry = (double)i; } /* get and check the attribute value */ else { /* if y-coordinate is real valued */ f = tpl_colval(tpl, yid)->f; if (f <= UV_FLT) continue; ry = (double)f; /* get and check the attribute value */ } /* then compute the screen coords. */ n = mrksize; i = n >> 1; /* compute the marker size parameters */ x = (int)((rx -xoff) /xscl +0.5) -i; y = (int)((yoff -ry) /yscl +0.5) -i; if ((mrkflgs & MRK_COLOR) /* if to mark in color */ || (colcnt <= 0)) { /* or the shades are grey */ pxl = ((col < 0) || (col >= shd_colcnt(datcols))) ? grey : shd_pixel(datcols, col, 0); } /* set the class/marker color */ XSetForeground(display, gc, pxl); XFillArc(display, window, gc, x, y, n, n, 0, 360*64); XSetForeground(display, gc, mrk); XDrawArc(display, window, gc, x, y, n, n, 0, 360*64); } /* draw a circle at the data point */ } /* if (table ... */ XFlush(display); /* flush buffered drawing commands */ XSetClipMask(display, gc, None); /* and clear clipping mask */} /* redraw() *//*--------------------------------------------------------------------*/static void about (Widget w, XEvent *e, String *s, Cardinal *c){ /* --- 'About' dialog box */ mn_enable(menu, MN_MENU, 0); /* disable menu bar */ if (db_about(w_top, dcb_nop) != 0) error(E_DIALOG); /* show `about' dialog box */} /* about() *//*---------------------------------------------------------------------- Main Function----------------------------------------------------------------------*/int main (int argc, char *argv[]){ /* --- main program */ Arg args[8]; /* widget arguments */ int n; /* argument counter */ Colormap colmap; /* color map of display */ XColor xc[2]; /* buffer for colors */ XtSetLanguageProc(NULL, (XtLanguageProc)NULL, NULL); /* --- create main window --- */ w_top = XtAppInitialize(&appctx, "XBCView", NULL, 0, &argc, argv, fallback, NULL, 0); if (!w_top) error(E_INIT); /* create toplevel widget */ n = 0; /* build argument list */ XtSetArg(args[n], XtNdefaultDistance, 0); n++; XtSetArg(args[n], XtNresizable, True); n++; w_main = XtCreateManagedWidget("main", formWidgetClass, w_top, args, n); /* create main widget */ if (!w_main) error(E_WIDGET); /* (form for window layout) */ menu = mn_create(w_main); /* create a menu bar and */ if (!menu) error(E_NOMEM); /* add titles and items */ if ((mn_addtitle(menu, "file", 0, 0, 0) != 0) || (mn_additem (menu, "ld_class", 0, mcb_class, 0) != 0) || (mn_additem (menu, "ld_data", 0, mcb_data, 0) != 0) || (mn_additem (menu, "format", 0, mcb_format, 0) != 0) || (mn_additem (menu, NULL, 0, 0, 0) != 0) || (mn_additem (menu, "quit", 0, mcb_quit, 0) != 0) || (mn_addtitle(menu, "actions", 0, 0, 0) != 0) || (mn_additem (menu, "atts", 0, mcb_atts, 0) != 0) || (mn_additem (menu, "colors", 0, mcb_colors, 0) != 0) || (mn_additem (menu, "marks", 0, mcb_marks, 0) != 0) || (mn_additem (menu, NULL, 0, 0, 0) != 0) || (mn_additem (menu, "redraw", 0, mcb_redraw, 0) != 0) || (mn_addtitle(menu, "help", 0, 0, 0) != 0) || (mn_additem (menu, "about", 0, mcb_about, 0) != 0) || (mn_addtitle(menu, NULL, 0, 0, 0) != 0)) error(E_WIDGET); mn_resize(menu, INITXEXT); /* set width of menu bar */ /* --- create viewport --- */ n = 0; /* build argument list */ XtSetArg(args[n], XtNfromVert, mn_menubar(menu)); n++; XtSetArg(args[n], XtNleft, XtChainLeft); n++; XtSetArg(args[n], XtNtop, XtChainTop); n++; XtSetArg(args[n], XtNright, XtChainRight); n++; XtSetArg(args[n], XtNbottom, XtChainBottom); n++; XtSetArg(args[n], XtNresizable, True); n++; w_view = XtCreateManagedWidget("view", coreWidgetClass, w_main, args, n); if (!w_view) error(E_WIDGET); /* create viewport */ XtVaSetValues(w_view, XtNwidth, INITXEXT, XtNheight, INITYEXT, NULL); XtVaSetValues(w_top, XtNminWidth, MINXEXT, XtNminHeight, MINYEXT, NULL); /* set window size */ XtOverrideTranslations(w_view,/* install redraw function */ XtParseTranslationTable("<Expose>: redraw()")); /* --- install actions, accelerators and translations --- */ XtAppAddActions(appctx, actions, XtNumber(actions)); XtInstallAllAccelerators(w_main, w_main); /* --- show window --- */ XtRealizeWidget(w_top); /* show window on display */ display = XtDisplay(w_top); /* get display of top window */ window = XtWindow(w_view); /* and drawable for window */ if (db_alert(w_top, dcb_nop, NULL) != 0) error(E_WIDGET); /* create alert dialog box */ /* --- override window manager delete --- */ XtOverrideTranslations(w_top, /* override window manager delete */ XtParseTranslationTable("<Message>WM_PROTOCOLS: quit()")); wm_delwin = XInternAtom(XtDisplay(w_top), "WM_DELETE_WINDOW", False); XSetWMProtocols(XtDisplay(w_top), XtWindow(w_top), &wm_delwin, 1); /* --- allocate colors --- */ screen = DefaultScreen(display); colmap = DefaultColormap(display, screen); if (XAllocNamedColor(display, colmap, "grey", xc+1, xc) == 0) error(E_COLOR); /* allocate colors */ black = BlackPixel(display, screen); white = WhitePixel(display, screen); grey = xc[1].pixel; /* enter the color values */ /* --- evaluate command line arguments --- */ if (argc > 1) dcb_class(NULL, (XtPointer)2, (XtPointer)argv[1]); if (argc > 2) dcb_data (NULL, (XtPointer)1, (XtPointer)argv[2]); /* --- start event loop --- */ XtAppMainLoop(appctx); /* enter main event loop */ return 0; /* return `ok' */} /* main() */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -