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 one *regular* univariate map (\"colormap\")" |
28 |
|
|
static const char *_unrrdu_rmapInfoL = |
29 |
|
|
(INFO |
30 |
|
|
". A map is regular if the control points are evenly " |
31 |
|
|
"spaced along the domain, and hence their position isn't " |
32 |
|
|
"explicitly represented in the map; the axis min, axis " |
33 |
|
|
"max, and number of points determine their location. " |
34 |
|
|
"The map can be a 1D nrrd (for \"grayscale\"), " |
35 |
|
|
"in which case the " |
36 |
|
|
"output has the same dimension as the input, " |
37 |
|
|
"or a 2D nrrd (for \"color\"), in which case " |
38 |
|
|
"the output has one more dimension than the input. In " |
39 |
|
|
"either case, the output is the result of linearly " |
40 |
|
|
"interpolating between map points, either scalar values " |
41 |
|
|
"(\"grayscale\"), or scanlines along axis 0 " |
42 |
|
|
"(\"color\").\n " |
43 |
|
|
"* Uses nrrdApply1DRegMap"); |
44 |
|
|
|
45 |
|
|
int |
46 |
|
|
unrrdu_rmapMain(int argc, const char **argv, const char *me, |
47 |
|
|
hestParm *hparm) { |
48 |
|
2 |
hestOpt *opt = NULL; |
49 |
|
1 |
char *out, *err; |
50 |
|
1 |
Nrrd *nin, *nmap, *nout; |
51 |
|
|
airArray *mop; |
52 |
|
|
NrrdRange *range=NULL; |
53 |
|
1 |
int typeOut, rescale, pret, blind8BitRange; |
54 |
|
1 |
double min, max; |
55 |
|
|
|
56 |
|
1 |
hestOptAdd(&opt, "m,map", "map", airTypeOther, 1, 1, &nmap, NULL, |
57 |
|
|
"regular map to map input nrrd through", |
58 |
|
1 |
NULL, NULL, nrrdHestNrrd); |
59 |
|
1 |
hestOptAdd(&opt, "r,rescale", NULL, airTypeInt, 0, 0, &rescale, NULL, |
60 |
|
|
"rescale the input values from the input range to the " |
61 |
|
|
"map domain. The map domain is either explicitly " |
62 |
|
|
"defined by the axis min,max along axis 0 or 1, or, it " |
63 |
|
|
"is implicitly defined as zero to the length of " |
64 |
|
|
"that axis minus one."); |
65 |
|
1 |
hestOptAdd(&opt, "min,minimum", "value", airTypeDouble, 1, 1, &min, "nan", |
66 |
|
|
"Low end of input range. Defaults to lowest value " |
67 |
|
|
"found in input nrrd. Explicitly setting this is useful " |
68 |
|
|
"only with rescaling (\"-r\") or if the map domain is only " |
69 |
|
|
"implicitly defined"); |
70 |
|
1 |
hestOptAdd(&opt, "max,maximum", "value", airTypeDouble, 1, 1, &max, "nan", |
71 |
|
|
"High end of input range. Defaults to highest value " |
72 |
|
|
"found in input nrrd. Explicitly setting this is useful " |
73 |
|
|
"only with rescaling (\"-r\") or if the map domain is only " |
74 |
|
|
"implicitly defined"); |
75 |
|
1 |
hestOptAdd(&opt, "blind8", "bool", airTypeBool, 1, 1, &blind8BitRange, |
76 |
|
1 |
nrrdStateBlind8BitRange ? "true" : "false", |
77 |
|
|
"Whether to know the range of 8-bit data blindly " |
78 |
|
|
"(uchar is always [0,255], signed char is [-128,127]). " |
79 |
|
|
"Explicitly setting this is useful " |
80 |
|
|
"only with rescaling (\"-r\") or if the map domain is only " |
81 |
|
|
"implicitly defined"); |
82 |
|
1 |
hestOptAdd(&opt, "t,type", "type", airTypeOther, 1, 1, &typeOut, "default", |
83 |
|
|
"specify the type (\"int\", \"float\", etc.) of the " |
84 |
|
|
"output nrrd. " |
85 |
|
|
"By default (not using this option), the output type " |
86 |
|
|
"is the map's type.", |
87 |
|
|
NULL, NULL, &unrrduHestMaybeTypeCB); |
88 |
|
1 |
OPT_ADD_NIN(nin, "input nrrd"); |
89 |
|
1 |
OPT_ADD_NOUT(out, "output nrrd"); |
90 |
|
|
|
91 |
|
1 |
mop = airMopNew(); |
92 |
|
1 |
airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); |
93 |
|
|
|
94 |
✓✗ |
2 |
USAGE(_unrrdu_rmapInfoL); |
95 |
|
|
PARSE(); |
96 |
|
|
airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); |
97 |
|
|
|
98 |
|
|
nout = nrrdNew(); |
99 |
|
|
airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); |
100 |
|
|
|
101 |
|
|
/* here is a big difference between unu and nrrd: we enforce |
102 |
|
|
rescaling any time that the map domain is implicit. This |
103 |
|
|
is how the pre-1.6 functionality is recreated. Also, whenever |
104 |
|
|
there is rescaling we pass a NrrdRange to reflect the (optional) |
105 |
|
|
user range specification, instead of letting nrrdApply1DRegMap |
106 |
|
|
find the input range itself (by passing a NULL NrrdRange). |
107 |
|
|
*/ |
108 |
|
|
if (!( AIR_EXISTS(nmap->axis[nmap->dim - 1].min) && |
109 |
|
|
AIR_EXISTS(nmap->axis[nmap->dim - 1].max) )) { |
110 |
|
|
rescale = AIR_TRUE; |
111 |
|
|
} |
112 |
|
|
if (rescale) { |
113 |
|
|
range = nrrdRangeNew(min, max); |
114 |
|
|
airMopAdd(mop, range, (airMopper)nrrdRangeNix, airMopAlways); |
115 |
|
|
nrrdRangeSafeSet(range, nin, blind8BitRange); |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
if (nrrdTypeDefault == typeOut) { |
119 |
|
|
typeOut = nmap->type; |
120 |
|
|
} |
121 |
|
|
if (nrrdApply1DRegMap(nout, nin, range, nmap, 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(rmap, INFO); |