/* ******** nrrdCopy ** ** copy method for nrrds. nout will end up as an "exact" copy of nin. ** New space for data is allocated here, and output nrrd points to it. ** Comments from old are added to comments for new, so these are also ** newly allocated. nout->ptr is not set, nin->ptr is not read. */ int nrrdCopy(Nrrd *nout, const Nrrd *nin) { char me[]="nrrdCopy", err[BIFF_STRLEN]; if (_nrrdCopy(nout, nin, NRRD_BASIC_INFO_NONE)) { sprintf(err, "%s:", me); biffAdd(NRRD, err); return 1; } return 0; }
/* ******** nrrdAxesInsert ** ** like reshape, but preserves axis information on old axes, and ** this is only for adding a "stub" axis with length 1. All other ** axis attributes are initialized as usual. */ int nrrdAxesInsert(Nrrd *nout, const Nrrd *nin, unsigned int axis) { static const char me[]="nrrdAxesInsert", func[]="axinsert"; unsigned int ai; if (!(nout && nin)) { biffAddf(NRRD, "%s: got NULL pointer", me); return 1; } if (!( axis <= nin->dim )) { biffAddf(NRRD, "%s: given axis (%d) outside valid range [0, %d]", me, axis, nin->dim); return 1; } if (NRRD_DIM_MAX == nin->dim) { biffAddf(NRRD, "%s: given nrrd already at NRRD_DIM_MAX (%d)", me, NRRD_DIM_MAX); return 1; } if (nout != nin) { if (_nrrdCopy(nout, nin, (NRRD_BASIC_INFO_COMMENTS_BIT | (nrrdStateKeyValuePairsPropagate ? 0 : NRRD_BASIC_INFO_KEYVALUEPAIRS_BIT)))) { biffAddf(NRRD, "%s:", me); return 1; } } nout->dim = 1 + nin->dim; for (ai=nin->dim; ai>axis; ai--) { _nrrdAxisInfoCopy(&(nout->axis[ai]), &(nin->axis[ai-1]), NRRD_AXIS_INFO_NONE); } /* the ONLY thing we can say about the new axis is its size */ _nrrdAxisInfoInit(&(nout->axis[axis])); if (!nrrdStateKindNoop) { /* except maybe the kind */ nout->axis[axis].kind = nrrdKindStub; } nout->axis[axis].size = 1; if (nrrdContentSet_va(nout, func, nin, "%d", axis)) { biffAddf(NRRD, "%s:", me); return 1; } /* all basic info has already been copied by nrrdCopy() above */ return 0; }