-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPerturbation.cpp
63 lines (49 loc) · 1.33 KB
/
Perturbation.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
#include "Perturbation.h"
#include <imagina/output_info_helper.h>
#include <imagina/pixel_management.h>
namespace Perturbation {
const PixelDataInfo *PerturbationEvaluator::GetOutputInfo() {
IM_GET_OUTPUT_INFO_IMPL(Output, Value);
}
void PerturbationEvaluator::Prepare(const real_hp &x, const real_hp &y, real_hr radius, const StandardEvaluationParameters ¶meters) {
this->parameters = parameters;
delete[] reference;
reference = new complex[parameters.Iterations + 1];
complex_hp C = complex_hp(x, y);
complex_hp Z = C;
reference[0] = 0.0;
reference[1] = complex(Z);
size_t i = 1;
while (i < parameters.Iterations) {
Z = Z * Z + C;
i++;
complex z = complex(Z);
reference[i] = z;
if (norm(z) > 16.0) break;
}
referenceLength = i;
}
void PerturbationEvaluator::Evaluate(IRasterizer rasterizer) {
real_hr x, y;
while (rasterizer.GetPixel(x, y)) {
complex dc = { real(x), real(y) };
complex Z = 0.0, z = 0.0, dz = 0.0;
uint_iter i = 0, j = 0;
while (i < parameters.Iterations) {
dz = dz * (Z + z) + dc;
i++; j++;
Z = reference[j];
z = Z + dz;
if (norm(z) > 4096.0) break;
if (j == referenceLength || norm(z) < norm(dz)) {
Z = real(0.0);
dz = z;
j = 0;
}
}
Output output;
output.Value = i;
rasterizer.WriteResults(&output);
}
}
}