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 "Calculate B-matrix given gradient directions" |
28 |
|
|
static const char *_tend_bmatInfoL = |
29 |
|
|
(INFO |
30 |
|
|
", assuming no diffusion weighting from the other imaging gradients. " |
31 |
|
|
"The input is a 3-by-N array of floats or doubles, each row being " |
32 |
|
|
"one of the gradient directions used for diffusion-weighted imaging. " |
33 |
|
|
"A plain text file with one gradient per line, no punctuation, is an " |
34 |
|
|
"easy way to specify this information. " |
35 |
|
|
"The gradient vector coefficients are used as is, without normalization " |
36 |
|
|
"(since different gradient strengths are sometimes desired). " |
37 |
|
|
"The output has one row of the B-matrix per line, with coefficient " |
38 |
|
|
"ordering Bxx, Bxy, Bxz, Byy, Byz, Bzz, and with the off-diagonal " |
39 |
|
|
"elements NOT pre-multiplied by 2."); |
40 |
|
|
|
41 |
|
|
int |
42 |
|
|
tend_bmatMain(int argc, const char **argv, const char *me, |
43 |
|
|
hestParm *hparm) { |
44 |
|
|
int pret; |
45 |
|
2 |
hestOpt *hopt = NULL; |
46 |
|
1 |
char *perr, *err; |
47 |
|
|
airArray *mop; |
48 |
|
|
|
49 |
|
1 |
Nrrd *ngrad, *nout; |
50 |
|
1 |
char *outS; |
51 |
|
|
|
52 |
|
1 |
hestOptAdd(&hopt, "i", "grads", airTypeOther, 1, 1, &ngrad, NULL, |
53 |
|
1 |
"array of gradient directions", NULL, NULL, nrrdHestNrrd); |
54 |
|
1 |
hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-", |
55 |
|
|
"output B matrix"); |
56 |
|
|
|
57 |
|
1 |
mop = airMopNew(); |
58 |
|
1 |
airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways); |
59 |
✓✗ |
2 |
USAGE(_tend_bmatInfoL); |
60 |
|
|
JUSTPARSE(); |
61 |
|
|
airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways); |
62 |
|
|
nout = nrrdNew(); |
63 |
|
|
airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways); |
64 |
|
|
|
65 |
|
|
if (tenBMatrixCalc(nout, ngrad)) { |
66 |
|
|
airMopAdd(mop, err=biffGetDone(TEN), airFree, airMopAlways); |
67 |
|
|
fprintf(stderr, "%s: trouble making B matrix:\n%s\n", me, err); |
68 |
|
|
airMopError(mop); return 1; |
69 |
|
|
} |
70 |
|
|
if (nrrdSave(outS, nout, NULL)) { |
71 |
|
|
airMopAdd(mop, err=biffGetDone(NRRD), airFree, airMopAlways); |
72 |
|
|
fprintf(stderr, "%s: trouble writing:\n%s\n", me, err); |
73 |
|
|
airMopError(mop); return 1; |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
airMopOkay(mop); |
77 |
|
|
return 0; |
78 |
|
1 |
} |
79 |
|
|
TEND_CMD(bmat, INFO); |