summaryrefslogtreecommitdiff
path: root/collective/kernel.c
blob: f3982a61fc8d8e1249d9b83406b4422985781628 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//#include <math.h>
#define PI 3.141592653589793115997963468544185161590576171875

double cosecant_single(double a, double b) { return a / cos(b); }
double secant_single(double a, double b) { return a / cos(b); }

/**
__kernel void render_frame_orbit_trap(__global double *frame_output, __global double *mask, 
    double x_step, double y_step,
    double x_start, double y_start,
    unsigned int iterations, unsigned int escape, double ratio) {  
  
  const vec2 point = (0, 0);
  
  unsigned int result;
  unsigned int iter;

  double min_distance = DBL_MAX; 
  
  for(iter = 0; iter < iterations; iter++) { 
    double next_x;
    double r = mask[img_index];
    next_x = (r * cosecant_single(x, y)) + ((1 - r) * secant_single(x, y));
    y = (r * cosecant_single(y, x)) + ((1 - r) * secant_single(y, x));
    x = next_x;
    if((pow(x, 2) + pow(y, 2)) >= escape) break;
  }
  
  frame_output[img_index] = total_curve / iter;

}
**/
 

__kernel void render_frame_curvature(__global double *frame_output, __global double *mask, 
    double x_step, double y_step,
    double x_start, double y_start,
    unsigned int iterations, unsigned int escape, double ratio) {  
  unsigned int result;
  unsigned int iter;
  
  double x_cart = (get_global_id(0) * x_step) + x_start;
  double y_cart = (get_global_id(1) * y_step) + y_start;
  double x = sqrt(pow(x_cart, 2) + pow(y_cart, 2));
  double y = atan(y_cart / x_cart);
 
  //double x = (get_global_id(0) * x_step) + x_start;
  //double y = (get_global_id(1) * y_step) + y_start;
  size_t img_index = (get_global_id(1) * get_global_size(1)) + get_global_id(0);

  double total_curve = 0;
  
  //just found out vectors are a thing
  double2 lp[3];
  
  for(iter = 0; iter < iterations; iter++) { 
    double next_x;
    double r = mask[img_index];
    next_x = (r * secant_single(x, y)) + ((1 - r) * cosecant_single(x, y));
    y = (r * secant_single(y, x)) + ((1 - r) * cosecant_single(y, x));
    x = next_x;

    if((pow(x, 2) + pow(y, 2)) >= escape) break;
    lp[2] = lp[1];
    lp[1] = lp[0];
    lp[0] = (double2)(x, y); //why do I have to cast this? hope no accuracy lost
      
    /**
    if(img_index == 254234) {
      printf("%u\n", ratio);
    }
    **/
    if(iter >= 2) {
      double curl = acos(dot((lp[0] - lp[1]), (lp[2] - lp[1])) / (distance(lp[0], lp[1]) * distance(lp[2], lp[1])));
      total_curve = (total_curve + curl);
    }
  }
  frame_output[img_index] = total_curve / iter;
}


__kernel void render_frame(__global double *frame_output, __global double *mask, 
    double x_step, double y_step,
    double x_start, double y_start,
    unsigned int iterations, unsigned int escape, double ratio) {  
  unsigned int result;
  double x_cart = (get_global_id(0) * x_step) + x_start;
  double y_cart = (get_global_id(1) * y_step) + y_start;
  size_t img_index = (get_global_id(1) * get_global_size(1)) + get_global_id(0);

  double x = sqrt(pow(x_cart, 2) + pow(y_cart, 2));
  double y = atan(y_cart / x_cart);
  
  //double x = (get_global_id(0) * x_step) + x_start;
  //double y = (get_global_id(1) * y_step) + y_start;
  

  unsigned int iter;

  //vec2 pos; 
  
  for(iter = 0; iter < iterations; iter++) { 
    double next_x;
    double r = ratio;
    next_x = (r * cosecant_single(x, y)) + ((1 - r) * secant_single(x, y));
    y = (r * cosecant_single(y, x)) + ((1 - r) * secant_single(y, x));
    x = next_x;
    //if(distance(pos) >= escape) break;
    if((pow(x, 2) + pow(y, 2)) >= escape) break;
  }
  

  //TODO turn back to int whenever 
  frame_output[img_index] = (double)iter;
  //frame_output[img_index] = mask[img_index] * 255;
}