GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/echo/methodsEcho.c Lines: 50 95 52.6 %
Date: 2017-05-26 Branches: 3 24 12.5 %

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 "echo.h"
25
#include "privateEcho.h"
26
27
const int
28
echoPresent = 42;
29
30
const char *
31
echoBiffKey = "echo";
32
33
echoRTParm *
34
echoRTParmNew(void) {
35
  echoRTParm *parm;
36
37
2
  parm = AIR_CALLOC(1, echoRTParm);
38
1
  if (parm) {
39
1
    parm->jitterType = echoJitterNone;
40
1
    parm->reuseJitter = AIR_FALSE;
41
1
    parm->permuteJitter = AIR_TRUE;
42
1
    parm->textureNN = AIR_TRUE;
43
1
    parm->numSamples = 1;
44
1
    parm->imgResU = parm->imgResV = 256;
45
1
    parm->maxRecDepth = 5;
46
1
    parm->renderLights = AIR_TRUE;
47
1
    parm->renderBoxes = AIR_FALSE;
48
1
    parm->seedRand = AIR_TRUE;
49
1
    parm->sqNRI = 15;
50
1
    parm->numThreads = 1;
51
1
    parm->sqTol = 0.0001;
52
1
    parm->aperture = 0.0;     /* pinhole camera by default */
53
1
    parm->timeGamma = 6.0;
54
1
    parm->boxOpac = 0.2f;
55
1
    parm->shadow = 1.0;
56
1
    parm->glassC = 3;
57
1
    ELL_3V_SET(parm->maxRecCol, 1.0, 0.0, 1.0);
58
1
  }
59
1
  return parm;
60
}
61
62
echoRTParm *
63
echoRTParmNix(echoRTParm *parm) {
64
65
2
  airFree(parm);
66
1
  return NULL;
67
}
68
69
echoGlobalState *
70
echoGlobalStateNew(void) {
71
  echoGlobalState *state;
72
73
  state = AIR_CALLOC(1, echoGlobalState);
74
  if (state) {
75
    state->verbose = 0;
76
    state->time = 0;
77
    state->nraw = NULL;
78
    state->cam = NULL;
79
    state->scene = NULL;
80
    state->parm = NULL;
81
    state->workIdx = 0;
82
    state->workMutex = NULL;
83
  }
84
  return state;
85
}
86
87
echoGlobalState *
88
echoGlobalStateNix(echoGlobalState *state) {
89
90
  airFree(state);
91
  /* mutex freed at end of echoRTRender() */
92
  return NULL;
93
}
94
95
echoThreadState *
96
echoThreadStateNew(void) {
97
  echoThreadState *state;
98
99
  state = AIR_CALLOC(1, echoThreadState);
100
  if (state) {
101
    state->thread = airThreadNew();
102
    state->verbose = 0;
103
    state->threadIdx = -1;
104
    state->depth = -1;
105
    state->njitt = nrrdNew();
106
    state->nperm = nrrdNew();
107
    state->permBuff = NULL;
108
    state->jitt = NULL;
109
    state->chanBuff = NULL;
110
    state->rst = airRandMTStateNew(0);
111
    state->returnPtr = NULL;
112
  }
113
  return state;
114
}
115
116
echoThreadState *
117
echoThreadStateNix(echoThreadState *state) {
118
119
  if (state) {
120
    state->thread = airThreadNix(state->thread);
121
    nrrdNuke(state->njitt);
122
    nrrdNuke(state->nperm);
123
    state->permBuff = AIR_CAST(unsigned int *, airFree(state->permBuff));
124
    state->chanBuff = AIR_CAST(echoCol_t *, airFree(state->chanBuff));
125
    airFree(state);
126
  }
127
  return NULL;
128
}
129
130
echoScene *
131
echoSceneNew(void) {
132
  echoScene *ret;
133
  echoPtrPtrUnion eppu;
134
135
2
  ret = AIR_CALLOC(1, echoScene);
136
1
  if (ret) {
137
1
    ret->cat = NULL;
138
1
    ret->catArr = airArrayNew((eppu.obj = &(ret->cat), eppu.v), NULL,
139
                              sizeof(echoObject *),
140
                              ECHO_LIST_OBJECT_INCR);
141
1
    airArrayPointerCB(ret->catArr,
142
                      airNull,
143
                      (void *(*)(void *))echoObjectNix);
144
1
    ret->rend = NULL;
145
1
    ret->rendArr = airArrayNew((eppu.obj = &(ret->rend), eppu.v), NULL,
146
                               sizeof(echoObject *),
147
                               ECHO_LIST_OBJECT_INCR);
148
    /* no callbacks set, renderable objecs are nixed from catArr */
149
1
    ret->light = NULL;
150
1
    ret->lightArr = airArrayNew((eppu.obj = &(ret->light), eppu.v), NULL,
151
                                sizeof(echoObject *),
152
                                ECHO_LIST_OBJECT_INCR);
153
    /* no callbacks set; light objects are nixed from catArr */
154
1
    ret->nrrd = NULL;
155
1
    ret->nrrdArr = airArrayNew((eppu.nrd = &(ret->nrrd), eppu.v), NULL,
156
                               sizeof(Nrrd *),
157
                               ECHO_LIST_OBJECT_INCR);
158
1
    airArrayPointerCB(ret->nrrdArr,
159
                      airNull,
160
                      (void *(*)(void *))nrrdNuke);
161
1
    ret->envmap = NULL;
162
1
    ELL_3V_SET(ret->ambi, 1.0, 1.0, 1.0);
163
1
    ELL_3V_SET(ret->bkgr, 0.0, 0.0, 0.0);
164
1
  }
165
1
  return ret;
166
}
167
168
void
169
_echoSceneLightAdd(echoScene *scene, echoObject *obj) {
170
  unsigned int idx;
171
172
  for (idx=0; idx<scene->lightArr->len; idx++) {
173
    if (obj == scene->light[idx]) {
174
      break;
175
    }
176
  }
177
  if (scene->lightArr->len == idx) {
178
    idx = airArrayLenIncr(scene->lightArr, 1);
179
    scene->light[idx] = obj;
180
  }
181
}
182
183
void
184
_echoSceneNrrdAdd(echoScene *scene, Nrrd *nrrd) {
185
  unsigned int idx;
186
187
  for (idx=0; idx<scene->nrrdArr->len; idx++) {
188
    if (nrrd == scene->nrrd[idx]) {
189
      break;
190
    }
191
    if (scene->nrrdArr->len == idx) {
192
      idx = airArrayLenIncr(scene->nrrdArr, 1);
193
      scene->nrrd[idx] = nrrd;
194
    }
195
  }
196
}
197
198
echoScene *
199
echoSceneNix(echoScene *scene) {
200
201
2
  if (scene) {
202
1
    airArrayNuke(scene->catArr);
203
1
    airArrayNuke(scene->rendArr);
204
1
    airArrayNuke(scene->lightArr);
205
1
    airArrayNuke(scene->nrrdArr);
206
    /* don't touch envmap nrrd */
207
1
    airFree(scene);
208
1
  }
209
1
  return NULL;
210
}