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 "Superficially change dimension and/or axes sizes" |
28 |
|
|
static const char *_unrrdu_reshapeInfoL = |
29 |
|
|
(INFO |
30 |
|
|
". The underlying linear ordering of the samples is " |
31 |
|
|
"unchanged, but the reported dimension or axes sizes " |
32 |
|
|
"are changed. Identical in concept to Matlab's " |
33 |
|
|
"\"reshape\" command.\n " |
34 |
|
|
"* Uses nrrdReshape_nva"); |
35 |
|
|
|
36 |
|
|
int |
37 |
|
|
unrrdu_reshapeMain(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; |
42 |
|
|
int pret; |
43 |
|
1 |
size_t *size; |
44 |
|
1 |
unsigned int sizeLen; |
45 |
|
|
airArray *mop; |
46 |
|
|
|
47 |
|
1 |
hestOptAdd(&opt, "s,size", "sz0 sz1 ", airTypeSize_t, 1, -1, &size, NULL, |
48 |
|
|
"new axes sizes", &sizeLen); |
49 |
|
1 |
OPT_ADD_NIN(nin, "input nrrd"); |
50 |
|
1 |
OPT_ADD_NOUT(out, "output nrrd"); |
51 |
|
|
|
52 |
|
1 |
mop = airMopNew(); |
53 |
|
1 |
airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); |
54 |
|
|
|
55 |
✓✗ |
2 |
USAGE(_unrrdu_reshapeInfoL); |
56 |
|
|
PARSE(); |
57 |
|
|
airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); |
58 |
|
|
|
59 |
|
|
nout = nrrdNew(); |
60 |
|
|
airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); |
61 |
|
|
|
62 |
|
|
if (nrrdReshape_nva(nout, nin, sizeLen, size)) { |
63 |
|
|
airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); |
64 |
|
|
fprintf(stderr, "%s: error reshaping nrrd:\n%s", me, err); |
65 |
|
|
airMopError(mop); |
66 |
|
|
return 1; |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
SAVE(out, nout, NULL); |
70 |
|
|
|
71 |
|
|
airMopOkay(mop); |
72 |
|
|
return 0; |
73 |
|
1 |
} |
74 |
|
|
|
75 |
|
|
UNRRDU_CMD(reshape, INFO); |