GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/unrrdu/ccmerge.c Lines: 18 35 51.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 "Merge CCs with their neighbors, under various constraints"
28
static const char *_unrrdu_ccmergeInfoL =
29
(INFO
30
 ".  This operates on the output of \"ccfind\". "
31
 "Merging of a CC is always done into its largest neighbor. "
32
 "Whether or not to merge can be constrained by one or more of: "
33
 "CC size (\"-s\"), original CC value being brighter or darker (\"-d\"), "
34
 "and number of neighbors (\"-n\").\n "
35
 "* Uses nrrdCCMerge");
36
37
int
38
unrrdu_ccmergeMain(int argc, const char **argv, const char *me,
39
                   hestParm *hparm) {
40
2
  hestOpt *opt = NULL;
41
1
  char *out, *err;
42
1
  Nrrd *nin, *nout, *nout2, *nval;
43
  airArray *mop;
44
1
  int pret, maxSize, dir, maxNeigh, revalue;
45
1
  unsigned int conny;
46
47
1
  hestOptAdd(&opt, "d,directed", "dir", airTypeInt, 1, 1, &dir, "0",
48
             "do value-driven merging.  Using (positive) \"1\" says that "
49
             "dark islands get merged with bright surrounds, while \"-1\" "
50
             "says the opposite.  By default, merging can go either way. ");
51
1
  hestOptAdd(&opt, "s,size", "max size", airTypeInt, 1, 1, &maxSize, "0",
52
             "a cap on the CC size that will be absorbed into its "
53
             "surround.  CCs larger than this are deemed too significant "
54
             "to mess with.  Or, use \"0\" to remove any such restriction "
55
             "on merging.");
56
1
  hestOptAdd(&opt, "n,neighbor", "max # neigh", airTypeInt, 1, 1,
57
             &maxNeigh, "1",
58
             "a cap on the number of neighbors that a CC may have if it is "
59
             "to be be merged.  \"1\" allows only islands to be merged, "
60
             "\"2\" does merging with bigger of two neighbors, etc, while "
61
             "\"0\" says that number of neighbors is no constraint");
62
1
  hestOptAdd(&opt, "c,connect", "connectivity", airTypeUInt, 1, 1,
63
             &conny, NULL,
64
             "what kind of connectivity to use: the number of coordinates "
65
             "that vary in order to traverse the neighborhood of a given "
66
             "sample.  In 2D: \"1\": 4-connected, \"2\": 8-connected");
67
1
  hestOptAdd(&opt, "revalue", NULL, airTypeInt, 0, 0, &revalue, NULL,
68
             "If this option is given, then after the merging, the CCs "
69
             "are re-assigned their original datavalues, as given by "
70
             "the \"-v\" option");
71
1
  OPT_ADD_NIN(nin, "input nrrd");
72
1
  hestOptAdd(&opt, "v,values", "values", airTypeOther, 1, 1, &nval, "",
73
             "result of using \"ccfind -v\", the record of which values "
74
             "were originally associated with each CC.  This is required "
75
             "for value-directed merging (with non-zero \"-d\" option), "
76
             "or if the \"-revalue\" option is given, "
77
             "but is not needed otherwise",
78
1
             NULL, NULL, nrrdHestNrrd);
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_ccmergeInfoL);
85
  PARSE();
86
  airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways);
87
88
  airMopAdd(mop, nout=nrrdNew(), (airMopper)nrrdNuke, airMopAlways);
89
  airMopAdd(mop, nout2=nrrdNew(), (airMopper)nrrdNuke, airMopAlways);
90
91
  if (nrrdCCMerge(nout, nin, nval, dir, maxSize, maxNeigh, conny)) {
92
    airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
93
    fprintf(stderr, "%s: error doing merging:\n%s", me, err);
94
    airMopError(mop);
95
    return 1;
96
  }
97
  if (revalue && nrrdCCRevalue(nout2, nout, nval)) {
98
    airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
99
    fprintf(stderr, "%s: error doing CC revalue:\n%s", me, err);
100
    airMopError(mop);
101
    return 1;
102
  }
103
104
  SAVE(out, revalue ? nout2 : nout, NULL);
105
106
  airMopOkay(mop);
107
  return 0;
108
1
}
109
110
UNRRDU_CMD(ccmerge, INFO);