GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/moss/methodsMoss.c Lines: 0 74 0.0 %
Date: 2017-05-26 Branches: 0 44 0.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 "moss.h"
25
#include "privateMoss.h"
26
27
const int
28
mossPresent = 42;
29
30
/*
31
******** mossSamplerNew()
32
**
33
*/
34
mossSampler *
35
mossSamplerNew (void) {
36
  mossSampler *smplr;
37
  int i;
38
39
  smplr = (mossSampler *)calloc(1, sizeof(mossSampler));
40
  if (smplr) {
41
    smplr->image = NULL;
42
    smplr->kernel = NULL;
43
    for (i=0; i<NRRD_KERNEL_PARMS_NUM; i++)
44
      smplr->kparm[i] = AIR_NAN;
45
    smplr->ivc = NULL;
46
    smplr->xFslw = smplr->yFslw = NULL;
47
    smplr->xIdx = smplr->yIdx = NULL;
48
    smplr->bg = NULL;
49
    smplr->fdiam = smplr->ncol = 0;
50
    smplr->boundary = mossDefBoundary;
51
    for (i=0; i<MOSS_FLAG_NUM; i++)
52
      smplr->flag[i] = AIR_FALSE;
53
  }
54
  return smplr;
55
}
56
57
int
58
mossSamplerFill (mossSampler *smplr, int fdiam, int ncol) {
59
  static const char me[]="_mossSamplerFill";
60
61
  if (!(smplr)) {
62
    biffAddf(MOSS, "%s: got NULL pointer", me);
63
    return 1;
64
  }
65
  smplr->ivc = (float*)calloc(fdiam*fdiam*ncol, sizeof(float));
66
  smplr->xFslw = (double*)calloc(fdiam, sizeof(double));
67
  smplr->yFslw = (double*)calloc(fdiam, sizeof(double));
68
  smplr->xIdx = (int*)calloc(fdiam, sizeof(int));
69
  smplr->yIdx = (int*)calloc(fdiam, sizeof(int));
70
  if (!( smplr->ivc && smplr->xFslw && smplr->yFslw
71
         && smplr->xIdx && smplr->yIdx )) {
72
    biffAddf(MOSS, "%s: couldn't allocate buffers", me);
73
    return 1;
74
  }
75
  smplr->fdiam = fdiam;
76
  smplr->ncol = ncol;
77
  return 0;
78
}
79
80
void
81
mossSamplerEmpty (mossSampler *smplr) {
82
83
  if (smplr) {
84
    smplr->ivc = (float *)airFree(smplr->ivc);
85
    smplr->xFslw = (double *)airFree(smplr->xFslw);
86
    smplr->yFslw = (double *)airFree(smplr->yFslw);
87
    smplr->xIdx = (int *)airFree(smplr->xIdx);
88
    smplr->yIdx = (int *)airFree(smplr->yIdx);
89
    smplr->fdiam = 0;
90
    smplr->ncol = 0;
91
  }
92
  return;
93
}
94
95
mossSampler *
96
mossSamplerNix (mossSampler *smplr) {
97
98
  if (smplr) {
99
    mossSamplerEmpty(smplr);
100
    smplr->bg = (float *)airFree(smplr->bg);
101
    free(smplr);
102
  }
103
  return NULL;
104
}
105
106
int
107
mossImageCheck (Nrrd *image) {
108
  static const char me[]="mossImageCheck";
109
110
  if (nrrdCheck(image)) {
111
    biffMovef(MOSS, NRRD, "%s: given nrrd invalid", me);
112
    return 1;
113
  }
114
  if (!( (2 == image->dim || 3 == image->dim)
115
         && nrrdTypeBlock != image->type )) {
116
    biffAddf(MOSS, "%s: image has invalid dimension (%d) or type (%s)", me,
117
             image->dim, airEnumStr(nrrdType, image->type));
118
    return 1;
119
  }
120
121
  return 0;
122
}
123
124
int
125
mossImageAlloc (Nrrd *image, int type, int sx, int sy, int ncol) {
126
  static const char me[]="mossImageAlloc";
127
  int ret;
128
129
  if (!(image && AIR_IN_OP(nrrdTypeUnknown, type, nrrdTypeBlock)
130
        && sx > 0 && sy > 0 && ncol > 0)) {
131
    biffAddf(MOSS, "%s: got NULL pointer or bad args", me);
132
    return 1;
133
  }
134
  if (1 == ncol) {
135
    ret = nrrdMaybeAlloc_va(image, type, 2,
136
                            AIR_CAST(size_t, sx),
137
                            AIR_CAST(size_t, sy));
138
  } else {
139
    ret = nrrdMaybeAlloc_va(image, type, 3,
140
                            AIR_CAST(size_t, ncol),
141
                            AIR_CAST(size_t, sx),
142
                            AIR_CAST(size_t, sy));
143
  }
144
  if (ret) {
145
    biffMovef(MOSS, NRRD, "%s: couldn't allocate image", me);
146
    return 1;
147
  }
148
149
150
  return 0;
151
}
152
153
int
154
_mossCenter(int center) {
155
156
  center =  (nrrdCenterUnknown == center
157
             ? mossDefCenter
158
             : center);
159
  center = AIR_CLAMP(nrrdCenterUnknown+1, center, nrrdCenterLast-1);
160
  return center;
161
}