1 /*
2   Teem: Tools to process and visualize scientific data and images             .
3   Copyright (C) 2008, 2007, 2006, 2005  Gordon Kindlmann
4   Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998  University of Utah
5 
6   This library is free software; you can redistribute it and/or
7   modify it under the terms of the GNU Lesser General Public License
8   (LGPL) as published by the Free Software Foundation; either
9   version 2.1 of the License, or (at your option) any later version.
10   The terms of redistributing and/or modifying this software also
11   include exceptions to the LGPL that facilitate static linking.
12 
13   This library is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16   Lesser General Public License for more details.
17 
18   You should have received a copy of the GNU Lesser General Public License
19   along with this library; if not, write to Free Software Foundation, Inc.,
20   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 */
22 
23 
24 #include "../ten.h"
25 
26 char *info = ("tests invariant grads and rotation tangents.");
27 
28 int
main(int argc,const char * argv[])29 main(int argc, const char *argv[]) {
30   const char *me;
31   hestOpt *hopt=NULL;
32   airArray *mop;
33 
34   double _ten[6], ten[7], minnorm, igrt[6][7], eval[3], evec[9],
35     pp[3], qq[4], rot[9], matA[9], matB[9], tmp;
36   int doK, ret, ii, jj;
37   mop = airMopNew();
38 
39   me = argv[0];
40   hestOptAdd(&hopt, NULL, "tensor", airTypeDouble, 6, 6, _ten, NULL,
41              "tensor value");
42   hestOptAdd(&hopt, "mn", "minnorm", airTypeDouble, 1, 1, &minnorm,
43              "0.00001",
44              "minimum norm before special handling");
45   hestOptAdd(&hopt, "k", NULL, airTypeInt, 0, 0, &doK, NULL,
46              "Use K invariants, instead of R (the default)");
47   hestOptAdd(&hopt, "p", "x y z", airTypeDouble, 3, 3, pp, "0 0 0",
48              "location in quaternion quotient space");
49   hestParseOrDie(hopt, argc-1, argv+1, NULL,
50                  me, info, AIR_TRUE, AIR_TRUE, AIR_TRUE);
51   airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways);
52   airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways);
53 
54   ELL_6V_COPY(ten+1, _ten);
55   ten[0] = 1.0;
56 
57   fprintf(stderr, "input tensor = %f %f %f    %f %f     %f\n",
58           ten[1], ten[2], ten[3], ten[4], ten[5], ten[6]);
59 
60   ELL_4V_SET(qq, 1, pp[0], pp[1], pp[2]);
61   ELL_4V_NORM(qq, qq, tmp);
62   ell_q_to_3m_d(rot, qq);
63   TEN_T2M(matA, ten);
64   ELL_3M_MUL(matB, rot, matA);
65   ELL_3M_TRANSPOSE_IP(rot, tmp);
66   ELL_3M_MUL(matA, matB, rot);
67   TEN_M2T(ten, matA);
68 
69   fprintf(stderr, "rotated tensor = %f %f %f    %f %f     %f\n",
70           ten[1], ten[2], ten[3], ten[4], ten[5], ten[6]);
71 
72   ret = tenEigensolve_d(eval, evec, ten);
73   fprintf(stderr, "eigensystem: %s: %g %g %g\n",
74           airEnumDesc(ell_cubic_root, ret),
75           eval[0], eval[1], eval[2]);
76 
77   if (doK) {
78     tenInvariantGradientsK_d(igrt[0], igrt[1], igrt[2], ten, minnorm);
79   } else {
80     tenInvariantGradientsR_d(igrt[0], igrt[1], igrt[2], ten, minnorm);
81   }
82   tenRotationTangents_d(igrt[3], igrt[4], igrt[5], evec);
83 
84   fprintf(stderr, "invariant gradients and rotation tangents:\n");
85   for (ii=0; ii<=2; ii++) {
86     fprintf(stderr, "  %s_%d: (norm=%g) %f %f %f     %f %f     %f\n",
87             doK ? "K" : "R", ii+1,
88             TEN_T_NORM(igrt[ii]),
89             igrt[ii][1], igrt[ii][2], igrt[ii][3],
90             igrt[ii][4], igrt[ii][5],
91             igrt[ii][6]);
92   }
93   for (ii=3; ii<=5; ii++) {
94     fprintf(stderr, "phi_%d: (norm=%g) %f %f %f     %f %f     %f\n",
95             ii-2,
96             TEN_T_NORM(igrt[ii]),
97             igrt[ii][1], igrt[ii][2], igrt[ii][3],
98             igrt[ii][4], igrt[ii][5],
99             igrt[ii][6]);
100   }
101 
102   fprintf(stderr, "dot products:\n");
103   for (ii=0; ii<=5; ii++) {
104     for (jj=ii+1; jj<=5; jj++) {
105       fprintf(stderr, "%d,%d==%f  ", ii, jj, TEN_T_DOT(igrt[ii], igrt[jj]));
106     }
107     fprintf(stderr, "\n");
108   }
109 
110 
111   airMopOkay(mop);
112   return 0;
113 }
114