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 world to index position"
28 static const char *_unrrdu_w2iInfoL =
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 pos2idx binary.\n "
34 "* Uses NRRD_IDX macro");
35
36 int
unrrdu_w2iMain(int argc,const char ** argv,const char * me,hestParm * hparm)37 unrrdu_w2iMain(int argc, const char **argv, const char *me, hestParm *hparm) {
38 hestOpt *opt = NULL;
39 airArray *mop;
40 int pret;
41 char *err;
42
43 int center;
44 double minPos, maxPos, pos, indx, size;
45
46 mop = airMopNew();
47 hestOptAdd(&opt, NULL, "center", airTypeEnum, 1, 1, ¢er, NULL,
48 "which centering applies to the quantized position.\n "
49 "Possibilities are:\n "
50 "\b\bo \"cell\": for histogram bins, quantized values, and "
51 "pixels-as-squares\n "
52 "\b\bo \"node\": for non-trivially interpolated "
53 "sample points", NULL, nrrdCenter);
54 hestOptAdd(&opt, NULL, "minPos", airTypeDouble, 1, 1, &minPos, NULL,
55 "smallest position associated with index 0");
56 hestOptAdd(&opt, NULL, "maxPos", airTypeDouble, 1, 1, &maxPos, NULL,
57 "highest position associated with highest index");
58 hestOptAdd(&opt, NULL, "num", airTypeDouble, 1, 1, &size, NULL,
59 "number of intervals into which position has been quantized");
60 hestOptAdd(&opt, NULL, "world", airTypeDouble, 1, 1, &pos, NULL,
61 "the input world position, to be converted to index");
62 airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways);
63 USAGE(_unrrdu_w2iInfoL);
64 PARSE();
65 airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways);
66
67 indx = NRRD_IDX(center, minPos, maxPos, size, pos);
68 printf("%g\n", indx);
69
70 airMopOkay(mop);
71 return 0;
72 }
73
74 UNRRDU_CMD(w2i, INFO);
75