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 PARM_NUM 4
28 static const tenModelParmDesc
29 parmDesc[] = {
30   /* 0 */ {"B0", 0.0, TEN_MODEL_B0_MAX, AIR_FALSE, AIR_FALSE, 0},
31   /* 1 */ {"th0",  0, 2*AIR_PI, AIR_TRUE, AIR_FALSE, 0},
32   /* 2 */ {"frac", 0, 1,        AIR_FALSE, AIR_FALSE, 0},
33   /* 3 */ {"th1",  0, 2*AIR_PI, AIR_TRUE, AIR_FALSE, 0}
34 };
35 
36 static void
simulate(double * dwiSim,const double * parm,const tenExperSpec * espec)37 simulate(double *dwiSim, const double *parm, const tenExperSpec *espec) {
38   unsigned int ii;
39   double th0, frac, th1, vec0[3], vec1[3];
40 
41   /* not used: b0 = parm[0]; */
42   th0 = parm[1];
43   frac = parm[2];
44   th1 = parm[3];
45   ELL_3V_SET(vec0, cos(th0), sin(th0), 0.0);
46   ELL_3V_SET(vec1, cos(th1), sin(th1), 0.0);
47   for (ii=0; ii<espec->imgNum; ii++) {
48     double dot0, dot1;
49     dot0 = ELL_3V_DOT(vec0, espec->grad + 3*ii);
50     dot1 = ELL_3V_DOT(vec1, espec->grad + 3*ii);
51     dwiSim[ii] = AIR_LERP(frac, dot0, dot1);
52   }
53   return;
54 }
55 
56 static char *
parmSprint(char str[AIR_STRLEN_MED],const double * parm)57 parmSprint(char str[AIR_STRLEN_MED], const double *parm) {
58   sprintf(str, "(%g) (1-f)*th0=%g + (f=%g)*th1=%g",
59           parm[0], parm[1], parm[2], parm[3]);
60   return str;
61 }
62 
63 _TEN_PARM_ALLOC
64 _TEN_PARM_RAND
65 _TEN_PARM_STEP
66 _TEN_PARM_DIST
67 _TEN_PARM_COPY
68 _TEN_PARM_CONVERT_NOOP
69 
70 _TEN_SQE
71 _TEN_SQE_GRAD_CENTDIFF
72 _TEN_SQE_FIT(tenModel2Unit2D)
73 
74 _TEN_NLL
75 _TEN_NLL_GRAD_STUB
76 _TEN_NLL_FIT_STUB
77 
78 tenModel
79 _tenModel2Unit2D = {
80   TEN_MODEL_STR_2UNIT2D,
81   _TEN_MODEL_FIELDS
82 };
83 const tenModel *const tenModel2Unit2D = &_tenModel2Unit2D;
84