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