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 |
|
|
miteUser * |
28 |
|
|
miteUserNew() { |
29 |
|
|
miteUser *muu; |
30 |
|
|
int i; |
31 |
|
|
|
32 |
|
|
muu = (miteUser *)calloc(1, sizeof(miteUser)); |
33 |
|
|
if (!muu) |
34 |
|
|
return NULL; |
35 |
|
|
|
36 |
|
|
muu->umop = airMopNew(); |
37 |
|
|
muu->nsin = NULL; |
38 |
|
|
muu->nvin = NULL; |
39 |
|
|
muu->ntin = NULL; |
40 |
|
|
muu->ntxf = NULL; /* managed by user (with miter: hest) */ |
41 |
|
|
muu->nout = NULL; /* managed by user (with miter: hest) */ |
42 |
|
|
muu->debug = NULL; |
43 |
|
|
muu->debugArr = NULL; |
44 |
|
|
muu->ndebug = NULL; /* not allocated until the debug pixel |
45 |
|
|
is rendered, see miteRayBegin */ |
46 |
|
|
muu->ntxfNum = 0; |
47 |
|
|
muu->shadeStr[0] = 0; |
48 |
|
|
muu->normalStr[0] = 0; |
49 |
|
|
for (i=0; i<MITE_RANGE_NUM; i++) { |
50 |
|
|
muu->rangeInit[i] = 1.0; |
51 |
|
|
} |
52 |
|
|
muu->normalSide = miteDefNormalSide; |
53 |
|
|
muu->refStep = miteDefRefStep; |
54 |
|
|
muu->rayStep = AIR_NAN; |
55 |
|
|
muu->opacMatters = miteDefOpacMatters; |
56 |
|
|
muu->opacNear1 = miteDefOpacNear1; |
57 |
|
|
muu->hctx = hooverContextNew(); |
58 |
|
|
ELL_3V_SET(muu->fakeFrom, AIR_NAN, AIR_NAN, AIR_NAN); |
59 |
|
|
ELL_3V_SET(muu->vectorD, 0, 0, 0); |
60 |
|
|
airMopAdd(muu->umop, muu->hctx, (airMopper)hooverContextNix, airMopAlways); |
61 |
|
|
for (i=gageKernelUnknown+1; i<gageKernelLast; i++) { |
62 |
|
|
muu->ksp[i] = NULL; |
63 |
|
|
} |
64 |
|
|
muu->shape = gageShapeNew(); |
65 |
|
|
muu->gctx0 = gageContextNew(); |
66 |
|
|
airMopAdd(muu->umop, muu->shape, (airMopper)gageShapeNix, airMopAlways); |
67 |
|
|
airMopAdd(muu->umop, muu->gctx0, (airMopper)gageContextNix, airMopAlways); |
68 |
|
|
/* gageParmSet(muu->gctx0, gageParmRequireAllSpacings, AIR_FALSE); */ |
69 |
|
|
muu->lit = limnLightNew(); |
70 |
|
|
airMopAdd(muu->umop, muu->lit, (airMopper)limnLightNix, airMopAlways); |
71 |
|
|
muu->normalSide = miteDefNormalSide; |
72 |
|
|
muu->verbUi = muu->verbVi = -1; |
73 |
|
|
muu->rendTime = 0; |
74 |
|
|
muu->sampRate = 0; |
75 |
|
|
return muu; |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
miteUser * |
79 |
|
|
miteUserNix(miteUser *muu) { |
80 |
|
|
|
81 |
|
|
if (muu) { |
82 |
|
|
airMopOkay(muu->umop); |
83 |
|
|
airFree(muu); |
84 |
|
|
} |
85 |
|
|
return NULL; |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
int |
89 |
|
|
_miteUserCheck(miteUser *muu) { |
90 |
|
|
static const char me[]="_miteUserCheck"; |
91 |
|
|
int T, gotOpac; |
92 |
|
|
gageItemSpec isp; |
93 |
|
|
gageQuery queryScl, queryVec, queryTen, queryMite; |
94 |
|
|
miteShadeSpec *shpec; |
95 |
|
|
airArray *mop; |
96 |
|
|
unsigned int axi; |
97 |
|
|
|
98 |
|
|
if (!muu) { |
99 |
|
|
biffAddf(MITE, "%s: got NULL pointer", me); |
100 |
|
|
return 1; |
101 |
|
|
} |
102 |
|
|
mop = airMopNew(); |
103 |
|
|
if (!( muu->ntxfNum >= 1 )) { |
104 |
|
|
biffAddf(MITE, "%s: need at least one transfer function", me); |
105 |
|
|
airMopError(mop); return 1; |
106 |
|
|
} |
107 |
|
|
gotOpac = AIR_FALSE; |
108 |
|
|
GAGE_QUERY_RESET(queryScl); |
109 |
|
|
GAGE_QUERY_RESET(queryVec); |
110 |
|
|
GAGE_QUERY_RESET(queryTen); |
111 |
|
|
GAGE_QUERY_RESET(queryMite); /* not actually used here */ |
112 |
|
|
|
113 |
|
|
/* add on all queries associated with transfer functions */ |
114 |
|
|
for (T=0; T<muu->ntxfNum; T++) { |
115 |
|
|
if (miteNtxfCheck(muu->ntxf[T])) { |
116 |
|
|
biffAddf(MITE, "%s: ntxf[%d] (%d of %d) can't be used as a txf", |
117 |
|
|
me, T, T+1, muu->ntxfNum); |
118 |
|
|
airMopError(mop); return 1; |
119 |
|
|
} |
120 |
|
|
/* NOTE: no error checking because miteNtxfCheck succeeded */ |
121 |
|
|
for (axi=1; axi<muu->ntxf[T]->dim; axi++) { |
122 |
|
|
miteVariableParse(&isp, muu->ntxf[T]->axis[axi].label); |
123 |
|
|
miteQueryAdd(queryScl, queryVec, queryTen, queryMite, &isp); |
124 |
|
|
} |
125 |
|
|
gotOpac |= !!strchr(muu->ntxf[T]->axis[0].label, 'A'); |
126 |
|
|
} |
127 |
|
|
if (!gotOpac) { |
128 |
|
|
fprintf(stderr, "\n\n%s: ****************************************" |
129 |
|
|
"************************\n", me); |
130 |
|
|
fprintf(stderr, "%s: !!! WARNING !!! opacity (\"A\") not set " |
131 |
|
|
"by any transfer function\n", me); |
132 |
|
|
fprintf(stderr, "%s: ****************************************" |
133 |
|
|
"************************\n\n\n", me); |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
/* add on "normal"-based queries */ |
137 |
|
|
if (airStrlen(muu->normalStr)) { |
138 |
|
|
miteVariableParse(&isp, muu->normalStr); |
139 |
|
|
if (miteValGageKind == isp.kind) { |
140 |
|
|
biffAddf(MITE, "%s: normalStr \"%s\" refers to a miteVal " |
141 |
|
|
"(normal must be data-intrinsic)", me, muu->normalStr); |
142 |
|
|
airMopError(mop); return 1; |
143 |
|
|
} |
144 |
|
|
if (3 != isp.kind->table[isp.item].answerLength) { |
145 |
|
|
biffAddf(MITE, "%s: %s not a vector: can't be used as normal", |
146 |
|
|
me, muu->normalStr); |
147 |
|
|
return 1; |
148 |
|
|
} |
149 |
|
|
miteQueryAdd(queryScl, queryVec, queryTen, queryMite, &isp); |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
/* add on shading-based queries */ |
153 |
|
|
shpec = miteShadeSpecNew(); |
154 |
|
|
airMopAdd(mop, shpec, (airMopper)miteShadeSpecNix, airMopAlways); |
155 |
|
|
if (miteShadeSpecParse(shpec, muu->shadeStr)) { |
156 |
|
|
biffAddf(MITE, "%s: couldn't parse shading spec \"%s\"", |
157 |
|
|
me, muu->shadeStr); |
158 |
|
|
airMopError(mop); return 1; |
159 |
|
|
} |
160 |
|
|
miteShadeSpecQueryAdd(queryScl, queryVec, queryTen, queryMite, shpec); |
161 |
|
|
|
162 |
|
|
/* see if anyone asked for an unspecified normal */ |
163 |
|
|
if ((GAGE_QUERY_ITEM_TEST(queryMite, miteValNdotV) |
164 |
|
|
|| GAGE_QUERY_ITEM_TEST(queryMite, miteValNdotL) |
165 |
|
|
|| GAGE_QUERY_ITEM_TEST(queryMite, miteValVrefN)) |
166 |
|
|
&& !airStrlen(muu->normalStr)) { |
167 |
|
|
biffAddf(MITE, "%s: txf or shading requested a miteVal's use of the " |
168 |
|
|
"\"normal\", but one has not been specified in muu->normalStr", |
169 |
|
|
me); |
170 |
|
|
airMopError(mop); return 1; |
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
/* see if we have volumes for requested queries */ |
174 |
|
|
if (GAGE_QUERY_NONZERO(queryScl) && !(muu->nsin)) { |
175 |
|
|
biffAddf(MITE, "%s: txf or shading require %s volume, but don't have one", |
176 |
|
|
me, gageKindScl->name); |
177 |
|
|
airMopError(mop); return 1; |
178 |
|
|
} |
179 |
|
|
if (GAGE_QUERY_NONZERO(queryVec) && !(muu->nvin)) { |
180 |
|
|
biffAddf(MITE, "%s: txf or shading require %s volume, but don't have one", |
181 |
|
|
me, gageKindVec->name); |
182 |
|
|
airMopError(mop); return 1; |
183 |
|
|
} |
184 |
|
|
if (GAGE_QUERY_NONZERO(queryTen) && !(muu->ntin)) { |
185 |
|
|
biffAddf(MITE, "%s: txf or shading require %s volume, but don't have one", |
186 |
|
|
me, tenGageKind->name); |
187 |
|
|
airMopError(mop); return 1; |
188 |
|
|
} |
189 |
|
|
|
190 |
|
|
/* check appropriateness of given volumes */ |
191 |
|
|
if (muu->nsin) { |
192 |
|
|
if (gageVolumeCheck(muu->gctx0, muu->nsin, gageKindScl)) { |
193 |
|
|
biffMovef(MITE, GAGE, "%s: trouble with input %s volume", |
194 |
|
|
me, gageKindScl->name); |
195 |
|
|
airMopError(mop); return 1; |
196 |
|
|
} |
197 |
|
|
} |
198 |
|
|
if (muu->nvin) { |
199 |
|
|
if (gageVolumeCheck(muu->gctx0, muu->nvin, gageKindVec)) { |
200 |
|
|
biffMovef(MITE, GAGE, "%s: trouble with input %s volume", |
201 |
|
|
me, gageKindVec->name); |
202 |
|
|
airMopError(mop); return 1; |
203 |
|
|
} |
204 |
|
|
} |
205 |
|
|
if (muu->ntin) { |
206 |
|
|
if (gageVolumeCheck(muu->gctx0, muu->ntin, tenGageKind)) { |
207 |
|
|
biffMovef(MITE, GAGE, "%s: trouble with input %s volume", |
208 |
|
|
me, tenGageKind->name); |
209 |
|
|
airMopError(mop); return 1; |
210 |
|
|
} |
211 |
|
|
} |
212 |
|
|
|
213 |
|
|
if (!muu->nout) { |
214 |
|
|
biffAddf(MITE, "%s: rendered image nrrd is NULL", me); |
215 |
|
|
airMopError(mop); return 1; |
216 |
|
|
} |
217 |
|
|
airMopOkay(mop); |
218 |
|
|
return 0; |
219 |
|
|
} |