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 "Merge two adjacent axes into one" |
28 |
|
|
static const char *_unrrdu_axmergeInfoL = |
29 |
|
|
(INFO |
30 |
|
|
". A more general version of \"unu axdelete\". " |
31 |
|
|
"The underlying linear ordering of the samples is " |
32 |
|
|
"unchanged, and the information about the other axes is " |
33 |
|
|
"shifted downwards as needed.\n " |
34 |
|
|
"* Uses nrrdAxesMerge"); |
35 |
|
|
|
36 |
|
|
int |
37 |
|
|
unrrdu_axmergeMain(int argc, const char **argv, const char *me, |
38 |
|
|
hestParm *hparm) { |
39 |
|
2 |
hestOpt *opt = NULL; |
40 |
|
1 |
char *out, *err; |
41 |
|
1 |
Nrrd *nin, *nout[2]; |
42 |
|
1 |
int *axes, pret, ni; |
43 |
|
1 |
unsigned int ii, jj, axesLen; |
44 |
|
|
airArray *mop; |
45 |
|
|
|
46 |
|
1 |
hestOptAdd(&opt, "a,axis", "ax0", airTypeInt, 1, -1, &axes, NULL, |
47 |
|
|
"axis (or axes) to merge. Each axis index identified is the " |
48 |
|
|
"lower of the pair of axes that will be merged. Saying \"-a 2\" " |
49 |
|
|
"means to merge axis 2 and axis 3 into axis 2. If multiple " |
50 |
|
|
"merges are to be done, the indices listed here are for " |
51 |
|
|
"the axes prior to any merging.", &axesLen); |
52 |
|
1 |
OPT_ADD_NIN(nin, "input nrrd"); |
53 |
|
1 |
OPT_ADD_NOUT(out, "output nrrd"); |
54 |
|
|
|
55 |
|
1 |
mop = airMopNew(); |
56 |
|
1 |
airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); |
57 |
|
|
|
58 |
✓✗ |
2 |
USAGE(_unrrdu_axmergeInfoL); |
59 |
|
|
PARSE(); |
60 |
|
|
airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); |
61 |
|
|
|
62 |
|
|
airMopAdd(mop, nout[0]=nrrdNew(), (airMopper)nrrdNuke, airMopAlways); |
63 |
|
|
airMopAdd(mop, nout[1]=nrrdNew(), (airMopper)nrrdNuke, airMopAlways); |
64 |
|
|
|
65 |
|
|
if (axesLen > 1) { |
66 |
|
|
/* sort merge axes into ascending order */ |
67 |
|
|
qsort(axes, axesLen, sizeof(*axes), nrrdValCompare[nrrdTypeInt]); |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
ni = 0; |
71 |
|
|
for (ii=0; ii<axesLen; ii++) { |
72 |
|
|
if (nrrdAxesMerge(nout[ni], !ii ? nin : nout[1-ni], axes[ii])) { |
73 |
|
|
airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); |
74 |
|
|
fprintf(stderr, "%s: error merging axes:\n%s", me, err); |
75 |
|
|
airMopError(mop); |
76 |
|
|
return 1; |
77 |
|
|
} |
78 |
|
|
for (jj=ii+1; jj<axesLen; jj++) { |
79 |
|
|
axes[jj] -= 1; |
80 |
|
|
} |
81 |
|
|
ni = 1-ni; |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
SAVE(out, nout[1-ni], NULL); |
85 |
|
|
|
86 |
|
|
airMopOkay(mop); |
87 |
|
|
return 0; |
88 |
|
1 |
} |
89 |
|
|
|
90 |
|
|
UNRRDU_CMD(axmerge, INFO); |