|
From: Gordon K. <kin...@us...> - 2004-04-04 21:33:38
|
Update of /cvsroot/teem/teem/src/unrrdu In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19622 Modified Files: GNUmakefile lut.c rmap.c subst.c unrrdu.h Added Files: mlut.c mrmap.c Log Message: added nrrdApplyMulti1DLut (unu mlut) and nrrdApplyMulti1DRegMap (unu mrmap), which seem to work, but no promises --- NEW FILE: mlut.c --- /* teem: Gordon Kindlmann's research software Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "unrrdu.h" #include "privateUnrrdu.h" #define INFO "Map nrrd through whole nrrd of univariate lookup tables" char *_unrrdu_mlutInfoL = (INFO ", with one lookup table per element of input nrrd. The multiple " "tables are stored in a nrrd with a dimension which is either 1 or 2 " "more than the dimension of the input nrrd, resulting in an output " "which has either the same or one more dimension than the input, " "resptectively. "); int unrrdu_mlutMain(int argc, char **argv, char *me, hestParm *hparm) { hestOpt *opt = NULL; char *out, *err; Nrrd *nin, **_nmlut, *nmlut, *nout; airArray *mop; int typeOut, rescale, pret, mapAxis, _nmlutLen; double min, max; NrrdRange *range=NULL; hestOptAdd(&opt, "m", "mlut", airTypeOther, 1, -1, &_nmlut, NULL, "one nrrd of lookup tables to map input nrrd through, or, " "list of nrrds which contain the individual entries of " "the lookup table at each voxel, which will be joined together.", &_nmlutLen, NULL, nrrdHestNrrd); hestOptAdd(&opt, "r", NULL, airTypeInt, 0, 0, &rescale, NULL, "rescale the input values from the input range to the " "lut domain. The lut domain is either explicitly " "defined by the axis min,max along axis 0 or 1, or, it " "is implicitly defined as zero to the length of that axis " "minus one."); hestOptAdd(&opt, "min", "value", airTypeDouble, 1, 1, &min, "nan", "Low end of input range. Defaults to lowest value " "found in input nrrd. Explicitly setting this is useful " "only with rescaling (\"-r\")"); hestOptAdd(&opt, "max", "value", airTypeDouble, 1, 1, &max, "nan", "High end of input range. Defaults to highest value " "found in input nrrd. Explicitly setting this is useful " "only with rescaling (\"-r\")"); hestOptAdd(&opt, "t", "type", airTypeOther, 1, 1, &typeOut, "default", "specify the type (\"int\", \"float\", etc.) of the " "output nrrd. " "By default (not using this option), the output type " "is the lut's type.", NULL, NULL, &unrrduHestMaybeTypeCB); OPT_ADD_NIN(nin, "input nrrd"); OPT_ADD_NOUT(out, "output nrrd"); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_unrrdu_mlutInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); /* by the end of this block we need to have nmlut and mapAxis */ if (1 == _nmlutLen) { /* we got the mlut as a single nrrd */ nmlut = _nmlut[0]; mapAxis = nmlut->dim - nin->dim - 1; /* its not our job to do real error checking ... */ mapAxis = AIR_CLAMP(0, mapAxis, nmlut->dim - 1); } else { /* we have to join together multiple nrrds to get the mlut */ nmlut = nrrdNew(); airMopAdd(mop, nmlut, (airMopper)nrrdNuke, airMopAlways); /* assume that mlut component nrrds are all compatible sizes, nrrdJoin will fail if they aren't */ mapAxis = _nmlut[0]->dim - nin->dim; if (nrrdJoin(nmlut, (const Nrrd**)_nmlut, _nmlutLen, mapAxis, AIR_TRUE)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: trouble joining mlut:\n%s", me, err); airMopError(mop); return 1; } /* set these if they were given, they'll be NaN otherwise */ nmlut->axis[mapAxis].min = min; nmlut->axis[mapAxis].max = max; } if (!( AIR_EXISTS(nmlut->axis[mapAxis].min) && AIR_EXISTS(nmlut->axis[mapAxis].max) )) { rescale = AIR_TRUE; } if (rescale) { range = nrrdRangeNew(min, max); airMopAdd(mop, range, (airMopper)nrrdRangeNix, airMopAlways); nrrdRangeSafeSet(range, nin, nrrdBlind8BitRangeState); } if (nrrdTypeDefault == typeOut) { typeOut = nmlut->type; } if (nrrdApplyMulti1DLut(nout, nin, range, nmlut, typeOut, rescale)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: trouble applying multi-LUT:\n%s", me, err); airMopError(mop); return 1; } SAVE(out, nout, NULL); airMopOkay(mop); return 0; } UNRRDU_CMD(mlut, INFO); Index: subst.c =================================================================== RCS file: /cvsroot/teem/teem/src/unrrdu/subst.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** subst.c 27 Feb 2004 06:05:18 -0000 1.2 --- subst.c 4 Apr 2004 21:21:06 -0000 1.3 *************** *** 21,25 **** #include "privateUnrrdu.h" ! #define INFO "Map nrrd through univariate substitution table" char *_unrrdu_substInfoL = (INFO --- 21,25 ---- #include "privateUnrrdu.h" ! #define INFO "Map nrrd through a univariate substitution table" char *_unrrdu_substInfoL = (INFO Index: lut.c =================================================================== RCS file: /cvsroot/teem/teem/src/unrrdu/lut.c,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** lut.c 7 Jan 2004 15:34:31 -0000 1.19 --- lut.c 4 Apr 2004 21:21:06 -0000 1.20 *************** *** 21,25 **** #include "privateUnrrdu.h" ! #define INFO "Map nrrd through univariate lookup table" char *_unrrdu_lutInfoL = (INFO --- 21,25 ---- #include "privateUnrrdu.h" ! #define INFO "Map nrrd through one univariate lookup table" char *_unrrdu_lutInfoL = (INFO *************** *** 48,52 **** "lut domain. The lut domain is either explicitly " "defined by the axis min,max along axis 0 or 1, or, it " ! "is implicitly defined as zero to the length of that axis."); hestOptAdd(&opt, "min", "value", airTypeDouble, 1, 1, &min, "nan", "Low end of input range. Defaults to lowest value " --- 48,53 ---- "lut domain. The lut domain is either explicitly " "defined by the axis min,max along axis 0 or 1, or, it " ! "is implicitly defined as zero to the length of that axis " ! "minus one."); hestOptAdd(&opt, "min", "value", airTypeDouble, 1, 1, &min, "nan", "Low end of input range. Defaults to lowest value " Index: unrrdu.h =================================================================== RCS file: /cvsroot/teem/teem/src/unrrdu/unrrdu.h,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** unrrdu.h 26 Feb 2004 20:59:45 -0000 1.26 --- unrrdu.h 4 Apr 2004 21:21:06 -0000 1.27 *************** *** 129,134 **** --- 129,136 ---- F(3op) \ F(lut) \ + F(mlut) \ F(subst) \ F(rmap) \ + F(mrmap) \ F(imap) \ F(ccfind) \ --- NEW FILE: mrmap.c --- /* teem: Gordon Kindlmann's research software Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "unrrdu.h" #include "privateUnrrdu.h" #define INFO "Map nrrd through a whole nrrd of regular univariate maps" char *_unrrdu_mrmapInfoL = (INFO ", one map per sample in input. The \"mmap\" nrrd has the same dimensional " "constraints as the \"mlut\" nrrd for \"unu mlut\". "); int unrrdu_mrmapMain(int argc, char **argv, char *me, hestParm *hparm) { hestOpt *opt = NULL; char *out, *err; Nrrd *nin, **_nmmap, *nmmap, *nout; airArray *mop; NrrdRange *range=NULL; int typeOut, rescale, pret, mapAxis, _nmmapLen; double min, max; hestOptAdd(&opt, "m", "mmap", airTypeOther, 1, -1, &_nmmap, NULL, "one nrrd of regular maps to map input nrrd through, or, " "list of nrrds which contain the individual entries of the map " "at each voxel, which will be joined together.", &_nmmapLen, NULL, nrrdHestNrrd); hestOptAdd(&opt, "r", NULL, airTypeInt, 0, 0, &rescale, NULL, "rescale the input values from the input range to the " "map domain. The map domain is either explicitly " "defined by the axis min,max along axis 0 or 1, or, it " "is implicitly defined as zero to one minus the length of " "that axis."); hestOptAdd(&opt, "min", "value", airTypeDouble, 1, 1, &min, "nan", "Low end of input range. Defaults to lowest value " "found in input nrrd. Explicitly setting this is useful " "only with rescaling (\"-r\") or if the map domain is only " "implicitly defined"); hestOptAdd(&opt, "max", "value", airTypeDouble, 1, 1, &max, "nan", "High end of input range. Defaults to highest value " "found in input nrrd. Explicitly setting this is useful " "only with rescaling (\"-r\") or if the map domain is only " "implicitly defined"); hestOptAdd(&opt, "t", "type", airTypeOther, 1, 1, &typeOut, "default", "specify the type (\"int\", \"float\", etc.) of the " "output nrrd. " "By default (not using this option), the output type " "is the map's type.", NULL, NULL, &unrrduHestMaybeTypeCB); OPT_ADD_NIN(nin, "input nrrd"); OPT_ADD_NOUT(out, "output nrrd"); mop = airMopNew(); airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); USAGE(_unrrdu_mrmapInfoL); PARSE(); airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); nout = nrrdNew(); airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); /* see comment rmap.c */ /* by the end of this block we need to have nmmap and mapAxis */ if (1 == _nmmapLen) { /* we got the mmap as a single nrrd */ nmmap = _nmmap[0]; mapAxis = nmmap->dim - nin->dim - 1; /* its not our job to do real error checking ... */ mapAxis = AIR_CLAMP(0, mapAxis, nmmap->dim - 1); } else { /* we have to join together multiple nrrds to get the mmap */ nmmap = nrrdNew(); airMopAdd(mop, nmmap, (airMopper)nrrdNuke, airMopAlways); /* assume that mmap component nrrds are all compatible sizes, nrrdJoin will fail if they aren't */ mapAxis = _nmmap[0]->dim - nin->dim; if (nrrdJoin(nmmap, (const Nrrd**)_nmmap, _nmmapLen, mapAxis, AIR_TRUE)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: trouble joining mmap:\n%s", me, err); airMopError(mop); return 1; } /* set these if they were given, they'll be NaN otherwise */ nmmap->axis[mapAxis].min = min; nmmap->axis[mapAxis].max = max; } if (!( AIR_EXISTS(nmmap->axis[mapAxis].min) && AIR_EXISTS(nmmap->axis[mapAxis].max) )) { rescale = AIR_TRUE; } if (rescale) { range = nrrdRangeNew(min, max); airMopAdd(mop, range, (airMopper)nrrdRangeNix, airMopAlways); nrrdRangeSafeSet(range, nin, nrrdBlind8BitRangeState); } if (nrrdTypeDefault == typeOut) { typeOut = nmmap->type; } if (nrrdApplyMulti1DRegMap(nout, nin, range, nmmap, typeOut, rescale)) { airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); fprintf(stderr, "%s: trouble applying map:\n%s", me, err); airMopError(mop); return 1; } SAVE(out, nout, NULL); airMopOkay(mop); return 0; } UNRRDU_CMD(mrmap, INFO); Index: GNUmakefile =================================================================== RCS file: /cvsroot/teem/teem/src/unrrdu/GNUmakefile,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** GNUmakefile 26 Feb 2004 20:59:45 -0000 1.21 --- GNUmakefile 4 Apr 2004 21:21:06 -0000 1.22 *************** *** 58,62 **** lut.o subst.o rmap.o imap.o save.o head.o data.o splice.o inset.o \ axinsert.o axdelete.o axinfo.o ccfind.o ccadj.o ccmerge.o \ ! ccsettle.o about.o axsplit.o axmerge.o #### #### --- 58,62 ---- lut.o subst.o rmap.o imap.o save.o head.o data.o splice.o inset.o \ axinsert.o axdelete.o axinfo.o ccfind.o ccadj.o ccmerge.o \ ! ccsettle.o about.o axsplit.o axmerge.o mlut.o mrmap.o #### #### Index: rmap.c =================================================================== RCS file: /cvsroot/teem/teem/src/unrrdu/rmap.c,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** rmap.c 7 Jan 2004 15:34:31 -0000 1.19 --- rmap.c 4 Apr 2004 21:21:06 -0000 1.20 *************** *** 21,25 **** #include "privateUnrrdu.h" ! #define INFO "Map nrrd through *regular* univariate map (\"colormap\")" char *_unrrdu_rmapInfoL = (INFO --- 21,25 ---- #include "privateUnrrdu.h" ! #define INFO "Map nrrd through one *regular* univariate map (\"colormap\")" char *_unrrdu_rmapInfoL = (INFO *************** *** 55,60 **** "map domain. The map domain is either explicitly " "defined by the axis min,max along axis 0 or 1, or, it " ! "is implicitly defined as zero to one minus the length of " ! "that axis."); hestOptAdd(&opt, "min", "value", airTypeDouble, 1, 1, &min, "nan", "Low end of input range. Defaults to lowest value " --- 55,60 ---- "map domain. The map domain is either explicitly " "defined by the axis min,max along axis 0 or 1, or, it " ! "is implicitly defined as zero to the length of " ! "that axis minus one."); hestOptAdd(&opt, "min", "value", airTypeDouble, 1, 1, &min, "nan", "Low end of input range. Defaults to lowest value " |