GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/unrrdu/lut.c Lines: 19 40 47.5 %
Date: 2017-05-26 Branches: 1 22 4.5 %

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 "Map nrrd through one univariate lookup table"
28
static const char *_unrrdu_lutInfoL =
29
(INFO
30
 " (itself represented as a nrrd). The lookup table "
31
 "can be 1D, in which case the output "
32
 "has the same dimension as the input, or 2D, in which case "
33
 "the output has one more dimension than the input, and each "
34
 "value is mapped to a scanline (along axis 0) from the "
35
 "lookup table.\n "
36
 "* Uses nrrdApply1DLut");
37
38
int
39
unrrdu_lutMain(int argc, const char **argv, const char *me,
40
               hestParm *hparm) {
41
2
  hestOpt *opt = NULL;
42
1
  char *out, *err;
43
1
  Nrrd *nin, *nlut, *nout;
44
  airArray *mop;
45
1
  int typeOut, rescale, pret, blind8BitRange;
46
1
  double min, max;
47
  NrrdRange *range=NULL;
48
49
1
  hestOptAdd(&opt, "m,map", "lut", airTypeOther, 1, 1, &nlut, NULL,
50
             "lookup table to map input nrrd through",
51
1
             NULL, NULL, nrrdHestNrrd);
52
1
  hestOptAdd(&opt, "r,rescale", NULL, airTypeInt, 0, 0, &rescale, NULL,
53
             "rescale the input values from the input range to the "
54
             "lut domain.  The lut domain is either explicitly "
55
             "defined by the axis min,max along axis 0 or 1, or, it "
56
             "is implicitly defined as zero to the length of that axis "
57
             "minus one.");
58
1
  hestOptAdd(&opt, "min,minimum", "value", airTypeDouble, 1, 1, &min, "nan",
59
             "Low end of input range. Defaults to lowest value "
60
             "found in input nrrd.  Explicitly setting this is useful "
61
             "only with rescaling (\"-r\")");
62
1
  hestOptAdd(&opt, "max,maximum", "value", airTypeDouble, 1, 1, &max, "nan",
63
             "High end of input range. Defaults to highest value "
64
             "found in input nrrd.  Explicitly setting this is useful "
65
             "only with rescaling (\"-r\")");
66
1
  hestOptAdd(&opt, "blind8", "bool", airTypeBool, 1, 1, &blind8BitRange,
67
1
             nrrdStateBlind8BitRange ? "true" : "false",
68
             "Whether to know the range of 8-bit data blindly "
69
             "(uchar is always [0,255], signed char is [-128,127]). "
70
             "Explicitly setting this is useful only with rescaling (\"-r\")");
71
1
  hestOptAdd(&opt, "t,type", "type", airTypeOther, 1, 1, &typeOut, "default",
72
             "specify the type (\"int\", \"float\", etc.) of the "
73
             "output nrrd. "
74
             "By default (not using this option), the output type "
75
             "is the lut's type.",
76
             NULL, NULL, &unrrduHestMaybeTypeCB);
77
1
  OPT_ADD_NIN(nin, "input nrrd");
78
1
  OPT_ADD_NOUT(out, "output nrrd");
79
80
1
  mop = airMopNew();
81
1
  airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways);
82
83
2
  USAGE(_unrrdu_lutInfoL);
84
  PARSE();
85
  airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways);
86
87
  nout = nrrdNew();
88
  airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways);
89
90
  /* see comment rmap.c */
91
  if (!( AIR_EXISTS(nlut->axis[nlut->dim - 1].min) &&
92
         AIR_EXISTS(nlut->axis[nlut->dim - 1].max) )) {
93
    rescale = AIR_TRUE;
94
  }
95
  if (rescale) {
96
    range = nrrdRangeNew(min, max);
97
    airMopAdd(mop, range, (airMopper)nrrdRangeNix, airMopAlways);
98
    nrrdRangeSafeSet(range, nin, blind8BitRange);
99
  }
100
101
  if (nrrdTypeDefault == typeOut) {
102
    typeOut = nlut->type;
103
  }
104
  if (nrrdApply1DLut(nout, nin, range, nlut, typeOut, rescale)) {
105
    airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
106
    fprintf(stderr, "%s: trouble applying LUT:\n%s", me, err);
107
    airMopError(mop);
108
    return 1;
109
  }
110
111
  SAVE(out, nout, NULL);
112
113
  airMopOkay(mop);
114
  return 0;
115
1
}
116
117
UNRRDU_CMD(lut, INFO);