GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/unrrdu/histo.c Lines: 20 37 54.1 %
Date: 2017-05-26 Branches: 1 16 6.2 %

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 "Create 1-D histogram of values in a nrrd"
28
static const char *_unrrdu_histoInfoL =
29
  (INFO
30
   ". Can explicitly set bounds of histogram domain or can learn these "
31
   "from the data.\n "
32
   "* Uses nrrdHisto");
33
34
int
35
unrrdu_histoMain(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, *nwght;
40
1
  char *minStr, *maxStr;
41
1
  int type, pret, blind8BitRange;
42
1
  unsigned int bins;
43
  NrrdRange *range;
44
  airArray *mop;
45
46
1
  hestOptAdd(&opt, "b,bins", "num", airTypeUInt, 1, 1, &bins, NULL,
47
             "# of bins in histogram");
48
1
  hestOptAdd(&opt, "w,weight", "nweight", airTypeOther, 1, 1, &nwght, "",
49
             "how to weigh contributions to histogram.  By default "
50
             "(not using this option), the increment is one bin count per "
51
             "sample, but by giving a nrrd, the value in the nrrd at the "
52
             "corresponding location will be the bin count increment ",
53
1
             NULL, NULL, nrrdHestNrrd);
54
1
  hestOptAdd(&opt, "min,minimum", "value", airTypeString, 1, 1,
55
             &minStr, "nan",
56
             "Value at low end of histogram, given explicitly as a "
57
             "regular number, "
58
             "*or*, if the number is given with a \"" NRRD_MINMAX_PERC_SUFF
59
             "\" suffix, this "
60
             "minimum is specified in terms of the percentage of samples in "
61
             "input that are lower. "
62
             "By default (not using this option), the lowest value "
63
             "found in input nrrd.");
64
1
  hestOptAdd(&opt, "max,maximum", "value", airTypeString, 1, 1,
65
             &maxStr, "nan",
66
             "Value at high end of histogram, given "
67
             "explicitly as a regular number, "
68
             "*or*, if the number is given with "
69
             "a \"" NRRD_MINMAX_PERC_SUFF "\" suffix, "
70
             "this maximum is specified "
71
             "in terms of the percentage of samples in input that are higher. "
72
             "Defaults to highest value found in input nrrd.");
73
1
  hestOptAdd(&opt, "blind8", "bool", airTypeBool, 1, 1, &blind8BitRange,
74
1
             nrrdStateBlind8BitRange ? "true" : "false",
75
             "Whether to know the range of 8-bit data blindly "
76
             "(uchar is always [0,255], signed char is [-128,127]).");
77
1
  OPT_ADD_TYPE(type, "type to use for bins in output histogram", "uint");
78
1
  OPT_ADD_NIN(nin, "input nrrd");
79
1
  OPT_ADD_NOUT(out, "output nrrd");
80
81
1
  mop = airMopNew();
82
1
  airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways);
83
84
2
  USAGE(_unrrdu_histoInfoL);
85
  PARSE();
86
  airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways);
87
88
  range = nrrdRangeNew(AIR_NAN, AIR_NAN);
89
  airMopAdd(mop, range, (airMopper)nrrdRangeNix, airMopAlways);
90
  nout = nrrdNew();
91
  airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways);
92
  if (nrrdRangePercentileFromStringSet(range, nin, minStr, maxStr,
93
                                       10*bins /* HEY magic */,
94
                                       blind8BitRange)
95
      || nrrdHisto(nout, nin, range, nwght, bins, type)) {
96
    airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
97
    fprintf(stderr, "%s: error with range or quantizing:\n%s", me, err);
98
    airMopError(mop);
99
    return 1;
100
  }
101
102
  SAVE(out, nout, NULL);
103
104
  airMopOkay(mop);
105
  return 0;
106
1
}
107
108
UNRRDU_CMD(histo, INFO);