예제 #1
0
파일: measure.c 프로젝트: rblake/seg3d2
void
_nrrdMeasureHistoMax(void *ans, int ansType,
                     const void *line, int lineType, size_t len, 
                     double axmin, double axmax) {
  double val, (*lup)(const void*, size_t);
  size_t ii;

  if (!(AIR_EXISTS(axmin) && AIR_EXISTS(axmax))) {
    axmin = -0.5;
    axmax = len-0.5;
  }
  lup = nrrdDLookup[lineType];
  /* we're using ii-1 as index to avoid wrap-around with size_t index */
  for (ii=len; ii>0; ii--) {
    if (lup(line, ii-1) > 0) {
      break;
    }
  }
  if (ii==0) {
    nrrdDStore[ansType](ans, AIR_NAN);
    return;
  }
  val = NRRD_CELL_POS(axmin, axmax, len, ii-1);
  nrrdDStore[ansType](ans, val);
}
예제 #2
0
파일: measure.c 프로젝트: rblake/seg3d2
void
_nrrdMeasureHistoMean(void *ans, int ansType,
                      const void *line, int lineType, size_t len, 
                      double axmin, double axmax) {
  double count, hits, ansD, (*lup)(const void*, size_t);
  size_t ii;
  
  lup = nrrdDLookup[lineType];
  ansD = count = 0;
  for (ii=0; ii<len; ii++) {
    hits = lup(line, ii);
    hits = AIR_MAX(hits, 0);
    count += hits;
    ansD += hits*ii;
  }
  if (!count) {
    nrrdDStore[ansType](ans, AIR_NAN);
    return;
  }
  ansD /= count;
  if (AIR_EXISTS(axmin) && AIR_EXISTS(axmax)) {
    ansD = NRRD_CELL_POS(axmin, axmax, len, ansD);
  }
  nrrdDStore[ansType](ans, ansD);
}
예제 #3
0
파일: measure.c 프로젝트: rblake/seg3d2
void
_nrrdMeasureHistoL2(void *ans, int ansType,
                    const void *line, int lineType, size_t len, 
                    double axmin, double axmax) {
  double l2, count, hits, val, (*lup)(const void*, size_t);
  size_t ii;
  
  if (!(AIR_EXISTS(axmin) && AIR_EXISTS(axmax))) {
    axmin = -0.5;
    axmax = len-0.5;
  }
  lup = nrrdDLookup[lineType];
  l2 = count = 0;
  for (ii=0; ii<len; ii++) {
    val = NRRD_CELL_POS(axmin, axmax, len, ii);
    hits = lup(line, ii);
    hits = AIR_MAX(hits, 0);
    count += hits;
    l2 += hits*val*val;
  }
  if (!count) {
    nrrdDStore[ansType](ans, AIR_NAN);
    return;
  }
  nrrdDStore[ansType](ans, l2);
}
예제 #4
0
파일: measure.c 프로젝트: rblake/seg3d2
void
_nrrdMeasureHistoVariance(void *ans, int ansType,
                          const void *line, int lineType, size_t len, 
                          double axmin, double axmax) {
  double S, SS, count, hits, val, (*lup)(const void*, size_t);
  size_t ii;
  
  lup = nrrdDLookup[lineType];
  count = 0;
  SS = S = 0.0;
  /* we fix axmin, axmax now because GK is better safe than sorry */
  if (!(AIR_EXISTS(axmin) && AIR_EXISTS(axmax))) {
    axmin = -0.5;
    axmax = len-0.5;
  }
  for (ii=0; ii<len; ii++) {
    val = NRRD_CELL_POS(axmin, axmax, len, ii);
    hits = lup(line, ii);
    hits = AIR_MAX(hits, 0);
    count += hits;
    S += hits*val;
    SS += hits*val*val;
  }
  if (!count) {
    nrrdDStore[ansType](ans, AIR_NAN);
    return;
  }
  S /= count;
  SS /= count;
  nrrdDStore[ansType](ans, SS - S*S);
}
예제 #5
0
파일: measure.c 프로젝트: rblake/seg3d2
void
_nrrdMeasureHistoMedian(void *ans, int ansType,
                        const void *line, int lineType, size_t len, 
                        double axmin, double axmax) {
  double sum, tmp, half, ansD, (*lup)(const void*, size_t);
  size_t ii;
  
  lup = nrrdDLookup[lineType];
  sum = 0;
  for (ii=0; ii<len; ii++) {
    tmp = lup(line, ii);
    sum += (tmp > 0 ? tmp : 0);
  }
  if (!sum) {
    nrrdDStore[ansType](ans, AIR_NAN);
    return;
  }
  /* else there was something in the histogram */
  half = sum/2;
  sum = 0;
  for (ii=0; ii<len; ii++) {
    tmp = lup(line, ii);
    sum += (tmp > 0 ? tmp : 0);
    if (sum >= half) {
      break;
    }
  }
  ansD = ii;
  if (AIR_EXISTS(axmin) && AIR_EXISTS(axmax)) {
    ansD = NRRD_CELL_POS(axmin, axmax, len, ansD);
  }
  nrrdDStore[ansType](ans, ansD);
}
예제 #6
0
/*
** Thu Dec 13 02:25:12 EST 2007:
** this had no use outside gage, added _ prefix
*/
void
_gageShapeUnitItoW(gageShape *shape, double world[3], double index[3]) {
  int i;
  
  if (nrrdCenterNode == shape->center) {
    for (i=0; i<=2; i++) {
      world[i] = NRRD_NODE_POS(-shape->volHalfLen[i], shape->volHalfLen[i],
                               shape->size[i], index[i]);
    }
  } else {
    for (i=0; i<=2; i++) {
      world[i] = NRRD_CELL_POS(-shape->volHalfLen[i], shape->volHalfLen[i],
                               shape->size[i], index[i]);
    }
  }
}
예제 #7
0
파일: measure.c 프로젝트: rblake/seg3d2
void
_nrrdMeasureHistoMode(void *ans, int ansType,
                      const void *line, int lineType, size_t len, 
                      double axmin, double axmax) {
  double val, max, idxsum, ansD, (*lup)(const void*, size_t);
  size_t ii, idxcount;
  
  lup = nrrdDLookup[lineType];
  max = -DBL_MAX;
  for (ii=0; ii<len; ii++) {
    val = lup(line, ii);
    max = AIR_MAX(max, val);
  }
  if (-DBL_MAX == max) {
    nrrdDStore[ansType](ans, AIR_NAN);
    return;
  }
  /* else there was something in the histogram */
  /* we assume that there may be multiple bins which reach the maximum
     height, and we average all those indices.  This may well be
     bone-headed, and is subject to change.  19 July 03: with the
     addition of the final "type" argument to nrrdProject, the
     bone-headedness has been alleviated somewhat, since you can pass
     nrrdTypeFloat or nrrdTypeDouble to get an accurate answer */
  idxsum = 0;
  idxcount = 0;
  for (ii=0; ii<len; ii++) {
    val = lup(line, ii);
    if (val == max) {
      idxcount++;
      idxsum += ii;
    }
  }
  ansD = idxsum/idxcount;
  /*
  printf("idxsum = %g; idxcount = %d --> ansD = %g --> ",
         (float)idxsum, idxcount, ansD);
  */
  if (AIR_EXISTS(axmin) && AIR_EXISTS(axmax)) {
    ansD = NRRD_CELL_POS(axmin, axmax, len, ansD);
  }
  /*
  printf("%g\n", ansD);
  */
  nrrdDStore[ansType](ans, ansD);
}
예제 #8
0
파일: shape.c 프로젝트: CIBC-Internal/teem
static void
shapeUnitItoW(const gageShape *shape, double world[3],
              const double indx[3], const double volHalfLen[3]) {
  unsigned int i;

  if (nrrdCenterNode == shape->center) {
    for (i=0; i<=2; i++) {
      world[i] = NRRD_NODE_POS(-volHalfLen[i], volHalfLen[i],
                               shape->size[i], indx[i]);
    }
  } else {
    for (i=0; i<=2; i++) {
      world[i] = NRRD_CELL_POS(-volHalfLen[i], volHalfLen[i],
                               shape->size[i], indx[i]);
    }
  }
}
예제 #9
0
파일: measure.c 프로젝트: rblake/seg3d2
void
_nrrdMeasureHistoSum(void *ans, int ansType,
                     const void *line, int lineType, size_t len, 
                     double axmin, double axmax) {
  double sum, hits, val, (*lup)(const void*, size_t);
  size_t ii;
  
  if (!(AIR_EXISTS(axmin) && AIR_EXISTS(axmax))) {
    axmin = -0.5;
    axmax = len-0.5;
  }
  lup = nrrdDLookup[lineType];
  sum = 0;
  for (ii=0; ii<len; ii++) {
    val = NRRD_CELL_POS(axmin, axmax, len, ii);
    hits = lup(line, ii);
    hits = AIR_MAX(hits, 0);
    sum += hits*val;
  }
  nrrdDStore[ansType](ans, sum);
}
예제 #10
0
파일: measure.c 프로젝트: rblake/seg3d2
void
_nrrdMeasureHistoMin(void *ans, int ansType,
                     const void *line, int lineType, size_t len, 
                     double axmin, double axmax) {
  double val, (*lup)(const void*, size_t);
  size_t ii;

  if (!(AIR_EXISTS(axmin) && AIR_EXISTS(axmax))) {
    axmin = -0.5;
    axmax = len-0.5;
  }
  lup = nrrdDLookup[lineType];
  for (ii=0; ii<len; ii++) {
    if (lup(line, ii) > 0) {
      break;
    }
  }
  if (ii==len) {
    nrrdDStore[ansType](ans, AIR_NAN);
    return;
  }
  val = NRRD_CELL_POS(axmin, axmax, len, ii);
  nrrdDStore[ansType](ans, val);
}
int
tend_ellipseDoit(FILE *file, Nrrd *nten, Nrrd *npos, Nrrd *nstn,
                 float min[2], float max[2],
                 float gscale, float dotRad, float lineWidth, float cthresh,
                 int invert) {
  size_t sx=0, sy=0, ti, nt;
  int x, y, vi, *sdata;
  double aspect, minX, minY, maxX, maxY, conf, Dxx, Dxy, Dyy, px, py, spx, spy;
  float *tdata, *pdata;
  
  if (npos) {
    nt = npos->axis[1].size;
    aspect = (max[0] - min[0])/(max[1] - min[1]);
  } else {
    spx = (AIR_EXISTS(nten->axis[1].spacing)
           ? nten->axis[1].spacing
           : 1);
    spy = (AIR_EXISTS(nten->axis[2].spacing)
           ? nten->axis[2].spacing
           : 1);
    sx = nten->axis[1].size;
    sy = nten->axis[2].size;
    nt = sx*sy;
    aspect = sx*spx/(sy*spy);
  }

  if (aspect > 7.5/10) {
    /* image has a wider aspect ratio than safely printable page area */
    minX = 0.5;
    maxX = 8.0;
    minY = 5.50 - 7.5/2/aspect;
    maxY = 5.50 + 7.5/2/aspect;
  } else {
    /* image is taller ... */
    minX = 4.25 - 10.0/2*aspect;
    maxX = 4.25 + 10.0/2*aspect;
    minY = 0.5;
    maxY = 10.5;
  }
  minX *= 72; minY *= 72;
  maxX *= 72; maxY *= 72;
  if (npos) {
    gscale *= AIR_CAST(float, (maxX - minX)/(max[0] - min[0]));
    dotRad *= AIR_CAST(float, (maxX - minX)/(max[0] - min[0]));
    lineWidth *= AIR_CAST(float, (maxX - minX)/(max[0] - min[0]));
  }

  fprintf(file, "%%!PS-Adobe-3.0 EPSF-3.0\n");
  fprintf(file, "%%%%Creator: tend ellipse\n");
  fprintf(file, "%%%%Title: blah blah blah\n");
  fprintf(file, "%%%%Pages: 1\n");
  fprintf(file, "%%%%BoundingBox: %d %d %d %d\n",
          AIR_CAST(int, floor(minX)), AIR_CAST(int, floor(minY)),
          AIR_CAST(int, ceil(maxX)), AIR_CAST(int, ceil(maxY)));
  fprintf(file, "%%%%HiResBoundingBox: %g %g %g %g\n", 
          minX, minY, maxX, maxY);
  fprintf(file, "%%%%EndComments\n");
  fprintf(file, "%%%%BeginProlog\n");
  fprintf(file, "%%%%EndProlog\n");
  fprintf(file, "%%%%Page: 1 1\n");

  fprintf(file, "gsave\n");

  if (invert) {
    fprintf(file, "0 setgray\n");
    fprintf(file, "%g %g moveto\n", minX, minY);
    fprintf(file, "%g %g lineto\n", maxX, minY);
    fprintf(file, "%g %g lineto\n", maxX, maxY);
    fprintf(file, "%g %g lineto\n", minX, maxY);
    fprintf(file, "closepath fill\n");
  }

  fprintf(file, "gsave\n");
  fprintf(file, "0.5 setgray\n");
  tdata = (float*)nten->data;
  pdata = npos ? (float*)npos->data : NULL;
  for (ti=0; ti<nt; ti++) {
    if (npos) {
      px = AIR_AFFINE(min[0], pdata[0], max[0], minX, maxX);
      py = AIR_AFFINE(min[1], pdata[1], max[1], maxY, minY);
      pdata += 2;
    } else {
      x = ti % sx;
      y = ti / sx;
      px = NRRD_CELL_POS(minX, maxX, sx, x);
      py = NRRD_CELL_POS(minY, maxY, sy, sy-1-y);
    }
    conf = tdata[0];
    if (conf > cthresh) {
      Dxx = tdata[1];
      Dxy = tdata[2];
      Dyy = tdata[3];
      fprintf(file, "gsave\n");
      fprintf(file, "matrix currentmatrix\n");
      fprintf(file, "[%g %g %g %g %g %g] concat\n",
              Dxx, -Dxy, -Dxy, Dyy, px, py);
      fprintf(file, "0 0 %g 0 360 arc closepath\n", gscale);
      fprintf(file, "setmatrix\n");
      fprintf(file, "fill\n");
      fprintf(file, "grestore\n");
    }
    tdata += 4;
  }
  fprintf(file, "grestore\n");

  if (dotRad && !nstn) {
    fprintf(file, "gsave\n");
    tdata = (float*)nten->data;
    pdata = npos ? (float*)npos->data : NULL;
    fprintf(file, "%g setgray\n", invert ? 1.0 : 0.0);
    for (ti=0; ti<nt; ti++) {
      if (npos) {
        px = AIR_AFFINE(min[0], pdata[0], max[0], minX, maxX);
        py = AIR_AFFINE(min[1], pdata[1], max[1], maxY, minY);
        pdata += 2;
      } else {
        x = ti % sx;
        y = ti / sx;
        px = NRRD_CELL_POS(minX, maxX, sx, x);
        py = NRRD_CELL_POS(minY, maxY, sy, sy-1-y);
      }
      conf = tdata[0];
      if (conf > cthresh) {
        fprintf(file, "%g %g %g 0 360 arc closepath fill\n", px, py, dotRad);
      }
      tdata += 4;
    }
    fprintf(file, "grestore\n");
  }

  if ((dotRad || lineWidth) && npos && nstn) {
    fprintf(file, "gsave\n");
    tdata = (float*)nten->data;
    pdata = npos ? (float*)npos->data : NULL;
    sdata = nstn ? (int*)nstn->data : NULL;
    fprintf(file, "%g setlinewidth\n", lineWidth);
    fprintf(file, "%g setgray\n", invert ? 1.0 : 0.0);
    fprintf(file, "1 setlinecap\n");
    fprintf(file, "1 setlinejoin\n");
    for (ti=0; ti<nstn->axis[1].size; ti++) {
      if (1 == sdata[1 + 3*ti]) {
        vi = sdata[0 + 3*ti];
        px = AIR_AFFINE(min[0], pdata[0 + 2*vi], max[0], minX, maxX);
        py = AIR_AFFINE(min[1], pdata[1 + 2*vi], max[1], maxY, minY);
        if (tdata[0 + 4*vi] > cthresh) {
          fprintf(file, "%g %g %g 0 360 arc closepath fill\n", px, py, dotRad);
        }
      } else {
        fprintf(file, "newpath\n");
        for (vi = sdata[0 + 3*ti];
             vi < sdata[0 + 3*ti] + sdata[1 + 3*ti];
             vi++) {
          px = AIR_AFFINE(min[0], pdata[0 + 2*vi], max[0], minX, maxX);
          py = AIR_AFFINE(min[1], pdata[1 + 2*vi], max[1], maxY, minY);
          fprintf(file, "%g %g %s\n", px, py,
                  vi == sdata[0 + 3*ti] ? "moveto" : "lineto");
        }
        fprintf(file, "stroke\n");
        vi = sdata[0 + 3*ti] + sdata[2 + 3*ti];
        px = AIR_AFFINE(min[0], pdata[0 + 2*vi], max[0], minX, maxX);
        py = AIR_AFFINE(min[1], pdata[1 + 2*vi], max[1], maxY, minY);
        fprintf(file, "%g %g %g 0 360 arc closepath fill\n",
                px, py, dotRad + lineWidth);
      }
    }
    fprintf(file, "grestore\n");
  }

  fprintf(file, "grestore\n");
  
  return 0;
}