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 "unrrdu.h"
25 #include "privateUnrrdu.h"
26 
27 #define INFO "converts from 1-D index to world position"
28 static const char *_unrrdu_i2wInfoL =
29 (INFO  ", given the centering of the data (cell vs. node), "
30  "the range of positions, and the number of intervals into "
31  "which position has been quantized. "
32  "This is a demo/utility, which does not actually operate on any nrrds. "
33  "Previously available as the stand-alone idx2pos binary.\n "
34  "* Uses NRRD_POS macro");
35 
36 int
unrrdu_i2wMain(int argc,const char ** argv,const char * me,hestParm * hparm)37 unrrdu_i2wMain(int argc, const char **argv, const char *me,
38                hestParm *hparm) {
39   hestOpt *opt = NULL;
40   airArray *mop;
41   int pret;
42   char *err;
43 
44   int center;
45   double minPos, maxPos, pos, indx, size;
46 
47   mop = airMopNew();
48   hestOptAdd(&opt, NULL, "center", airTypeEnum, 1, 1, &center, NULL,
49              "which centering applies to the quantized position.\n "
50              "Possibilities are:\n "
51              "\b\bo \"cell\": for histogram bins, quantized values, and "
52              "pixels-as-squares\n "
53              "\b\bo \"node\": for non-trivially interpolated "
54              "sample points", NULL, nrrdCenter);
55   hestOptAdd(&opt, NULL, "minPos", airTypeDouble, 1, 1, &minPos, NULL,
56              "smallest position associated with index 0");
57   hestOptAdd(&opt, NULL, "maxPos", airTypeDouble, 1, 1, &maxPos, NULL,
58              "highest position associated with highest index");
59   hestOptAdd(&opt, NULL, "num", airTypeDouble, 1, 1, &size, NULL,
60              "number of intervals into which position has been quantized");
61   hestOptAdd(&opt, NULL, "index", airTypeDouble, 1, 1, &indx, NULL,
62              "the input index position, to be converted to world");
63   airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways);
64   USAGE(_unrrdu_i2wInfoL);
65   PARSE();
66   airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways);
67 
68   pos = NRRD_POS(center, minPos, maxPos, size, indx);
69   printf("%g\n", pos);
70 
71   airMopOkay(mop);
72   return 0;
73 }
74 
75 UNRRDU_CMD(i2w, INFO);
76