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 "ten.h" |
25 |
|
|
#include "privateTen.h" |
26 |
|
|
|
27 |
|
|
#define INFO "convert from one model to another" |
28 |
|
|
static const char *_tend_mconvInfoL = |
29 |
|
|
(INFO |
30 |
|
|
". More docs here."); |
31 |
|
|
|
32 |
|
|
int |
33 |
|
|
tend_mconvMain(int argc, const char **argv, const char *me, |
34 |
|
|
hestParm *hparm) { |
35 |
|
|
int pret; |
36 |
|
2 |
hestOpt *hopt = NULL; |
37 |
|
1 |
char *perr, *err; |
38 |
|
|
airArray *mop; |
39 |
|
|
|
40 |
|
1 |
Nrrd *nin, *nout; |
41 |
|
1 |
char *outS, *modelSrcS, *modelDstS; |
42 |
|
1 |
const tenModel *modelDst, *modelSrc; |
43 |
|
1 |
int saveB0; |
44 |
|
|
|
45 |
|
1 |
hestOptAdd(&hopt, "mo", "model", airTypeString, 1, 1, &modelDstS, NULL, |
46 |
|
|
"which model to convert to"); |
47 |
|
1 |
hestOptAdd(&hopt, "mi", "model", airTypeString, 1, 1, &modelSrcS, "", |
48 |
|
|
"model converting from; if not set, will try to determine " |
49 |
|
|
"from input nrrd"); |
50 |
|
1 |
hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, "-", |
51 |
|
|
"input nrrd of model parms", |
52 |
|
1 |
NULL, NULL, nrrdHestNrrd); |
53 |
|
1 |
hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-", |
54 |
|
|
"output nrrd of model parms"); |
55 |
|
|
|
56 |
|
1 |
mop = airMopNew(); |
57 |
|
1 |
airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); |
58 |
✓✗ |
2 |
USAGE(_tend_mconvInfoL); |
59 |
|
|
JUSTPARSE(); |
60 |
|
|
airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); |
61 |
|
|
|
62 |
|
|
nout = nrrdNew(); |
63 |
|
|
airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); |
64 |
|
|
if (tenModelParse(&modelDst, &saveB0, AIR_FALSE, modelDstS)) { |
65 |
|
|
airMopAdd(mop, err=biffGetDone(TEN), airFree, airMopAlways); |
66 |
|
|
fprintf(stderr, "%s: trouble parsing model \"%s\":\n%s\n", me, |
67 |
|
|
modelDstS, err); |
68 |
|
|
airMopError(mop); return 1; |
69 |
|
|
} |
70 |
|
|
if (saveB0) { |
71 |
|
|
printf("%s: warning: saving B0 is determined by input nrrd " |
72 |
|
|
"having B0 info.\n", me); |
73 |
|
|
} |
74 |
|
|
if (airStrlen(modelSrcS)) { |
75 |
|
|
if (tenModelParse(&modelSrc, &saveB0, AIR_FALSE, modelSrcS)) { |
76 |
|
|
airMopAdd(mop, err=biffGetDone(TEN), airFree, airMopAlways); |
77 |
|
|
fprintf(stderr, "%s: trouble parsing model \"%s\":\n%s\n", me, |
78 |
|
|
modelSrcS, err); |
79 |
|
|
airMopError(mop); return 1; |
80 |
|
|
} |
81 |
|
|
} else { |
82 |
|
|
modelSrc = NULL; |
83 |
|
|
} |
84 |
|
|
if (tenModelConvert(nout, NULL, modelDst, nin, modelSrc)) { |
85 |
|
|
airMopAdd(mop, err=biffGetDone(TEN), airFree, airMopAlways); |
86 |
|
|
fprintf(stderr, "%s: trouble converting:\n%s\n", me, err); |
87 |
|
|
airMopError(mop); return 1; |
88 |
|
|
} |
89 |
|
|
if (nrrdSave(outS, nout, NULL)) { |
90 |
|
|
airMopAdd(mop, err=biffGetDone(NRRD), airFree, airMopAlways); |
91 |
|
|
fprintf(stderr, "%s: trouble writing:\n%s\n", me, err); |
92 |
|
|
airMopError(mop); return 1; |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
airMopOkay(mop); |
96 |
|
|
return 0; |
97 |
|
1 |
} |
98 |
|
|
TEND_CMD(mconv, INFO); |