GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/unrrdu/sselect.c Lines: 17 43 39.5 %
Date: 2017-05-26 Branches: 1 30 3.3 %

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 "Select subset of slices along an axis"
28
static const char *_unrrdu_sselectInfoL =
29
  (INFO ". The choice to keep or nix a slice is determined by whether the "
30
   "values in a given 1-D line of values is above or below a given "
31
   "threshold.\n "
32
   "* Uses nrrdSliceSelect");
33
34
int
35
unrrdu_sselectMain(int argc, const char **argv, const char *me,
36
                   hestParm *hparm) {
37
2
  hestOpt *opt = NULL;
38
1
  char *err;
39
1
  Nrrd *nin, *noutAbove, *noutBelow, *nline;
40
1
  unsigned int axis;
41
1
  double thresh;
42
  int pret;
43
  airArray *mop;
44
1
  char *outS[2];
45
46
1
  OPT_ADD_NIN(nin, "input nrrd");
47
1
  OPT_ADD_AXIS(axis, "axis to slice along");
48
1
  hestOptAdd(&opt, "s,selector", "nline", airTypeOther, 1, 1, &nline, NULL,
49
             "the 1-D nrrd of values to compare with threshold",
50
1
             NULL, NULL, nrrdHestNrrd);
51
1
  hestOptAdd(&opt, "th", "thresh", airTypeDouble, 1, 1, &thresh,
52
             NULL, "threshold on selector line");
53
1
  hestOptAdd(&opt, "o,output", "above below", airTypeString, 2, 2,
54
1
             outS, "- x",
55
             "outputs for slices corresponding to values "
56
             "above (first) and below (second) given threshold. "
57
             "Use \"x\" to say that no output is desired.");
58
59
1
  mop = airMopNew();
60
1
  airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways);
61
62
2
  USAGE(_unrrdu_sselectInfoL);
63
  PARSE();
64
  airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways);
65
66
  if (!strcmp(outS[0], "x") && !strcmp(outS[1], "x")) {
67
    fprintf(stderr, "%s: need to save either above or below slices "
68
            "(can't use \"x\" for both)\n", me);
69
    airMopError(mop);
70
    return 1;
71
  }
72
  if (strcmp(outS[0], "x")) {
73
    noutAbove = nrrdNew();
74
    airMopAdd(mop, noutAbove, (airMopper)nrrdNuke, airMopAlways);
75
  } else {
76
    noutAbove = NULL;
77
  }
78
  if (strcmp(outS[1], "x")) {
79
    noutBelow = nrrdNew();
80
    airMopAdd(mop, noutBelow, (airMopper)nrrdNuke, airMopAlways);
81
  } else {
82
    noutBelow = NULL;
83
  }
84
85
  if (nrrdSliceSelect(noutAbove, noutBelow, nin, axis,
86
                      nline, thresh)) {
87
    airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
88
    fprintf(stderr, "%s: error selecting slices:\n%s", me, err);
89
    airMopError(mop);
90
    return 1;
91
  }
92
93
  if (noutAbove) {
94
    SAVE(outS[0], noutAbove, NULL);
95
  }
96
  if (noutBelow) {
97
    SAVE(outS[1], noutBelow, NULL);
98
  }
99
100
  airMopOkay(mop);
101
  return 0;
102
1
}
103
104
UNRRDU_CMD(sselect, INFO);