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 "Pad along each axis to make a bigger nrrd" |
28 |
|
|
static const char *_unrrdu_padInfoL = |
29 |
|
|
(INFO ".\n " |
30 |
|
|
"* Uses nrrdPad_nva"); |
31 |
|
|
|
32 |
|
|
int |
33 |
|
|
unrrdu_padMain(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; |
38 |
|
|
unsigned int ai; |
39 |
|
1 |
int minLen, maxLen, bb, pret; |
40 |
|
1 |
long int *minOff, *maxOff; |
41 |
|
1 |
ptrdiff_t min[NRRD_DIM_MAX], max[NRRD_DIM_MAX]; |
42 |
|
1 |
double padVal; |
43 |
|
|
airArray *mop; |
44 |
|
|
|
45 |
|
1 |
OPT_ADD_BOUND("min,minimum", 1, minOff, NULL, |
46 |
|
|
"low corner of bounding box.\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 |
OPT_ADD_BOUND("max,maximum", 1, maxOff, NULL, |
52 |
|
|
"high corner of bounding box. " |
53 |
|
|
"Besides the specification styles described above, " |
54 |
|
|
"there's also:\n " |
55 |
|
|
"\b\bo m+<int> give index relative to minimum.", |
56 |
|
|
maxLen); |
57 |
|
1 |
hestOptAdd(&opt, "b,boundary", "behavior", airTypeEnum, 1, 1, &bb, "bleed", |
58 |
|
|
"How to handle samples beyond the input bounds:\n " |
59 |
|
|
"\b\bo \"pad\": use some specified value\n " |
60 |
|
|
"\b\bo \"bleed\": extend border values outward\n " |
61 |
|
|
"\b\bo \"mirror\": repeated reflections\n " |
62 |
|
|
"\b\bo \"wrap\": wrap-around to other side", |
63 |
|
1 |
NULL, nrrdBoundary); |
64 |
|
1 |
hestOptAdd(&opt, "v,value", "val", airTypeDouble, 1, 1, &padVal, "0.0", |
65 |
|
|
"for \"pad\" boundary behavior, pad with this value"); |
66 |
|
1 |
OPT_ADD_NIN(nin, "input nrrd"); |
67 |
|
1 |
OPT_ADD_NOUT(out, "output nrrd"); |
68 |
|
|
|
69 |
|
1 |
mop = airMopNew(); |
70 |
|
1 |
airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); |
71 |
|
|
|
72 |
✓✗ |
2 |
USAGE(_unrrdu_padInfoL); |
73 |
|
|
/* hammerhead problems were here */ |
74 |
|
|
PARSE(); |
75 |
|
|
airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); |
76 |
|
|
|
77 |
|
|
if (!( minLen == (int)nin->dim && maxLen == (int)nin->dim )) { |
78 |
|
|
fprintf(stderr, |
79 |
|
|
"%s: # min coords (%d) or max coords (%d) != nrrd dim (%d)\n", |
80 |
|
|
me, minLen, maxLen, nin->dim); |
81 |
|
|
airMopError(mop); |
82 |
|
|
return 1; |
83 |
|
|
} |
84 |
|
|
for (ai=0; ai<nin->dim; ai++) { |
85 |
|
|
if (-1 == minOff[0 + 2*ai]) { |
86 |
|
|
fprintf(stderr, "%s: can't use m+<int> specification for axis %d min\n", |
87 |
|
|
me, ai); |
88 |
|
|
airMopError(mop); |
89 |
|
|
return 1; |
90 |
|
|
} |
91 |
|
|
} |
92 |
|
|
for (ai=0; ai<nin->dim; ai++) { |
93 |
|
|
min[ai] = minOff[0 + 2*ai]*(nin->axis[ai].size-1) + minOff[1 + 2*ai]; |
94 |
|
|
if (-1 == maxOff[0 + 2*ai]) { |
95 |
|
|
max[ai] = min[ai] + maxOff[1 + 2*ai]; |
96 |
|
|
} else { |
97 |
|
|
max[ai] = maxOff[0 + 2*ai]*(nin->axis[ai].size-1) + maxOff[1 + 2*ai]; |
98 |
|
|
} |
99 |
|
|
/* |
100 |
|
|
fprintf(stderr, "%s: ai %2d: min = %4d, max = %4d\n", |
101 |
|
|
me, ai, min[ai], mai[ai]); |
102 |
|
|
*/ |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
nout = nrrdNew(); |
106 |
|
|
airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); |
107 |
|
|
|
108 |
|
|
if (nrrdPad_nva(nout, nin, min, max, bb, padVal)) { |
109 |
|
|
airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); |
110 |
|
|
fprintf(stderr, "%s: error padding nrrd:\n%s", me, err); |
111 |
|
|
airMopError(mop); |
112 |
|
|
return 1; |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
SAVE(out, nout, NULL); |
116 |
|
|
|
117 |
|
|
airMopOkay(mop); |
118 |
|
|
return 0; |
119 |
|
1 |
} |
120 |
|
|
|
121 |
|
|
UNRRDU_CMD(pad, INFO); |