GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: Testing/ten/glyphBqd.c Lines: 26 41 63.4 %
Date: 2017-05-26 Branches: 10 18 55.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 "teem/ten.h"
25
#include <testDataPath.h>
26
27
/*
28
** Tests:
29
*/
30
31
int
32
main(int argc, const char **argv) {
33
  airArray *mop;
34
35
  Nrrd *nabc, *nref;
36
  double *abc;
37
  unsigned int sz, ui, vi, bi, betaMaxNum;
38
2
  double uv[2], betaMax[2] = {2.5555555555, 3.888888888888};
39
1
  char *err, *refname, explain[AIR_STRLEN_LARGE];
40
1
  int differ, ret;
41
42
1
  mop = airMopNew();
43
1
  nabc = nrrdNew();
44
1
  airMopAdd(mop, nabc, (airMopper)nrrdNuke, airMopAlways);
45
  sz = 100;
46
  betaMaxNum = AIR_CAST(unsigned int, sizeof(betaMax)/sizeof(double));
47
1
  if (nrrdMaybeAlloc_va(nabc, nrrdTypeDouble, 3,
48
                        AIR_CAST(size_t, 3),
49
                        AIR_CAST(size_t, sz),
50
                        AIR_CAST(size_t, sz*betaMaxNum))) {
51
    airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
52
    fprintf(stderr, "trouble allocating:\n%s", err);
53
    airMopError(mop); return 1;
54
  }
55
56
1
  abc = AIR_CAST(double *, nabc->data);
57
6
  for (bi=0; bi<betaMaxNum; bi++) {
58
404
    for (vi=0; vi<sz; vi++) {
59
200
      uv[1] = NRRD_CELL_POS(0.0, 1.0, sz, vi);
60
40400
      for (ui=0; ui<sz; ui++) {
61
20000
        uv[0] = NRRD_CELL_POS(0.0, 1.0, sz, ui);
62
20000
        tenGlyphBqdAbcUv(abc + 3*(ui + sz*(vi + sz*bi)), uv, betaMax[bi]);
63
      }
64
    }
65
  }
66
67
1
  refname = testDataPathPrefix("test/tenGlyphBqdAbcUv.nrrd");
68
1
  airMopAdd(mop, refname, airFree, airMopAlways);
69
1
  nref = nrrdNew();
70
1
  airMopAdd(mop, nref, (airMopper)nrrdNuke, airMopAlways);
71
2
  if (nrrdLoad(nref, refname, NULL)
72
2
      || nrrdCompare(nref, nabc, AIR_FALSE /* onlyData */,
73
1
                     5e-15 /* epsilon */, &differ, explain)) {
74
    airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
75
    fprintf(stderr, "trouble loading or comparing with ref:\n%s", err);
76
    airMopError(mop); return 1;
77
  }
78
79
1
  if (differ) {
80
    printf("generated and reference arrays differ:\n%s\n", explain);
81
    if (2 == argc) {
82
      if (nrrdSave(argv[1], nabc, NULL)) {
83
        airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
84
        fprintf(stderr, "oops, can't save generated array:\n%s", err);
85
      } else {
86
        printf("%s: saved generated (and different) array as %s\n",
87
               argv[0], argv[1]);
88
      }
89
    }
90
    ret = 1;
91
  } else {
92
1
    printf("All ok.\n");
93
    ret = 0;
94
  }
95
96
1
  airMopOkay(mop);
97
1
  return ret;
98
1
}