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 "Permute ordering of axes" |
28 |
|
|
static const char *_unrrdu_permuteInfoL = |
29 |
|
|
(INFO |
30 |
|
|
". The permutation gives the new ordering of the old " |
31 |
|
|
"axes (in 0-based numbering). For example, the " |
32 |
|
|
"permutation 0->1,\t1->2,\t2->0 would be \"2 0 1\".\n " |
33 |
|
|
"* Uses nrrdAxesPermute"); |
34 |
|
|
|
35 |
|
|
int |
36 |
|
|
unrrdu_permuteMain(int argc, const char **argv, const char *me, |
37 |
|
|
hestParm *hparm) { |
38 |
|
2 |
hestOpt *opt = NULL; |
39 |
|
1 |
char *out, *err; |
40 |
|
1 |
Nrrd *nin, *nout; |
41 |
|
1 |
unsigned int *perm, permLen; |
42 |
|
|
int pret; |
43 |
|
|
airArray *mop; |
44 |
|
|
|
45 |
|
1 |
hestOptAdd(&opt, "p,permute", "ax0 ax1", airTypeUInt, 1, -1, &perm, NULL, |
46 |
|
|
"new axis ordering", &permLen); |
47 |
|
1 |
OPT_ADD_NIN(nin, "input nrrd"); |
48 |
|
1 |
OPT_ADD_NOUT(out, "output nrrd"); |
49 |
|
|
|
50 |
|
1 |
mop = airMopNew(); |
51 |
|
1 |
airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); |
52 |
|
|
|
53 |
✓✗ |
2 |
USAGE(_unrrdu_permuteInfoL); |
54 |
|
|
PARSE(); |
55 |
|
|
airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); |
56 |
|
|
|
57 |
|
|
nout = nrrdNew(); |
58 |
|
|
airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); |
59 |
|
|
|
60 |
|
|
if (!( permLen == nin->dim )) { |
61 |
|
|
fprintf(stderr,"%s: # axes in permutation (%u) != nrrd dim (%d)\n", |
62 |
|
|
me, permLen, nin->dim); |
63 |
|
|
airMopError(mop); |
64 |
|
|
return 1; |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
if (nrrdAxesPermute(nout, nin, perm)) { |
68 |
|
|
airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); |
69 |
|
|
fprintf(stderr, "%s: error permuting nrrd:\n%s", me, err); |
70 |
|
|
airMopError(mop); |
71 |
|
|
return 1; |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
SAVE(out, nout, NULL); |
75 |
|
|
|
76 |
|
|
airMopOkay(mop); |
77 |
|
|
return 0; |
78 |
|
1 |
} |
79 |
|
|
|
80 |
|
|
UNRRDU_CMD(permute, INFO); |