예제 #1
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;
}
예제 #2
0
/*
******** nrrdBasicInfoCopy
**
** copies "basic" (per-array) information
** formerly known as nrrdPeripheralCopy, which was not used consistently
**
** the bitflag communicates which fields should *not* be copied
*/
int
nrrdBasicInfoCopy(Nrrd *dest, const Nrrd *src, int bitflag)
{
  char me[]="nrrdBasicInfoCopy", err[BIFF_STRLEN];
  unsigned int dd, ee;

  if (!( dest && src ))
    return 0;
  if (dest == src)
  {
    /* nothing to do */
    return 0;
  }

  if (!(NRRD_BASIC_INFO_DATA_BIT & bitflag))
  {
    dest->data = src->data;
  }
  if (!(NRRD_BASIC_INFO_TYPE_BIT & bitflag))
  {
    dest->type = src->type;
  }
  if (!(NRRD_BASIC_INFO_BLOCKSIZE_BIT & bitflag))
  {
    dest->blockSize = src->blockSize;
  }
  if (!(NRRD_BASIC_INFO_DIMENSION_BIT & bitflag))
  {
    dest->dim = src->dim;
  }
  if (!(NRRD_BASIC_INFO_CONTENT_BIT & bitflag))
  {
    dest->content = (char *)airFree(dest->content);
    dest->content = airStrdup(src->content);
    if (src->content && !dest->content)
    {
      sprintf(err, "%s: couldn't copy content", me);
      biffAdd(NRRD, err);
      return 1;
    }
  }
  if (!(NRRD_BASIC_INFO_SAMPLEUNITS_BIT & bitflag))
  {
    dest->sampleUnits = (char *)airFree(dest->sampleUnits);
    dest->sampleUnits = airStrdup(src->sampleUnits);
    if (src->sampleUnits && !dest->sampleUnits)
    {
      sprintf(err, "%s: couldn't copy sampleUnits", me);
      biffAdd(NRRD, err);
      return 1;
    }
  }
  if (!(NRRD_BASIC_INFO_SPACE_BIT & bitflag))
  {
    dest->space = src->space;
  }
  if (!(NRRD_BASIC_INFO_SPACEDIMENSION_BIT & bitflag))
  {
    dest->spaceDim = src->spaceDim;
  }
  if (!(NRRD_BASIC_INFO_SPACEUNITS_BIT & bitflag))
  {
    for (dd=0; dd<src->spaceDim; dd++)
    {
      dest->spaceUnits[dd] = (char *)airFree(dest->spaceUnits[dd]);
      dest->spaceUnits[dd] = airStrdup(src->spaceUnits[dd]);
      if (src->spaceUnits[dd] && !dest->spaceUnits[dd])
      {
        sprintf(err, "%s: couldn't copy spaceUnits[%d]", me, dd);
        biffAdd(NRRD, err);
        return 1;
      }
    }
    for (dd=src->spaceDim; dd<NRRD_SPACE_DIM_MAX; dd++)
    {
      dest->spaceUnits[dd] = (char *)airFree(dest->spaceUnits[dd]);
    }
  }
  if (!(NRRD_BASIC_INFO_SPACEORIGIN_BIT & bitflag))
  {
    for (dd=0; dd<NRRD_SPACE_DIM_MAX; dd++)
    {
      if (dd <= src->spaceDim-1)
      {
        dest->spaceOrigin[dd] = src->spaceOrigin[dd];
      }
      else
      {
        dest->spaceOrigin[dd] = AIR_NAN;
      }
    }
  }
  if (!(NRRD_BASIC_INFO_MEASUREMENTFRAME_BIT & bitflag))
  {
    for (dd=0; dd<NRRD_SPACE_DIM_MAX; dd++)
    {
      for (ee=0; ee<NRRD_SPACE_DIM_MAX; ee++)
      {
        if (dd <= src->spaceDim-1 && ee <= src->spaceDim-1)
        {
          dest->measurementFrame[dd][ee] = src->measurementFrame[dd][ee];
        }
        else
        {
          dest->measurementFrame[dd][ee] = AIR_NAN;
        }
      }
    }
    for (dd=src->spaceDim; dd<NRRD_SPACE_DIM_MAX; dd++)
    {
      dest->spaceOrigin[dd] = AIR_NAN;
    }
  }
  if (!(NRRD_BASIC_INFO_OLDMIN_BIT & bitflag))
  {
    dest->oldMin = src->oldMin;
  }
  if (!(NRRD_BASIC_INFO_OLDMAX_BIT & bitflag))
  {
    dest->oldMax = src->oldMax;
  }
  if (!(NRRD_BASIC_INFO_COMMENTS_BIT & bitflag))
  {
    if (nrrdCommentCopy(dest, src))
    {
      sprintf(err, "%s: trouble copying comments", me);
      biffAdd(NRRD, err);
      return 1;
    }
  }
  if (!(NRRD_BASIC_INFO_KEYVALUEPAIRS_BIT & bitflag))
  {
    if (nrrdKeyValueCopy(dest, src))
    {
      sprintf(err, "%s: trouble copying key/value pairs", me);
      biffAdd(NRRD, err);
      return 1;
    }
  }
  return 0;
}