-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdendnode.h
More file actions
122 lines (96 loc) · 2.31 KB
/
dendnode.h
File metadata and controls
122 lines (96 loc) · 2.31 KB
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
/*
Created by: Jason Carlisle Mann (on2valhalla | jcm2207@columbia.edu)
A Node class for making dendrograms, as well as displaying with D3
*/
#ifndef DENDNODE_H
#define DENDNODE_H
#include <string>
#include <vector>
#include <stack>
#include <iostream>
#include <fstream>
#include <cmath>
#include <opencv2/core/core.hpp>
class DendNode
{
public:
static const float VALUE = 1.0;
double distance;
DendNode *left;
DendNode *right;
std::vector<int> idxs;
DendNode()
{
distance = -1;
left = NULL;
right = NULL;
}
DendNode(int idx)
{
distance = -1;
idxs.push_back(idx);
left = NULL;
right = NULL;
}
DendNode(DendNode *l, DendNode *r, double matchD)
{
distance = matchD;
left = l;
right = r;
idxs.insert(idxs.begin(),
l->idxs.begin(), l->idxs.end());
idxs.insert(idxs.begin(),
r->idxs.begin(), r->idxs.end());
}
DendNode(const DendNode &node)
{
distance = node.distance;
left = node.left;
right = node.right;
idxs = node.idxs;
}
~DendNode()
{
if( left != NULL)
delete left;
if( right != NULL)
delete right;
}
friend std::ostream& operator<< (std::ostream &o, const DendNode &n);
// finds the maximum match between two nodes (possibly trees)
// by checking the lookup Mat provided
float maxMatch(const DendNode* node, const cv::Mat &lookup)
{
float max = 0;
std::vector<int>::iterator it = idxs.begin();
std::vector<int>::const_iterator jt;
for (; it != idxs.end(); it++)
for (jt = node->idxs.begin(); jt != node->idxs.end(); jt++)
if (lookup.at<float>(*it, *jt) > max)
max = lookup.at<float>(*it, *jt);
return max;
}
// finds the minimum match between two nodes (possibly trees)
// by checking the lookup Mat provided
float minMatch(const DendNode* node, const cv::Mat &lookup)
{
float min = 2;
std::vector<int>::iterator it = idxs.begin();
std::vector<int>::const_iterator jt;
for (; it != idxs.end(); it++)
for (jt = node->idxs.begin(); jt != node->idxs.end(); jt++)
if (lookup.at<float>(*it, *jt) < min)
min = lookup.at<float>(*it, *jt);
return min;
}
int getIdx()
{
if(idxs.size() > 1)
return -1;
return idxs[0];
}
void toJson(std::string fileName);
int recursiveWriter(DendNode *node, std::ofstream &file,
std::stringstream &links, int *group, float *distTrack);
};
#endif // DENDNODE_H