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 "Connect slices and/or slabs into a bigger nrrd" |
28 |
|
|
static const char *_unrrdu_joinInfoL = |
29 |
|
|
(INFO |
30 |
|
|
". Can stich images into volumes, or tile images side " |
31 |
|
|
"by side, or attach images onto volumes. If there are many many " |
32 |
|
|
"files to name in the \"-i\" option, and using wildcards won't work, " |
33 |
|
|
"consider putting the list of " |
34 |
|
|
"filenames into a separate text file (e.g. \"slices.txt\"), and then " |
35 |
|
|
"name this file as a response file (e.g. \"-i @slices.txt\"). " |
36 |
|
|
"This command now allows you to set the same pieces of information that " |
37 |
|
|
"previously had to be set with \"unu axinfo\": label, spacing, and min/max. " |
38 |
|
|
"These can be use whether the join axis is new (because of \"-incr\") or " |
39 |
|
|
"not.\n " |
40 |
|
|
"* Uses nrrdJoin"); |
41 |
|
|
|
42 |
|
|
int |
43 |
|
|
unrrdu_joinMain(int argc, const char **argv, const char *me, |
44 |
|
|
hestParm *hparm) { |
45 |
|
2 |
hestOpt *opt = NULL; |
46 |
|
1 |
char *out, *err, *label, *kindStr; |
47 |
|
1 |
Nrrd **nin; |
48 |
|
|
Nrrd *nout; |
49 |
|
1 |
int incrDim, pret, kind; |
50 |
|
1 |
unsigned int ninLen, axis; |
51 |
|
1 |
double mm[2], spc; |
52 |
|
|
airArray *mop; |
53 |
|
|
|
54 |
|
1 |
hparm->respFileEnable = AIR_TRUE; |
55 |
|
|
|
56 |
|
1 |
hestOptAdd(&opt, "i,input", "nin0", airTypeOther, 1, -1, &nin, NULL, |
57 |
|
|
"everything to be joined together", |
58 |
|
1 |
&ninLen, NULL, nrrdHestNrrd); |
59 |
|
1 |
OPT_ADD_AXIS(axis, "axis to join along"); |
60 |
|
1 |
hestOptAdd(&opt, "incr", NULL, airTypeInt, 0, 0, &incrDim, NULL, |
61 |
|
|
"in situations where the join axis is *not* among the existing " |
62 |
|
|
"axes of the input nrrds, then this flag signifies that the join " |
63 |
|
|
"axis should be *inserted*, and the output dimension should " |
64 |
|
|
"be one greater than input dimension. Without this flag, the " |
65 |
|
|
"nrrds are joined side-by-side, along an existing axis."); |
66 |
|
1 |
hestOptAdd(&opt, "l,label", "label", airTypeString, 1, 1, &label, "", |
67 |
|
|
"label to associate with join axis"); |
68 |
|
1 |
hestOptAdd(&opt, "k,kind", "kind", airTypeString, 1, 1, &kindStr, "", |
69 |
|
|
"kind to set on join axis. " |
70 |
|
|
"Not using this option leaves the kind as is"); |
71 |
|
1 |
hestOptAdd(&opt, "mm,minmax", "min max", airTypeDouble, 2, 2, mm, "nan nan", |
72 |
|
|
"min and max values along join axis"); |
73 |
|
1 |
hestOptAdd(&opt, "sp,spacing", "spc", airTypeDouble, 1, 1, &spc, "nan", |
74 |
|
|
"spacing between samples along join axis"); |
75 |
|
1 |
OPT_ADD_NOUT(out, "output nrrd"); |
76 |
|
|
|
77 |
|
1 |
mop = airMopNew(); |
78 |
|
1 |
airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways); |
79 |
|
|
|
80 |
✓✗ |
2 |
USAGE(_unrrdu_joinInfoL); |
81 |
|
|
PARSE(); |
82 |
|
|
airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways); |
83 |
|
|
|
84 |
|
|
nout = nrrdNew(); |
85 |
|
|
airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); |
86 |
|
|
|
87 |
|
|
if (nrrdJoin(nout, AIR_CAST(const Nrrd*const*, nin), ninLen, |
88 |
|
|
axis, incrDim)) { |
89 |
|
|
airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways); |
90 |
|
|
fprintf(stderr, "%s: error joining nrrds:\n%s", me, err); |
91 |
|
|
airMopError(mop); |
92 |
|
|
return 1; |
93 |
|
|
} |
94 |
|
|
if (strlen(label)) { |
95 |
|
|
nout->axis[axis].label = (char *)airFree(nout->axis[axis].label); |
96 |
|
|
nout->axis[axis].label = airStrdup(label); |
97 |
|
|
} |
98 |
|
|
if (airStrlen(kindStr)) { |
99 |
|
|
if (!strcmp("none", kindStr) |
100 |
|
|
|| !strcmp("???", kindStr)) { |
101 |
|
|
kind = nrrdKindUnknown; |
102 |
|
|
} else { |
103 |
|
|
if (!(kind = airEnumVal(nrrdKind, kindStr))) { |
104 |
|
|
fprintf(stderr, "%s: couldn't parse \"%s\" as %s\n", me, |
105 |
|
|
kindStr, nrrdKind->name); |
106 |
|
|
airMopError(mop); |
107 |
|
|
return 1; |
108 |
|
|
} |
109 |
|
|
} |
110 |
|
|
nout->axis[axis].kind = kind; |
111 |
|
|
} |
112 |
|
|
if (AIR_EXISTS(mm[0])) { |
113 |
|
|
nout->axis[axis].min = mm[0]; |
114 |
|
|
} |
115 |
|
|
if (AIR_EXISTS(mm[1])) { |
116 |
|
|
nout->axis[axis].max = mm[1]; |
117 |
|
|
} |
118 |
|
|
if (AIR_EXISTS(spc)) { |
119 |
|
|
nout->axis[axis].spacing = spc; |
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
SAVE(out, nout, NULL); |
123 |
|
|
|
124 |
|
|
airMopOkay(mop); |
125 |
|
|
return 0; |
126 |
|
1 |
} |
127 |
|
|
|
128 |
|
|
UNRRDU_CMD(join, INFO); |