1 /*
2   Teem: Tools to process and visualize scientific data and images             .
3   Copyright (C) 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 "Create DT volume from confidence and eigensystem"
28 static const char *_tend_makeInfoL =
29   (INFO
30    ".  The input is in the form of three nrrds, one for confidence "
31    "values (3D), one for eigenvalues (4D, three evals per voxel), and "
32    "one for eigenvectors (4D, nine evec components per voxel).");
33 
34 int
tend_makeMain(int argc,const char ** argv,const char * me,hestParm * hparm)35 tend_makeMain(int argc, const char **argv, const char *me,
36               hestParm *hparm) {
37   int pret;
38   hestOpt *hopt = NULL;
39   char *perr, *err;
40   airArray *mop;
41 
42   Nrrd *nin[3], *nout;
43   char *outS;
44 
45   hestOptAdd(&hopt, "i", "conf evals evecs", airTypeOther, 3, 3, nin, NULL,
46              "input diffusion tensor volume", NULL, NULL, nrrdHestNrrd);
47   hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-",
48              "output image (floating point)");
49 
50   mop = airMopNew();
51   airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways);
52   USAGE(_tend_makeInfoL);
53   JUSTPARSE();
54   airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways);
55 
56   nout = nrrdNew();
57   airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways);
58   if (tenMake(nout, nin[0], nin[1], nin[2])) {
59     airMopAdd(mop, err=biffGetDone(TEN), airFree, airMopAlways);
60     fprintf(stderr, "%s: trouble making tensor volume:\n%s\n", me, err);
61     airMopError(mop); return 1;
62   }
63 
64   if (nrrdSave(outS, nout, NULL)) {
65     airMopAdd(mop, err=biffGetDone(NRRD), airFree, airMopAlways);
66     fprintf(stderr, "%s: trouble writing:\n%s\n", me, err);
67     airMopError(mop); return 1;
68   }
69 
70   airMopOkay(mop);
71   return 0;
72 }
73 unrrduCmd tend_makeCmd = { "make", INFO, tend_makeMain };
74