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 "Graph anisotropy metric in barycentric coords"
28 static const char *_tend_anplotInfoL =
29   (INFO
30    ".  The metrics all vary from 0.0 to 1.0, and will be sampled "
31    "in the lower right half of the image.  The plane on which they are "
32    "sampled is a surface of constant trace.  You may want to use "
33    "\"unu resample -s = x0.57735 -k tent\" to transform the triangle into "
34    "a 30-60-90 triangle, and \"ilk -t 1,-0.5,0,0,0.866,0 -k tent "
35    "-0 u:0,1 -b pad -bg 0\" (possibly followed by "
36    "teem/src/limntest/triimg) to transform the domain into an equilateral "
37    "triangle.");
38 
39 int
tend_anplotMain(int argc,const char ** argv,const char * me,hestParm * hparm)40 tend_anplotMain(int argc, const char **argv, const char *me,
41                 hestParm *hparm) {
42   int pret;
43   hestOpt *hopt = NULL;
44   char *perr, *err;
45   airArray *mop;
46 
47   int res, aniso, whole, nanout, hflip;
48   Nrrd *nout;
49   char *outS;
50 
51   hestOptAdd(&hopt, "r", "res", airTypeInt, 1, 1, &res, "256",
52              "resolution of anisotropy plot");
53   hestOptAdd(&hopt, "w", NULL, airTypeInt, 0, 0, &whole, NULL,
54              "sample the whole triangle of constant trace, "
55              "instead of just the "
56              "sixth of it in which the eigenvalues have the "
57              "traditional sorted order. ");
58   hestOptAdd(&hopt, "hflip", NULL, airTypeInt, 0, 0, &hflip, NULL,
59              "flip the two bottom corners (swapping the place of "
60              "linear and planar)");
61   hestOptAdd(&hopt, "nan", NULL, airTypeInt, 0, 0, &nanout, NULL,
62              "set the pixel values outside the triangle to be NaN, "
63              "instead of 0");
64   hestOptAdd(&hopt, "a", "aniso", airTypeEnum, 1, 1, &aniso, NULL,
65              "Which anisotropy metric to plot.  " TEN_ANISO_DESC,
66              NULL, tenAniso);
67   hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-",
68              "output image (floating point)");
69 
70   mop = airMopNew();
71   airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways);
72   USAGE(_tend_anplotInfoL);
73   JUSTPARSE();
74   airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways);
75 
76   nout = nrrdNew();
77   airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways);
78   if (tenAnisoPlot(nout, aniso, res, hflip, whole, nanout)) {
79     airMopAdd(mop, err=biffGetDone(TEN), airFree, airMopAlways);
80     fprintf(stderr, "%s: trouble making plot:\n%s\n", me, err);
81     airMopError(mop); return 1;
82   }
83 
84   if (nrrdSave(outS, nout, NULL)) {
85     airMopAdd(mop, err=biffGetDone(NRRD), airFree, airMopAlways);
86     fprintf(stderr, "%s: trouble writing:\n%s\n", me, err);
87     airMopError(mop); return 1;
88   }
89 
90   airMopOkay(mop);
91   return 0;
92 }
93 /* TEND_CMD(anplot, INFO); */
94 unrrduCmd tend_anplotCmd = { "anplot", INFO, tend_anplotMain };
95 
96