forked from segfault87/stitchy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkdtree.h
66 lines (50 loc) · 1.17 KB
/
kdtree.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
// Copyright (c) 2012 Park Joon-Kyu
#ifndef _KDTREE_H_
#define _KDTREE_H_
#include <vector>
#include "color.h"
class ColorManager;
namespace Comparator
{
struct Red {
bool operator()(const Color *lhs, const Color *rhs) {
return lhs->red() < rhs->red();
}
};
struct Green {
bool operator()(const Color *lhs, const Color *rhs) {
return lhs->green() < rhs->green();
}
};
struct Blue {
bool operator()(const Color *lhs, const Color *rhs) {
return lhs->blue() < rhs->blue();
}
};
}
typedef std::vector<const Color *> ColorList;
typedef ColorList::iterator ColorListItr;
class KdNode
{
private:
KdNode(ColorListItr begin, ColorListItr end, int depth = 0);
~KdNode();
const Color *color_;
KdNode *left_;
KdNode *right_;
friend class KdTree;
};
class KdTree
{
public:
KdTree(ColorManager *manager, const Color *transparentColor);
KdTree(ColorListItr begin, ColorListItr end);
~KdTree();
const Color* nearest(const QColor &color);
private:
static int distance(byte a[], const Color *b);
const Color* nearest(KdNode *node, byte color[],
const Color *&min, int depth = 0);
KdNode *root_;
};
#endif