forked from starkdg/Redis-ImageScout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mvpnode.hpp
137 lines (93 loc) · 3.62 KB
/
mvpnode.hpp
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#ifndef _MVPNODE_H
#define _MVPNODE_H
#include <cstring>
#include <map>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stdexcept>
#include "datapoint.hpp"
using namespace std;
class MVPNode {
public:
MVPNode(){}
virtual ~MVPNode(){};
static MVPNode* CreateNode(vector<DataPoint*> &points,
map<int,vector<DataPoint*>*> &childpoints,
int level, int index);
void InsertItemIntoList(list<QueryResult> &list, QueryResult &item)const;
virtual MVPNode* AddDataPoints(vector<DataPoint*> &points,
map<int,vector<DataPoint*>*> &childpoints,
const int level, const int index) = 0;
virtual const int GetCount()const = 0;
virtual void SetChildNode(const int n, MVPNode *node) = 0;
virtual MVPNode* GetChildNode(int n)const = 0;
virtual const vector<DataPoint*> GetVantagePoints()const = 0;
virtual const vector<DataPoint*> GetDataPoints()const = 0;
virtual const vector<DataPoint*> FilterDataPoints(const DataPoint *target, const double radius)const = 0;
virtual void TraverseNode(const DataPoint &target,
const double radius,
map<int, MVPNode*> &childnodes,
const int index,
list<QueryResult> &results)const = 0;
virtual const vector<DataPoint*> PurgeDataPoints()=0;
};
class MVPInternal : public MVPNode {
private:
int m_nvps;
DataPoint* m_vps[MVP_LEVELSPERNODE];
MVPNode* m_childnodes[MVP_FANOUT];
double m_splits[MVP_LEVELSPERNODE][MVP_NUMSPLITS];
void SelectVantagePoints(vector<DataPoint*> &points);
void CalcSplitPoints(const vector<double> &dists, int n, int split_index);
vector<double> CalcPointDistances(DataPoint &vp, vector<DataPoint*> &points);
vector<DataPoint*>* CullPoints(vector<DataPoint*> &list, vector<double> &dists,
double split, bool less);
void CollatePoints(vector<DataPoint*> &points,
map<int, vector<DataPoint*>*> &childpoints,
const int level, const int index);
public:
MVPInternal();
~MVPInternal(){};
MVPNode* AddDataPoints(vector<DataPoint*> &points,
map<int,vector<DataPoint*>*> &childpoints,
const int level, const int index);
const int GetCount()const;
void SetChildNode(const int n, MVPNode *node);
MVPNode* GetChildNode(const int n)const;
const vector<DataPoint*> GetVantagePoints()const;
const vector<DataPoint*> GetDataPoints()const;
const vector<DataPoint*> FilterDataPoints(const DataPoint *target, const double radius)const;
void TraverseNode(const DataPoint &target,const double radius,
map<int, MVPNode*> &childnodes,
const int index,
list<QueryResult> &results)const;
const vector<DataPoint*> PurgeDataPoints();
};
class MVPLeaf : public MVPNode {
private:
int m_nvps;
DataPoint* m_vps[MVP_PATHLENGTH];
double m_pdists[MVP_PATHLENGTH][MVP_LEAFCAP];
vector<DataPoint*> m_points;
void SelectVantagePoints(vector<DataPoint*> &points);
void MarkLeafDistances(vector<DataPoint*> &points);
public:
MVPLeaf();
~MVPLeaf(){};
MVPNode* AddDataPoints(vector<DataPoint*> &points,
map<int,vector<DataPoint*>*> &childpoints,
const int level, const int index);
const int GetCount()const;
void SetChildNode(const int n, MVPNode *node);
MVPNode* GetChildNode(const int n)const;
const vector<DataPoint*> GetVantagePoints()const;
const vector<DataPoint*> GetDataPoints()const;
const vector<DataPoint*> FilterDataPoints(const DataPoint *target, const double radius)const;
void TraverseNode(const DataPoint &target,const double radius,
map<int, MVPNode*> &childnodes,
const int index,
list<QueryResult> &results)const;
const vector<DataPoint*> PurgeDataPoints();
};
#endif /* _MVPNODE_H */