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 *irregular* univariate map (\"colormap\")" |
28 |
|
|
static const char *_unrrdu_imapInfoL = |
29 |
|
|
(INFO |
30 |
|
|
". A map is irregular if the control points are not evenly " |
31 |
|
|
"spaced along the domain, and hence their position must be " |
32 |
|
|
"explicitly represented in the map. As nrrds, these maps " |
33 |
|
|
"are necessarily 2D. Along axis 0, the first value is the " |
34 |
|
|
"location of the control point, and the remaining values " |
35 |
|
|
"give are the range of the map for that control point. " |
36 |
|
|
"The output value(s) is the result of linearly " |
37 |
|
|
"interpolating between value(s) from the map.\n " |
38 |
|
|
"* Uses nrrdApply1DIrregMap"); |
39 |
|
|
|
40 |
|
|
int |
41 |
|
|
unrrdu_imapMain(int argc, const char **argv, const char *me, |
42 |
|
|
hestParm *hparm) { |
43 |
|
2 |
hestOpt *opt = NULL; |
44 |
|
1 |
char *out, *err; |
45 |
|
1 |
Nrrd *nin, *nmap, *nacl, *nout; |
46 |
|
|
airArray *mop; |
47 |
|
|
NrrdRange *range=NULL; |
48 |
|
1 |
unsigned int aclLen; |
49 |
|
1 |
int typeOut, rescale, pret, blind8BitRange; |
50 |
|
1 |
double min, max; |
51 |
|
|
|
52 |
|
1 |
hestOptAdd(&opt, "m,map", "map", airTypeOther, 1, 1, &nmap, NULL, |
53 |
|
|
"irregular map to map input nrrd through", |
54 |
|
1 |
NULL, NULL, nrrdHestNrrd); |
55 |
|
1 |
hestOptAdd(&opt, "l,length", "aclLen", airTypeUInt, 1, 1, &aclLen, "0", |
56 |
|
|
"length of accelerator array, used to try to speed-up " |
57 |
|
|
"task of finding between which pair of control points " |
58 |
|
|
"a given value lies. Not terribly useful for small maps " |
59 |
|
|
"(about 10 points or less). Use 0 to turn accelorator off. "); |
60 |
|
1 |
hestOptAdd(&opt, "r,rescale", NULL, airTypeInt, 0, 0, &rescale, NULL, |
61 |
|
|
"rescale the input values from the input range to the " |
62 |
|
|
"map domain"); |
63 |
|
1 |
hestOptAdd(&opt, "min,minimum", "value", airTypeDouble, 1, 1, &min, "nan", |
64 |
|
|
"Low end of input range. Defaults to lowest value " |
65 |
|
|
"found in input nrrd. Explicitly setting this is useful " |
66 |
|
|
"only with rescaling (\"-r\")"); |
67 |
|
1 |
hestOptAdd(&opt, "max,maximum", "value", airTypeDouble, 1, 1, &max, "nan", |
68 |
|
|
"High end of input range. Defaults to highest value " |
69 |
|
|
"found in input nrrd. Explicitly setting this is useful " |
70 |
|
|
"only with rescaling (\"-r\")"); |
71 |
|
1 |
hestOptAdd(&opt, "blind8", "bool", airTypeBool, 1, 1, &blind8BitRange, |
72 |
|
1 |
nrrdStateBlind8BitRange ? "true" : "false", |
73 |
|
|
"Whether to know the range of 8-bit data blindly " |
74 |
|
|
"(uchar is always [0,255], signed char is [-128,127]). " |
75 |
|
|
"Explicitly setting this is useful only with rescaling (\"-r\")"); |
76 |
|
1 |
hestOptAdd(&opt, "t,type", "type", airTypeOther, 1, 1, &typeOut, "default", |
77 |
|
|
"specify the type (\"int\", \"float\", etc.) of the " |
78 |
|
|
"output nrrd. " |
79 |
|
|
"By default (not using this option), the output type " |
80 |
|
|
"is the map's type.", |
81 |
|
|
NULL, NULL, &unrrduHestMaybeTypeCB); |
82 |
|
1 |
OPT_ADD_NIN(nin, "input nrrd"); |
83 |
|
1 |
OPT_ADD_NOUT(out, "output nrrd"); |
84 |
|
|
|
85 |
|
1 |
mop = airMopNew(); |
86 |
|
1 |
airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); |
87 |
|
|
|
88 |
✓✗ |
2 |
USAGE(_unrrdu_imapInfoL); |
89 |
|
|
PARSE(); |
90 |
|
|
airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); |
91 |
|
|
|
92 |
|
|
nout = nrrdNew(); |
93 |
|
|
airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); |
94 |
|
|
|
95 |
|
|
if (aclLen) { |
96 |
|
|
nacl = nrrdNew(); |
97 |
|
|
airMopAdd(mop, nacl, (airMopper)nrrdNuke, airMopAlways); |
98 |
|
|
if (nrrd1DIrregAclGenerate(nacl, nmap, aclLen)) { |
99 |
|
|
airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); |
100 |
|
|
fprintf(stderr, "%s: trouble generating accelerator:\n%s", me, err); |
101 |
|
|
airMopError(mop); |
102 |
|
|
return 1; |
103 |
|
|
} |
104 |
|
|
} else { |
105 |
|
|
nacl = NULL; |
106 |
|
|
} |
107 |
|
|
if (rescale) { |
108 |
|
|
range = nrrdRangeNew(min, max); |
109 |
|
|
airMopAdd(mop, range, (airMopper)nrrdRangeNix, airMopAlways); |
110 |
|
|
nrrdRangeSafeSet(range, nin, blind8BitRange); |
111 |
|
|
} |
112 |
|
|
if (nrrdTypeDefault == typeOut) { |
113 |
|
|
typeOut = nmap->type; |
114 |
|
|
} |
115 |
|
|
/* some very non-exhaustive tests seemed to indicate that the |
116 |
|
|
accelerator does not in fact reliably speed anything up. |
117 |
|
|
This of course depends on the size of the imap (# points), |
118 |
|
|
but chances are most imaps will have only a handful of points, |
119 |
|
|
in which case the binary search in _nrrd1DIrregFindInterval() |
120 |
|
|
will finish quickly ... */ |
121 |
|
|
if (nrrdApply1DIrregMap(nout, nin, range, nmap, nacl, typeOut, rescale)) { |
122 |
|
|
airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); |
123 |
|
|
fprintf(stderr, "%s: trouble applying map:\n%s", me, err); |
124 |
|
|
airMopError(mop); |
125 |
|
|
return 1; |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
SAVE(out, nout, NULL); |
129 |
|
|
|
130 |
|
|
airMopOkay(mop); |
131 |
|
|
return 0; |
132 |
|
1 |
} |
133 |
|
|
|
134 |
|
|
UNRRDU_CMD(imap, INFO); |
135 |
|
|
|