GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/unrrdu/ccfind.c Lines: 14 30 46.7 %
Date: 2017-05-26 Branches: 1 20 5.0 %

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 "Find connected components (CCs)"
28
static const char *_unrrdu_ccfindInfoL =
29
(INFO
30
 ". This works on 1-byte and 2-byte integral values, as well as "
31
 "4-byte ints.\n "
32
 "* Uses nrrdCCFind");
33
34
int
35
unrrdu_ccfindMain(int argc, const char **argv, const char *me,
36
                  hestParm *hparm) {
37
2
  hestOpt *opt = NULL;
38
1
  char *out, *err, *valS;
39
1
  Nrrd *nin, *nout, *nval=NULL;
40
  airArray *mop;
41
1
  int type, pret;
42
1
  unsigned int conny;
43
44
1
  hestOptAdd(&opt, "v,values", "filename", airTypeString, 1, 1, &valS, "",
45
             "Giving a filename here allows you to save out the values "
46
             "associated with each connect component.  This can be used "
47
             "later with \"ccmerge -d\".  By default, no record of the "
48
             "original CC values is kept.");
49
1
  hestOptAdd(&opt, "t,type", "type", airTypeOther, 1, 1, &type, "default",
50
             "type to use for output, to store the CC ID values.  By default "
51
             "(not using this option), the type used will be the smallest of "
52
             "uchar, ushort, or int, that can represent all the CC ID values. "
53
             "Using this option allows one to specify the integral type to "
54
             "be used.",
55
             NULL, NULL, &unrrduHestMaybeTypeCB);
56
1
  hestOptAdd(&opt, "c,connect", "connectivity", airTypeUInt, 1, 1,
57
             &conny, NULL,
58
             "what kind of connectivity to use: the number of coordinates "
59
             "that vary in order to traverse the neighborhood of a given "
60
             "sample.  In 2D: \"1\": 4-connected, \"2\": 8-connected");
61
1
  OPT_ADD_NIN(nin, "input nrrd");
62
1
  OPT_ADD_NOUT(out, "output nrrd");
63
64
1
  mop = airMopNew();
65
1
  airMopAdd(mop, opt, (airMopper)hestOptFree, airMopAlways);
66
67
2
  USAGE(_unrrdu_ccfindInfoL);
68
  PARSE();
69
  airMopAdd(mop, opt, (airMopper)hestParseFree, airMopAlways);
70
71
  nout = nrrdNew();
72
  airMopAdd(mop, nout, (airMopper)nrrdNuke, airMopAlways);
73
74
  if (nrrdCCFind(nout, airStrlen(valS) ? &nval : NULL, nin, type, conny)) {
75
    airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
76
    fprintf(stderr, "%s: error doing connected components:\n%s", me, err);
77
    airMopError(mop);
78
    return 1;
79
  }
80
  if (nval) {
81
    airMopAdd(mop, nval, (airMopper)nrrdNuke, airMopAlways);
82
  }
83
84
  if (airStrlen(valS)) {
85
    SAVE(valS, nval, NULL);
86
  }
87
  SAVE(out, nout, NULL);
88
89
  airMopOkay(mop);
90
  return 0;
91
1
}
92
93
UNRRDU_CMD(ccfind, INFO);