1//The BOXM2_MOG6_view datatype is a float16 and is laid out as follows:
2// [mu_x, sigma_x, mu_y, sigma_y, mu_z, sigma_z, mu_(-x), sigma_(-x), mu_(-y), sigma_(-y), mu_(-z), sigma_(-z)]
3
4//The BOXM2_NUM_OBS_VIEW datatype is a float8 and is laid out as follows:
5// [num_obs_(x),num_obs_(y),num_obs_(z),num_obs_(-x),num_obs_(-y),num_obs_(-z) ]
6// num_obs_(x) is simply the sum of weights received so far for the appearance model at direction x.
7// The weights are computed as visibility times the dot product between the viewing direction and appearance model direction.
8
9//DECLARE app_model_view_directions
10
11#if 0
12__constant  float4  app_model_view_directions[8] = {  (float4)(0,       0,      1,  0),
13                                                      (float4)(1,    0,         0,  0),
14                                                      (float4)(0.5,    0.866,   0,  0),
15                                                      (float4)(-0.5,    0.866,  0,  0),
16                                                      (float4)(-1,    0,        0,  0),
17                                                      (float4)(-0.5,   -0.866,  0,  0),
18                                                      (float4)(0.5,   -0.866,   0,  0),
19                                                      (float4)(0,         0,    0,  0)  };
20#endif
21
22#if 1
23//used for aerial scenes.
24__constant  float4  app_model_view_directions[8] = {  (float4)(0,       0,      1, 0),
25                                                      (float4)(0.707,    0,      0.707,0),
26                                                      (float4)(0.354,    0.612,  0.707, 0),
27                                                      (float4)(-0.354,    0.612, 0.707,0),
28                                                      (float4)(-0.707,    0,     0.707,0),
29                                                      (float4)(-0.354,   -0.612, 0.707,0),
30                                                      (float4)(0.354,    -0.612, 0.707,0),
31                                                      (float4)(0,         0,     0,0)};
32#endif
33
34#if 0
35//used for aerial scenes.
36__constant  float4  app_model_view_directions[8] = {  (float4)(0.81654 ,  0.00000 ,  0.57729 ,0),
37                                                       (float4)(0.00000 ,  0.81654 ,  0.57729,0),
38                                                      (float4)(-0.81654 ,  0.00000 ,  0.57729,0),
39                                                       (float4)(0.00000 , -0.81654 ,  0.57729,0),
40                                                       (float4)(0.57735 ,  0.57735 ,  0.57735,0),
41                                                       (float4)(0.57735 , -0.57735 ,  0.57735,0),
42                                                      (float4)(-0.57735 ,  0.57735 ,  0.57735,0),
43                                                      (float4)(-0.57735 , -0.57735 ,  0.57735,0) };
44#endif
45
46#if 0
47//used for motion capture scenes
48__constant  float4  app_model_view_directions[8] = {  (float4)(0,       0,      1, 0),
49                                                      (float4)(1,    0,      0,0),
50                                                      (float4)(0.5,    0.866,  0, 0),
51                                                      (float4)(-0.5,    0.866, 0,0),
52                                                      (float4)(-1,    0,     0,0),
53                                                      (float4)(-0.5,   -0.866, 0,0),
54                                                      (float4)(0.5,   -0.866, 0,0),
55                                                      (float4)(0,         0,     0,0)};
56#endif
57
58void compute_app_model_weights(float* app_model_weights, float4 viewdir,__constant float4* app_model_view_directions)
59{
60    //compute the dot product btw ray dir and canonical directions
61    //normalize weights to 1 in the end
62    float sum_weights = 0.0f;
63    for(short i = 0; i < 8; i++) {
64        float cos_angle = -dot(viewdir,app_model_view_directions[i]);
65        app_model_weights[i] = (cos_angle > 0.01f) ? cos_angle : 0.0f; //if negative, set to 0
66        sum_weights += app_model_weights[i];
67    }
68
69#define NORMALIZE_VIEW_WEIGHTS
70#ifdef NORMALIZE_VIEW_WEIGHTS
71    for(short i = 0; i < 8; i++) {
72      app_model_weights[i] /= sum_weights;
73    }
74#endif
75}
76
77#if 0
78void compute_app_model_weights_unormalized(float* app_model_weights, float4 viewdir,__constant float4* app_model_view_directions)
79{
80    //compute the dot product btw ray dir and canonical directions
81    for (short i = 0; i < 8; i++) {
82        float cos_angle = -dot(viewdir,app_model_view_directions[i]);
83        app_model_weights[i] = (cos_angle > 0.01f) ? cos_angle : 0.0f; //if negative, set to 0
84    }
85}
86#endif // 0
87