-
Notifications
You must be signed in to change notification settings - Fork 0
/
binary_mean_tree.cpp
36 lines (28 loc) · 1.08 KB
/
binary_mean_tree.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
#include "distances.h"
#include "binary_mean_tree.h"
BinaryMeanTree::BinaryMeanTree(const vector<int> &cluster) {
this->pos = 0;
this->head = new Node;
int height = ceil(log2(cluster.size()));
build_tree(head, 0, height, cluster);
}
void BinaryMeanTree::build_tree(Node *node, int curr, int height, const vector<int> &cluster) {
if (curr < height) {
node->left = new Node;
node->right = new Node;
build_tree(node->left, curr + 1, height, cluster);
if (this->pos < (int)cluster.size()) {
build_tree(node->right, curr + 1, height, cluster);
discrete_frechet_distance(node->left->curve, node->right->curve, node->curve, true);
node->curve.set_dimension(input_curves[0].get_dimension());
} else {
node->curve = node->left->curve;
}
} else if (curr == height) {
node->curve = input_curves[cluster[this->pos++]];
node->curve.set_dimension(input_curves[0].get_dimension());
}
}
const Curve* BinaryMeanTree::get_mean() const {
return &head->curve;
}