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 "Remove one or more singleton axes from a nrrd" |
28 |
|
|
static const char *_unrrdu_axdeleteInfoL = |
29 |
|
|
(INFO |
30 |
|
|
". Singleton axes have only a single sample along them. " |
31 |
|
|
"The underlying linear ordering of the samples is " |
32 |
|
|
"unchanged, and the information about the other axes is " |
33 |
|
|
"shifted downwards as needed. As a total hack, if you give " |
34 |
|
|
"-1 as the axis, this will do a matlab-style \"squeeze\", in which " |
35 |
|
|
"any and all singleton axes are removed.\n " |
36 |
|
|
"* Uses nrrdAxesDelete"); |
37 |
|
|
|
38 |
|
|
int |
39 |
|
|
unrrdu_axdeleteMain(int argc, const char **argv, const char *me, |
40 |
|
|
hestParm *hparm) { |
41 |
|
2 |
hestOpt *opt = NULL; |
42 |
|
1 |
char *out, *err; |
43 |
|
1 |
Nrrd *nin, *nout, *ntmp; |
44 |
|
1 |
int pret, _axis; |
45 |
|
|
unsigned axis; |
46 |
|
|
airArray *mop; |
47 |
|
|
|
48 |
|
1 |
hestOptAdd(&opt, "a,axis", "axis", airTypeInt, 1, 1, &_axis, NULL, |
49 |
|
|
"dimension (axis index) of the axis to remove"); |
50 |
|
1 |
OPT_ADD_NIN(nin, "input nrrd"); |
51 |
|
1 |
OPT_ADD_NOUT(out, "output nrrd"); |
52 |
|
|
|
53 |
|
1 |
mop = airMopNew(); |
54 |
|
1 |
airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); |
55 |
|
|
|
56 |
✓✗ |
2 |
USAGE(_unrrdu_axdeleteInfoL); |
57 |
|
|
PARSE(); |
58 |
|
|
airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); |
59 |
|
|
|
60 |
|
|
nout = nrrdNew(); |
61 |
|
|
airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); |
62 |
|
|
|
63 |
|
|
if (-1 == _axis) { |
64 |
|
|
ntmp = nrrdNew(); |
65 |
|
|
airMopAdd(mop, ntmp, (airMopper)nrrdNuke, airMopAlways); |
66 |
|
|
if (nrrdCopy(nout, nin)) { |
67 |
|
|
airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); |
68 |
|
|
fprintf(stderr, "%s: error copying axis:\n%s", me, err); |
69 |
|
|
airMopError(mop); return 1; |
70 |
|
|
} |
71 |
|
|
for (axis=0; |
72 |
|
|
axis<nout->dim && nout->axis[axis].size > 1; |
73 |
|
|
axis++) |
74 |
|
|
; |
75 |
|
|
while (axis<nout->dim) { |
76 |
|
|
if (nrrdAxesDelete(ntmp, nout, axis) |
77 |
|
|
|| nrrdCopy(nout, ntmp)) { |
78 |
|
|
airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); |
79 |
|
|
fprintf(stderr, "%s: error deleting axis:\n%s", me, err); |
80 |
|
|
airMopError(mop); return 1; |
81 |
|
|
} |
82 |
|
|
for (axis=0; |
83 |
|
|
axis<nout->dim && nout->axis[axis].size > 1; |
84 |
|
|
axis++) |
85 |
|
|
; |
86 |
|
|
} |
87 |
|
|
} else { |
88 |
|
|
if (nrrdAxesDelete(nout, nin, _axis)) { |
89 |
|
|
airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); |
90 |
|
|
fprintf(stderr, "%s: error deleting axis:\n%s", me, err); |
91 |
|
|
airMopError(mop); return 1; |
92 |
|
|
} |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
SAVE(out, nout, NULL); |
96 |
|
|
|
97 |
|
|
airMopOkay(mop); |
98 |
|
|
return 0; |
99 |
|
1 |
} |
100 |
|
|
|
101 |
|
|
UNRRDU_CMD(axdelete, INFO); |