-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lens.cpp
105 lines (78 loc) · 1.54 KB
/
Lens.cpp
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
//
// Created by jwc on 2/16/19.
//
#include "Lens.h"
Lens::Lens()
{
for (int i=0; i<2; i++) {
cacheData[i].s=-1;
cacheData[i].dta = nullptr;
cacheData[i].needUpdate = true;
}
size = .05;
intensity = 1.0;
}
float Lens::get(float x, float y)
{
return proc(x,y)*intensity;
}
void Lens::setSize(float size)
{
if (size != this->size)
{
//cacheData[0].s = -1;
//cacheData[1].s = -1;
this->size = size;
}
}
void Lens::setIntensity(float intensity) {
if (intensity != this->intensity) {
cacheData[0].needUpdate = true;
cacheData[1].needUpdate = true;
this->intensity = intensity;
}
}
bool Lens::getData(int entry, int s, Cache **data)
{
bool rc;
if (s != cacheData[entry].s)
{
rc = false;
} else rc = true;
*data = &cacheData[entry];
return rc;
}
float **Lens::map(int sz)
{
int q = (sz<<1)+1;
float *m = new float[q*q];
float **lines = new float*[q];
float *cur = m+sz;
for (int y=0; y<q; y++)
{
lines[y] = cur;
cur += q;
}
float **ret = lines+sz;
return ret;
}
void Lens::updateMap(float **map, int sz)
{
float _sz = (float)sz;
for (int y=-sz; y<=sz; y++)
{
float _y = y / _sz;
for (int x=-sz; x<=sz; x++)
{
float _x = x / _sz;
map[y][x] = get(_x,_y);
}
}
}
void Lens::freeMap(float **map, int sz)
{
int q = (sz<<1)+1;
float *m = map[-sz]-sz;
delete[] (map-sz);
delete[] m;
}