-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRendering.cu
55 lines (47 loc) · 1.61 KB
/
Rendering.cu
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
/*
* Run simple plotting algorithms.
*/
#include<stdint.h>
// Disable mangling.
extern "C"{
// Draws multiple lines to output images.
// Drawing uses polar coordinates.
// Parameters in are tick angle and radius of the line
// which satisfy equation:
// <radius tick>*<radius diff>=x*cos(<angle tick>*<angle diff>)+y*sin(<angle tick>*<angle diff>)
__global__ void renderLinesPolar(uint32_t *lineparameters,uint32_t lineparametercount,uint8_t *frame,uint32_t width,uint32_t height,float angled,float radiusd){
// Calculate and check index in the list for this
// thread.
int index=blockIdx.x*gridDim.x+threadIdx.x;
if(index<lineparametercount){
float angle=(lineparameters[index]>>16)*angled;
float radius=((uint16_t)lineparameters[index])*radiusd;
float sinangle;
float cosangle;
sincosf(angle,&sinangle,&cosangle);
// Since equation to satisfy is
// <radius>=x*cos(<angle>)+y*sin(<angle>)
// then
// y=x*cos(<angle>)*sin(<angle>)^(-1)+<radius>*sin(<angle>)^(-1)
// if sin(<angle>)!=0.
// IF sin(<angle>)==0 we have vertical line
if(sinangle==0){
// Loop over x dimension (width) and calculate
// closest y dimension (height) pixel.
for(uint32_t x=0;x<width;x++){
// Calculate closes y to used in the frame.
double yprecise=round((x*cosangle+radius)/sinangle);
uint32_t y=(uint32_t)(yprecise+1/2);
if(y<height) frame[y*width+x]=255;
else break;
}
}
else{
// Draw horizontal line at radius distance away.
uint32_t x=round(radius);
for(uint32_t y=0;y<height;y++) frame[y*width+x]=255;
}
}
}
// End bracket for mangling.
}