GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/mite/renderMite.c Lines: 0 107 0.0 %
Date: 2017-05-26 Branches: 0 68 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 "mite.h"
25
#include "privateMite.h"
26
27
miteRender *
28
_miteRenderNew(void) {
29
  miteRender *mrr;
30
31
  mrr = (miteRender *)calloc(1, sizeof(miteRender));
32
  if (mrr) {
33
    mrr->rmop = airMopNew();
34
    if (!mrr->rmop) {
35
      airFree(mrr);
36
      return NULL;
37
    }
38
    mrr->ntxf = NULL;
39
    mrr->ntxfNum = 0;
40
    mrr->sclPvlIdx = -1;
41
    mrr->vecPvlIdx = -1;
42
    mrr->tenPvlIdx = -1;
43
    mrr->normalSpec = gageItemSpecNew();
44
    airMopAdd(mrr->rmop, mrr->normalSpec,
45
              (airMopper)gageItemSpecNix, airMopAlways);
46
    mrr->shadeSpec = miteShadeSpecNew();
47
    airMopAdd(mrr->rmop, mrr->shadeSpec,
48
              (airMopper)miteShadeSpecNix, airMopAlways);
49
    mrr->time0 = AIR_NAN;
50
    GAGE_QUERY_RESET(mrr->queryMite);
51
    mrr->queryMiteNonzero = AIR_FALSE;
52
  }
53
  return mrr;
54
}
55
56
miteRender *
57
_miteRenderNix(miteRender *mrr) {
58
59
  if (mrr) {
60
    airMopOkay(mrr->rmop);
61
    airFree(mrr);
62
  }
63
  return NULL;
64
}
65
66
int
67
miteRenderBegin(miteRender **mrrP, miteUser *muu) {
68
  static const char me[]="miteRenderBegin";
69
  gagePerVolume *pvl;
70
  int E, T, pvlIdx;
71
  gageQuery queryScl, queryVec, queryTen;
72
  gageItemSpec isp;
73
  unsigned int axi, thr;
74
75
  if (!(mrrP && muu)) {
76
    biffAddf(MITE, "%s: got NULL pointer", me);
77
    return 1;
78
  }
79
  if (_miteUserCheck(muu)) {
80
    biffAddf(MITE, "%s: problem with user-set parameters", me);
81
    return 1;
82
  }
83
  if (!( *mrrP = _miteRenderNew() )) {
84
    biffAddf(MITE, "%s: couldn't alloc miteRender", me);
85
    return 1;
86
  }
87
  if (_miteNtxfAlphaAdjust(*mrrP, muu)) {
88
    biffAddf(MITE, "%s: trouble copying and alpha-adjusting txfs", me);
89
    return 1;
90
  }
91
92
  GAGE_QUERY_RESET(queryScl);
93
  GAGE_QUERY_RESET(queryVec);
94
  GAGE_QUERY_RESET(queryTen);
95
  GAGE_QUERY_RESET((*mrrP)->queryMite);
96
  for (T=0; T<muu->ntxfNum; T++) {
97
    for (axi=1; axi<muu->ntxf[T]->dim; axi++) {
98
      miteVariableParse(&isp, muu->ntxf[T]->axis[axi].label);
99
      miteQueryAdd(queryScl, queryVec, queryTen, (*mrrP)->queryMite, &isp);
100
    }
101
  }
102
  miteVariableParse((*mrrP)->normalSpec, muu->normalStr);
103
  miteQueryAdd(queryScl, queryVec, queryTen, (*mrrP)->queryMite,
104
               (*mrrP)->normalSpec);
105
  miteShadeSpecParse((*mrrP)->shadeSpec, muu->shadeStr);
106
  miteShadeSpecQueryAdd(queryScl, queryVec, queryTen, (*mrrP)->queryMite,
107
                        (*mrrP)->shadeSpec);
108
  (*mrrP)->queryMiteNonzero = GAGE_QUERY_NONZERO((*mrrP)->queryMite);
109
110
  E = 0;
111
  pvlIdx = 0;
112
  if (muu->nsin) {
113
    if (!E) E |= !(pvl = gagePerVolumeNew(muu->gctx0, muu->nsin, gageKindScl));
114
    if (!E) E |= gageQuerySet(muu->gctx0, pvl, queryScl);
115
    if (!E) E |= gagePerVolumeAttach(muu->gctx0, pvl);
116
    if (!E) (*mrrP)->sclPvlIdx = pvlIdx++;
117
  }
118
  if (muu->nvin) {
119
    if (!E) E |= !(pvl = gagePerVolumeNew(muu->gctx0, muu->nvin, gageKindVec));
120
    if (!E) E |= gageQuerySet(muu->gctx0, pvl, queryVec);
121
    if (!E) E |= gagePerVolumeAttach(muu->gctx0, pvl);
122
    if (!E) (*mrrP)->vecPvlIdx = pvlIdx++;
123
  }
124
  if (muu->ntin) {
125
    if (!E) E |= !(pvl = gagePerVolumeNew(muu->gctx0, muu->ntin, tenGageKind));
126
    if (!E) E |= gageQuerySet(muu->gctx0, pvl, queryTen);
127
    if (!E) E |= gagePerVolumeAttach(muu->gctx0, pvl);
128
    if (!E) (*mrrP)->tenPvlIdx = pvlIdx++;
129
  }
130
  if (!E) E |= gageKernelSet(muu->gctx0, gageKernel00,
131
                             muu->ksp[gageKernel00]->kernel,
132
                             muu->ksp[gageKernel00]->parm);
133
  if (!E) E |= gageKernelSet(muu->gctx0, gageKernel11,
134
                             muu->ksp[gageKernel11]->kernel,
135
                             muu->ksp[gageKernel11]->parm);
136
  if (!E) E |= gageKernelSet(muu->gctx0, gageKernel22,
137
                             muu->ksp[gageKernel22]->kernel,
138
                             muu->ksp[gageKernel22]->parm);
139
  if (!E) E |= gageUpdate(muu->gctx0);
140
  if (E) {
141
    biffMovef(MITE, GAGE, "%s: gage trouble", me);
142
    return 1;
143
  }
144
  fprintf(stderr, "!%s: kernel support = %d^3 samples\n",
145
          me, 2*muu->gctx0->radius);
146
147
  if (nrrdMaybeAlloc_va(muu->nout, mite_nt, 3,
148
                        AIR_CAST(size_t, 5) /* RGBAZ */ ,
149
                        AIR_CAST(size_t, muu->hctx->imgSize[0]),
150
                        AIR_CAST(size_t, muu->hctx->imgSize[1]))) {
151
    biffMovef(MITE, NRRD, "%s: nrrd trouble", me);
152
    return 1;
153
  }
154
  muu->nout->axis[1].center = nrrdCenterCell;
155
  muu->nout->axis[1].min = muu->hctx->cam->uRange[0];
156
  muu->nout->axis[1].max = muu->hctx->cam->uRange[1];
157
  muu->nout->axis[2].center = nrrdCenterCell;
158
  muu->nout->axis[2].min = muu->hctx->cam->vRange[0];
159
  muu->nout->axis[2].max = muu->hctx->cam->vRange[1];
160
161
  for (thr=0; thr<muu->hctx->numThreads; thr++) {
162
    (*mrrP)->tt[thr] = miteThreadNew();
163
    if (!((*mrrP)->tt[thr])) {
164
      biffAddf(MITE, "%s: couldn't allocate thread[%d]", me, thr);
165
      return 1;
166
    }
167
    airMopAdd((*mrrP)->rmop, (*mrrP)->tt[thr],
168
              (airMopper)miteThreadNix, airMopAlways);
169
  }
170
171
  (*mrrP)->time0 = airTime();
172
  return 0;
173
}
174
175
int
176
miteRenderEnd(miteRender *mrr, miteUser *muu) {
177
  unsigned int thr;
178
  double samples;
179
180
  muu->rendTime = airTime() - mrr->time0;
181
  samples = 0;
182
  for (thr=0; thr<muu->hctx->numThreads; thr++) {
183
    samples += mrr->tt[thr]->samples;
184
  }
185
  muu->sampRate = samples/(1000.0*muu->rendTime);
186
  _miteRenderNix(mrr);
187
  return 0;
188
}