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

📄 wbcview.c

📁 BCView - Bayes Classifier Visualization Download xbcview Linux executable (218 kb) wbcview.exe W
💻 C
📖 第 1 页 / 共 3 页
字号:
static void redraw (HDC hdc){                               /* --- redraw window contents */  int     i, k, n;              /* loop variable, buffers */  int     clscnt;               /* number of classes/clusters */  int     colcnt;               /* number of colors */  RECT    rc;                   /* clipping rectangle */  int     x,  y;                /* pixel coordinates */  double  rx, ry;               /* real  coordinates */  double  dx, dy;               /* standard deviations */  double  xoff, yoff;           /* offsets of window borders */  double  xscl, yscl;           /* scaling factors */  double  val, sum, max;        /* function value, sum and maximum */  PIXEL   mrk;                  /* color value for markers */  int     col, shd, shdcnt;     /* color, shade, and number of shades */  HBRUSH  brush;                /* brush for drawing data points */  double  a, b;                 /* transformation constants */  int     xid, yid, clsid;      /* attribute identifiers */  int     xtype, ytype;         /* attribute types */  TUPLE   *tpl;                 /* to traverse the data tuples */  float   f;                    /* temporary buffer */  int     cmin, cmax;           /* minimal and maximal coordinate */  double  t0, t1, t2;           /* temporary buffers */  GetClientRect(hmain, &rc);    /* get the window's client rectangle */  if (!bvnorm || !attset || !shades) {    FillRect(hdc, &rc, GetStockObject(WHITE_BRUSH)); return; }  /* --- initialize normal distributions --- */  clscnt = bc_bvnorm();         /* init. the normal distributions */  if (clscnt < 0) return;       /* and check for success */  /* --- draw rectangle contents --- */  xoff = ranges[attinfo.h_att].min;  /* get coordinate offsets and */  yoff = ranges[attinfo.v_att].max;  /* compute the scaling factors */  xscl = (ranges[attinfo.h_att].max -xoff) /(rc.right -rc.left);  yscl = (yoff -ranges[attinfo.v_att].min) /(rc.bottom -rc.top);  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 */  GetClipBox(hdc, &rc);         /* get the rectangle to redraw */  for (y = rc.top; y <= rc.bottom; y++) {    for (x = rc.left; x <= rc.right; x++) {      rx = xoff +x *xscl;       /* traverse the points and */      ry = yoff -y *yscl;       /* compute their real coordinates */      max = sum = 0; col = 0;   /* traverse the classes */      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;      SetPixel(hdc, x, y, shd_pixel(shades, col, shd));    }                           /* draw a pixel in the */  }                             /* computed color shade */  /* --- get color and pen for markers --- */  if ((colcnt > 0) && (shd_shdbase(shades) == SHD_BLACK))       { mrk = RGB(255,255,255); SelectObject(hdc, p_white); }  else { mrk = RGB(  0,  0,  0); SelectObject(hdc, p_black); }  /* --- draw markers --- */  if (mrkflgs & (MRK_CENTER|MRK_ELL1S|MRK_ELL2S|MRK_ELL3S)) {    for (i = clscnt; --i >= 0; ) {   /* traverse the classes */      if (colcnt <= 0)          /* on grey use the class color */        mrk = 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);        y = (int)((yoff -ry) /yscl +0.5);        SetPixel(hdc, x-1, y-1, mrk);        SetPixel(hdc, x,   y-1, mrk);        SetPixel(hdc, x+1, y-1, mrk);        SetPixel(hdc, x-1, y,   mrk);        SetPixel(hdc, x+1, y,   mrk);        SetPixel(hdc, x-1, y+1, mrk);        SetPixel(hdc, x,   y+1, mrk);        SetPixel(hdc, x+1, y+1, mrk);      }                         /* 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);          SetPixel(hdc, x, y, mrk);          y = (int)((yoff -t2) /yscl +0.5);          SetPixel(hdc, x, y, mrk);        }        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);          SetPixel(hdc, x, y, mrk);          x = (int)((t2 -xoff) /xscl +0.5);          SetPixel(hdc, x, y, mrk);        }                       /* 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 no data table has been loaded */  ||  !(mrkflgs & MRK_DATA))    /* and the marker flag is not set */    return;                     /* abort the function */  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));  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 +2; i = n >> 1; /* compute the marker size parameters */    x = (int)((rx -xoff) /xscl +0.5) -i;    y = (int)((yoff -ry) /yscl +0.5) -i;    brush = ((colcnt > 0) && !(mrkflgs & MRK_COLOR))         || ((col < 0) && (col >= shd_colcnt(datcols)))          ? br_grey : brushes[col];    SelectObject(hdc, brush);   /* get and set the brush for drawing */    Ellipse(hdc, x, y, x+n, y+n);  }                             /* draw a circle at the data point */}  /* redraw() *//*----------------------------------------------------------------------  File Selector Function----------------------------------------------------------------------*/static const char* fselect (HWND hwnd, char *title){                               /* --- select a file name */  static char fname[_MAX_PATH+1] = "";  /* file name */  static char path [_MAX_PATH+1];       /* and path */  static char filter[] =        /* file selection filter */    "all files (*.*)\0*.*\0";   /* (filter for all files) */  static OPENFILENAME ofn = {   /* file selector structure */    sizeof(OPENFILENAME),       /* lStructSize */    NULL,   NULL,               /* hwndOwner, hInstance */    filter, NULL,               /* lpstrFilter, lpstrCustomFilter */    0, 1,                       /* nMaxCustFilter, nFilterIndex */    fname, _MAX_PATH,           /* lpstrFile, nMaxFile */    NULL, _MAX_FNAME+_MAX_EXT,  /* lpstrFileTitle, nMaxFileTitle */    path,                       /* lpstrInitialDir */    "Select File...",           /* lpstrTitle (with default init.) */    OFN_PATHMUSTEXIST, 0, 0,    /* Flags, nFileOffset, nFileExtension */    NULL, 0L,                   /* lpstrDefExt, lCustData */    NULL, NULL };               /* lpfnHook, lpTemplateName */  ofn.hwndOwner  = hwnd;        /* set parent window handle */  ofn.lpstrTitle = title;       /* and dialog box title */  ofn.Flags      = OFN_FILEMUSTEXIST;  if (GetOpenFileName(&ofn) == 0)    return NULL;                /* open file selector box */  return fname;                 /* return name of selected file */}  /* fselect() *//*----------------------------------------------------------------------  Dialog Box Procedures----------------------------------------------------------------------*/BOOL CALLBACK dp_format (HWND hwnd, UINT msg, WPARAM wp, LPARAM lp){                               /* --- characters dialog box proc. */  switch (msg) {                /* evaluate message */    case WM_INITDIALOG:         /* dialog initialization */      LoadString(hinst, CS_FR_ATTS,    buf, sizeof(buf));      cmb_add(hwnd, DI_FIRST, buf);      LoadString(hinst, CS_FR_DATA,    buf, sizeof(buf));      cmb_add(hwnd, DI_FIRST, buf);      LoadString(hinst, CS_FR_COMMENT, buf, sizeof(buf));      cmb_add(hwnd, DI_FIRST, buf);      cmb_set(hwnd, DI_FIRST,   fmtinfo.first);

⌨️ 快捷键说明

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