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 "Compute volume of shape triples"
28 static const char *_tend_tripleInfoL =
29   (INFO
30    ".  The triple can be eignvalues, invariants (J, K, R), "
31    "and lots of other things.");
32 
33 int
tend_tripleMain(int argc,const char ** argv,const char * me,hestParm * hparm)34 tend_tripleMain(int argc, const char **argv, const char *me,
35                 hestParm *hparm) {
36   int pret;
37   hestOpt *hopt = NULL;
38   char *perr, *err;
39   airArray *mop;
40 
41   int ttype;
42   Nrrd *nin, *nout;
43   char *outS;
44 
45   hestOptAdd(&hopt, "t", "type", airTypeEnum, 1, 1, &ttype, NULL,
46              "desired output triple type", NULL, tenTripleType);
47   hestOptAdd(&hopt, "i", "nin", airTypeOther, 1, 1, &nin, "-",
48              "input tensor volume", NULL, NULL, nrrdHestNrrd);
49   hestOptAdd(&hopt, "o", "nout", airTypeString, 1, 1, &outS, "-",
50              "output triple volume");
51 
52   mop = airMopNew();
53   airMopAdd(mop, hopt, (airMopper)hestOptFree, airMopAlways);
54   USAGE(_tend_tripleInfoL);
55   PARSE();
56   airMopAdd(mop, hopt, (airMopper)hestParseFree, airMopAlways);
57 
58   nout = nrrdNew();
59   airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways);
60   if (tenTripleCalc(nout, ttype, nin)) {
61     airMopAdd(mop, err=biffGetDone(TEN), airFree, airMopAlways);
62     fprintf(stderr, "%s: trouble:\n%s\n", me, err);
63     airMopError(mop); return 1;
64   }
65   if (nrrdSave(outS, nout, NULL)) {
66     airMopAdd(mop, err=biffGetDone(NRRD), airFree, airMopAlways);
67     fprintf(stderr, "%s: trouble writing:\n%s\n", me, err);
68     airMopError(mop); return 1;
69   }
70 
71   airMopOkay(mop);
72   return 0;
73 }
74 /* TEND_CMD(anvol, INFO); */
75 unrrduCmd tend_tripleCmd = { "triple", INFO, tend_tripleMain };
76