1 |
|
|
/* |
2 |
|
|
Teem: Tools to process and visualize scientific data and images . |
3 |
|
|
Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago |
4 |
|
|
Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann |
5 |
|
|
Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah |
6 |
|
|
|
7 |
|
|
This library is free software; you can redistribute it and/or |
8 |
|
|
modify it under the terms of the GNU Lesser General Public License |
9 |
|
|
(LGPL) as published by the Free Software Foundation; either |
10 |
|
|
version 2.1 of the License, or (at your option) any later version. |
11 |
|
|
The terms of redistributing and/or modifying this software also |
12 |
|
|
include exceptions to the LGPL that facilitate static linking. |
13 |
|
|
|
14 |
|
|
This library is distributed in the hope that it will be useful, |
15 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 |
|
|
Lesser General Public License for more details. |
18 |
|
|
|
19 |
|
|
You should have received a copy of the GNU Lesser General Public License |
20 |
|
|
along with this library; if not, write to Free Software Foundation, Inc., |
21 |
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
#include "unrrdu.h" |
25 |
|
|
#include "privateUnrrdu.h" |
26 |
|
|
|
27 |
|
|
#define INFO "Map nrrd through a univariate substitution table" |
28 |
|
|
static const char *_unrrdu_substInfoL = |
29 |
|
|
(INFO |
30 |
|
|
" (itself represented as a nrrd). The substitution table " |
31 |
|
|
"is a 2-by-N table: a list of pairs giving the old value (to replace) " |
32 |
|
|
"and the the new value (to change to), in that order. A plain text file " |
33 |
|
|
"makes this easy. Unlike with \"unu lut\", \"unu rmap\", and \"unu imap\", " |
34 |
|
|
"the output type is the same as the input type, rather than the type of " |
35 |
|
|
"the lut or map.\n " |
36 |
|
|
"* Uses nrrdApply1DSubstitution"); |
37 |
|
|
|
38 |
|
|
int |
39 |
|
|
unrrdu_substMain(int argc, const char **argv, const char *me, |
40 |
|
|
hestParm *hparm) { |
41 |
|
2 |
hestOpt *opt = NULL; |
42 |
|
1 |
char *out, *err; |
43 |
|
|
int pret; |
44 |
|
1 |
Nrrd *nin, *nsubst, *nout; |
45 |
|
|
airArray *mop; |
46 |
|
|
|
47 |
|
1 |
hestOptAdd(&opt, "s,subst", "subst", airTypeOther, 1, 1, &nsubst, NULL, |
48 |
|
|
"substition table to map input nrrd through", |
49 |
|
1 |
NULL, NULL, nrrdHestNrrd); |
50 |
|
1 |
OPT_ADD_NIN(nin, "input nrrd"); |
51 |
|
1 |
OPT_ADD_NOUT(out, "output nrrd"); |
52 |
|
|
|
53 |
|
1 |
mop = airMopNew(); |
54 |
|
1 |
airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); |
55 |
|
|
|
56 |
✓✗ |
2 |
USAGE(_unrrdu_substInfoL); |
57 |
|
|
PARSE(); |
58 |
|
|
airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); |
59 |
|
|
|
60 |
|
|
nout = nrrdNew(); |
61 |
|
|
airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); |
62 |
|
|
|
63 |
|
|
if (nrrdApply1DSubstitution(nout, nin, nsubst)) { |
64 |
|
|
airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); |
65 |
|
|
fprintf(stderr, "%s: trouble applying SUBST:\n%s", me, err); |
66 |
|
|
airMopError(mop); |
67 |
|
|
return 1; |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
SAVE(out, nout, NULL); |
71 |
|
|
|
72 |
|
|
airMopOkay(mop); |
73 |
|
|
return 0; |
74 |
|
1 |
} |
75 |
|
|
|
76 |
|
|
UNRRDU_CMD(subst, INFO); |