@@ -20,7 +20,8 @@ For quick reference, the contents of `vklTutorial.c` are shown below.
20
20
#include < stdio.h>
21
21
22
22
#if defined(_MSC_VER)
23
- #include <malloc.h> // _ malloca
23
+ #include <malloc.h> // _ malloca
24
+ #include <windows.h> // Sleep
24
25
#endif
25
26
26
27
void demoScalarAPI (VKLVolume volume)
@@ -36,18 +37,36 @@ void demoScalarAPI(VKLVolume volume)
36
37
printf("\t\tlower = %f %f %f\n", bbox.lower.x, bbox.lower.y, bbox.lower.z);
37
38
printf("\t\tupper = %f %f %f\n\n", bbox.upper.x, bbox.upper.y, bbox.upper.z);
38
39
39
- // value range
40
- vkl_range1f valueRange = vklGetValueRange (volume);
41
- printf("\tvalue range = (%f %f) \n\n", valueRange.lower, valueRange.upper );
40
+ // number of attributes
41
+ unsigned int numAttributes = vklGetNumAttributes (volume);
42
+ printf("\tnum attributes = %d \n\n", numAttributes );
42
43
43
- // sample, gradient
44
- vkl_vec3f coord = {1.f, 1.f, 1.f};
45
- float sample = vklComputeSample(sampler, &coord);
46
- vkl_vec3f grad = vklComputeGradient(sampler, &coord);
47
- printf("\tcoord = %f %f %f\n", coord.x, coord.y, coord.z);
44
+ // value range (first attribute)
45
+ vkl_range1f valueRange = vklGetValueRange(volume);
46
+ printf("\tvalue range (first attribute) = (%f %f)\n\n",
47
+ valueRange.lower,
48
+ valueRange.upper);
49
+
50
+ // coordinate for sampling / gradients
51
+ vkl_vec3f coord = {1.f, 2.f, 3.f};
52
+ printf("\tcoord = %f %f %f\n\n", coord.x, coord.y, coord.z);
53
+
54
+ // sample, gradient (first attribute)
55
+ unsigned int attributeIndex = 0;
56
+ float sample = vklComputeSample(sampler, &coord, attributeIndex);
57
+ vkl_vec3f grad = vklComputeGradient(sampler, &coord, attributeIndex);
58
+ printf("\tsampling and gradient computation (first attribute)\n");
48
59
printf("\t\tsample = %f\n", sample);
49
60
printf("\t\tgrad = %f %f %f\n\n", grad.x, grad.y, grad.z);
50
61
62
+ // sample (multiple attributes)
63
+ unsigned int M = 3;
64
+ unsigned int attributeIndices[ ] = {0, 1, 2};
65
+ float samples[ 3] ;
66
+ vklComputeSampleM(sampler, &coord, samples, M, attributeIndices);
67
+ printf("\tsampling (multiple attributes)\n");
68
+ printf("\t\tsamples = %f %f %f\n\n", samples[ 0] , samples[ 1] , samples[ 2] );
69
+
51
70
// value selector setup (note the commit at the end)
52
71
vkl_range1f ranges[ 2] = {{10, 20}, {50, 75}};
53
72
int num_ranges = 2;
@@ -75,12 +94,12 @@ void demoScalarAPI(VKLVolume volume)
75
94
#if defined(_ MSC_VER)
76
95
// MSVC does not support variable length arrays, but provides a
77
96
// safer version of alloca.
78
- char * buffer = _ malloca(vklGetIntervalIteratorSize(volume ));
97
+ char * buffer = _ malloca(vklGetIntervalIteratorSize(sampler ));
79
98
#else
80
- char buffer[ vklGetIntervalIteratorSize(volume )] ;
99
+ char buffer[ vklGetIntervalIteratorSize(sampler )] ;
81
100
#endif
82
101
VKLIntervalIterator intervalIterator = vklInitIntervalIterator(
83
- volume , &rayOrigin, &rayDirection, &rayTRange, selector, buffer);
102
+ sampler , &rayOrigin, &rayDirection, &rayTRange, selector, buffer);
84
103
85
104
printf("\n\tinterval iterator for value ranges {%f %f} {%f %f}\n",
86
105
ranges[0].lower,
@@ -109,12 +128,12 @@ void demoScalarAPI(VKLVolume volume)
109
128
#if defined(_ MSC_VER)
110
129
// MSVC does not support variable length arrays, but provides a
111
130
// safer version of alloca.
112
- char * buffer = _ malloca(vklGetHitIteratorSize(volume ));
131
+ char * buffer = _ malloca(vklGetHitIteratorSize(sampler ));
113
132
#else
114
- char buffer[ vklGetHitIteratorSize(volume )] ;
133
+ char buffer[ vklGetHitIteratorSize(sampler )] ;
115
134
#endif
116
135
VKLHitIterator hitIterator = vklInitHitIterator(
117
- volume , &rayOrigin, &rayDirection, &rayTRange, selector, buffer);
136
+ sampler , &rayOrigin, &rayDirection, &rayTRange, selector, buffer);
118
137
119
138
printf("\thit iterator for values %f %f\n", values[0], values[1]);
120
139
@@ -141,26 +160,57 @@ void demoVectorAPI(VKLVolume volume)
141
160
VKLSampler sampler = vklNewSampler(volume);
142
161
vklCommit(sampler);
143
162
144
- vkl_vvec3f4 coord4; // structure-of-array layout
163
+ // structure-of-array layout
164
+ vkl_vvec3f4 coord4;
145
165
int valid[ 4] ;
146
166
for (int i = 0; i < 4; i++) {
147
- coord4.x[ i] = coord4.y[ i] = coord4.z[ i] = i;
148
- valid[ i] = -1; // valid mask: 0 = not valid, -1 = valid
167
+ coord4.x[ i] = i * 3 + 0;
168
+ coord4.y[ i] = i * 3 + 1;
169
+ coord4.z[ i] = i * 3 + 2;
170
+ valid[ i] = -1; // valid mask: 0 = not valid, -1 = valid
149
171
}
150
172
173
+ for (int i = 0; i < 4; i++) {
174
+ printf(
175
+ "\tcoord[ %d] = %f %f %f\n", i, coord4.x[ i] , coord4.y[ i] , coord4.z[ i] );
176
+ }
177
+
178
+ // sample, gradient (first attribute)
179
+ unsigned int attributeIndex = 0;
151
180
float sample4[ 4] ;
152
181
vkl_vvec3f4 grad4;
153
- vklComputeSample4(valid, sampler, &coord4, sample4);
154
- vklComputeGradient4(valid, sampler, &coord4, &grad4);
182
+ vklComputeSample4(valid, sampler, &coord4, sample4, attributeIndex);
183
+ vklComputeGradient4(valid, sampler, &coord4, &grad4, attributeIndex);
184
+
185
+ printf("\n\tsampling and gradient computation (first attribute)\n");
155
186
156
187
for (int i = 0; i < 4; i++) {
157
- printf(
158
- "\tcoord[ %d] = %f %f %f\n", i, coord4.x[ i] , coord4.y[ i] , coord4.z[ i] );
159
188
printf("\t\tsample[ %d] = %f\n", i, sample4[ i] );
160
189
printf(
161
190
"\t\tgrad[ %d] = %f %f %f\n", i, grad4.x[ i] , grad4.y[ i] , grad4.z[ i] );
162
191
}
163
192
193
+ // sample (multiple attributes)
194
+ unsigned int M = 3;
195
+ unsigned int attributeIndices[ ] = {0, 1, 2};
196
+ float samples[ 3 * 4] ;
197
+ vklComputeSampleM4(valid, sampler, &coord4, samples, M, attributeIndices);
198
+
199
+ printf("\n\tsampling (multiple attributes)\n");
200
+
201
+ printf("\t\tsamples = ");
202
+
203
+ for (unsigned int j = 0; j < M; j++) {
204
+ printf("%f %f %f %f\n",
205
+ samples[ j * 4 + 0] ,
206
+ samples[ j * 4 + 1] ,
207
+ samples[ j * 4 + 2] ,
208
+ samples[ j * 4 + 3] );
209
+ printf("\t\t ");
210
+ }
211
+
212
+ printf("\n");
213
+
164
214
vklRelease(sampler);
165
215
}
166
216
@@ -175,20 +225,47 @@ void demoStreamAPI(VKLVolume volume)
175
225
vkl_vec3f coord[ 5] ;
176
226
177
227
for (int i = 0; i < 5; i++) {
178
- coord[ i] .x = coord[ i] .y = coord[ i] .z = i;
228
+ coord[ i] .x = i * 3 + 0;
229
+ coord[ i] .y = i * 3 + 1;
230
+ coord[ i] .z = i * 3 + 2;
179
231
}
180
232
233
+ for (int i = 0; i < 5; i++) {
234
+ printf("\tcoord[ %d] = %f %f %f\n", i, coord[ i] .x, coord[ i] .y, coord[ i] .z);
235
+ }
236
+
237
+ // sample, gradient (first attribute)
238
+ printf("\n\tsampling and gradient computation (first attribute)\n");
239
+ unsigned int attributeIndex = 0;
181
240
float sample[ 5] ;
182
241
vkl_vec3f grad[ 5] ;
183
- vklComputeSampleN(sampler, 5, coord, sample);
184
- vklComputeGradientN(sampler, 5, coord, grad);
242
+ vklComputeSampleN(sampler, 5, coord, sample, attributeIndex );
243
+ vklComputeGradientN(sampler, 5, coord, grad, attributeIndex );
185
244
186
245
for (int i = 0; i < 5; i++) {
187
- printf("\tcoord[ %d] = %f %f %f\n", i, coord[ i] .x, coord[ i] .y, coord[ i] .z);
188
246
printf("\t\tsample[ %d] = %f\n", i, sample[ i] );
189
247
printf("\t\tgrad[ %d] = %f %f %f\n", i, grad[ i] .x, grad[ i] .y, grad[ i] .z);
190
248
}
191
249
250
+ // sample (multiple attributes)
251
+ unsigned int M = 3;
252
+ unsigned int attributeIndices[ ] = {0, 1, 2};
253
+ float samples[ 3 * 5] ;
254
+ vklComputeSampleMN(sampler, 5, coord, samples, M, attributeIndices);
255
+
256
+ printf("\n\tsampling (multiple attributes)\n");
257
+
258
+ printf("\t\tsamples = ");
259
+
260
+ for (int i = 0; i < 5; i++) {
261
+ for (unsigned int j = 0; j < M; j++) {
262
+ printf("%f ", samples[ i * M + j] );
263
+ }
264
+ printf("\n\t\t ");
265
+ }
266
+
267
+ printf("\n");
268
+
192
269
vklRelease(sampler);
193
270
}
194
271
@@ -200,10 +277,12 @@ int main()
200
277
vklCommitDriver(driver);
201
278
vklSetCurrentDriver(driver);
202
279
203
- int dimensions[ ] = {128, 128, 128};
280
+ const int dimensions[ ] = {128, 128, 128};
204
281
205
282
const int numVoxels = dimensions[ 0] * dimensions[ 1] * dimensions[ 2] ;
206
283
284
+ const int numAttributes = 3;
285
+
207
286
VKLVolume volume = vklNewVolume("structuredRegular");
208
287
vklSetVec3i(
209
288
volume, "dimensions", dimensions[ 0] , dimensions[ 1] , dimensions[ 2] );
@@ -217,16 +296,44 @@ int main()
217
296
return 1;
218
297
}
219
298
220
- // x-grad sample volume
299
+ // volume attribute 0: x-grad
221
300
for (int k = 0; k < dimensions[ 2] ; k++)
222
301
for (int j = 0; j < dimensions[ 1] ; j++)
223
302
for (int i = 0; i < dimensions[ 0] ; i++)
224
303
voxels[ k * dimensions[ 0] * dimensions[ 1] + j * dimensions[ 2] + i] =
225
304
(float)i;
226
305
227
- VKLData data = vklNewData(numVoxels, VKL_FLOAT, voxels, VKL_DATA_DEFAULT, 0);
228
- vklSetData(volume, "data", data);
229
- vklRelease(data);
306
+ VKLData data0 = vklNewData(numVoxels, VKL_FLOAT, voxels, VKL_DATA_DEFAULT, 0);
307
+
308
+ // volume attribute 1: y-grad
309
+ for (int k = 0; k < dimensions[ 2] ; k++)
310
+ for (int j = 0; j < dimensions[ 1] ; j++)
311
+ for (int i = 0; i < dimensions[ 0] ; i++)
312
+ voxels[ k * dimensions[ 0] * dimensions[ 1] + j * dimensions[ 2] + i] =
313
+ (float)j;
314
+
315
+ VKLData data1 = vklNewData(numVoxels, VKL_FLOAT, voxels, VKL_DATA_DEFAULT, 0);
316
+
317
+ // volume attribute 2: z-grad
318
+ for (int k = 0; k < dimensions[ 2] ; k++)
319
+ for (int j = 0; j < dimensions[ 1] ; j++)
320
+ for (int i = 0; i < dimensions[ 0] ; i++)
321
+ voxels[ k * dimensions[ 0] * dimensions[ 1] + j * dimensions[ 2] + i] =
322
+ (float)k;
323
+
324
+ VKLData data2 = vklNewData(numVoxels, VKL_FLOAT, voxels, VKL_DATA_DEFAULT, 0);
325
+
326
+ VKLData attributes[ ] = {data0, data1, data2};
327
+
328
+ VKLData attributesData =
329
+ vklNewData(numAttributes, VKL_DATA, attributes, VKL_DATA_DEFAULT, 0);
330
+
331
+ vklRelease(data0);
332
+ vklRelease(data1);
333
+ vklRelease(data2);
334
+
335
+ vklSetData(volume, "data", attributesData);
336
+ vklRelease(attributesData);
230
337
231
338
vklCommit(volume);
232
339
@@ -240,6 +347,14 @@ int main()
240
347
241
348
free(voxels);
242
349
350
+ printf("complete.\n");
351
+
352
+ #if defined(_ MSC_VER)
353
+ // On Windows, sleep for a few seconds so the terminal window doesn't close
354
+ // immediately.
355
+ Sleep(3000);
356
+ #endif
357
+
243
358
return 0;
244
359
}
245
360
```
0 commit comments