コード例 #1
0
ファイル: histogram.c プロジェクト: sinkpoint/hodaie-teem
int
nrrdHistoCheck(const Nrrd *nhist) {
  static const char me[]="nrrdHistoCheck";

  if (!nhist) {
    biffAddf(NRRD, "%s: got NULL pointer", me);
    return 1;
  }
  if (nrrdTypeBlock == nhist->type) {
    biffAddf(NRRD, "%s: has non-scalar %s type",
             me, airEnumStr(nrrdType, nrrdTypeBlock));
    return 1;
  }
  if (nrrdHasNonExist(nhist)) {
    biffAddf(NRRD, "%s: has non-existent values", me);
    return 1;
  }
  if (1 != nhist->dim) {
    biffAddf(NRRD, "%s: dim == %u != 1", 
             me, nhist->dim);
    return 1;
  }
  if (!(nhist->axis[0].size > 1)) {
    biffAddf(NRRD, "%s: has single sample along sole axis", me);
    return 1;
  }
  
  return 0;
}
コード例 #2
0
ファイル: simple.c プロジェクト: 151706061/ITK
/*
******** nrrdSpaceSet
**
** What to use to set space, when a value from nrrdSpace enum is known,
** or, to nullify all space-related information when passed nrrdSpaceUnknown
*/
int
nrrdSpaceSet(Nrrd *nrrd, int space) {
  static const char me[]="nrrdSpaceSet";
  unsigned axi, saxi;

  if (!nrrd) {
    biffAddf(NRRD, "%s: got NULL pointer", me);
    return 1;
  }
  if (nrrdSpaceUnknown == space) {
    nrrd->space = nrrdSpaceUnknown;
    nrrd->spaceDim = 0;
    for (axi=0; axi<NRRD_DIM_MAX; axi++) {
      nrrdSpaceVecSetNaN(nrrd->axis[axi].spaceDirection);
    }
    for (saxi=0; saxi<NRRD_SPACE_DIM_MAX; saxi++) {
      airFree(nrrd->spaceUnits[saxi]);
      nrrd->spaceUnits[saxi] = NULL;
    }
    nrrdSpaceVecSetNaN(nrrd->spaceOrigin);
  } else {
    if (airEnumValCheck(nrrdSpace, space)) {
      biffAddf(NRRD, "%s: given space (%d) not valid", me, space);
      return 1;
    }
    nrrd->space = space;
    nrrd->spaceDim = nrrdSpaceDimension(space);
  }
  return 0;
}
コード例 #3
0
ファイル: spec.c プロジェクト: kindlmann/reva
int
rvaLattSpecConvert(rvaLattSpec *dst, int latt, const rvaLattSpec *src) {
  static const char me[]="rvaLattSpecConvert";
  int nocando;

  if (!(dst && src)) {
    biffAddf(RVA, "%s: got NULL pointer", me);
    return 1;
  }
  if (airEnumValCheck(rvaLatt, latt)) {
    biffAddf(RVA, "%s: %d not valid %s", me, latt, rvaLatt->name);
    return 1;
  }
  if (latt == src->latt) {
    rvaLattSpecCopy(dst, src);
    return 0;
  }
  /* else have work to do */
  if (lattConv(latt, dst->parm, src->latt, src->parm)) {
    dst->latt = rvaLattUnknown;
    biffAddf(RVA, "%s: %s -> %s conversion not implemented", me,
             airEnumStr(rvaLatt, src->latt), airEnumStr(rvaLatt, latt));
    return 1;
  }
  /* else no error; we're done */
  dst->latt = latt;

  return 0;
}
コード例 #4
0
ファイル: simple.c プロジェクト: 151706061/ITK
/*
******** nrrdContentSet
**
** Kind of like sprintf, but for the content string of the nrrd.
**
** Whether or not we write a new content for an old nrrd ("nin") with
** NULL content is decided here, according to
** nrrdStateAlwaysSetContent.
**
** Does the string allocation and some attempts at error detection.
** Does allow nout==nin, which requires some care.
*/
int
nrrdContentSet_va(Nrrd *nout, const char *func,
                  const Nrrd *nin, const char *format, ...) {
  static const char me[]="nrrdContentSet_va";
  va_list ap;
  char *content;

  if (!(nout && func && nin && format)) {
    biffAddf(NRRD, "%s: got NULL pointer", me);
    return 1;
  }
  if (nrrdStateDisableContent) {
    /* we kill content always */
    nout->content = (char *)airFree(nout->content);
    return 0;
  }
  if (!nin->content && !nrrdStateAlwaysSetContent) {
    /* there's no input content, and we're not supposed to invent any
       content, so after freeing nout's content we're done */
    nout->content = (char *)airFree(nout->content);
    return 0;
  }
  /* we copy the input nrrd content first, before blowing away the
     output content, in case nout == nin */
  content = _nrrdContentGet(nin);
  va_start(ap, format);
  if (_nrrdContentSet_nva(nout, func, content, format, ap)) {
    biffAddf(NRRD, "%s:", me);
    va_end(ap); free(content); return 1;
  }
  va_end(ap);
  free(content);

  return 0;
}
コード例 #5
0
ファイル: arith.c プロジェクト: BRAINSia/teem
int
nrrdArithIterTernaryOp(Nrrd *nout, int op,
                       NrrdIter *inA, NrrdIter *inB, NrrdIter *inC) {
  static const char me[]="nrrdArithIterTernaryOp";
  unsigned int which;

  if (!(nout && inA && inB && inC)) {
    biffAddf(NRRD, "%s: got NULL pointer", me);
    return 1;
  }
  which = (_NRRD_ITER_NRRD(inA)
           ? 0
           : (_NRRD_ITER_NRRD(inB)
              ? 1
              : (_NRRD_ITER_NRRD(inC)
                 ? 2
                 : 3 )));
  if (3 == which) {
    biffAddf(NRRD, "%s: can't operate on 3 fixed values", me);
    return 1;
  }
  if (nrrdArithIterTernaryOpSelect(nout, op, inA, inB, inC, which)) {
    biffAddf(NRRD, "%s: trouble", me);
    return 1;
  }
  return 0;
}
コード例 #6
0
ファイル: enumall.c プロジェクト: atisman89/teem
int
meetAirEnumAllCheck(void) {
  static const char me[]="meetAirEnumAllCheck";
  const airEnum **enm, *ee;
  char err[AIR_STRLEN_LARGE];
  unsigned int ei;
  airArray *mop;

  mop = airMopNew();
  enm = meetAirEnumAll();
  airMopAdd(mop, (void*)enm, airFree, airMopAlways);
  ei = 0;
  while ((ee = enm[ei])) {
    /* fprintf(stderr, "!%s: %u %s\n", me, ei, ee->name); */
    if (airEnumCheck(err, ee)) {
      biffAddf(MEET, "%s: problem with enum %u", me, ei);
      biffAddf(MEET, "%s", err); /* kind of a hack */
      airMopError(mop);
      return 1;
    }
    ei++;
  }
  airMopOkay(mop);
  return 0;
}
コード例 #7
0
ファイル: genmat.c プロジェクト: CIBC-Internal/teem
/*
******** ell_Nm_inv
**
** computes the inverse of given matrix in nmat, and puts the
** inverse in the (maybe allocated) ninv.  Does not touch the
** values in nmat.
*/
int
ell_Nm_inv(Nrrd *ninv, Nrrd *nmat) {
  static const char me[]="ell_Nm_inv";
  double *mat, *inv;
  size_t NN;

  if (!( ninv && !ell_Nm_check(nmat, AIR_FALSE) )) {
    biffAddf(ELL, "%s: NULL or invalid args", me);
    return 1;
  }

  NN = nmat->axis[0].size;
  if (!( NN == nmat->axis[1].size )) {
    char stmp[2][AIR_STRLEN_SMALL];
    biffAddf(ELL, "%s: need a square matrix, not %s-by-%s", me,
             airSprintSize_t(stmp[0], nmat->axis[1].size),
             airSprintSize_t(stmp[1], NN));
    return 1;
  }
  if (nrrdMaybeAlloc_va(ninv, nrrdTypeDouble, 2,
                        NN, NN)) {
    biffMovef(ELL, NRRD, "%s: trouble", me);
    return 1;
  }
  inv = (double*)(ninv->data);
  mat = (double*)(nmat->data);
  if (_ell_inv(inv, mat, NN)) {
    biffAddf(ELL, "%s: trouble", me);
    return 1;
  }

  return 0;
}
コード例 #8
0
ファイル: genmat.c プロジェクト: CIBC-Internal/teem
int
ell_Nm_check(Nrrd *mat, int doNrrdCheck) {
  static const char me[]="ell_Nm_check";

  if (doNrrdCheck) {
    if (nrrdCheck(mat)) {
      biffMovef(ELL, NRRD, "%s: basic nrrd validity check failed", me);
      return 1;
    }
  } else {
    if (!mat) {
      biffAddf(ELL, "%s: got NULL pointer", me);
      return 1;
    }
  }
  if (!( 2 == mat->dim )) {
    biffAddf(ELL, "%s: nrrd must be 2-D (not %d-D)", me, mat->dim);
    return 1;
  }
  if (!( nrrdTypeDouble == mat->type )) {
    biffAddf(ELL, "%s: nrrd must be type %s (not %s)", me,
             airEnumStr(nrrdType, nrrdTypeDouble),
             airEnumStr(nrrdType, mat->type));
    return 1;
  }

  return 0;
}
コード例 #9
0
ファイル: genmat.c プロジェクト: CIBC-Internal/teem
/*
** _ell_inv
**
** Invert NNxNN matrix based on LU-decomposition
**
** The given matrix is copied, turned into its LU-decomposition, and
** then repeated backsubstitution is used to get successive columns of
** the inverse.
*/
int
_ell_inv(double *inv, double *_mat, size_t NN) {
  static const char me[]="_ell_inv";
  size_t ii, jj, *indx=NULL;
  double *col=NULL, *mat=NULL;
  int ret=0;

  if (!( (col = (double*)calloc(NN, sizeof(double))) &&
         (mat = (double*)calloc(NN*NN, sizeof(double))) &&
         (indx = (size_t*)calloc(NN, sizeof(size_t))) )) {
    biffAddf(ELL, "%s: couldn't allocate all buffers", me);
    ret = 1; goto seeya;
  }

  memcpy(mat, _mat, NN*NN*sizeof(double));

  if (_ell_LU_decomp(mat, indx, NN)) {
    biffAddf(ELL, "%s: trouble", me);
    ret = 1; goto seeya;
  }

  for (jj=0; jj<NN; jj++) {
    memset(col, 0, NN*sizeof(double));
    col[jj] = 1.0;
    _ell_LU_back_sub(mat, indx, col, NN);
    /* set column jj of inv to result of backsub */
    for (ii=0; ii<NN; ii++) {
      inv[ii*NN + jj] = col[ii];
    }
  }
 seeya:
  airFree(col); airFree(mat); airFree(indx);
  return ret;
}
コード例 #10
0
ファイル: gzio.c プロジェクト: BRAINSia/teem
/*
** _nrrdGzDestroy()
**
** Cleans up then free the given _NrrdGzStream. Returns a zlib error code.
** Try freeing in the reverse order of allocations.  FILE* s->file is not
** closed.  Because we didn't allocate it, we shouldn't delete it.
*/
static int
_nrrdGzDestroy(_NrrdGzStream *s) {
  static const char me[]="_nrrdGzDestroy";
  int error = Z_OK;

  if (s == NULL) {
    biffAddf(NRRD, "%s: invalid stream", me);
    return 1;
  }
  s->msg = (char *)airFree(s->msg);
  if (s->stream.state != NULL) {
    if (s->mode == 'w') {
      error = deflateEnd(&(s->stream));
    } else if (s->mode == 'r') {
      error = inflateEnd(&(s->stream));
    }
  }
  if (error != Z_OK) {
    biffAddf(NRRD, "%s: %s", me, _NRRD_GZ_ERR_MSG(error));
  }
  if (s->z_err < 0) error = s->z_err;
  if (error != Z_OK) {
    biffAddf(NRRD, "%s: %s", me, _NRRD_GZ_ERR_MSG(error));
  }
  s->inbuf = (Byte *)airFree(s->inbuf);
  s->outbuf = (Byte *)airFree(s->outbuf);
  airFree(s);   /* avoiding unused value warnings, no NULL set */
  return error != Z_OK;
}
コード例 #11
0
ファイル: grads.c プロジェクト: BRAINSia/teem
int
tenGradientCheck(const Nrrd *ngrad, int type, unsigned int minnum) {
  static const char me[]="tenGradientCheck";

  if (nrrdCheck(ngrad)) {
    biffMovef(TEN, NRRD, "%s: basic validity check failed", me);
    return 1;
  }
  if (!( 3 == ngrad->axis[0].size && 2 == ngrad->dim )) {
    char stmp[AIR_STRLEN_SMALL];
    biffAddf(TEN, "%s: need a 3xN 2-D array (not a %sx? %u-D array)", me,
             airSprintSize_t(stmp, ngrad->axis[0].size), ngrad->dim);
    return 1;
  }
  if (nrrdTypeDefault != type && type != ngrad->type) {
    biffAddf(TEN, "%s: requested type %s but got type %s", me,
             airEnumStr(nrrdType, type), airEnumStr(nrrdType, ngrad->type));
    return 1;
  }
  if (nrrdTypeBlock == ngrad->type) {
    biffAddf(TEN, "%s: sorry, can't use %s type", me,
             airEnumStr(nrrdType, nrrdTypeBlock));
    return 1;
  }
  if (!( minnum <= ngrad->axis[1].size )) {
    char stmp[AIR_STRLEN_SMALL];
    biffAddf(TEN, "%s: have only %s gradients, need at least %d", me,
             airSprintSize_t(stmp, ngrad->axis[1].size), minnum);
    return 1;
  }

  return 0;
}
コード例 #12
0
ファイル: genmat.c プロジェクト: CIBC-Internal/teem
/*
******** ell_Nm_wght_pseudo_inv()
**
** determines a weighted least squares solution via
** P = (A^T * W * A)^(-1) * A^T * W
*/
int
ell_Nm_wght_pseudo_inv(Nrrd *ninv, Nrrd *nA, Nrrd *nW) {
  static const char me[]="ell_Nm_wght_pseudo_inv";
  Nrrd *nAt, *nAtW, *nAtWA, *nAtWAi;
  int ret=0;

  if (!( ninv && !ell_Nm_check(nA, AIR_FALSE)
         && !ell_Nm_check(nW, AIR_FALSE) )) {
    biffAddf(ELL, "%s: NULL or invalid args", me);
    return 1;
  }
  nAt = nrrdNew();
  nAtW = nrrdNew();
  nAtWA = nrrdNew();
  nAtWAi = nrrdNew();
  if (ell_Nm_tran(nAt, nA)
      || ell_Nm_mul(nAtW, nAt, nW)
      || ell_Nm_mul(nAtWA, nAtW, nA)
      || ell_Nm_inv(nAtWAi, nAtWA)
      || ell_Nm_mul(ninv, nAtWAi, nAtW)) {
    biffAddf(ELL, "%s: trouble", me);
    ret = 1; goto seeya;
  }

 seeya:
  nrrdNuke(nAt); nrrdNuke(nAtW); nrrdNuke(nAtWA); nrrdNuke(nAtWAi);
  return ret;
}
コード例 #13
0
ファイル: cam.c プロジェクト: BRAINSia/teem
/*
******** limnCameraAspectSet
**
** simply sets the "aspect" field of the cam.  Note that calling this
** does *not* automatically mean that the uRange and vRange in the camera
** will be set according to the "fov"- the "fov" has to actually be set
** (be non-NaN) for that to happen.  This allows dumber functions to
** call this whenever they have the information required to do so, even
** if the "aspect" is not going to be needed for a given camera use
*/
int
limnCameraAspectSet(limnCamera *cam, unsigned int horz, unsigned int vert,
                    int centering) {
  static const char me[] = "limnCameraAspectSet";

  if (!cam) {
    biffAddf(LIMN, "%s: got NULL pointer", me);
    return 1;
  }
  if (!( horz > 0 && vert > 0 )) {
    biffAddf(LIMN, "%s: bad image dimensions %ux%u", me, horz, vert);
    return 1;
  }
  if (airEnumValCheck(nrrdCenter, centering)) {
    biffAddf(LIMN, "%s: centering %d not valid", me, centering);
    return 1;
  }

  if (nrrdCenterCell == centering) {
    cam->aspect = ((double)horz)/vert;
  } else {
    cam->aspect = ((double)(horz-1))/(vert-1);
  }

  return 0;
}
コード例 #14
0
ファイル: encodingAscii.c プロジェクト: CapeDrew/DITK
int
_nrrdEncodingAscii_read(FILE *file, void *_data, size_t elNum,
                        Nrrd *nrrd, NrrdIoState *nio) {
  static const char me[]="_nrrdEncodingAscii_read";
  char numbStr[AIR_STRLEN_HUGE];  /* HEY: fix this */
  char *nstr;
  size_t I;
  char *data;
  int tmp;

  AIR_UNUSED(nio);
  if (nrrdTypeBlock == nrrd->type) {
    biffAddf(NRRD, "%s: can't read nrrd type %s from %s", me,
             airEnumStr(nrrdType, nrrdTypeBlock),
             nrrdEncodingAscii->name);
    return 1;
  }
  data = (char*)_data;
  I = 0;
  while (I < elNum) {
    if (1 != fscanf(file, "%s", numbStr)) {
      biffAddf(NRRD, "%s: couldn't parse element " _AIR_SIZE_T_CNV
               " of " _AIR_SIZE_T_CNV, me, I+1, elNum);
      return 1;
    }
    if (!strcmp(",", numbStr)) {
      /* its an isolated comma, not a value, pass over this */
      continue;
    }
    /* get past any commas prefixing a number (without space) */
    nstr = numbStr + strspn(numbStr, ",");
    if (nrrd->type >= nrrdTypeInt) {
      /* sscanf supports putting value directly into this type */
      if (1 != airSingleSscanf(nstr, nrrdTypePrintfStr[nrrd->type], 
                               (void*)(data + I*nrrdElementSize(nrrd)))) {
        biffAddf(NRRD, "%s: couln't parse %s " _AIR_SIZE_T_CNV
                 " of " _AIR_SIZE_T_CNV " (\"%s\")", me,
                 airEnumStr(nrrdType, nrrd->type),
                 I+1, elNum, nstr);
        return 1;
      }
    } else {
      /* sscanf value into an int first */
      if (1 != airSingleSscanf(nstr, "%d", &tmp)) {
        biffAddf(NRRD, "%s: couln't parse element " _AIR_SIZE_T_CNV
                 " of " _AIR_SIZE_T_CNV " (\"%s\")",
                 me, I+1, elNum, nstr);
        return 1;
      }
      nrrdIInsert[nrrd->type](data, I, tmp);
    }
    I++;
  }
  
  return 0;
}
コード例 #15
0
ファイル: ninspect.c プロジェクト: CIBC-Internal/teem
int
ninspect_proj(Nrrd *nout, Nrrd *nin, int axis, int smart, float amount) {
  static const char me[]="ninspect_proj";
  airArray *mop;
  Nrrd *ntmpA, *ntmpB, **nrgb;
  int bins;

  if (!(nout && nin)) {
    biffAddf(NINSPECT, "%s: got NULL pointer", me);
    return 1;
  }
  if (!( AIR_IN_CL(0, axis, 2) )) {
    biffAddf(NINSPECT, "%s: given axis %d outside valid range [0,1,2]",
             me, axis);
    return 1;
  }

  /* allocate a bunch of nrrds to use as basically temp variables */
  mop = airMopNew();
  airMopAdd(mop, ntmpA = nrrdNew(), (airMopper)nrrdNuke, airMopAlways);
  airMopAdd(mop, ntmpB = nrrdNew(), (airMopper)nrrdNuke, airMopAlways);
  /* HEY: this used to be nrgb[3], but its passing to nrrdJoin caused
     "dereferencing type-punned pointer might break strict-aliasing rules"
     warning; GLK not sure how else to fix it */
  nrgb = AIR_CALLOC(3, Nrrd*);
  airMopAdd(mop, nrgb, airFree, airMopAlways);
  airMopAdd(mop, nrgb[0] = nrrdNew(), (airMopper)nrrdNuke, airMopAlways);
  airMopAdd(mop, nrgb[1] = nrrdNew(), (airMopper)nrrdNuke, airMopAlways);
  airMopAdd(mop, nrgb[2] = nrrdNew(), (airMopper)nrrdNuke, airMopAlways);

  /* these arguments to nrrdHistoEq will control its behavior */
  bins = 3000;  /* equalization will use a histogram with this many bins */

  /* the following idiom is one way of handling the fact that any
     non-trivial nrrd call can fail, and if it does, then any subsequent
     nrrd calls should be avoided (to be perfectly safe), so that you can
     get the error message from biff.  Because of the left-to-right ordering
     ensured for logical expressions, this will all be called in sequence
     until one of them has a non-zero return.  If he had exception handling,
     we'd put all the nrrd calls in one "try" block.  */
  if (nrrdProject(ntmpA, nin, axis, nrrdMeasureSum, nrrdTypeDefault)
      || nrrdHistoEq(ntmpB, ntmpA, NULL, bins, smart, amount)
      || nrrdQuantize(nrgb[0], ntmpB, NULL, 8)
      || nrrdProject(ntmpA, nin, axis, nrrdMeasureVariance, nrrdTypeDefault)
      || nrrdHistoEq(ntmpB, ntmpA, NULL, bins, smart, amount)
      || nrrdQuantize(nrgb[1], ntmpB, NULL, 8)
      || nrrdProject(ntmpA, nin, axis, nrrdMeasureMax, nrrdTypeDefault)
      || nrrdQuantize(nrgb[2], ntmpA, NULL, 8)
      || nrrdJoin(nout, (const Nrrd*const*)nrgb, 3, 0, AIR_TRUE)) {
    biffMovef(NINSPECT, NRRD, "%s: trouble with nrrd operations", me);
    airMopError(mop); return 1;
  }

  airMopOkay(mop);
  return 0;
}
コード例 #16
0
ファイル: update.c プロジェクト: CIBC-Internal/teem
/*
** ctx's needD & k3pack --> needK
*/
static int
_gageNeedKUpdate(gageContext *ctx) {
  static const char me[]="_gageNeedKUpdate";
  int kernIdx, needK[GAGE_KERNEL_MAX+1], change;
  unsigned int di;

  if (ctx->verbose) fprintf(stderr, "%s: hello\n", me);
  for (kernIdx=gageKernelUnknown+1; kernIdx<gageKernelLast; kernIdx++) {
    needK[kernIdx] = AIR_FALSE;
  }
  if (!ctx->parm.k3pack) {
    biffAddf(GAGE, "%s: sorry, only 3-pack filtering implemented now", me);
    return 1;
  }
  di = 0;
  if (ctx->needD[di]) {
    needK[gageKernel00] = AIR_TRUE;
  }
  di += 1;
  if (ctx->needD[di]) {
    needK[gageKernel00] = needK[gageKernel11] = AIR_TRUE;
  }
  di += 1;
  if (ctx->needD[di]) {
    needK[gageKernel00] = needK[gageKernel11] =
      needK[gageKernel22] = AIR_TRUE;
  }
  if (GAGE_DERIV_MAX != di) {
    biffAddf(GAGE, "%s: sorry, code needs updating for GAGE_DERIV_MAX %u",
             me, GAGE_DERIV_MAX);
    return 1;
  }
  change = AIR_FALSE;
  for (kernIdx=gageKernelUnknown+1; kernIdx<gageKernelLast; kernIdx++) {
    change |= (needK[kernIdx] != ctx->needK[kernIdx]);
  }
  if (change) {
    if (ctx->verbose) {
      fprintf(stderr, "%s: changing needK to (", me);
      for (kernIdx=gageKernelUnknown+1; kernIdx<gageKernelLast; kernIdx++) {
        fprintf(stderr, "%s%d", kernIdx > gageKernelUnknown+1 ? "," : "",
                needK[kernIdx]);
      }
      fprintf(stderr, ")\n");
    }
    for (kernIdx=gageKernelUnknown+1; kernIdx<gageKernelLast; kernIdx++) {
      ctx->needK[kernIdx] = needK[kernIdx];
    }
    ctx->flag[gageCtxFlagNeedK] = AIR_TRUE;
  }
  if (ctx->verbose) fprintf(stderr, "%s: bye\n", me);

  return 0;
}
コード例 #17
0
ファイル: strace.c プロジェクト: BRAINSia/teem
int
pullScaleTracePlotAdd(pullContext *pctx, Nrrd *nwild, Nrrd *nccd,
                      Nrrd *nmask, double mth, airArray *insideArr,
                      double velHalf, pullTrace *pts) {
  static const char me[]="pullScaleTracePlotAdd";
  double ssr[2], *pos, *velo, *wild, *ccd, *mask;
  unsigned int pnum, pidx, sizeS, sizeV;

  if (!(pctx && nwild && nccd && pts)) {
    biffAddf(PULL, "%s: got NULL pointer", me);
    return 1;
  }
  if (!nrrdSameSize(nwild, nccd, AIR_TRUE)) {
    biffMovef(PULL, NRRD, "%s: nwild not same size as nccd", me);
    return 1;
  }
  if (nmask || insideArr) {
    if (!insideArr) {
      biffAddf(PULL, "%s: got nmask but not insideArr", me);
      return 1;
    }
    if (!nmask) {
      biffAddf(PULL, "%s: got insideArr but not nmask", me);
      return 1;
    }
    if (nrrdTypeDouble != nmask->type) {
      biffAddf(PULL, "%s: nmask has type %s but want %s", me,
               airEnumStr(nrrdType, nmask->type),
               airEnumStr(nrrdType, nrrdTypeDouble));
      return 1;
    }
    if (!nrrdSameSize(nwild, nmask, AIR_TRUE)) {
      biffMovef(PULL, NRRD, "%s: nwild not same size as nmask", me);
      return 1;
    }
    if (!nrrdSameSize(nccd, nmask, AIR_TRUE)) {
      biffMovef(PULL, NRRD, "%s: nccd not same size as nmask", me);
      return 1;
    }
    if (!AIR_EXISTS(mth)) {
      biffAddf(PULL, "%s: got non-existent mask thresh %g", me, mth);
      return 1;
    }
  }
  ssr[0] = nwild->axis[0].min;
  ssr[1] = nwild->axis[0].max;
  sizeS = AIR_CAST(unsigned int, nwild->axis[0].size);
  sizeV = AIR_CAST(unsigned int, nwild->axis[1].size);
  wild = AIR_CAST(double *, nwild->data);
  ccd = AIR_CAST(double *, nccd->data);
  if (nmask) {
    mask = AIR_CAST(double *, nmask->data);
  } else {
コード例 #18
0
ファイル: encodingHex.c プロジェクト: CIBC-Internal/teem
static int
_nrrdEncodingHex_read(FILE *file, void *_data, size_t elNum,
                      Nrrd *nrrd, NrrdIoState *nio) {
  static const char me[]="_nrrdEncodingHex_read";
  size_t nibIdx, nibNum;
  unsigned char *data;
  int car=0, nib;

  AIR_UNUSED(nio);
  data = AIR_CAST(unsigned char *, _data);
  nibIdx = 0;
  nibNum = 2*elNum*nrrdElementSize(nrrd);
  if (nibNum/elNum != 2*nrrdElementSize(nrrd)) {
    biffAddf(NRRD, "%s: size_t can't hold 2*(#bytes in array)\n", me);
    return 1;
  }
  while (nibIdx < nibNum) {
    unsigned char nibshift;
    car = fgetc(file);
    if (EOF == car) break;
    nib = _nrrdReadHexTable[car & 127];
    if (-2 == nib) {
      /* not a valid hex character */
      break;
    }
    if (-1 == nib) {
      /* its white space */
      continue;
    }
    /* else it is a valid character, representing a value from 0 to 15 */
    nibshift = AIR_CAST(unsigned char, nib << (4*(1-(nibIdx & 1))));
    /* HEY not sure why the cast is needed with gcc v4.8 -Wconversion */
    *data = AIR_CAST(unsigned char, *data + nibshift);
    data += nibIdx & 1;
    nibIdx++;
  }
  if (nibIdx != nibNum) {
    char stmp1[AIR_STRLEN_SMALL], stmp2[AIR_STRLEN_SMALL];
    if (EOF == car) {
      biffAddf(NRRD, "%s: hit EOF getting byte %s of %s", me,
               airSprintSize_t(stmp1, nibIdx/2),
               airSprintSize_t(stmp2, nibNum/2));
    } else {
      biffAddf(NRRD, "%s: hit invalid character ('%c') getting "
               "byte %s of %s", me, car,
               airSprintSize_t(stmp1, nibIdx/2),
               airSprintSize_t(stmp2, nibNum/2));
    }
    return 1;
  }
  return 0;
}
コード例 #19
0
ファイル: write.c プロジェクト: sinkpoint/hodaie-teem
/*
******** nrrdSave
**
** save a given nrrd to a given filename, with cleverness to guess
** format if not specified by the caller
**
** currently, for NRRD format files, we play the detached header game
** whenever the filename ends in NRRD_EXT_NHDR, and when we play this
** game, the data file is ALWAYS header relative.
*/
int
nrrdSave(const char *filename, const Nrrd *nrrd, NrrdIoState *nio) {
  static const char me[]="nrrdSave";
  FILE *file;
  airArray *mop;

  if (!(nrrd && filename)) {
    biffAddf(NRRD, "%s: got NULL pointer", me);
    return 1;
  }
  mop = airMopNew();
  if (!nio) {
    nio = nrrdIoStateNew();
    if (!nio) {
      biffAddf(NRRD, "%s: couldn't alloc local NrrdIoState", me);
      return 1;
    }
    airMopAdd(mop, nio, (airMopper)nrrdIoStateNix, airMopAlways);
  }
  if (_nrrdEncodingMaybeSet(nio)
      || _nrrdFormatMaybeGuess(nrrd, nio, filename)) {
    biffAddf(NRRD, "%s: ", me);
    airMopError(mop); return 1;
  }
  
  if (nrrdFormatNRRD == nio->format 
      && airEndsWith(filename, NRRD_EXT_NHDR)) {
    nio->detachedHeader = AIR_TRUE;
    _nrrdSplitName(&(nio->path), &(nio->base), filename);
    /* nix the ".nhdr" suffix */
    nio->base[strlen(nio->base) - strlen(NRRD_EXT_NHDR)] = 0;
    /* nrrdFormatNRRD->write will do the rest */
  } else {
    nio->detachedHeader = AIR_FALSE;
  }

  if (!( file = airFopen(filename, stdout, "wb") )) {
    biffAddf(NRRD, "%s: couldn't fopen(\"%s\",\"wb\"): %s", 
             me, filename, strerror(errno));
    airMopError(mop); return 1;
  }
  airMopAdd(mop, file, (airMopper)airFclose, airMopAlways);

  if (nrrdWrite(file, nrrd, nio)) {
    biffAddf(NRRD, "%s:", me);
    airMopError(mop); return 1;
  }
  
  airMopOkay(mop);
  return 0;
}
コード例 #20
0
ファイル: fftNrrd.c プロジェクト: CIBC-Internal/teem
int
nrrdFFTWWisdomRead(FILE *file) {
  static const char me[]="nrrdFFTWWisdomRead";

  if (!(file)) {
    biffAddf(NRRD, "%s: given file NULL", me);
    return 1;
  }
  if (!fftw_import_wisdom_from_file(file)) {
    biffAddf(NRRD, "%s: trouble importing wisdom", me);
    return 1;
  }
  return 0;
}
コード例 #21
0
ファイル: txf.c プロジェクト: CIBC-Internal/teem
int
_miteNtxfCopy(miteRender *mrr, miteUser *muu) {
  static const char me[]="_miteNtxfCopy";
  int ni, E;

  mrr->ntxf = AIR_CALLOC(muu->ntxfNum, Nrrd *);
  if (!mrr->ntxf) {
    biffAddf(MITE, "%s: couldn't calloc %d ntxf pointers", me, muu->ntxfNum);
    return 1;
  }
  mrr->ntxfNum = muu->ntxfNum;
  airMopAdd(mrr->rmop, mrr->ntxf, airFree, airMopAlways);
  E = 0;
  for (ni=0; ni<mrr->ntxfNum; ni++) {
    mrr->ntxf[ni] = nrrdNew();
    if (!E) airMopAdd(mrr->rmop, mrr->ntxf[ni],
                      (airMopper)nrrdNuke, airMopAlways);
    if (!( nrrdTypeUChar == muu->ntxf[ni]->type
           || nrrdTypeFloat == muu->ntxf[ni]->type
           || nrrdTypeDouble == muu->ntxf[ni]->type )) {
      biffAddf(MITE,
               "%s: sorry, can't handle txf of type %s (only %s, %s, %s)",
               me, airEnumStr(nrrdType, muu->ntxf[ni]->type),
               airEnumStr(nrrdType, nrrdTypeUChar),
               airEnumStr(nrrdType, nrrdTypeFloat),
               airEnumStr(nrrdType, nrrdTypeDouble));
      return 1;
    }
    /* note that key/values need to be copied for the sake of
       identifying a non-default miteStageOp */
    switch(muu->ntxf[ni]->type) {
    case nrrdTypeUChar:
      if (!E) E |= nrrdUnquantize(mrr->ntxf[ni], muu->ntxf[ni], nrrdTypeUChar);
      if (!E) E |= nrrdKeyValueCopy(mrr->ntxf[ni], muu->ntxf[ni]);
      break;
    case mite_nt:
      if (!E) E |= nrrdCopy(mrr->ntxf[ni], muu->ntxf[ni]);
      break;
    default:  /* will be either float or double (whatever mite_nt isn't) */
      if (!E) E |= nrrdConvert(mrr->ntxf[ni], muu->ntxf[ni], mite_nt);
      if (!E) E |= nrrdKeyValueCopy(mrr->ntxf[ni], muu->ntxf[ni]);
      break;
    }
  }
  if (E) {
    biffMovef(MITE, NRRD, "%s: troubling copying/converting all ntxfs", me);
    return 1;
  }
  return 0;
}
コード例 #22
0
ファイル: superset.c プロジェクト: CIBC-Internal/teem
/*
******** nrrdPad_va()
**
** strictly for padding
*/
int
nrrdPad_va(Nrrd *nout, const Nrrd *nin,
           const ptrdiff_t *min, const ptrdiff_t *max, int boundary, ...) {
  static const char me[]="nrrdPad_va", func[]="pad";
  char buff1[NRRD_DIM_MAX*30], buff2[AIR_STRLEN_MED];
  double padValue=AIR_NAN;
  int outside; /* whether current sample in output has any coordinates
                  that are outside the input volume (this is per-sample,
                  not per-axis) */
  unsigned int ai;
  ptrdiff_t
    cIn[NRRD_DIM_MAX];       /* coords for line start, in input */
  size_t
    typeSize,
    idxIn, idxOut,           /* linear indices for input and output */
    numOut,                  /* number of elements in output nrrd */
    szIn[NRRD_DIM_MAX],
    szOut[NRRD_DIM_MAX],
    cOut[NRRD_DIM_MAX];      /* coords for line start, in output */
  va_list ap;
  char *dataIn, *dataOut;
  char stmp[2][AIR_STRLEN_SMALL];

  if (!(nout && nin && min && max)) {
    biffAddf(NRRD, "%s: got NULL pointer", me);
    return 1;
  }
  if (nout == nin) {
    biffAddf(NRRD, "%s: nout==nin disallowed", me);
    return 1;
  }
  if (!AIR_IN_OP(nrrdBoundaryUnknown, boundary, nrrdBoundaryLast)) {
    biffAddf(NRRD, "%s: boundary behavior %d invalid", me, boundary);
    return 1;
  }
  if (nrrdBoundaryWeight == boundary) {
    biffAddf(NRRD, "%s: boundary strategy %s not applicable here", me,
             airEnumStr(nrrdBoundary, boundary));
    return 1;
  }
  if (nrrdTypeBlock == nin->type && nrrdBoundaryPad == boundary) {
    biffAddf(NRRD, "%s: with nrrd type %s, boundary %s not valid", me,
             airEnumStr(nrrdType, nrrdTypeBlock),
             airEnumStr(nrrdBoundary, nrrdBoundaryPad));
    return 1;
  }
  va_start(ap, boundary);
  if (nrrdBoundaryPad == boundary) {
    padValue = va_arg(ap, double);
  }
コード例 #23
0
ファイル: write.c プロジェクト: sinkpoint/hodaie-teem
/*
** we can assume (via action of caller nrrdSave) that nio->encoding
** has been set
**
** we must set nio->format to something useful/non-trivial
*/
int
_nrrdFormatMaybeGuess(const Nrrd *nrrd, NrrdIoState *nio,
                      const char *filename) {
  static const char me[]="_nrrdFormatMaybeGuess";
  char mesg[AIR_STRLEN_MED];
  int fi, guessed, available, fits;

  if (!nio->format) {
    biffAddf(NRRD, "%s: got invalid (NULL) format", me);
    return 1;
  }
  if (nrrdFormatUnknown == nio->format) {
    for (fi = nrrdFormatTypeUnknown+1; 
         fi < nrrdFormatTypeLast; 
         fi++) {
      if (nrrdFormatArray[fi]->nameLooksLike(filename)) {
        nio->format = nrrdFormatArray[fi];
        break;
      }
    }
    if (nrrdFormatUnknown == nio->format) {
      /* no nameLooksLike() returned non-zero, punt */
      nio->format = nrrdFormatNRRD;
    }
    guessed = AIR_TRUE;
  } else {
    guessed = AIR_FALSE;
  }
  available = nio->format->available();
  fits = nio->format->fitsInto(nrrd, nio->encoding, AIR_FALSE);
  /* !available ==> !fits, by the nature of fitsInto() */
  if (!( available && fits )) {
    sprintf(mesg, "can not use %s format: %s", nio->format->name,
            (!available 
             ? "not available in this Teem build"
             : "array doesn\'t fit"));
    if (guessed) {
      if (1 <= nrrdStateVerboseIO) {
        fprintf(stderr, "(%s: %s --> saving to NRRD format)\n", me, mesg);
      }
      nio->format = nrrdFormatNRRD;
    } else {
      /* problem: this was the format someone explicitly requested */
      biffAddf(NRRD, "%s: %s", me, mesg);
      return 1;
    }
  }

  return 0;
}
コード例 #24
0
ファイル: thread.c プロジェクト: BRAINSia/teem
miteThread *
miteThreadNew() {
  static const char me[]="miteThreadNew";
  miteThread *mtt;
  int ii;

  mtt = (miteThread *)calloc(1, sizeof(miteThread));
  if (!mtt) {
    biffAddf(MITE, "%s: couldn't calloc miteThread", me);
    return NULL;
  }

  mtt->rmop = airMopNew();
  if (!mtt->rmop) {
    biffAddf(MITE, "%s: couldn't calloc thread's mop", me);
    airFree(mtt); return NULL;
  }
  mtt->gctx = NULL;
  mtt->ansScl = mtt->ansVec = mtt->ansTen = NULL;
  mtt->_normal = NULL;
  mtt->shadeVec0 = NULL;
  mtt->shadeVec1 = NULL;
  mtt->shadeScl0 = NULL;
  mtt->shadeScl1 = NULL;
  /* were miteVal a full-fledged gageKind, the following would
     be done by gagePerVolumeNew */
  mtt->ansMiteVal = AIR_CALLOC(gageKindTotalAnswerLength(miteValGageKind),
                               double);
  mtt->directAnsMiteVal = AIR_CALLOC(miteValGageKind->itemMax+1,
                                     double *);
  if (!(mtt->ansMiteVal && mtt->directAnsMiteVal)) {
    biffAddf(MITE, "%s: couldn't calloc miteVal answer arrays", me);
    return NULL;
  }
  for (ii=0; ii<=miteValGageKind->itemMax; ii++) {
    mtt->directAnsMiteVal[ii] = mtt->ansMiteVal
      + gageKindAnswerOffset(miteValGageKind, ii);
  }
  mtt->verbose = 0;
  mtt->skip = 0;
  mtt->thrid = -1;
  mtt->ui = mtt->vi = -1;
  mtt->raySample = 0;
  mtt->samples = 0;
  mtt->stage = NULL;
  /* mtt->range[], rayStep, V, RR, GG, BB, TT  initialized in
     miteRayBegin or in miteSample */

  return mtt;
}
コード例 #25
0
ファイル: clip.c プロジェクト: CIBC-Internal/teem
int
baneClipAnswer(int *countP, baneClip *clip, Nrrd *hvol) {
  static const char me[]="baneClipAnswer";

  if (!( countP && clip && hvol )) {
    biffAddf(BANE, "%s: got NULL pointer", me);
    return 0;
  }
  if (clip->answer(countP, hvol, clip->parm)) {
    biffAddf(BANE, "%s: trouble", me);
    return 0;
  }
  return 0;
}
コード例 #26
0
ファイル: triple.c プロジェクト: BRAINSia/teem
int
tenTripleConvert(Nrrd *nout, int dstType,
                 const Nrrd *nin, int srcType) {
  static const char me[]="tenTripleConvert";
  size_t II, NN;
  double (*ins)(void *, size_t, double), (*lup)(const void *, size_t);

  if (!( nout && nin )) {
    biffAddf(TEN, "%s: got NULL pointer", me);
    return 1;
  }
  if ( airEnumValCheck(tenTripleType, dstType) ||
       airEnumValCheck(tenTripleType, srcType) ) {
    biffAddf(TEN, "%s: got invalid %s dst (%d) or src (%d)", me,
             tenTripleType->name, dstType, srcType);
    return 1;
  }
  if (3 != nin->axis[0].size) {
    char stmp[AIR_STRLEN_SMALL];
    biffAddf(TEN, "%s: need axis[0].size 3, not %s", me,
             airSprintSize_t(stmp, nin->axis[0].size));
    return 1;
  }
  if (nrrdTypeBlock == nin->type) {
    biffAddf(TEN, "%s: input has non-scalar %s type",
             me, airEnumStr(nrrdType, nrrdTypeBlock));
    return 1;
  }

  if (nrrdCopy(nout, nin)) {
    biffMovef(TEN, NRRD, "%s: couldn't initialize output", me);
    return 1;
  }
  lup = nrrdDLookup[nin->type];
  ins = nrrdDInsert[nout->type];
  NN = nrrdElementNumber(nin)/3;
  for (II=0; II<NN; II++) {
    double src[3], dst[3];
    src[0] = lup(nin->data, 0 + 3*II);
    src[1] = lup(nin->data, 1 + 3*II);
    src[2] = lup(nin->data, 2 + 3*II);
    tenTripleConvertSingle_d(dst, dstType, src, srcType);
    ins(nout->data, 0 + 3*II, dst[0]);
    ins(nout->data, 1 + 3*II, dst[1]);
    ins(nout->data, 2 + 3*II, dst[2]);
  }

  return 0;
}
コード例 #27
0
ファイル: clip.c プロジェクト: CIBC-Internal/teem
baneClip *
baneClipNew(int type, double *parm) {
  static const char me[]="baneClipNew";
  baneClip *clip;

  if (!( AIR_IN_OP(baneClipUnknown, type, baneClipLast) )) {
    biffAddf(BANE, "%s: baneClip %d invalid", me, type);
    return NULL;
  }
  if (!parm) {
    biffAddf(BANE, "%s: got NULL pointer", me);
    return NULL;
  }
  if (!(AIR_EXISTS(parm[0]))) {
    biffAddf(BANE, "%s: parm[0] doesn't exist", me);
    return NULL;
  }
  clip = (baneClip*)calloc(1, sizeof(baneClip));
  if (!clip) {
    biffAddf(BANE, "%s: couldn't allocate baneClip!", me);
    return NULL;
  }
  clip->parm[0] = parm[0];
  clip->type = type;
  switch(type) {
  case baneClipAbsolute:
    sprintf(clip->name, "absolute");
    clip->answer = _baneClipAnswer_Absolute;
    break;
  case baneClipPeakRatio:
    sprintf(clip->name, "peak ratio");
    clip->answer = _baneClipAnswer_PeakRatio;
    break;
  case baneClipPercentile:
    sprintf(clip->name, "percentile");
    clip->answer = _baneClipAnswer_Percentile;
    break;
  case baneClipTopN:
    sprintf(clip->name, "top N");
    clip->answer = _baneClipAnswer_TopN;
    break;
  default:
    biffAddf(BANE, "%s: sorry, baneClip %d not implemented", me, type);
    baneClipNix(clip); return NULL;
    break;
  }
  return clip;
}
コード例 #28
0
ファイル: simple.c プロジェクト: 151706061/ITK
static int
_nrrdCheckEnums(void) {
  static const char me[]="_nrrdCheckEnums";
  char which[AIR_STRLEN_SMALL];

  if (nrrdFormatTypeLast-1 != NRRD_FORMAT_TYPE_MAX) {
    strcpy(which, "nrrdFormat"); goto err;
  }
  if (nrrdTypeLast-1 != NRRD_TYPE_MAX) {
    strcpy(which, "nrrdType"); goto err;
  }
  if (nrrdEncodingTypeLast-1 != NRRD_ENCODING_TYPE_MAX) {
    strcpy(which, "nrrdEncodingType"); goto err;
  }
  if (nrrdCenterLast-1 != NRRD_CENTER_MAX) {
    strcpy(which, "nrrdCenter"); goto err;
  }
  if (nrrdAxisInfoLast-1 != NRRD_AXIS_INFO_MAX) {
    strcpy(which, "nrrdAxisInfo"); goto err;
  }
  /* can't really check on endian enum */
  if (nrrdField_last-1 != NRRD_FIELD_MAX) {
    strcpy(which, "nrrdField"); goto err;
  }
  if (nrrdHasNonExistLast-1 != NRRD_HAS_NON_EXIST_MAX) {
    strcpy(which, "nrrdHasNonExist"); goto err;
  }

  /* no errors so far */
  return 0;

 err:
  biffAddf(NRRD, "%s: Last vs. MAX incompatibility for %s enum", me, which);
  return 1;
}
コード例 #29
0
ファイル: simple.c プロジェクト: 151706061/ITK
/*
******** nrrdSpaceDimensionSet
**
** What to use to set space, based on spaceDim alone (nrrd->space set to
** nrrdSpaceUnknown)
*/
int
nrrdSpaceDimensionSet(Nrrd *nrrd, unsigned int spaceDim) {
  static const char me[]="nrrdSpaceDimensionSet";

  if (!nrrd) {
    biffAddf(NRRD, "%s: got NULL pointer", me);
    return 1;
  }
  if (!( spaceDim <= NRRD_SPACE_DIM_MAX )) {
    biffAddf(NRRD, "%s: given spaceDim (%u) not valid", me, spaceDim);
    return 1;
  }
  nrrd->space = nrrdSpaceUnknown;
  nrrd->spaceDim = spaceDim;
  return 0;
}
コード例 #30
0
ファイル: grads.c プロジェクト: BRAINSia/teem
/*
******** tenGradientJitter
**
** moves all gradients by amount dist on tangent plane, in a random
** direction, and then renormalizes. The distance is a fraction
** of the ideal edge length (via tenGradientIdealEdge)
*/
int
tenGradientJitter(Nrrd *nout, const Nrrd *nin, double dist) {
  static const char me[]="tenGradientJitter";
  double *grad, perp0[3], perp1[3], len, theta, cc, ss, edge;
  unsigned int gi, num;

  if (nrrdConvert(nout, nin, nrrdTypeDouble)) {
    biffMovef(TEN, NRRD, "%s: trouble converting input to double", me);
    return 1;
  }
  if (tenGradientCheck(nout, nrrdTypeDouble, 3)) {
    biffAddf(TEN, "%s: didn't get valid gradients", me);
    return 1;
  }
  grad = AIR_CAST(double*, nout->data);
  num = AIR_UINT(nout->axis[1].size);
  /* HEY: possible confusion between single and not */
  edge = tenGradientIdealEdge(num, AIR_FALSE);
  for (gi=0; gi<num; gi++) {
    ELL_3V_NORM(grad, grad, len);
    ell_3v_perp_d(perp0, grad);
    ELL_3V_CROSS(perp1, perp0, grad);
    theta = AIR_AFFINE(0, airDrandMT(), 1, 0, 2*AIR_PI);
    cc = dist*edge*cos(theta);
    ss = dist*edge*sin(theta);
    ELL_3V_SCALE_ADD3(grad, 1.0, grad, cc, perp0, ss, perp1);
    ELL_3V_NORM(grad, grad, len);
    grad += 3;
  }

  return 0;
}