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 "Replace a slice with a different nrrd" |
28 |
|
|
static const char *_unrrdu_spliceInfoL = |
29 |
|
|
(INFO ". This is functionally the opposite of \"slice\".\n " |
30 |
|
|
"* Uses nrrdSplice"); |
31 |
|
|
|
32 |
|
|
int |
33 |
|
|
unrrdu_spliceMain(int argc, const char **argv, const char *me, |
34 |
|
|
hestParm *hparm) { |
35 |
|
2 |
hestOpt *opt = NULL; |
36 |
|
1 |
char *out, *err; |
37 |
|
1 |
Nrrd *nin, *nout, *nslice; |
38 |
|
1 |
unsigned int axis; |
39 |
|
|
int pret; |
40 |
|
1 |
long int _pos[2]; |
41 |
|
|
size_t pos; |
42 |
|
|
airArray *mop; |
43 |
|
|
|
44 |
|
1 |
OPT_ADD_AXIS(axis, "axis to splice along"); |
45 |
|
1 |
hestOptAdd(&opt, "p,position", "pos", airTypeOther, 1, 1, _pos, NULL, |
46 |
|
|
"position to splice at:\n " |
47 |
|
|
"\b\bo <int> gives 0-based index\n " |
48 |
|
|
"\b\bo M-<int> give index relative " |
49 |
|
|
"to the last sample on the axis (M == #samples-1).", |
50 |
|
|
NULL, NULL, &unrrduHestPosCB); |
51 |
|
1 |
hestOptAdd(&opt, "s,slice", "nslice", airTypeOther, 1, 1, &(nslice), NULL, |
52 |
|
|
"slice nrrd. This is the slice to insert into \"nin\"", |
53 |
|
1 |
NULL, NULL, nrrdHestNrrd); |
54 |
|
1 |
OPT_ADD_NIN(nin, "input nrrd. This is the nrrd into which the slice is " |
55 |
|
|
"inserted"); |
56 |
|
1 |
OPT_ADD_NOUT(out, "output nrrd"); |
57 |
|
|
|
58 |
|
1 |
mop = airMopNew(); |
59 |
|
1 |
airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); |
60 |
|
|
|
61 |
✓✗ |
2 |
USAGE(_unrrdu_spliceInfoL); |
62 |
|
|
PARSE(); |
63 |
|
|
airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); |
64 |
|
|
if (!( axis < nin->dim )) { |
65 |
|
|
fprintf(stderr, "%s: axis %u not in range [0,%u]\n", me, axis, nin->dim-1); |
66 |
|
|
return 1; |
67 |
|
|
} |
68 |
|
|
if (_pos[0] == -1) { |
69 |
|
|
fprintf(stderr, "%s: m+<int> specification format meaningless here\n", me); |
70 |
|
|
return 1; |
71 |
|
|
} |
72 |
|
|
pos = _pos[0]*(nin->axis[axis].size-1) + _pos[1]; |
73 |
|
|
|
74 |
|
|
nout = nrrdNew(); |
75 |
|
|
airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); |
76 |
|
|
|
77 |
|
|
if (nrrdSplice(nout, nin, nslice, axis, pos)) { |
78 |
|
|
airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); |
79 |
|
|
fprintf(stderr, "%s: error splicing nrrd:\n%s", me, err); |
80 |
|
|
airMopError(mop); |
81 |
|
|
return 1; |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
SAVE(out, nout, NULL); |
85 |
|
|
|
86 |
|
|
airMopOkay(mop); |
87 |
|
|
return 0; |
88 |
|
1 |
} |
89 |
|
|
|
90 |
|
|
UNRRDU_CMD(splice, INFO); |