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 |
|
|
|
25 |
|
|
#include "pull.h" |
26 |
|
|
#include "privatePull.h" |
27 |
|
|
|
28 |
|
|
void |
29 |
|
|
_pullInitParmInit(pullInitParm *initParm) { |
30 |
|
|
|
31 |
|
|
initParm->method = pullInitMethodUnknown; |
32 |
|
|
initParm->liveThreshUse = AIR_FALSE; |
33 |
|
|
initParm->unequalShapesAllow = AIR_FALSE; |
34 |
|
|
initParm->jitter = 1.0; |
35 |
|
|
initParm->numInitial = 0; |
36 |
|
|
initParm->haltonStartIndex = 0; |
37 |
|
|
initParm->samplesAlongScaleNum = 0; |
38 |
|
|
initParm->ppvZRange[0] = 1; |
39 |
|
|
initParm->ppvZRange[1] = 0; |
40 |
|
|
initParm->pointPerVoxel = 0; |
41 |
|
|
initParm->npos = NULL; |
42 |
|
|
return; |
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
#define CHECK(thing, min, max) \ |
46 |
|
|
if (!( AIR_EXISTS(iparm->thing) \ |
47 |
|
|
&& min <= iparm->thing && iparm->thing <= max )) { \ |
48 |
|
|
biffAddf(PULL, "%s: initParm->" #thing " %g not in range [%g,%g]", \ |
49 |
|
|
me, iparm->thing, min, max); \ |
50 |
|
|
return 1; \ |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
int |
54 |
|
|
_pullInitParmCheck(pullInitParm *iparm) { |
55 |
|
|
static const char me[]="_pullInitParmCheck"; |
56 |
|
|
|
57 |
|
|
if (!AIR_IN_OP(pullInitMethodUnknown, iparm->method, pullInitMethodLast)) { |
58 |
|
|
biffAddf(PULL, "%s: init method %d not valid", me, iparm->method); |
59 |
|
|
return 1; |
60 |
|
|
} |
61 |
|
|
CHECK(jitter, 0.0, 2.0); |
62 |
|
|
switch (iparm->method) { |
63 |
|
|
case pullInitMethodGivenPos: |
64 |
|
|
if (nrrdCheck(iparm->npos)) { |
65 |
|
|
biffMovef(PULL, NRRD, "%s: got a broken npos", me); |
66 |
|
|
return 1; |
67 |
|
|
} |
68 |
|
|
if (!( 2 == iparm->npos->dim |
69 |
|
|
&& 4 == iparm->npos->axis[0].size |
70 |
|
|
&& (nrrdTypeDouble == iparm->npos->type |
71 |
|
|
|| nrrdTypeFloat == iparm->npos->type) )) { |
72 |
|
|
biffAddf(PULL, "%s: npos not a 2-D 4-by-N array of %s or %s" |
73 |
|
|
"(got %u-D %u-by-X of %s)", me, |
74 |
|
|
airEnumStr(nrrdType, nrrdTypeFloat), |
75 |
|
|
airEnumStr(nrrdType, nrrdTypeDouble), |
76 |
|
|
iparm->npos->dim, |
77 |
|
|
AIR_CAST(unsigned int, iparm->npos->axis[0].size), |
78 |
|
|
airEnumStr(nrrdType, iparm->npos->type)); |
79 |
|
|
return 1; |
80 |
|
|
} |
81 |
|
|
break; |
82 |
|
|
case pullInitMethodPointPerVoxel: |
83 |
|
|
if (iparm->pointPerVoxel < -3001 || iparm->pointPerVoxel > 10) { |
84 |
|
|
biffAddf(PULL, "%s: pointPerVoxel %d unreasonable", me, |
85 |
|
|
iparm->pointPerVoxel); |
86 |
|
|
return 1; |
87 |
|
|
} |
88 |
|
|
if (-1 == iparm->pointPerVoxel) { |
89 |
|
|
biffAddf(PULL, "%s: pointPerVoxel should be < -1 or >= 1", me); |
90 |
|
|
return 1; |
91 |
|
|
} |
92 |
|
|
if (0 == iparm->jitter && 1 < iparm->pointPerVoxel) { |
93 |
|
|
biffAddf(PULL, "%s: must have jitter > 0 if pointPerVoxel (%d) > 1", me, |
94 |
|
|
iparm->pointPerVoxel); |
95 |
|
|
return 1; |
96 |
|
|
} |
97 |
|
|
break; |
98 |
|
|
case pullInitMethodRandom: |
99 |
|
|
case pullInitMethodHalton: |
100 |
|
|
if (!( iparm->numInitial >= 1 )) { |
101 |
|
|
biffAddf(PULL, "%s: iparm->numInitial (%d) not >= 1\n", me, |
102 |
|
|
iparm->numInitial); |
103 |
|
|
return 1; |
104 |
|
|
} |
105 |
|
|
break; |
106 |
|
|
/* no check needed on haltonStartIndex */ |
107 |
|
|
default: |
108 |
|
|
biffAddf(PULL, "%s: init method %d valid but not handled?", me, |
109 |
|
|
iparm->method); |
110 |
|
|
return 1; |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
return 0; |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
int |
117 |
|
|
pullInitRandomSet(pullContext *pctx, unsigned int numInitial) { |
118 |
|
|
static const char me[]="pullInitRandomSet"; |
119 |
|
|
|
120 |
|
|
if (!pctx) { |
121 |
|
|
biffAddf(PULL, "%s: got NULL pointer", me); |
122 |
|
|
return 1; |
123 |
|
|
} |
124 |
|
|
if (!numInitial) { |
125 |
|
|
biffAddf(PULL, "%s: need non-zero numInitial", me); |
126 |
|
|
return 1; |
127 |
|
|
} |
128 |
|
|
|
129 |
|
|
pctx->initParm.method = pullInitMethodRandom; |
130 |
|
|
pctx->initParm.numInitial = numInitial; |
131 |
|
|
return 0; |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
int |
135 |
|
|
pullInitHaltonSet(pullContext *pctx, unsigned int numInitial, |
136 |
|
|
unsigned int startIndex) { |
137 |
|
|
static const char me[]="pullInitHaltonSet"; |
138 |
|
|
|
139 |
|
|
if (!pctx) { |
140 |
|
|
biffAddf(PULL, "%s: got NULL pointer", me); |
141 |
|
|
return 1; |
142 |
|
|
} |
143 |
|
|
if (!numInitial) { |
144 |
|
|
biffAddf(PULL, "%s: need non-zero numInitial", me); |
145 |
|
|
return 1; |
146 |
|
|
} |
147 |
|
|
|
148 |
|
|
pctx->initParm.method = pullInitMethodHalton; |
149 |
|
|
pctx->initParm.numInitial = numInitial; |
150 |
|
|
pctx->initParm.haltonStartIndex = startIndex; |
151 |
|
|
return 0; |
152 |
|
|
} |
153 |
|
|
|
154 |
|
|
int |
155 |
|
|
pullInitPointPerVoxelSet(pullContext *pctx, int pointPerVoxel, |
156 |
|
|
unsigned int zSlcMin, unsigned int zSlcMax, |
157 |
|
|
unsigned int alongScaleNum, |
158 |
|
|
double jitter) { |
159 |
|
|
static const char me[]="pullInitPointPerVoxelSet"; |
160 |
|
|
|
161 |
|
|
if (!pctx) { |
162 |
|
|
biffAddf(PULL, "%s: got NULL pointer", me); |
163 |
|
|
return 1; |
164 |
|
|
} |
165 |
|
|
if (!pointPerVoxel) { |
166 |
|
|
biffAddf(PULL, "%s: need non-zero pointPerVoxel", me); |
167 |
|
|
return 1; |
168 |
|
|
} |
169 |
|
|
if (!AIR_EXISTS(jitter)) { |
170 |
|
|
biffAddf(PULL, "%s: got non-existent jitter %g", me, jitter); |
171 |
|
|
return 1; |
172 |
|
|
} |
173 |
|
|
|
174 |
|
|
pctx->initParm.method = pullInitMethodPointPerVoxel; |
175 |
|
|
pctx->initParm.pointPerVoxel = pointPerVoxel; |
176 |
|
|
pctx->initParm.samplesAlongScaleNum = alongScaleNum; |
177 |
|
|
pctx->initParm.ppvZRange[0] = zSlcMin; |
178 |
|
|
pctx->initParm.ppvZRange[1] = zSlcMax; |
179 |
|
|
pctx->initParm.jitter = jitter; |
180 |
|
|
return 0; |
181 |
|
|
} |
182 |
|
|
|
183 |
|
|
int |
184 |
|
|
pullInitGivenPosSet(pullContext *pctx, const Nrrd *npos) { |
185 |
|
|
static const char me[]="pullInitGivenPosSet"; |
186 |
|
|
|
187 |
|
|
if (!(pctx && npos)) { |
188 |
|
|
biffAddf(PULL, "%s: got NULL pointer", me); |
189 |
|
|
return 1; |
190 |
|
|
} |
191 |
|
|
|
192 |
|
|
pctx->initParm.method = pullInitMethodGivenPos; |
193 |
|
|
pctx->initParm.npos = npos; |
194 |
|
|
return 0; |
195 |
|
|
} |
196 |
|
|
|
197 |
|
|
int |
198 |
|
|
pullInitLiveThreshUseSet(pullContext *pctx, int liveThreshUse) { |
199 |
|
|
static const char me[]="pullInitLiveThreshUseSet"; |
200 |
|
|
|
201 |
|
|
if (!pctx) { |
202 |
|
|
biffAddf(PULL, "%s: got NULL pointer", me); |
203 |
|
|
return 1; |
204 |
|
|
} |
205 |
|
|
|
206 |
|
|
pctx->initParm.liveThreshUse = liveThreshUse; |
207 |
|
|
return 0; |
208 |
|
|
} |
209 |
|
|
|
210 |
|
|
int |
211 |
|
|
pullInitUnequalShapesAllowSet(pullContext *pctx, int allow) { |
212 |
|
|
static const char me[]="pullInitUnequalShapesAllowSet"; |
213 |
|
|
|
214 |
|
|
if (!pctx) { |
215 |
|
|
biffAddf(PULL, "%s: got NULL pointer", me); |
216 |
|
|
return 1; |
217 |
|
|
} |
218 |
|
|
|
219 |
|
|
pctx->initParm.unequalShapesAllow = allow; |
220 |
|
|
return 0; |
221 |
|
|
} |
222 |
|
|
|
223 |
|
|
#undef CHECK |
224 |
|
|
|
225 |
|
|
FILE * |
226 |
|
|
_pullPointAddLog = NULL; |