The following code example demonstrates how the Intel IPP realistic rendering functions can be used to perform the ray casting of the primary rays.
The input of the tracer is the scene (Teapot) specified as two arrays: array of the vertex coordinates ( pTeapotVertCoord) and array of the indexes of the triangles (pTeapotIndex) (see Figure “Structure of Arrays for Triangle Description”).
As the result of the tracing, the RGB 3-channel (8u_C3) image is created (see Figure “Rendered Image”).
#include "ipp.h"
#define NVERTEX 302
#define NTRIAGLE 576
__declspec (align(16))static const float pTeapotVertCoord[NVERTEX*3] = {
17.500000f, 30.000000f, 0.000000f, 17.303200f, 31.093700f, 0.000000f,
17.905100f, 31.093800f, 0.000000f, 18.750000f, 30.000000f, 0.000000f,
15.140700f, 30.000000f, 8.892590f, 14.970500f, 31.093700f, 8.792610f,
15.491200f, 31.093700f, 9.098440f, 16.222200f, 30.000000f, 9.527780f,
8.892590f, 30.000000f, 15.140700f, 8.792610f, 31.093700f, 14.970500f,
9.098440f, 31.093800f, 15.491200f, 9.527780f, 30.000000f, 16.222200f,
0.000000f, 30.000000f, 17.500000f, 0.000000f, 31.093700f, 17.303200f,
0.000000f, 31.093800f, 17.905100f, 0.000000f, 30.000000f, 18.750000f,
-9.392590f, 30.000000f, 15.140700f, -8.940760f, 31.093700f, 14.970500f,
-9.116960f, 31.093700f, 15.491200f, -9.527780f, 30.000000f, 16.222200f,
-15.390700f, 30.000000f, 8.892590f, -15.044600f, 31.093700f, 8.792610f,
-15.500500f, 31.093800f, 9.098440f, -16.222200f, 30.000000f, 9.527780f,
-17.500000f, 30.000000f, 0.000000f, -17.303200f, 31.093700f, 0.000000f,
-17.905100f, 31.093800f, 0.000000f, -18.750000f, 30.000000f, 0.000000f,
-15.140700f, 30.000000f, -8.892590f, -14.970500f, 31.093700f, -8.792610f,
-15.491200f, 31.093700f, -9.098440f, -16.222200f, 30.000000f, -9.527780f,
-8.892590f, 30.000000f, -15.140700f, -8.792610f, 31.093700f, -14.970500f,
-9.098440f, 31.093800f, -15.491200f, -9.527780f, 30.000000f, -16.222200f,
0.000000f, 30.000000f, -17.500000f, 0.000000f, 31.093700f, -17.303200f,
0.000000f, 31.093800f, -17.905100f, 0.000000f, 30.000000f, -18.750000f,
8.892590f, 30.000000f, -15.140700f, 8.792610f, 31.093700f, -14.970500f,
9.098440f, 31.093700f, -15.491200f, 9.527780f, 30.000000f, -16.222200f,
15.140700f, 30.000000f, -8.892590f,
14.970500f, 31.093700f, -8.792610f, 15.491200f, 31.093800f, -9.098440f,
16.222200f, 30.000000f, -9.527780f, 21.759300f, 23.472200f, 0.000000f,
24.074100f, 17.152800f, 0.000000f, 25.000000f, 11.250000f, 0.000000f,
18.825800f, 23.472200f, 11.056900f, 20.828501f, 17.152800f, 12.233200f,
21.629601f, 11.250000f, 12.703700f, 11.056900f, 23.472200f, 18.825800f,
12.233200f, 17.152800f, 20.828501f, 12.703700f, 11.250000f, 21.629601f,
0.000000f, 23.472200f, 21.759300f, 0.000000f, 17.152800f, 24.074100f,
0.000000f, 11.250000f, 25.000000f, -11.056900f, 23.472200f, 18.825800f,
-12.233200f, 17.152800f, 20.828501f, -12.703700f, 11.250000f, 21.629601f,
-18.825800f, 23.472200f, 11.056900f, -20.828501f, 17.152800f, 12.233200f,
-21.629601f, 11.250000f, 12.703700f, -21.759300f, 23.472200f, 0.000000f,
-24.074100f, 17.152800f, 0.000000f, -25.000000f, 11.250000f, 0.000000f,
-18.825800f, 23.472200f, -11.056900f, -20.828501f, 17.152800f, -12.233200f,
-21.629601f, 11.250000f, -12.703700f, -11.056900f, 23.472200f, -18.825800f,
-12.233200f, 17.152800f, -20.828501f, -12.703700f, 11.250000f, -21.629601f,
0.000000f, 23.472200f, -21.759300f, 0.000000f, 17.152800f, -24.074100f,
0.000000f, 11.250000f, -25.000000f, 11.056900f, 23.472200f, -18.825800f,
12.233200f, 17.152800f, -20.828501f, 12.703700f, 11.250000f, -21.629601f,
18.825800f, 23.472200f, -11.056900f, 20.828501f, 17.152800f, -12.233200f,
21.629601f, 11.250000f, -12.703700f, 23.379601f, 6.527780f, 0.000000f,
20.370399f, 3.472220f, 0.000000f, 18.750000f, 1.875000f, 0.000000f,
20.227699f, 6.527780f, 11.880300f, 17.624100f, 3.472220f, 10.351200f,
16.222200f, 1.875000f, 9.527780f, 11.880300f, 6.527780f, 20.227699f,
10.351200f, 3.472220f, 17.624100f, 9.527780f, 1.875000f, 16.222200f,
0.000000f, 6.527780f, 23.379601f, 0.000000f, 3.472220f, 20.370399f,
0.000000f, 1.875000f, 18.750000f, -11.880300f, 6.527780f, 20.227699f,
-10.351200f, 3.472220f, 17.624100f, -9.527780f, 1.875000f, 16.222200f,
-20.227699f, 6.527780f, 11.880300f, -17.624100f, 3.472220f, 10.351200f,
-16.222200f, 1.875000f, 9.527780f, -23.379601f, 6.527780f, 0.000000f,
-20.370399f, 3.472220f, 0.000000f, -18.750000f, 1.875000f, 0.000000f,
-20.227699f, 6.527780f, -11.880300f, -17.624100f, 3.472220f, -10.351200f,
-16.222200f, 1.875000f, -9.527780f, -11.880300f, 6.527780f, -20.227699f,
-10.351200f, 3.472220f, -17.624100f, -9.527780f, 1.875000f, -16.222200f,
0.000000f, 6.527780f, -23.379601f, 0.000000f, 3.472220f, -20.370399f,
0.000000f, 1.875000f, -18.750000f, 11.880300f, 6.527780f, -20.227699f,
10.351200f, 3.472220f, -17.624100f, 9.527780f, 1.875000f, -16.222200f,
20.227699f, 6.527780f, -11.880300f, 17.624100f, 3.472220f, -10.351200f,
16.222200f, 1.875000f, -9.527780f, 17.847200f, 0.972222f, 0.000000f,
12.777800f, 0.277778f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 15.441100f,
0.972222f, 9.069030f, 11.055100f, 0.277778f, 6.493000f, 9.069030f, 0.972222f,
15.441100f, 6.493000f, 0.277778f, 11.055100f, 0.000000f, 0.972222f,
17.847200f, 0.000000f, 0.277778f, 12.777800f, -9.069030f, 0.972222f
, 15.441100f, -6.493000f, 0.277778f, 11.055100f, -15.441100f, 0.972222f,
9.069030f, -11.055100f, 0.277778f, 6.493000f, -17.847200f, 0.972222f,
0.000000f, -12.777800f, 0.277778f, 0.000000f, -15.441100f, 0.972222f,
-9.069030f, -11.055100f, 0.277778f, -6.493000f, -9.069030f, 0.972222f,
-15.441100f, -6.493000f, 0.277778f, -11.055100f, 0.000000f, 0.972222f,
-17.847200f, 0.000000f, 0.277778f, -12.777800f, 9.069030f, 0.972222f,
-15.441100f, 6.493000f, 0.277778f, -11.055100f, 15.441100f, 0.972222f,
-9.069030f, 11.055100f, 0.277778f, -6.493000f, -20.000000f, 25.312500f,
0.000000f, -27.453699f, 25.208300f, 0.000000f, -32.129601f, 24.479200f,
0.000000f, -33.750000f, 22.500000f, 0.000000f, -19.675900f, 26.041700f,
2.500000f, -27.897800f, 25.910500f, 2.500000f, -32.981800f, 24.992300f,
2.500000f, -34.722198f, 22.500000f, 2.500000f, -19.074100f, 27.395800f,
2.500000f, -28.722601f, 27.214500f, 2.500000f, -34.564499f, 25.945200f,
2.500000f, -36.527802f, 22.500000f, 2.500000f, -18.750000f, 28.125000f,
0.000000f, -29.166700f, 27.916700f, 0.000000f, -35.416698f, 26.458300f,
0.000000f, -37.500000f, 22.500000f, 0.000000f, -19.074100f, 27.395800f,
-2.500000f, -28.722601f, 27.214500f, -2.500000f, -34.564499f, 25.945200f,
-2.500000f, -36.527802f, 22.500000f, -2.500000f, -19.675900f, 26.041700f,
-2.500000f, -27.897800f, 25.910500f, -2.500000f, -32.981800f, 24.992300f,
-2.500000f, -34.722198f, 22.500000f, -2.500000f, -32.870399f, 18.958300f,
0.000000f, -30.046301f, 14.791700f, 0.000000f, -25.000000f, 11.250000f,
0.000000f, -33.686600f, 18.463200f, 2.500000f, -30.418400f, 14.071500f,
2.500000f, -24.675900f, 10.277800f, 2.500000f, -35.202301f, 17.543699f,
2.500000f, -31.109400f, 12.734100f, 2.500000f, -24.074100f, 8.472220f,
2.500000f, -36.018501f, 17.048599f, 0.000000f, -31.481501f, 12.013900f,
0.000000f, -23.750000f, 7.500000f, 0.000000f, -35.202301f, 17.543699f,
-2.500000f, -31.109400f, 12.734100f, -2.500000f, -24.074100f, 8.472220f,
-2.500000f, -33.686600f, 18.463200f, -2.500000f, -30.418400f, 14.071500f,
-2.500000f, -24.675900f, 10.277800f, -2.500000f, 21.250000f, 17.812500f,
0.000000f, 28.379601f, 20.138901f, 0.000000f, 30.787001f, 25.173599f,
0.000000f, 33.750000f, 30.000000f, 0.000000f, 21.250000f, 15.138900f,
5.500000f, 29.243799f, 18.428499f, 4.614200f, 31.867300f, 24.534500f,
2.969140f, 35.694401f, 30.000000f, 2.083330f, 21.250000f, 10.173600f,
5.500000f, 30.848801f, 15.252100f, 4.614200f, 33.873501f, 23.347500f,
2.969140f, 39.305599f, 30.000000f, 2.083330f, 21.250000f, 7.500000f,
0.000000f, 31.712999f, 13.541700f, 0.000000f, 34.953701f, 22.708300f,
0.000000f, 41.250000f, 30.000000f, 0.000000f, 21.250000f, 10.173600f,
-5.500000f, 30.848801f, 15.252100f, -4.614200f, 33.873501f, 23.347500f,
-2.969140f, 39.305599f, 30.000000f, -2.083330f, 21.250000f, 15.138900f
, -5.500000f, 29.243799f, 18.428499f, -4.614200f, 31.867300f, 24.534500f,
-2.969140f, 35.694401f, 30.000000f, -2.083330f, 34.907398f, 30.625000f,
0.000000f, 35.509300f, 30.625000f, 0.000000f, 35.000000f, 30.000000f,
0.000000f, 36.971901f, 30.679001f, 1.867280f, 37.279701f, 30.692499f,
1.466050f, 36.296299f, 30.000000f, 1.250000f, 40.805901f, 30.779301f,
1.867280f, 40.567600f, 30.817900f, 1.466050f, 38.703701f, 30.000000f,
1.250000f, 42.870399f, 30.833300f, 0.000000f, 42.338001f, 30.885401f,
0.000000f, 40.000000f, 30.000000f, 0.000000f, 40.805901f, 30.779301f,
-1.867280f, 40.567600f, 30.817900f, -1.466050f, 38.703701f, 30.000000f,
-1.250000f, 36.971901f, 30.679001f, -1.867280f, 37.279701f, 30.692499f,
-1.466050f, 36.296299f, 30.000000f, -1.250000f, 0.000000f, 39.375000f,
0.000000f, 4.537040f, 38.333302f, 0.000000f, 2.962960f, 36.041698f, 0.000000f,
2.500000f, 33.750000f, 0.000000f, 3.927850f, 38.333302f, 2.310430f,
2.564750f, 36.041698f, 1.508090f, 2.162960f, 33.750000f, 1.270370f, 2.310430f,
38.333302f, 3.927850f, 1.508090f, 36.041698f, 2.564750f, 1.270370f,
33.750000f, 2.162960f, 0.000000f, 38.333302f, 4.537040f, 0.000000f,
36.041698f, 2.962960f, 0.000000f, 33.750000f, 2.500000f, -2.310430f,
38.333302f, 3.927850f, -1.508090f, 36.041698f, 2.564750f, -1.270370f,
33.750000f, 2.162960f, -3.927850f, 38.333302f, 2.310430f, -2.564750f,
36.041698f, 1.508090f, -2.162960f, 33.750000f, 1.270370f, -4.537040f,
38.333302f, 0.000000f, -2.962960f, 36.041698f, 0.000000f, -2.500000f,
33.750000f, 0.000000f, -3.927850f, 38.333302f, -2.310430f, -2.564750f,
36.041698f, -1.508090f, -2.162960f, 33.750000f, -1.270370f, -2.310430f,
38.333302f, -3.927850f, -1.508090f, 36.041698f, -2.564750f, -1.270370f,
33.750000f, -2.162960f, 0.000000f, 38.333302f, -4.537040f, 0.000000f,
36.041698f, -2.962960f, 0.000000f, 33.750000f, -2.500000f, 2.310430f,
38.333302f, -3.927850f, 1.508090f, 36.041698f, -2.564750f, 1.270370f,
33.750000f, -2.162960f, 3.927850f, 38.333302f, -2.310430f, 2.564750f,
36.041698f, -1.508090f, 2.162960f, 33.750000f, -1.270370f, 7.175930f,
32.361099f, 0.000000f, 13.240700f, 31.388901f, 0.000000f, 16.250000f,
30.000000f, 0.000000f, 6.208500f, 32.361099f, 3.646430f, 11.455700f,
31.388901f, 6.728260f, 14.059300f, 30.000000f, 8.257410f, 3.646430f,
32.361099f, 6.208500f, 6.728260f, 31.388901f, 11.455700f, 8.257410f,
30.000000f, 14.059300f, 0.000000f, 32.361099f, 7.175930f, 0.000000f,
31.388901f, 13.240700f, 0.000000f, 30.000000f, 16.250000f, -3.646430f,
32.361099f, 6.208500f, -6.728260f, 31.388901f, 11.455700f, -8.257410f,
30.000000f, 14.059300f, -6.208500f, 32.361099f, 3.646430f, -11.455700f,
31.388901f, 6.728260f, -14.059300f, 30.000000f, 8.257410f, -7.175930f,
32.361099f, 0.000000f, -13.240700f, 31.388901f, 0.000000f, -16.250000f,
30.000000f, 0.000000f, -6.208500f, 32.361099f, -3.646430f, -11.455700f,
31.388901f, -6.728260f, -14.059300f, 30.000000f, -8.257410f, -3.646430f,
32.361099f, -6.208500f, -6.728260f, 31.388901f, -11.455700f, -8.257410f,
30.000000f, -14.059300f, 0.000000f, 32.361099f, -7.175930f, 0.000000f,
31.388901f, -13.240700f, 0.000000f, 30.000000f, -16.250000f, 3.646430f,
32.361099f, -6.208500f, 6.728260f, 31.388901f, -11.455700f, 8.257410f,
30.000000f, -14.059300f, 6.208500f, 32.361099f, -3.646430f, 11.455700f,
31.388901f, -6.728260f, 14.059300f, 30.000000f, -8.257410f
};
__declspec (align(16))static const int pTeapotIndex[NTRIAGLE*4] = {
0, 4, 5, 1, 5, 1, 0, 1, 1, 5, 6, 1,
6, 2, 1, 1, 2, 6, 7, 1, 7, 3, 2, 1,
4, 8, 9, 1, 9, 5, 4, 1, 5, 9, 10, 1,
10, 6, 5, 1, 6, 10, 11, 1, 11, 7, 6, 1,
8, 12, 13, 1, 13, 9, 8, 1, 9, 13, 14, 1,
14, 10, 9, 1, 10, 14, 15, 1, 15, 11, 10, 1,
12, 16, 17, 1, 17, 13, 12, 1, 13, 17, 18, 1,
18, 14, 13, 1, 14, 18, 19, 1, 19, 15, 14, 1,
16, 20, 21, 1, 21, 17, 16, 1, 17, 21, 22, 1,
22, 18, 17, 1, 18, 22, 23, 1, 23, 19, 18, 1,
20, 24, 25, 1, 25, 21, 20, 1, 21, 25, 26, 1,
26, 22, 21, 1, 22, 26, 27, 1, 27, 23, 22, 1,
24, 28, 29, 1, 29, 25, 24, 1, 25, 29, 30, 1,
30, 26, 25, 1, 26, 30, 31, 1, 31, 27, 26, 1,
28, 32, 33, 1, 33, 29, 28, 1, 29, 33, 34, 1,
34, 30, 29, 1, 30, 34, 35, 1, 35, 31, 30, 1,
32, 36, 37, 1, 37, 33, 32, 1, 33, 37, 38, 1,
38, 34, 33, 1, 34, 38, 39, 1, 39, 35, 34, 1,
36, 40, 41, 1, 41, 37, 36, 1, 37, 41, 42, 1,
42, 38, 37, 1, 38, 42, 43, 1, 43, 39, 38, 1,
40, 44, 45, 1, 45, 41, 40, 1, 41, 45, 46, 1,
46, 42, 41, 1, 42, 46, 47, 1, 47, 43, 42, 1,
44, 0, 1, 1, 1, 45, 44, 1, 45, 1, 2, 1,
2, 46, 45, 1, 46, 2, 3, 1, 3, 47, 46, 1,
3, 7, 51, 1, 51, 48, 3, 1, 48, 51, 52, 1,
52, 49, 48, 1, 49, 52, 53, 1, 53, 50, 49, 1,
7, 11, 54, 1, 54, 51, 7, 1, 51, 54, 55, 1,
55, 52, 51, 1, 52, 55, 56, 1, 56, 53, 52, 1,
11, 15, 57, 1, 57, 54, 11, 1, 54, 57, 58, 1,
58, 55, 54, 1, 55, 58, 59, 1, 59, 56, 55, 1,
15, 19, 60, 1, 60, 57, 15, 1, 57, 60, 61, 1,
61, 58, 57, 1, 58, 61, 62, 1, 62, 59, 58, 1,
19, 23, 63, 1, 63, 60, 19, 1, 60, 63, 64, 1,
64, 61, 60, 1, 61, 64, 65, 1, 65, 62, 61, 1,
23, 27, 66, 1, 66, 63, 23, 1, 63, 66, 67, 1,
67, 64, 63, 1, 64, 67, 68, 1, 68, 65, 64, 1,
27, 31, 69, 1, 69, 66, 27, 1, 66, 69, 70, 1,
70, 67, 66, 1, 67, 70, 71, 1, 71, 68, 67, 1,
31, 35, 72, 1, 72, 69, 31, 1, 69, 72, 73, 1,
73, 70, 69, 1, 70, 73, 74, 1, 74, 71, 70, 1,
35, 39, 75, 1, 75, 72, 35, 1, 72, 75, 76, 1,
76, 73, 72, 1, 73, 76, 77, 1, 77, 74, 73, 1,
39, 43, 78, 1, 78, 75, 39, 1, 75, 78, 79, 1,
79, 76, 75, 1, 76, 79, 80, 1, 80, 77, 76, 1,
43, 47, 81, 1, 81, 78, 43, 1, 78, 81, 82, 1,
82, 79, 78, 1, 79, 82, 83, 1, 83, 80, 79, 1,
47, 3, 48, 1, 48, 81, 47, 1, 81, 48, 49, 1,
49, 82, 81, 1, 82, 49, 50, 1, 50, 83, 82, 1,
50, 53, 87, 1, 87, 84, 50, 1, 84, 87, 88, 1,
88, 85, 84, 1, 85, 88, 89, 1, 89, 86, 85, 1,
53, 56, 90, 1, 90, 87, 53, 1, 87, 90, 91, 1,
91, 88, 87, 1, 88, 91, 92, 1, 92, 89, 88, 1,
56, 59, 93, 1, 93, 90, 56, 1, 90, 93, 94, 1,
94, 91, 90, 1, 91, 94, 95, 1, 95, 92, 91, 1,
59, 62, 96, 1, 96, 93, 59, 1, 93, 96, 97, 1,
97, 94, 93, 1, 94, 97, 98, 1, 98, 95, 94, 1,
62, 65, 99, 1, 99, 96, 62, 1, 96, 99, 100, 1,
100, 97, 96, 1, 97, 100, 101, 1, 101, 98, 97, 1,
65, 68, 102, 1, 102, 99, 65, 1, 99, 102, 103, 1,
103, 100, 99, 1, 100, 103, 104, 1, 104, 101, 100, 1,
68, 71, 105, 1, 105, 102, 68, 1, 102, 105, 106, 1,
106, 103, 102, 1, 103, 106, 107, 1, 107, 104, 103, 1,
71, 74, 108, 1, 108, 105, 71, 1, 105, 108, 109, 1,
109, 106, 105, 1, 106, 109, 110, 1, 110, 107, 106, 1,
74, 77, 111, 1, 111, 108, 74, 1, 108, 111, 112, 1,
112, 109, 108, 1, 109, 112, 113, 1, 113, 110, 109, 1,
77, 80, 114, 1, 114, 111, 77, 1, 111, 114, 115, 1,
115, 112, 111, 1, 112, 115, 116, 1, 116, 113, 112, 1,
80, 83, 117, 1, 117, 114, 80, 1, 114, 117, 118, 1,
118, 115, 114, 1, 115, 118, 119, 1, 119, 116, 115, 1,
83, 50, 84, 1, 84, 117, 83, 1, 117, 84, 85, 1,
85, 118, 117, 1, 118, 85, 86, 1, 86, 119, 118, 1,
86, 89, 123, 1, 123, 120, 86, 1, 120, 123, 124, 1,
124, 121, 120, 1, 121, 124, 122, 1, 122, 122, 121, 1,
89, 92, 125, 1, 125, 123, 89, 1, 123, 125, 126, 1,
126, 124, 123, 1, 124, 126, 122, 1, 122, 122, 124, 1,
92, 95, 127, 1, 127, 125, 92, 1, 125, 127, 128, 1,
128, 126, 125, 1, 126, 128, 122, 1, 122, 122, 126, 1,
95, 98, 129, 1, 129, 127, 95, 1, 127, 129, 130, 1,
130, 128, 127, 1, 128, 130, 122, 1, 122, 122, 128, 1,
98, 101, 131, 1, 131, 129, 98, 1, 129, 131, 132, 1,
132, 130, 129, 1, 130, 132, 122, 1, 122, 122, 130, 1,
101, 104, 133, 1, 133, 131, 101, 1, 131, 133, 134, 1,
134, 132, 131, 1, 132, 134, 122, 1, 122, 122, 132, 1,
104, 107, 135, 1, 135, 133, 104, 1, 133, 135, 136, 1,
136, 134, 133, 1, 134, 136, 122, 1, 122, 122, 134, 1,
107, 110, 137, 1, 137, 135, 107, 1, 135, 137, 138, 1,
138, 136, 135, 1, 136, 138, 122, 1, 122, 122, 136, 1,
110, 113, 139, 1, 139, 137, 110, 1, 137, 139, 140, 1,
140, 138, 137, 1, 138, 140, 122, 1, 122, 122, 138, 1,
113, 116, 141, 1, 141, 139, 113, 1, 139, 141, 142, 1,
142, 140, 139, 1, 140, 142, 122, 1, 122, 122, 140, 1,
116, 119, 143, 1, 143, 141, 116, 1, 141, 143, 144, 1,
144, 142, 141, 1, 142, 144, 122, 1, 122, 122, 142, 1,
119, 86, 120, 1, 120, 143, 119, 1, 143, 120, 121, 1,
121, 144, 143, 1, 144, 121, 122, 1, 122, 122, 144, 1,
145, 149, 150, 1, 150, 146, 145, 1, 146, 150, 151, 1,
151, 147, 146, 1, 147, 151, 152, 1, 152, 148, 147, 1,
149, 153, 154, 1, 154, 150, 149, 1, 150, 154, 155, 1,
155, 151, 150, 1, 151, 155, 156, 1, 156, 152, 151, 1,
153, 157, 158, 1, 158, 154, 153, 1, 154, 158, 159, 1,
159, 155, 154, 1, 155, 159, 160, 1, 160, 156, 155, 1,
157, 161, 162, 1, 162, 158, 157, 1, 158, 162, 163, 1,
163, 159, 158, 1, 159, 163, 164, 1, 164, 160, 159, 1,
161, 165, 166, 1, 166, 162, 161, 1, 162, 166, 167, 1,
167, 163, 162, 1, 163, 167, 168, 1, 168, 164, 163, 1,
165, 145, 146, 1, 146, 166, 165, 1, 166, 146, 147, 1,
147, 167, 166, 1, 167, 147, 148, 1, 148, 168, 167, 1,
148, 152, 172, 1, 172, 169, 148, 1, 169, 172, 173, 1,
173, 170, 169, 1, 170, 173, 174, 1, 174, 171, 170, 1,
152, 156, 175, 1, 175, 172, 152, 1, 172, 175, 176, 1,
176, 173, 172, 1, 173, 176, 177, 1, 177, 174, 173, 1,
156, 160, 178, 1, 178, 175, 156, 1, 175, 178, 179, 1,
179, 176, 175, 1, 176, 179, 180, 1, 180, 177, 176, 1,
160, 164, 181, 1, 181, 178, 160, 1, 178, 181, 182, 1,
182, 179, 178, 1, 179, 182, 183, 1, 183, 180, 179, 1,
164, 168, 184, 1, 184, 181, 164, 1, 181, 184, 185, 1,
185, 182, 181, 1, 182, 185, 186, 1, 186, 183, 182, 1,
168, 148, 169, 1, 169, 184, 168, 1, 184, 169, 170, 1,
170, 185, 184, 1, 185, 170, 171, 1, 171, 186, 185, 1,
187, 191, 192, 1, 192, 188, 187, 1, 188, 192, 193, 1,
193, 189, 188, 1, 189, 193, 194, 1, 194, 190, 189, 1,
191, 195, 196, 1, 196, 192, 191, 1, 192, 196, 197, 1,
197, 193, 192, 1, 193, 197, 198, 1, 198, 194, 193, 1,
195, 199, 200, 1, 200, 196, 195, 1, 196, 200, 201, 1,
201, 197, 196, 1, 197, 201, 202, 1, 202, 198, 197, 1,
199, 203, 204, 1, 204, 200, 199, 1, 200, 204, 205, 1,
205, 201, 200, 1, 201, 205, 206, 1, 206, 202, 201, 1,
203, 207, 208, 1, 208, 204, 203, 1, 204, 208, 209, 1,
209, 205, 204, 1, 205, 209, 210, 1, 210, 206, 205, 1,
207, 187, 188, 1, 188, 208, 207, 1, 208, 188, 189, 1,
189, 209, 208, 1, 209, 189, 190, 1, 190, 210, 209, 1,
190, 194, 214, 1, 214, 211, 190, 1, 211, 214, 215, 1,
215, 212, 211, 1, 212, 215, 216, 1, 216, 213, 212, 1,
194, 198, 217, 1, 217, 214, 194, 1, 214, 217, 218, 1,
218, 215, 214, 1, 215, 218, 219, 1, 219, 216, 215, 1,
198, 202, 220, 1, 220, 217, 198, 1, 217, 220, 221, 1,
221, 218, 217, 1, 218, 221, 222, 1, 222, 219, 218, 1,
202, 206, 223, 1, 223, 220, 202, 1, 220, 223, 224, 1,
224, 221, 220, 1, 221, 224, 225, 1, 225, 222, 221, 1,
206, 210, 226, 1, 226, 223, 206, 1, 223, 226, 227, 1,
227, 224, 223, 1, 224, 227, 228, 1, 228, 225, 224, 1,
210, 190, 211, 1, 211, 226, 210, 1, 226, 211, 212, 1,
212, 227, 226, 1, 227, 212, 213, 1, 213, 228, 227, 1,
229, 229, 233, 1, 233, 230, 229, 1, 230, 233, 234, 1,
234, 231, 230, 1, 231, 234, 235, 1, 235, 232, 231, 1,
229, 229, 236, 1, 236, 233, 229, 1, 233, 236, 237, 1,
237, 234, 233, 1, 234, 237, 238, 1, 238, 235, 234, 1,
229, 229, 239, 1, 239, 236, 229, 1, 236, 239, 240, 1,
240, 237, 236, 1, 237, 240, 241, 1, 241, 238, 237, 1,
229, 229, 242, 1, 242, 239, 229, 1, 239, 242, 243, 1,
243, 240, 239, 1, 240, 243, 244, 1, 244, 241, 240, 1,
229, 229, 245, 1, 245, 242, 229, 1, 242, 245, 246, 1,
246, 243, 242, 1, 243, 246, 247, 1, 247, 244, 243, 1,
229, 229, 248, 1, 248, 245, 229, 1, 245, 248, 249, 1,
249, 246, 245, 1, 246, 249, 250, 1, 250, 247, 246, 1,
229, 229, 251, 1, 251, 248, 229, 1, 248, 251, 252, 1,
252, 249, 248, 1, 249, 252, 253, 1, 253, 250, 249, 1,
229, 229, 254, 1, 254, 251, 229, 1, 251, 254, 255, 1,
255, 252, 251, 1, 252, 255, 256, 1, 256, 253, 252, 1,
229, 229, 257, 1, 257, 254, 229, 1, 254, 257, 258, 1,
258, 255, 254, 1, 255, 258, 259, 1, 259, 256, 255, 1,
229, 229, 260, 1, 260, 257, 229, 1, 257, 260, 261, 1,
261, 258, 257, 1, 258, 261, 262, 1, 262, 259, 258, 1,
229, 229, 263, 1, 263, 260, 229, 1, 260, 263, 264, 1,
264, 261, 260, 1, 261, 264, 265, 1, 265, 262, 261, 1,
229, 229, 230, 1, 230, 263, 229, 1, 263, 230, 231, 1,
231, 264, 263, 1, 264, 231, 232, 1, 232, 265, 264, 1,
232, 235, 269, 1, 269, 266, 232, 1, 266, 269, 270, 1,
270, 267, 266, 1, 267, 270, 271, 1, 271, 268, 267, 1,
235, 238, 272, 1, 272, 269, 235, 1, 269, 272, 273, 1,
273, 270, 269, 1, 270, 273, 274, 1, 274, 271, 270, 1,
238, 241, 275, 1, 275, 272, 238, 1, 272, 275, 276, 1,
276, 273, 272, 1, 273, 276, 277, 1, 277, 274, 273, 1,
241, 244, 278, 1, 278, 275, 241, 1, 275, 278, 279, 1,
279, 276, 275, 1, 276, 279, 280, 1, 280, 277, 276, 1,
244, 247, 281, 1, 281, 278, 244, 1, 278, 281, 282, 1,
282, 279, 278, 1, 279, 282, 283, 1, 283, 280, 279, 1,
247, 250, 284, 1, 284, 281, 247, 1, 281, 284, 285, 1,
285, 282, 281, 1, 282, 285, 286, 1, 286, 283, 282, 1,
250, 253, 287, 1, 287, 284, 250, 1, 284, 287, 288, 1,
288, 285, 284, 1, 285, 288, 289, 1, 289, 286, 285, 1,
253, 256, 290, 1, 290, 287, 253, 1, 287, 290, 291, 1,
291, 288, 287, 1, 288, 291, 292, 1, 292, 289, 288, 1,
256, 259, 293, 1, 293, 290, 256, 1, 290, 293, 294, 1,
294, 291, 290, 1, 291, 294, 295, 1, 295, 292, 291, 1,
259, 262, 296, 1, 296, 293, 259, 1, 293, 296, 297, 1,
297, 294, 293, 1, 294, 297, 298, 1, 298, 295, 294, 1,
262, 265, 299, 1, 299, 296, 262, 1, 296, 299, 300, 1,
300, 297, 296, 1, 297, 300, 301, 1, 301, 298, 297, 1,
265, 232, 266, 1, 266, 299, 265, 1, 299, 266, 267, 1,
267, 300, 299, 1, 300, 267, 268, 1, 268, 301, 300, 1
};
static void rrOptimCheckMask_32s( Ipp32s* pMask, int len, int* check)
{
Ipp32s pMax=-1;
if( pMask[0] != -1 )
{
*check = 33;
return;
}
if( pMask[len-1] != -1 )
{
*check = 33;
return;
}
ippsMax_32s( pMask, len, &pMax );
*check = pMax;
return;
}
#define MAX_KDTREE_DEPTH 33
#define _WIDTH 320
#define _HEIGHT 256
typedef struct SceneContext {
int nVert;
Ipp32f *pVrt; /* pointer to array of Vertices */
int nTriangles;
Ipp32s *pTng; /* pointer to array of Triangels */
IpprIntersectContext iCtx; /* Intersection context */
}SampleSceneContext;
#define NBUNCH 10
typedef struct TraceContext {
Ipp32f *p3D_0[3];
Ipp32f *p1D_1 ;
Ipp32f *p2D_2[2];
Ipp32s *pTrngl;
Ipp32f *p3D_3[3];
}SampleTraceContext;
int main(/*int argc, char** argv*/)
{
IppiSize sizeImPlane={_WIDTH,_HEIGHT}; /* pixels */
SampleSceneContext sceneContext;
IppStatus status;
Ipp32f *pFlatNorm;
IppBox3D_32f pBound;
int pTriAccelSize;
int KDTreeSize;
IppPoint3D_32f ul_corner = {-0.70281667f, 0.52656168f, -1.000000f},
/* upper left coner of Image plane */
dx = { 0.0044063739f, 0.000000f, 0.000000f},
dy = { 0.000000f, -0.0044063739f, 0.000000f},
eye_pos = { 2.6851997f, 23.162521f, 75.012863f};
int isNotFinished = 1;
IppiSize bunchSize = { 16, 16};
int lenBunch=bunchSize.height *bunchSize.width;
int nBunch = NBUNCH; /* #bunch of rays */
SampleTraceContext rtContext;
Ipp32f* pMemForTrace;
int pStepBMP;
Ipp8u* pBMP;
Ipp8u value[3];
IppPoint3D_32f defColour;
int xCnt;
int yCnt;
int last_cnt;
int stepBunch;
int counter;
IpprPSAHBldContext fastKDCont;
sceneContext.nVert = NVERTEX;
sceneContext.nTriangles = NTRIAGLE;
/* allocate memory for the coordinates of triangle's vertexes. */
sceneContext.pVrt = ippsMalloc_32f( sceneContext.nVert * 3 );
if (!sceneContext.pVrt ) return -1;
status = ippsCopy_32f( pTeapotVertCoord, sceneContext.pVrt,
sceneContext.nVert * 3 );
if(status < 0 ) return -1;
/* allocate memory for the triangle's indexes */
sceneContext.pTng = ippsMalloc_32s( sceneContext.nTriangles * 4 );
if (!sceneContext.pVrt ) return -1;
status = ippsCopy_32s( pTeapotIndex, sceneContext.pTng,
sceneContext.nTriangles * 4);
if(status < 0 ) return -1;
/* allocate memory for the triangle's flat normales */
pFlatNorm = ippsMalloc_32f( sceneContext.nTriangles * 3 );
ipprTriangleNormal_32f(sceneContext.pVrt, sceneContext.pTng, pFlatNorm,
sceneContext.nTriangles);
/*
/////////////////////////////////////////////////////
// Initialization of the acceleration structures ////
/////////////////////////////////////////////////////
*/
/* create the AABB */
status = ipprSetBoundBox_32f( sceneContext.pVrt, sceneContext.nVert, &(pBound));
if(status < 0 ) return -1;
sceneContext.iCtx.pBound = &(pBound);
/* create triangle acceleration structure */
ipprTriangleAccelGetSize( &pTriAccelSize);
sceneContext.iCtx.pAccel = (IpprTriangleAccel *)ippsMalloc_8u( pTriAccelSize *
sceneContext.nTriangles );
status = ipprTriangleAccelInit( sceneContext.iCtx.pAccel, sceneContext.pVrt,
sceneContext.pTng, sceneContext.nTriangles );
if(status < 0 ) return -1;
/* create the KDtree structure */
fastKDCont.Bounds = 0;
fastKDCont.Alg = ippKDTBuildPureSAH;
fastKDCont.AvailMemory = 2046;
fastKDCont.MaxDepth = MAX_KDTREE_DEPTH;
fastKDCont.QoS = 1.0f;
status = ipprKDTreeBuildAlloc(
&(sceneContext.iCtx.pRootNode),
sceneContext.pVrt,
sceneContext.pTng,
sceneContext.nVert,
sceneContext.nTriangles,
&KDTreeSize,
(void*)&fastKDCont );
if(status < 0 ) return -1;
/* allocate memory for all temporary arrays */
pMemForTrace = ippsMalloc_32f( bunchSize.height *bunchSize.width * nBunch );
if(!pMemForTrace) return -1;
rtContext.p3D_0[0] = pMemForTrace + 0*lenBunch;
rtContext.p3D_0[1] = pMemForTrace + 1*lenBunch;
rtContext.p3D_0[2] = pMemForTrace + 2*lenBunch;
rtContext.p1D_1 = pMemForTrace + 3*lenBunch;
rtContext.p2D_2[0] = pMemForTrace + 4*lenBunch;
rtContext.p2D_2[1] = pMemForTrace + 5*lenBunch;
rtContext.pTrngl =(Ipp32s*)(pMemForTrace + 6*lenBunch);
rtContext.p3D_3[0] = pMemForTrace + 7*lenBunch;
rtContext.p3D_3[1] = pMemForTrace + 8*lenBunch;
rtContext.p3D_3[2] = pMemForTrace + 9*lenBunch;
/* allocate memory for resal Image */
pBMP = ippiMalloc_8u_C3(sizeImPlane.width, sizeImPlane.height, &pStepBMP);
if(!pBMP) return -1;
/* init resal Image */
value[0] =value[1] =value[2] = 0;
ippiSet_8u_C3R( value, pBMP, pStepBMP, sizeImPlane );
/* for simplicity we'll */
xCnt = sizeImPlane.width / bunchSize.width;
yCnt = sizeImPlane.height / bunchSize.height;
last_cnt = xCnt * yCnt;
stepBunch = bunchSize.width*sizeof(float);
counter = 0;
defColour[0] = 0.999f;
defColour[1] = 0.899f;
defColour[2] = 0.799f;
/*
Simple tracer
Groups of rays, or bunches, of the size bunchSize are traced.
*/
while(isNotFinished)
{
int x = counter % xCnt, y = counter / xCnt;
int check;
Ipp8u* pCurrentBMP_8u;
Ipp8u* pBMP_8u[3];
pCurrentBMP_8u = pBMP + bunchSize.width * x * 3 +
bunchSize.height * y * pStepBMP;
/* calculate Eye/Primary Rays */
ipprCastEye_32f(
ul_corner,
dx, dy,
x, y, /* coordinates of the bunch on the Image playne */
bunchSize,
rtContext.p3D_0, /* direction of primary rays */
bunchSize);
ippsSet_32f(IPP_MAXABS_32F, rtContext.p1D_1, lenBunch);
ipprIntersectEyeSO_32f(eye_pos,
rtContext.p3D_0, /* direction of primary rays */
rtContext.p1D_1, /* distance from origin to intersection point. */
rtContext.p2D_2, /* local surface parameters( u, v )at hit point. */
rtContext.pTrngl, /* the Triangle index, just it's array of masks */
&sceneContext.iCtx, bunchSize);
rrOptimCheckMask_32s( rtContext.pTrngl, lenBunch, &check);
if( check== -1 ){
goto secondaryEnd; /* there was no any intersections */
}
/* simple shader is based on Lambert low */
ipprSurfFlatNormal_32f(pFlatNorm, rtContext.pTrngl,
rtContext.p3D_3,
lenBunch);
ipprDot_32f_P3C1M( rtContext.p3D_0, rtContext.p3D_3, rtContext.pTrngl,
rtContext.p1D_1, /* < N * EyeDir > */
lenBunch);
ippsAbs_32f_I( rtContext.p1D_1, lenBunch);
ippsSet_32f( defColour[0], rtContext.p3D_0[0], lenBunch );
ippsSet_32f( defColour[1], rtContext.p3D_0[1], lenBunch );
ippsSet_32f( defColour[2], rtContext.p3D_0[2], lenBunch );
ipprMul_32f_C1P3IM( rtContext.p1D_1, rtContext.pTrngl, rtContext.p3D_0,
lenBunch);
pBMP_8u[0] = (Ipp8u*)rtContext.p3D_3[0];
pBMP_8u[1] = (Ipp8u*)rtContext.p3D_3[1];
pBMP_8u[2] = (Ipp8u*)rtContext.p3D_3[2];
ippiReduceBits_32f8u_C1R( rtContext.p3D_0[0], stepBunch, pBMP_8u[0],
stepBunch, bunchSize, 0, ippDitherBayer, 255);
ippiReduceBits_32f8u_C1R( rtContext.p3D_0[1], stepBunch, pBMP_8u[1],
stepBunch, bunchSize, 0, ippDitherBayer, 255);
ippiReduceBits_32f8u_C1R( rtContext.p3D_0[2], stepBunch, pBMP_8u[2],
stepBunch, bunchSize, 0, ippDitherBayer, 255);
ippiCopy_8u_P3C3R( pBMP_8u, stepBunch, pCurrentBMP_8u, pStepBMP,
bunchSize );
secondaryEnd:
if(++counter==last_cnt) isNotFinished = 0;
}
/* free context */
ippsFree(sceneContext.pVrt);
ippsFree(sceneContext.pTng);
ippsFree(sceneContext.iCtx.pAccel);
ippsFree(pMemForTrace);
ippsFree(pFlatNorm);
ippiFree(pBMP);
ipprKDTreeFree(sceneContext.iCtx.pRootNode);
return 0;
}
Copyright © 2000 - 2011, Intel Corporation. All rights reserved.