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 "Describe everything about one sample in a DT volume"
28 static const char *_tend_pointInfoL =
29   (INFO
30    ". ");
31 
32 int
tend_pointMain(int argc,const char ** argv,const char * me,hestParm * hparm)33 tend_pointMain(int argc, const char **argv, const char *me,
34                hestParm *hparm) {
35   int pret;
36   hestOpt *hopt = NULL;
37   char *perr, *err;
38   airArray *mop;
39 
40   int loc[3], idx, sx, sy, sz, i;
41   Nrrd *nin;
42   float *tdata, eval[3], evec[9], angle, axis[3], mat[9];
43 
44   hestOptAdd(&hopt, "p", "x y z", airTypeInt, 3, 3, loc, NULL,
45              "coordinates of sample to be described");
46   hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, "-",
47              "input diffusion tensor volume", NULL, NULL, nrrdHestNrrd);
48 
49   mop = airMopNew();
50   airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways);
51   USAGE(_tend_pointInfoL);
52   PARSE();
53   airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways);
54 
55   if (tenTensorCheck(nin, nrrdTypeFloat, AIR_TRUE, AIR_TRUE)) {
56     airMopAdd(mop, err=biffGetDone(TEN), airFree, airMopAlways);
57     fprintf(stderr, "%s: didn't get a valid DT volume:\n%s\n", me, err);
58     airMopError(mop); return 1;
59   }
60   sx = nin->axis[1].size;
61   sy = nin->axis[2].size;
62   sz = nin->axis[3].size;
63   if (!( AIR_IN_CL(0, loc[0], sx-1) &&
64          AIR_IN_CL(0, loc[1], sy-1) &&
65          AIR_IN_CL(0, loc[2], sz-1) )) {
66     fprintf(stderr, "%s: location (%d,%d,%d) not inside volume "
67             "[0..%d]x[0..%d]x[0..%d]\n",
68             me, loc[0], loc[1], loc[2],
69             sx-1, sy-1, sz-1);
70     airMopError(mop); return 1;
71   }
72 
73   idx = loc[0] + sx*(loc[1] + sy*loc[2]);
74   tdata = (float*)(nin->data) + 7*idx;
75   fprintf(stderr, "location = (%d,%d,%d) = %d\n", loc[0], loc[1], loc[2], idx);
76   fprintf(stderr, "confidence = %g\n", tdata[0]);
77   fprintf(stderr, "tensor =\n");
78   fprintf(stderr, "{%.7f,%.7f,%.7f,%.7f,%.7f,%.7f} = \n",
79           tdata[1], tdata[2], tdata[3], tdata[4], tdata[5], tdata[6]);
80   fprintf(stderr, "% 15.7f % 15.7f % 15.7f\n", tdata[1], tdata[2], tdata[3]);
81   fprintf(stderr, "% 15.7f % 15.7f % 15.7f\n", tdata[2], tdata[4], tdata[5]);
82   fprintf(stderr, "% 15.7f % 15.7f % 15.7f\n", tdata[3], tdata[5], tdata[6]);
83   tenEigensolve_f(eval, evec, tdata);
84   fprintf(stderr, "eigensystem = (<eigenvalue> : <eigenvector>):\n");
85   fprintf(stderr, "% 15.7f : % 15.7f % 15.7f % 15.7f\n",
86           eval[0], evec[0], evec[1], evec[2]);
87   fprintf(stderr, "% 15.7f : % 15.7f % 15.7f % 15.7f\n",
88           eval[1], evec[3], evec[4], evec[5]);
89   fprintf(stderr, "% 15.7f : % 15.7f % 15.7f % 15.7f\n",
90           eval[2], evec[6], evec[7], evec[8]);
91   angle = ell_3m_to_aa_f(axis, evec);
92   fprintf(stderr, "eigenvector rotation: %g around {%g,%g,%g}\n",
93           angle, axis[0], axis[1], axis[2]);
94   ell_aa_to_3m_f(mat, angle, axis);
95   fprintf(stderr, "% 15.7f % 15.7f % 15.7f\n",
96           mat[0], mat[1], mat[2]);
97   fprintf(stderr, "% 15.7f % 15.7f % 15.7f\n",
98           mat[3], mat[4], mat[5]);
99   fprintf(stderr, "% 15.7f % 15.7f % 15.7f\n",
100           mat[6], mat[7], mat[8]);
101   fprintf(stderr, "anisotropies = \n");
102   for (i=1; i<=TEN_ANISO_MAX; i++) {
103     fprintf(stderr, "%s: % 15.7f\n",
104             airEnumStr(tenAniso, i), tenAnisoEval_f(eval, i));
105   }
106 
107   airMopOkay(mop);
108   return 0;
109 }
110 TEND_CMD(point, INFO);
111 
112