GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/unrrdu/unquantize.c Lines: 15 31 48.4 %
Date: 2017-05-26 Branches: 1 18 5.6 %

Line Branch Exec Source
1
/*
2
  Teem: Tools to process and visualize scientific data and images             .
3
  Copyright (C) 2013, 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 "Recover floating point values from quantized data"
28
static const char *_unrrdu_unquantizeInfoL =
29
  (INFO ". Uses the oldMin and oldMax fields in the Nrrd of quantized values "
30
   "to regenerate approximate versions of the original unquantized values. "
31
   "Can also override these with \"-min\" and \"-max\".\n "
32
   "* Uses nrrdUnquantize");
33
34
int
35
unrrdu_unquantizeMain(int argc, const char **argv, const char *me,
36
                      hestParm *hparm) {
37
2
  hestOpt *opt = NULL;
38
1
  char *out, *err;
39
1
  Nrrd *nin, *nout;
40
1
  int dbl, pret;
41
1
  double oldMin, oldMax;
42
  airArray *mop;
43
44
  /* mandatory arg so that "unu unquantize" produces usage info */
45
1
  hestOptAdd(&opt, "i,input", "nin", airTypeOther, 1, 1, &nin, NULL,
46
             "input nrrd.  That this argument is required instead of "
47
             "optional, as with most unu commands, is a quirk caused by the "
48
             "need to have \"unu unquantize\" generate usage info, combined "
49
             "with the fact that all the other arguments have sensible "
50
             "defaults",
51
1
             NULL, NULL, nrrdHestNrrd);
52
1
  hestOptAdd(&opt, "min,minimum", "value", airTypeDouble, 1, 1, &oldMin, "nan",
53
             "Lowest value prior to quantization.  Defaults to "
54
             "nin->oldMin if it exists, otherwise 0.0");
55
1
  hestOptAdd(&opt, "max,maximum", "value", airTypeDouble, 1, 1, &oldMax, "nan",
56
             "Highest value prior to quantization.  Defaults to "
57
             "nin->oldMax if it exists, otherwise 1.0");
58
1
  hestOptAdd(&opt, "double", NULL, airTypeBool, 0, 0, &dbl, NULL,
59
             "Use double for output type, instead of float");
60
1
  OPT_ADD_NOUT(out, "output nrrd");
61
62
1
  mop = airMopNew();
63
1
  airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways);
64
65
2
  USAGE(_unrrdu_unquantizeInfoL);
66
  PARSE();
67
  airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways);
68
69
  nout = nrrdNew();
70
  airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways);
71
72
  if (AIR_EXISTS(oldMin))
73
    nin->oldMin = oldMin;
74
  if (AIR_EXISTS(oldMax))
75
    nin->oldMax = oldMax;
76
  if (nrrdUnquantize(nout, nin, dbl ? nrrdTypeDouble : nrrdTypeFloat)) {
77
    airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
78
    fprintf(stderr, "%s: error unquantizing nrrd:\n%s", me, err);
79
    airMopError(mop);
80
    return 1;
81
  }
82
83
  SAVE(out, nout, NULL);
84
85
  airMopOkay(mop);
86
  return 0;
87
1
}
88
89
UNRRDU_CMD(unquantize, INFO);