comparison toolboxes/FullBNT-1.0.7/KPMtools/rectintLoopC.c @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1
2 #include "mex.h"
3 #include <stdio.h>
4
5 #define MAX(x,y) ((x)>(y) ? (x) : (y))
6 #define MIN(x,y) ((x)<(y) ? (x) : (y))
7
8 void mexFunction(
9 int nlhs, mxArray *plhs[],
10 int nrhs, const mxArray *prhs[]
11 )
12 {
13 int j,k,m,n,nzmax,*irs,*jcs, *irs2, *jcs2;
14 double *overlap, *overlap2, tmp, areaA, areaB;
15 double *leftA, *rightA, *topA, *bottomA;
16 double *leftB, *rightB, *topB, *bottomB;
17 double *verbose;
18
19 m = MAX(mxGetM(prhs[0]), mxGetN(prhs[0]));
20 n = MAX(mxGetM(prhs[4]), mxGetN(prhs[4]));
21 /* printf("A=%d, B=%d\n", m, n); */
22
23 leftA = mxGetPr(prhs[0]);
24 rightA = mxGetPr(prhs[1]);
25 topA = mxGetPr(prhs[2]);
26 bottomA = mxGetPr(prhs[3]);
27
28 leftB = mxGetPr(prhs[4]);
29 rightB = mxGetPr(prhs[5]);
30 topB = mxGetPr(prhs[6]);
31 bottomB = mxGetPr(prhs[7]);
32
33 verbose = mxGetPr(prhs[8]);
34
35 plhs[0] = mxCreateDoubleMatrix(m,n, mxREAL);
36 overlap = mxGetPr(plhs[0]);
37
38 plhs[1] = mxCreateDoubleMatrix(m,n, mxREAL);
39 overlap2 = mxGetPr(plhs[1]);
40
41 k = 0;
42 for (j = 0; (j < n); j++) {
43 int i;
44 for (i = 0; (i < m); i++) {
45 tmp = (MAX(0, MIN(rightA[i], rightB[j]) - MAX(leftA[i], leftB[j]) )) *
46 (MAX(0, MIN(topA[i], topB[j]) - MAX(bottomA[i], bottomB[j]) ));
47
48 if (tmp > 0) {
49 overlap[k] = tmp;
50
51 areaA = (rightA[i]-leftA[i])*(topA[i]-bottomA[i]);
52 areaB = (rightB[j]-leftB[j])*(topB[j]-bottomB[j]);
53 overlap2[k] = tmp/MIN(areaA, areaB);
54
55 if (*verbose) {
56 printf("j=%d,i=%d,overlap=%5.3f, norm=%5.3f\n", j,i, overlap[k], overlap2[k]);
57 }
58 }
59
60 k++;
61 }
62 }
63 }
64
65
66
67
68
69
70
71