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 sub-region with a different nrrd" |
28 |
|
|
static const char *_unrrdu_insetInfoL = |
29 |
|
|
(INFO ". This is functionally the opposite of \"crop\".\n " |
30 |
|
|
"* Uses nrrdInset"); |
31 |
|
|
|
32 |
|
|
int |
33 |
|
|
unrrdu_insetMain(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, *nsub; |
38 |
|
1 |
unsigned int ai, minLen; |
39 |
|
|
int pret; |
40 |
|
1 |
long int *minOff; |
41 |
|
1 |
size_t min[NRRD_DIM_MAX]; |
42 |
|
|
airArray *mop; |
43 |
|
|
|
44 |
|
1 |
OPT_ADD_BOUND("min,minimum", 1, minOff, NULL, |
45 |
|
|
"coordinates of where to locate sub-volume within " |
46 |
|
|
"input nrrd.\n " |
47 |
|
|
"\b\bo <int> gives 0-based index\n " |
48 |
|
|
"\b\bo M, M+<int>, M-<int> give index relative " |
49 |
|
|
"to the last sample on the axis (M == #samples-1).", |
50 |
|
|
minLen); |
51 |
|
1 |
hestOptAdd(&opt, "s,subset", "nsub", airTypeOther, 1, 1, &(nsub), NULL, |
52 |
|
|
"sub-region nrrd. This the data to be inset in \"nin\"", |
53 |
|
1 |
NULL, NULL, nrrdHestNrrd); |
54 |
|
1 |
OPT_ADD_NIN(nin, "input nrrd"); |
55 |
|
1 |
OPT_ADD_NOUT(out, "output nrrd"); |
56 |
|
|
|
57 |
|
1 |
mop = airMopNew(); |
58 |
|
1 |
airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); |
59 |
|
|
|
60 |
✓✗ |
2 |
USAGE(_unrrdu_insetInfoL); |
61 |
|
|
PARSE(); |
62 |
|
|
airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); |
63 |
|
|
|
64 |
|
|
if (!( minLen == nin->dim )) { |
65 |
|
|
fprintf(stderr, |
66 |
|
|
"%s: # min coords (%d) != nrrd dim (%d)\n", |
67 |
|
|
me, minLen, nin->dim); |
68 |
|
|
airMopError(mop); |
69 |
|
|
return 1; |
70 |
|
|
} |
71 |
|
|
for (ai=0; ai<nin->dim; ai++) { |
72 |
|
|
if (-1 == minOff[0 + 2*ai]) { |
73 |
|
|
fprintf(stderr, "%s: can't use m+<int> specification for axis %u min\n", |
74 |
|
|
me, ai); |
75 |
|
|
airMopError(mop); |
76 |
|
|
return 1; |
77 |
|
|
} |
78 |
|
|
} |
79 |
|
|
for (ai=0; ai<=nin->dim-1; ai++) { |
80 |
|
|
min[ai] = minOff[0 + 2*ai]*(nin->axis[ai].size-1) + minOff[1 + 2*ai]; |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
nout = nrrdNew(); |
84 |
|
|
airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); |
85 |
|
|
|
86 |
|
|
if (nrrdInset(nout, nin, nsub, min)) { |
87 |
|
|
airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); |
88 |
|
|
fprintf(stderr, "%s: error insetting nrrd:\n%s", me, err); |
89 |
|
|
airMopError(mop); |
90 |
|
|
return 1; |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
SAVE(out, nout, NULL); |
94 |
|
|
|
95 |
|
|
airMopOkay(mop); |
96 |
|
|
return 0; |
97 |
|
1 |
} |
98 |
|
|
|
99 |
|
|
UNRRDU_CMD(inset, INFO); |