-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPTWithCompression.h
103 lines (83 loc) · 2.15 KB
/
PTWithCompression.h
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
#pragma once
#include <imagina/evaluator.h>
#include <vector>
namespace PTWithCompression {
using namespace Imagina;
using real = real_sr;
using complex = complex_sr;
struct Waypoint {
complex Z;
uint_iter Iteration;
};
struct CompressedReference {
std::vector<Waypoint> Waypoints;
complex_sr C;
};
class ReferenceCompressor {
CompressedReference &reference;
complex z = 0.0, c = 0.0;
uint_iter iteration = 0;
real tolerance = 0x1p-32;
public:
ReferenceCompressor(CompressedReference &reference, complex_sr C, real tolerance = 0x1p-32)
: reference(reference), c(C), tolerance(tolerance) {
reference.Waypoints.clear();
reference.C = C;
}
void Add(complex Z) {
z = z * z + c;
iteration++;
if (chebyshev_norm(z - Z) > chebyshev_norm(Z) * tolerance) {
reference.Waypoints.push_back({ Z, iteration });
z = Z;
}
}
void Finalize(complex Z) {
iteration++;
reference.Waypoints.push_back({ Z, iteration });
}
};
class ReferenceDecompressor {
using Iterator = std::vector<Waypoint>::const_iterator;
const CompressedReference &reference;
complex Z = 0.0;
uint_iter iteration = 0;
Iterator nextWaypoint;
public:
ReferenceDecompressor(const CompressedReference &reference) : reference(reference) {
nextWaypoint = reference.Waypoints.begin();
}
complex Get() { return Z; }
complex Next() {
iteration++;
if (iteration == nextWaypoint->Iteration) {
Z = nextWaypoint->Z;
nextWaypoint++;
} else {
Z = Z * Z + reference.C;
}
return Z;
}
bool End() {
return nextWaypoint == reference.Waypoints.end();
}
complex Reset() {
Z = 0.0;
iteration = 0;
nextWaypoint = reference.Waypoints.begin();
return Z;
}
};
class PTWithCompressionEvaluator {
struct Output {
double Value;
};
StandardEvaluationParameters parameters;
CompressedReference reference;
public:
const PixelDataInfo *GetOutputInfo();
void Prepare(const real_hp &x, const real_hp &y, real_hr radius, const StandardEvaluationParameters ¶meters);
void Evaluate(IRasterizer rasterizer);
};
}
IMPLEMENT_INTERFACE(PTWithCompression::PTWithCompressionEvaluator, Imagina::IEvaluator);