forked from snailcon/QuadtreeAmogufier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Quadtree.h
68 lines (50 loc) · 1.58 KB
/
Quadtree.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
#ifndef QUADTREE_H
#define QUADTREE_H
#include "Image.h"
#include <cstdint>
#include <map>
#include <memory>
#include <optional>
#include <shared_mutex>
#include <tuple>
#include <variant>
struct BWParameters {
int similarityThreshold;
};
struct ColorParameters {
int similarityThreshold;
};
struct QuadtreeParameters {
int minSize;
RgbColor background;
};
class SubdivisionChecker {
public:
using Ptr = std::shared_ptr<SubdivisionChecker>;
virtual ~SubdivisionChecker() = default;
virtual RgbColor GetColor(const Image &frame, Rect r) const = 0;
virtual std::tuple<bool, RgbColor> Merge(const RgbColor &tl, const RgbColor &tr, const RgbColor &bl,
const RgbColor &br) const = 0;
};
class Quadtree {
public:
Quadtree(Image leafImage, QuadtreeParameters params, SubdivisionChecker::Ptr checker);
Image ProcessFrame(Image frame);
private:
struct LeafData {
RgbColor color;
Rect bounds;
};
using ProcResult = std::optional<LeafData>;
void RenderLeaf(Image &dst, const LeafData &data);
ProcResult ProcessFrame(Image &dst, Rect bounds);
const Image &GetLeaf(Rect bounds);
std::unique_ptr<std::shared_mutex> mCacheMutex = std::make_unique<std::shared_mutex>();
std::map<std::pair<int, int>, Image> mLeafCache;
Image mLeafImage;
QuadtreeParameters mParams;
SubdivisionChecker::Ptr mSubChecker;
};
SubdivisionChecker::Ptr CreateSubdivisionChecker(const BWParameters ¶ms);
SubdivisionChecker::Ptr CreateSubdivisionChecker(const ColorParameters ¶ms);
#endif