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 "limn.h" |
25 |
|
|
|
26 |
|
|
int |
27 |
|
|
limnEnvMapFill(Nrrd *map, limnEnvMapCB cb, int qnMethod, void *data) { |
28 |
|
|
static const char me[]="limnEnvMapFill"; |
29 |
|
|
unsigned int sx, sy, qn; |
30 |
|
|
float vec[3], *mapData; |
31 |
|
|
|
32 |
|
|
if (!(map && cb)) { |
33 |
|
|
biffAddf(LIMN, "%s: got NULL pointer", me); |
34 |
|
|
return 1; |
35 |
|
|
} |
36 |
|
|
if (!AIR_IN_OP(limnQNUnknown, qnMethod, limnQNLast)) { |
37 |
|
|
biffAddf(LIMN, "%s: QN method %d invalid", me, qnMethod); |
38 |
|
|
return 1; |
39 |
|
|
} |
40 |
|
|
switch(qnMethod) { |
41 |
|
|
case limnQN16checker: |
42 |
|
|
case limnQN16octa: |
43 |
|
|
sx = sy = 256; |
44 |
|
|
break; |
45 |
|
|
case limnQN14checker: |
46 |
|
|
case limnQN14octa: |
47 |
|
|
sx = sy = 128; |
48 |
|
|
break; |
49 |
|
|
case limnQN12checker: |
50 |
|
|
case limnQN12octa: |
51 |
|
|
sx = sy = 64; |
52 |
|
|
break; |
53 |
|
|
case limnQN10checker: |
54 |
|
|
case limnQN10octa: |
55 |
|
|
sx = sy = 32; |
56 |
|
|
break; |
57 |
|
|
case limnQN8checker: |
58 |
|
|
case limnQN8octa: |
59 |
|
|
sx = sy = 16; |
60 |
|
|
break; |
61 |
|
|
case limnQN15octa: |
62 |
|
|
sx = 128; |
63 |
|
|
sy = 256; |
64 |
|
|
break; |
65 |
|
|
case limnQN13octa: |
66 |
|
|
sx = 64; |
67 |
|
|
sy = 128; |
68 |
|
|
break; |
69 |
|
|
case limnQN11octa: |
70 |
|
|
sx = 32; |
71 |
|
|
sy = 64; |
72 |
|
|
break; |
73 |
|
|
case limnQN9octa: |
74 |
|
|
sx = 16; |
75 |
|
|
sy = 32; |
76 |
|
|
break; |
77 |
|
|
default: |
78 |
|
|
biffAddf(LIMN, "%s: sorry, QN method %d not implemented", me, qnMethod); |
79 |
|
|
return 1; |
80 |
|
|
} |
81 |
|
|
if (nrrdMaybeAlloc_va(map, nrrdTypeFloat, 3, |
82 |
|
|
AIR_CAST(size_t, 3), |
83 |
|
|
AIR_CAST(size_t, sx), |
84 |
|
|
AIR_CAST(size_t, sy))) { |
85 |
|
|
biffMovef(LIMN, NRRD, "%s: couldn't alloc output", me); |
86 |
|
|
return 1; |
87 |
|
|
} |
88 |
|
|
mapData = (float *)map->data; |
89 |
|
|
for (qn=0; qn<sx*sy; qn++) { |
90 |
|
|
limnQNtoV_f[qnMethod](vec, qn); |
91 |
|
|
cb(mapData + 3*qn, vec, data); |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
return 0; |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
void |
98 |
|
|
limnLightDiffuseCB(float rgb[3], float vec[3], void *_lit) { |
99 |
|
|
float dot, r, g, b, norm; |
100 |
|
|
limnLight *lit; |
101 |
|
|
int i; |
102 |
|
|
|
103 |
|
|
lit = (limnLight *)_lit; |
104 |
|
|
ELL_3V_NORM_TT(vec, float, vec, norm); |
105 |
|
|
r = lit->amb[0]; |
106 |
|
|
g = lit->amb[1]; |
107 |
|
|
b = lit->amb[2]; |
108 |
|
|
for (i=0; i<LIMN_LIGHT_NUM; i++) { |
109 |
|
|
if (!lit->on[i]) |
110 |
|
|
continue; |
111 |
|
|
dot = ELL_3V_DOT(vec, lit->dir[i]); |
112 |
|
|
dot = AIR_MAX(0, dot); |
113 |
|
|
r += dot*lit->col[i][0]; |
114 |
|
|
g += dot*lit->col[i][1]; |
115 |
|
|
b += dot*lit->col[i][2]; |
116 |
|
|
} |
117 |
|
|
/* not really our job to be doing clamping here ... */ |
118 |
|
|
rgb[0] = r; |
119 |
|
|
rgb[1] = g; |
120 |
|
|
rgb[2] = b; |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
int |
124 |
|
|
limnEnvMapCheck(Nrrd *envMap) { |
125 |
|
|
static const char me[]="limnEnvMapCheck"; |
126 |
|
|
|
127 |
|
|
if (nrrdCheck(envMap)) { |
128 |
|
|
biffMovef(LIMN, NRRD, "%s: basic nrrd validity check failed", me); |
129 |
|
|
return 1; |
130 |
|
|
} |
131 |
|
|
if (!(nrrdTypeFloat == envMap->type)) { |
132 |
|
|
biffAddf(LIMN, "%s: type should be %s, not %s", me, |
133 |
|
|
airEnumStr(nrrdType, nrrdTypeFloat), |
134 |
|
|
airEnumStr(nrrdType, envMap->type)); |
135 |
|
|
return 1; |
136 |
|
|
} |
137 |
|
|
if (!(3 == envMap->dim)) { |
138 |
|
|
biffAddf(LIMN, "%s: dimension should be 3, not %d", me, envMap->dim); |
139 |
|
|
return 1; |
140 |
|
|
} |
141 |
|
|
if (!(3 == envMap->axis[0].size |
142 |
|
|
&& 256 == envMap->axis[1].size |
143 |
|
|
&& 256 == envMap->axis[2].size)) { |
144 |
|
|
char stmp[3][AIR_STRLEN_SMALL]; |
145 |
|
|
biffAddf(LIMN, "%s: dimension should be 3x256x256, not " |
146 |
|
|
"%s x %s x %s", me, |
147 |
|
|
airSprintSize_t(stmp[0], envMap->axis[0].size), |
148 |
|
|
airSprintSize_t(stmp[1], envMap->axis[1].size), |
149 |
|
|
airSprintSize_t(stmp[2], envMap->axis[2].size)); |
150 |
|
|
return 1; |
151 |
|
|
} |
152 |
|
|
return 0; |
153 |
|
|
} |