GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/seek/setSeek.c Lines: 0 192 0.0 %
Date: 2017-05-26 Branches: 0 108 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 "seek.h"
25
#include "privateSeek.h"
26
27
/*
28
******** seekVerboseSet
29
**
30
*/
31
void
32
seekVerboseSet(seekContext *sctx, int verbose) {
33
34
  if (sctx) {
35
    sctx->verbose = verbose;
36
  }
37
  return;
38
}
39
40
/*
41
******** seekDataSet
42
**
43
** user sets EITHER: ninscl, or, gctx and pvlIdx
44
**
45
** if ninscl: this is a vanilla scalar volume, and we can do seekTypeIsocontour
46
** if gctx: this is a scalar or non-scalar volume, and we can do any seekType
47
**
48
** sets from input:
49
** ninscl, gctx, pvl
50
**
51
** So the rest of seek can use "if (sctx->ninscl)" to see if we're working
52
** with a vanilla scalar volume or not
53
**
54
** invalidates:
55
** valItem, normItem, gradItem, evalItem, evecItem
56
*/
57
int
58
seekDataSet(seekContext *sctx, const Nrrd *ninscl,
59
            gageContext *gctx, unsigned int pvlIdx) {
60
  static const char me[]="seekDataSet";
61
62
  if (!( sctx && (ninscl || gctx) )) {
63
    biffAddf(SEEK, "%s: got NULL pointer", me);
64
    return 1;
65
  }
66
  if (ninscl && gctx) {
67
    biffAddf(SEEK, "%s: must give ninscl or gctx, but not both", me);
68
    return 1;
69
  }
70
71
  if (ninscl) {
72
    if (nrrdCheck(ninscl)) {
73
      biffMovef(SEEK, NRRD, "%s: problem with volume", me);
74
      return 1;
75
    }
76
    if (3 != ninscl->dim) {
77
      biffAddf(SEEK, "%s: vanilla scalar volume must be 3-D (not %d-D)",
78
               me, ninscl->dim);
79
      return 1;
80
    }
81
    if (nrrdTypeBlock == ninscl->type) {
82
      biffAddf(SEEK, "%s: can't work with %s type values", me,
83
               airEnumStr(nrrdType, nrrdTypeBlock));
84
      return 1;
85
    }
86
    sctx->ninscl = ninscl;
87
    sctx->gctx = NULL;
88
    sctx->pvl = NULL;
89
  } else {
90
    if (!( pvlIdx < gctx->pvlNum )) {
91
      biffAddf(SEEK, "%s: pvlIdx %u not < pvlNum %u",
92
               me, pvlIdx, gctx->pvlNum);
93
      return 1;
94
    }
95
    /* we assume that caller has done a gageUpdate(), so no other error
96
       checking is required (or really possible) here */
97
    sctx->ninscl = NULL;
98
    sctx->gctx = gctx;
99
    sctx->pvl = gctx->pvl[pvlIdx];
100
  }
101
  sctx->flag[flagData] = AIR_TRUE;
102
103
  sctx->sclvItem = -1;
104
  sctx->normItem = -1;
105
  sctx->gradItem = -1;
106
  sctx->evalItem = -1;
107
  sctx->evecItem = -1;
108
  sctx->hessItem = -1;
109
110
  return 0;
111
}
112
113
/*
114
******** seekSamplesSet
115
**
116
** sets: samples[3]
117
*/
118
int
119
seekSamplesSet(seekContext *sctx, size_t samples[3]) {
120
  static const char me[]="seekSamplesSet";
121
  unsigned int numZero;
122
123
  if (!(sctx && samples)) {
124
    biffAddf(SEEK, "%s: got NULL pointer", me);
125
    return 1;
126
  }
127
  numZero = 0;
128
  numZero += 0 == samples[0];
129
  numZero += 0 == samples[1];
130
  numZero += 0 == samples[2];
131
  if (!( 0 == numZero || 3 == numZero )) {
132
    biffAddf(SEEK, "%s: samples (%u,%u,%u) must all be 0 or !=0 together", me,
133
             AIR_CAST(unsigned int, samples[0]),
134
             AIR_CAST(unsigned int, samples[1]),
135
             AIR_CAST(unsigned int, samples[2]));
136
    return 1;
137
  }
138
  if (sctx->samples[0] != samples[0]
139
      || sctx->samples[1] != samples[1]
140
      || sctx->samples[2] != samples[2]) {
141
    sctx->samples[0] = samples[0];
142
    sctx->samples[1] = samples[1];
143
    sctx->samples[2] = samples[2];
144
    sctx->flag[flagSamples] = AIR_TRUE;
145
  }
146
  return 0;
147
}
148
149
/*
150
******** seekTypeSet
151
**
152
** sets: featureType
153
*/
154
int
155
seekTypeSet(seekContext *sctx, int type) {
156
  static const char me[]="seekTypeSet";
157
158
  if (!sctx) {
159
    biffAddf(SEEK, "%s: got NULL pointer", me);
160
    return 1;
161
  }
162
  if (airEnumValCheck(seekType, type)) {
163
    biffAddf(SEEK, "%s: %d not a valid %s", me, type, seekType->name);
164
    return 1;
165
  }
166
  if (sctx->type != type) {
167
    sctx->type = type;
168
    sctx->flag[flagType] = AIR_TRUE;
169
  }
170
  return 0;
171
}
172
173
/*
174
********* seekLowerInsideSet
175
**
176
** sets: lowerInside
177
*/
178
int
179
seekLowerInsideSet(seekContext *sctx, int lowerInside) {
180
  static const char me[]="seekLowerInsideSet";
181
182
  if (!sctx) {
183
    biffAddf(SEEK, "%s: got NULL pointer", me);
184
    return 1;
185
  }
186
  if (sctx->lowerInside != lowerInside) {
187
    sctx->lowerInside = lowerInside;
188
    sctx->flag[flagLowerInside] = AIR_TRUE;
189
  }
190
  return 0;
191
}
192
193
/*
194
********* seekNormalsFindSet
195
**
196
** sets: normalsFind
197
*/
198
int
199
seekNormalsFindSet(seekContext *sctx, int normalsFind) {
200
  static const char me[]="seekNormalsFindSet";
201
202
  if (!sctx) {
203
    biffAddf(SEEK, "%s: got NULL pointer", me);
204
    return 1;
205
  }
206
  if (sctx->normalsFind != normalsFind) {
207
    sctx->normalsFind = normalsFind;
208
    sctx->flag[flagNormalsFind] = AIR_TRUE;
209
  }
210
  return 0;
211
}
212
213
int
214
seekStrengthUseSet(seekContext *sctx, int doit) {
215
  static const char me[]="seekStrengthUseSet";
216
217
  if (!sctx) {
218
    biffAddf(SEEK, "%s: got NULL pointer", me);
219
    return 1;
220
  }
221
  if (sctx->strengthUse != doit) {
222
    sctx->strengthUse = doit;
223
    sctx->flag[flagStrengthUse] = AIR_TRUE;
224
  }
225
  return 0;
226
}
227
228
int
229
seekStrengthSet(seekContext *sctx, int strengthSign,
230
                double strength) {
231
  static const char me[]="seekStrengthSet";
232
233
  if (!sctx) {
234
    biffAddf(SEEK, "%s: got NULL pointer", me);
235
    return 1;
236
  }
237
  if (!(1 == strengthSign || -1 == strengthSign)) {
238
    biffAddf(SEEK, "%s: strengthSign (%d) not +1 or -1", me, strengthSign);
239
    return 1;
240
  }
241
  if (!AIR_EXISTS(strength)) {
242
    biffAddf(SEEK, "%s: strength %g doesn't exist", me, strength);
243
    return 1;
244
  }
245
  if (sctx->strengthSign != strengthSign) {
246
    sctx->strengthSign = strengthSign;
247
    sctx->flag[flagStrength] = AIR_TRUE;
248
  }
249
  if (sctx->strength != strength) {
250
    sctx->strength = strength;
251
    sctx->flag[flagStrength] = AIR_TRUE;
252
  }
253
  return 0;
254
}
255
256
static int
257
itemCheck(seekContext *sctx, int item, unsigned int wantLen) {
258
  static const char me[]="itemCheck";
259
260
  if (!sctx) {
261
    biffAddf(SEEK, "%s: got NULL pointer", me);
262
    return 1;
263
  }
264
  if (!(sctx->gctx && sctx->pvl)) {
265
    biffAddf(SEEK, "%s: don't have a gage context", me);
266
    return 1;
267
  }
268
  if (airEnumValCheck(sctx->pvl->kind->enm, item)) {
269
    biffAddf(SEEK, "%s: %d not valid %s item", me, item,
270
             sctx->pvl->kind->enm->name);
271
    return 1;
272
  }
273
  if (!GAGE_QUERY_ITEM_TEST(sctx->pvl->query, item)) {
274
    biffAddf(SEEK, "%s: item \"%s\" (%d) not set in query", me,
275
             airEnumStr(sctx->pvl->kind->enm, item), item);
276
    return 1;
277
  }
278
  if (sctx->pvl->kind->table[item].answerLength != wantLen) {
279
    biffAddf(SEEK, "%s: item %s has length %u, not wanted %u", me,
280
             airEnumStr(sctx->pvl->kind->enm, item),
281
             sctx->pvl->kind->table[item].answerLength, wantLen);
282
    return 1;
283
  }
284
  return 0;
285
}
286
287
/*
288
******** seekItemScalarSet
289
**
290
** sets: sclvItem
291
*/
292
int
293
seekItemScalarSet(seekContext *sctx, int item) {
294
  static const char me[]="seekItemScalarSet";
295
296
  if (itemCheck(sctx, item, 1)) {
297
    biffAddf(SEEK, "%s: trouble", me);
298
    return 1;
299
  }
300
  if (sctx->sclvItem != item) {
301
    sctx->sclvItem = item;
302
    sctx->flag[flagItemValue] = AIR_TRUE;
303
  }
304
  return 0;
305
}
306
307
/*
308
******** seekItemStrengthSet
309
**
310
*/
311
int
312
seekItemStrengthSet(seekContext *sctx, int item) {
313
  static const char me[]="seekItemStrengthSet";
314
315
  if (itemCheck(sctx, item, 1)) {
316
    biffAddf(SEEK, "%s: trouble", me);
317
    return 1;
318
  }
319
  if (sctx->stngItem != item) {
320
    sctx->stngItem = item;
321
    sctx->flag[flagItemStrength] = AIR_TRUE;
322
  }
323
  return 0;
324
}
325
326
/*
327
******** seekItemHessSet
328
**
329
*/
330
int
331
seekItemHessSet(seekContext *sctx, int item) {
332
  char me[]="seekItemHessSet";
333
334
  if (itemCheck(sctx, item, 9)) {
335
    biffAddf(SEEK, "%s: trouble", me); return 1;
336
  }
337
  if (sctx->hessItem != item) {
338
    sctx->hessItem = item;
339
    sctx->flag[flagItemHess] = AIR_TRUE;
340
  }
341
  return 0;
342
}
343
344
/*
345
******** seekItemGradientSet
346
**
347
** sets: gradItem
348
*/
349
int
350
seekItemGradientSet(seekContext *sctx, int item) {
351
  static const char me[]="seekItemGradientSet";
352
353
  if (itemCheck(sctx, item, 3)) {
354
    biffAddf(SEEK, "%s: trouble", me);
355
    return 1;
356
  }
357
  if (sctx->gradItem != item) {
358
    sctx->gradItem = item;
359
    sctx->flag[flagItemGradient] = AIR_TRUE;
360
  }
361
  /* sctx->gradAns = gageAnswerPointer(sctx->gctx, sctx->pvl, item); */
362
  return 0;
363
}
364
365
/*
366
******** seekItemNormalSet
367
**
368
** sets: normItem
369
*/
370
int
371
seekItemNormalSet(seekContext *sctx, int item) {
372
  static const char me[]="seekItemNormalSet";
373
374
  if (itemCheck(sctx, item, 3)) {
375
    biffAddf(SEEK, "%s: trouble", me);
376
    return 1;
377
  }
378
  if (sctx->normItem != item) {
379
    sctx->normItem = item;
380
    sctx->flag[flagItemNormal] = AIR_TRUE;
381
  }
382
  /* sctx->normAns = gageAnswerPointer(sctx->gctx, sctx->pvl, item); */
383
  return 0;
384
}
385
386
/*
387
******** seekItemEigensystemSet
388
**
389
** sets: evalItem, evecItem
390
*/
391
int
392
seekItemEigensystemSet(seekContext *sctx, int evalItem, int evecItem) {
393
  static const char me[]="seekItemEigenvectorSet";
394
395
  if (itemCheck(sctx, evalItem, 3)) {
396
    biffAddf(SEEK, "%s: trouble", me);
397
    return 1;
398
  }
399
  if (itemCheck(sctx, evecItem, 9)) {
400
    biffAddf(SEEK, "%s: trouble", me);
401
    return 1;
402
  }
403
  if (sctx->evalItem != evalItem
404
      || sctx->evecItem != evecItem) {
405
    sctx->evalItem = evalItem;
406
    sctx->evecItem = evecItem;
407
    sctx->flag[flagItemEigensystem] = AIR_TRUE;
408
  }
409
  /*
410
  sctx->evalAns = gageAnswerPointer(sctx->gctx, sctx->pvl, sctx->evalItem);
411
  sctx->evecAns = gageAnswerPointer(sctx->gctx, sctx->pvl, sctx->evecItem);
412
  */
413
  return 0;
414
}
415
416
/*
417
******** seekIsovalueSet
418
**
419
** sets: isovalue
420
*/
421
int
422
seekIsovalueSet(seekContext *sctx, double isovalue) {
423
  static const char me[]="seekIsovalueSet";
424
425
  if (!sctx) {
426
    biffAddf(SEEK, "%s: got NULL pointer", me);
427
    return 1;
428
  }
429
  if (!AIR_EXISTS(isovalue)) {
430
    biffAddf(SEEK, "%s: given isovalue %g doesn't exit", me, isovalue);
431
    return 1;
432
  }
433
  if (sctx->isovalue != isovalue) {
434
    sctx->isovalue = isovalue;
435
    sctx->flag[flagIsovalue] = AIR_TRUE;
436
  }
437
  return 0;
438
}
439
440
/*
441
******** seekEvalDiffThreshSet
442
**
443
** sets: difference threshold from which two eigenvalues are
444
** considered "similar" (cf. Eq. (4) in TVCG paper by
445
** Schultz/Theisel/Seidel)
446
*/
447
int
448
seekEvalDiffThreshSet(seekContext *sctx, double evalDiffThresh) {
449
  char me[]="seekEvalDiffThreshSet";
450
451
  if (!sctx) {
452
    biffAddf(SEEK, "%s: got NULL pointer", me); return 1;
453
  }
454
  if (!AIR_EXISTS(evalDiffThresh)) {
455
    biffAddf(SEEK, "%s: given eigenvalue difference threshold %g doesn't exit",
456
             me, evalDiffThresh); return 1;
457
  }
458
  if (sctx->evalDiffThresh != evalDiffThresh) {
459
    sctx->evalDiffThresh = evalDiffThresh;
460
    sctx->flag[flagEvalDiffThresh] = AIR_TRUE;
461
  }
462
  return 0;
463
}