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 "Normalizes array orientation and meta-data" |
28 |
|
|
static const char *_unrrdu_dnormInfoL = |
29 |
|
|
(INFO |
30 |
|
|
". Forces information about kind and orientation into " |
31 |
|
|
"a consistent form, and nixes various other fields. This was " |
32 |
|
|
"originally created as a utility for the Diderot project " |
33 |
|
|
"(http://diderot-language.cs.uchicago.edu), hence the name, " |
34 |
|
|
"but it has proven useful in other contexts (uses of gage) in which " |
35 |
|
|
"it is important to have standardized orientation information.\n " |
36 |
|
|
"* Uses nrrdMetaDataNormalize"); |
37 |
|
|
|
38 |
|
|
int |
39 |
|
|
unrrdu_dnormMain(int argc, const char **argv, const char *me, |
40 |
|
|
hestParm *hparm) { |
41 |
|
2 |
char *outS; |
42 |
|
|
int pret; |
43 |
|
|
|
44 |
|
1 |
Nrrd *nin, *nout; |
45 |
|
|
NrrdIoState *nio; |
46 |
|
1 |
int version, lostmf, headerOnly, trivialOrient, recenter; |
47 |
|
1 |
double newSpacing; |
48 |
|
|
|
49 |
|
1 |
hestOpt *opt = NULL; |
50 |
|
1 |
char *err; |
51 |
|
|
airArray *mop; |
52 |
|
|
|
53 |
|
1 |
hestOptAdd(&opt, "h,header", NULL, airTypeInt, 0, 0, &headerOnly, NULL, |
54 |
|
|
"output header of nrrd file only, not the data itself"); |
55 |
|
1 |
hestOptAdd(&opt, "v,version", "version", airTypeEnum, 1,1,&version, "alpha", |
56 |
|
|
"what version of canonical meta-data to convert to; " |
57 |
|
|
"\"alpha\" is what has been used for Diderot until at least " |
58 |
|
1 |
"2016", NULL, nrrdMetaDataCanonicalVersion); |
59 |
|
1 |
hestOptAdd(&opt, "to", NULL, airTypeInt, 0, 0, &trivialOrient, NULL, |
60 |
|
|
"(*t*rivial *o*rientation) " |
61 |
|
|
"even if the input nrrd comes with full orientation or " |
62 |
|
|
"per-axis min-max info, ignore it and instead assert the " |
63 |
|
|
"identity mapping between index and world space"); |
64 |
|
1 |
hestOptAdd(&opt, "rc,recenter", NULL, airTypeInt, 0, 0, &recenter, NULL, |
65 |
|
|
"re-locate output spaceOrigin so that field is centered " |
66 |
|
|
"around origin of space coordinates"); |
67 |
|
1 |
hestOptAdd(&opt, "sp,spacing", "scl", airTypeDouble, 1, 1, &newSpacing, |
68 |
|
|
"1.0", |
69 |
|
|
"when having to contrive orientation information and there's " |
70 |
|
|
"no per-axis min/max or spacing, this is the sample spacing " |
71 |
|
|
"to assert"); |
72 |
|
1 |
OPT_ADD_NIN(nin, "input image"); |
73 |
|
1 |
OPT_ADD_NOUT(outS, "output filename"); |
74 |
|
|
|
75 |
|
1 |
mop = airMopNew(); |
76 |
|
1 |
airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); |
77 |
✓✗ |
2 |
USAGE(_unrrdu_dnormInfoL); |
78 |
|
|
PARSE(); |
79 |
|
|
airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); |
80 |
|
|
|
81 |
|
|
if (headerOnly) { |
82 |
|
|
/* no reason to duplicate data */ |
83 |
|
|
nout = nin; |
84 |
|
|
} else { |
85 |
|
|
nout = nrrdNew(); |
86 |
|
|
airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
if (nrrdMetaDataNormalize(nout, nin, |
90 |
|
|
version, trivialOrient, |
91 |
|
|
AIR_FALSE /* permuteComponentAxisFastest */, |
92 |
|
|
recenter, |
93 |
|
|
newSpacing, |
94 |
|
|
&lostmf)) { |
95 |
|
|
airMopAdd(mop, err = biffGet(NRRD), airFree, airMopAlways); |
96 |
|
|
fprintf(stderr, "%s: trouble:\n%s", me, err); |
97 |
|
|
airMopError(mop); return 1; |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
if (lostmf) { |
101 |
|
|
fprintf(stderr, "%s: WARNING: input array measurement frame " |
102 |
|
|
"will be erased on output.\n", me); |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
nio = nrrdIoStateNew(); |
106 |
|
|
airMopAdd(mop, nio, (airMopper)nrrdIoStateNix, airMopAlways); |
107 |
|
|
/* disable printing comments about NRRD format URL */ |
108 |
|
|
nio->skipFormatURL = AIR_TRUE; |
109 |
|
|
if (headerOnly) { |
110 |
|
|
nio->skipData = AIR_TRUE; |
111 |
|
|
} |
112 |
|
|
if (nrrdSave(outS, nout, nio)) { |
113 |
|
|
airMopAdd(mop, err = biffGet(NRRD), airFree, airMopAlways); |
114 |
|
|
fprintf(stderr, "%s: trouble saving \"%s\":\n%s", |
115 |
|
|
me, outS, err); |
116 |
|
|
airMopError(mop); return 1; |
117 |
|
|
} |
118 |
|
|
|
119 |
|
|
airMopOkay(mop); |
120 |
|
|
return 0; |
121 |
|
1 |
} |
122 |
|
|
|
123 |
|
|
UNRRDU_CMD_HIDE(dnorm, INFO); |