-
Notifications
You must be signed in to change notification settings - Fork 0
/
bottleneck_distance.cpp
73 lines (51 loc) · 1.73 KB
/
bottleneck_distance.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
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
/**
* Author: Kelvin Abrokwa ([email protected])
*/
#include "mex.h"
#include "CBottleneckDistance.cpp"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]);
void printGenerators(std::vector<Generator> generators);
std::vector<Generator> loadGenerators(double* A, int m, int n, double maxLevel);
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
double *A, *B;
int mA, nA, mB, nB;
// TODO: accept as parameter
double maxLevel = 1;
// validate Matlab arguments
if (nrhs != 2)
mexErrMsgIdAndTxt("Bottleneck:b:nrhs", "Arguments: 2 Mx2 matrices");
A = mxGetPr(prhs[0]);
B = mxGetPr(prhs[1]);
mA = mxGetM(prhs[0]);
nA = mxGetN(prhs[0]);
mB = mxGetM(prhs[1]);
nB = mxGetN(prhs[1]);
if (nA != 2 || nB != 2)
mexErrMsgIdAndTxt("Bottleneck:b:nrhs", "Mx2 matrices required");
CBottleneckDistance d;
std::vector<Generator> gensA = loadGenerators(A, mA, nB, maxLevel);
std::vector<Generator> gensB = loadGenerators(B, mB, nB, maxLevel);
float distance = d.Distance(gensA, gensB, maxLevel);
plhs[0] = mxCreateDoubleScalar(distance);
}
/**
*
*/
std::vector<Generator> loadGenerators(double* A, int m, int n, double maxLevel)
{
std::vector<Generator> generators;
Generator gen;
for (int row = 0; row < m; row++) {
for (int col = 0; col < n; col++) {
if (col % 2)
gen.death = A[row + col*m] == -1 ? maxLevel : A[row + col*m];
else
gen.birth = A[row + col*m] == -1 ? maxLevel : A[row + col*m];
}
// TODO: incorporate generator neglection
generators.push_back(gen);
}
return generators;
}