void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int i, j, m, n; double s1=0.0, s2=0.0; double *dat; MAPTYPE *map, *get_maps(); static double M[] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1}; if (nrhs != 1 || nlhs > 1) { mexErrMsgTxt("Incorrect usage."); } map = get_maps(prhs[0], &j); if (j != 1) { free_maps(map, j); mexErrMsgTxt("Incorrect usage."); } n = (map->dim[0])*(map->dim[1]); dat = (double *)mxCalloc(n, sizeof(double)); s1 = 0.0; m = 0; for (i=0; i<map->dim[2]; i++) { M[14] = i+1; slice(M, dat, map->dim[0],map->dim[1], map, 0,0); for(j=0;j<n; j++) if (mxIsFinite(dat[j])) { s1 += dat[j]; m ++; } } s1/=(8.0*m); s2=0.0; m =0; for (i=0; i<map->dim[2]; i++) { M[14] = i+1; slice(M, dat, map->dim[0],map->dim[1], map, 0,0); for(j=0;j<n; j++) if (mxIsFinite(dat[j]) && dat[j]>s1) { m++; s2+=dat[j]; } } s2/=m; plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL); mxGetPr(plhs[0])[0]=s2; free_maps(map, 1); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int k, d[3], sts; MAPTYPE *vol, *get_maps(); double *c; void (*splinc[3])(); if (nrhs < 2 || nlhs > 1) mexErrMsgTxt("Incorrect usage."); if (mxIsComplex(prhs[1]) || mxIsSparse(prhs[1]) || (mxGetM(prhs[1])*mxGetN(prhs[1]) != 3 && mxGetM(prhs[1])*mxGetN(prhs[1]) != 6)) mexErrMsgTxt("Incorrect usage."); for(k=0; k<3; k++) { d[k] = floor(mxGetPr(prhs[1])[k]+0.5); if (d[k]<0 || d[k]>7) mexErrMsgTxt("Bad spline degree."); } /* for(k=0; k<3; k++) splinc[k] = splinc_mirror; */ for(k=0; k<3; k++) splinc[k] = splinc_neumann; if (mxGetM(prhs[1])*mxGetN(prhs[1]) == 6) { for(k=0; k<3; k++) if (mxGetPr(prhs[1])[k+3]) splinc[k] = splinc_wrap; } vol=get_maps(prhs[0], &k); if (k!=1) { free_maps(vol, k); mexErrMsgTxt("Too many images."); } plhs[0] = mxCreateNumericArray(3,vol->dim, mxDOUBLE_CLASS, mxREAL); c = mxGetPr(plhs[0]); sts = vol_coeffs(vol, c, d, splinc); if (sts) { free_maps(vol, k); mexErrMsgTxt("Problem with deconvolution."); } free_maps(vol, k); }
void mexFunction1(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { MAPTYPE *vol, *get_maps(); int m0,m1,m2, n0,n1,n2; double *B0, *B1, *B2; for(n0=1; n0<nrhs; n0++) { if (!mxIsNumeric(prhs[n0]) || mxIsComplex(prhs[n0]) || mxIsSparse(prhs[n0]) || !mxIsDouble(prhs[n0])) { mexErrMsgTxt("Arguments must be numeric, real, full and double."); } } vol = get_maps(prhs[0], &n0); if (n0!=1) { free_maps(vol, n0); mexErrMsgTxt("Incorrect usage."); } n0 = vol->dim[0]; n1 = vol->dim[1]; n2 = vol->dim[2]; m0 = mxGetN(prhs[1]); m1 = mxGetN(prhs[2]); m2 = mxGetN(prhs[3]); if (m0>MAXB || m1>MAXB || m2>MAXB) { free_maps(vol, 1); mexErrMsgTxt("Too many basis functions."); } B0 = mxGetPr(prhs[1]); B1 = mxGetPr(prhs[2]); B2 = mxGetPr(prhs[3]); if (mxGetM(prhs[1])!=n0 || mxGetM(prhs[2])!=n1 || mxGetM(prhs[3])!=n2) { free_maps(vol, 1); mexErrMsgTxt("Inappropriate matrix dimensions."); } plhs[0] = mxCreateDoubleMatrix(m0*m1*m2,1, mxREAL); plhs[1] = mxCreateDoubleMatrix(1,1, mxREAL); mxGetPr(plhs[1])[0] = constr(m0,m1,m2,n0,n1,n2,mxGetPr(plhs[0]),vol,B0,B1,B2); free_maps(vol, 1); }
static void test_read_maps(void) { FILE *fp = fopen("maps.txt", "r"); struct proc_map *result = read_maps(fp, "libc-2.11.1.so"); fclose(fp); assert(result != NULL); assert(0 == result->base); assert(0x00b16000 == result->lo); assert(0x00c69000 == result->hi); struct proc_map *next = result->next; assert(next != NULL); assert(0x00153000 == next->base); assert(0x00c69000 == next->lo); assert(0x00c6a000 == next->hi); next = next->next; assert(next != NULL); assert(0x00153000 == next->base); assert(0x00c6a000 == next->lo); assert(0x00c6c000 == next->hi); next = next->next; assert(next != NULL); assert(0x00155000 == next->base); assert(0x00c6c000 == next->lo); assert(0x00c6d000 == next->hi); unsigned int fake = 0x00b16000 + 0x000f7e30; unsigned int realaddr = get_real_address(result, fake); assert(realaddr == 0x000f7e30); free_maps(result); }
void default_unicode_map(smb_ucs2_t **pp_cp_to_ucs2, uint16 **pp_ucs2_to_cp) { int i; free_maps(pp_cp_to_ucs2, pp_ucs2_to_cp); if ((*pp_ucs2_to_cp = (uint16 *)malloc(2*65536)) == NULL) { DEBUG(0,("default_unicode_map: malloc fail for ucs2_to_cp size %u.\n", 2*65536)); abort(); } *pp_cp_to_ucs2 = *pp_ucs2_to_cp; /* Default map is an identity. */ for (i = 0; i < 65536; i++) (*pp_cp_to_ucs2)[i] = i; }
static void get_map_dat(int i, const mxArray *ptr, MAPTYPE *maps) { mxArray *tmp; double *pr; int num_dims, j, t, dtype = 0; const mwSize *dims; unsigned char *dptr; tmp=mxGetField(ptr,i,"dat"); if (tmp == (mxArray *)0) { free_maps(maps,i); mexErrMsgTxt("Cant find dat."); } if (mxIsDouble(tmp)) dtype = SPM_DOUBLE; else if (mxIsSingle(tmp)) dtype = SPM_FLOAT; else if (mxIsInt32 (tmp)) dtype = SPM_SIGNED_INT; else if (mxIsUint32(tmp)) dtype = SPM_UNSIGNED_INT; else if (mxIsInt16 (tmp)) dtype = SPM_SIGNED_SHORT; else if (mxIsUint16(tmp)) dtype = SPM_UNSIGNED_SHORT; else if (mxIsInt8 (tmp)) dtype = SPM_SIGNED_CHAR; else if (mxIsUint8 (tmp)) dtype = SPM_UNSIGNED_CHAR; else { free_maps(maps,i); mexErrMsgTxt("Unknown volume datatype."); } dptr = (unsigned char *)mxGetPr(tmp); num_dims = mxGetNumberOfDimensions(tmp); if (num_dims > 3) { free_maps(maps,i); mexErrMsgTxt("Too many dimensions."); } dims = mxGetDimensions(tmp); for(j=0; j<num_dims; j++) maps[i].dim[j]=dims[j]; for(j=num_dims; j<3; j++) maps[i].dim[j]=1; tmp=mxGetField(ptr,i,"dim"); if (tmp != (mxArray *)0) { if (mxGetM(tmp)*mxGetN(tmp) != 3) { free_maps(maps,i); mexErrMsgTxt("Wrong sized dim."); } pr = mxGetPr(tmp); if (maps[i].dim[0] != (mwSize)fabs(pr[0]) || maps[i].dim[1] != (mwSize)fabs(pr[1]) || maps[i].dim[2] != (mwSize)fabs(pr[2])) { free_maps(maps,i); mexErrMsgTxt("Incompatible volume dimensions in dim."); } } tmp=mxGetField(ptr,i,"dt"); if (tmp != (mxArray *)0) { if (mxGetM(tmp)*mxGetN(tmp) != 1 && mxGetM(tmp)*mxGetN(tmp) != 2) { free_maps(maps,i); mexErrMsgTxt("Wrong sized dt."); } pr = mxGetPr(tmp); if (dtype != (int)fabs(pr[0])) { free_maps(maps,i); mexErrMsgTxt("Incompatible datatype in dt."); } } maps[i].addr = 0; maps[i].len = 0; maps[i].dtype = dtype; maps[i].data = (void **)mxCalloc(maps[i].dim[2],sizeof(void *)); maps[i].scale = (double *)mxCalloc(maps[i].dim[2],sizeof(double)); maps[i].offset = (double *)mxCalloc(maps[i].dim[2],sizeof(double)); t = maps[i].dim[0]*maps[i].dim[1]*get_datasize(maps[i].dtype)/8; tmp = mxGetField(ptr,i,"pinfo"); if (tmp != (mxArray *)0) { if ((mxGetM(tmp) != 2 && mxGetM(tmp) != 3) || (mxGetN(tmp) != 1 && mxGetN(tmp) != maps[i].dim[2])) { free_maps(maps,i+1); mexErrMsgTxt("Wrong sized pinfo."); } if (mxGetM(tmp) == 3 && mxGetPr(tmp)[2] != 0) { free_maps(maps,i+1); mexErrMsgTxt("pinfo(3) must equal 0 to read dat field."); } pr = mxGetPr(tmp); if (mxGetN(tmp) == 1) for(j=0; j<maps[i].dim[2]; j++) { maps[i].scale[j] = pr[0]; maps[i].offset[j] = pr[1]; maps[i].data[j] = &(dptr[j*t]); } else for(j=0; j<maps[i].dim[2]; j++) { maps[i].scale[j] = pr[0+j*2]; maps[i].offset[j] = pr[1+j*2]; maps[i].data[j] = &(dptr[j*t]); } } else for(j=0; j<maps[i].dim[2]; j++) { maps[i].scale[j] = 1.0; maps[i].offset[j] = 0.0; maps[i].data[j] = &(dptr[j*t]); } tmp=mxGetField(ptr,i,"mat"); if (tmp != (mxArray *)0) { if (mxGetM(tmp) != 4 || mxGetN(tmp) != 4) { free_maps(maps,i+1); mexErrMsgTxt("Wrong sized mat."); } pr = mxGetPr(tmp); for(j=0; j<16; j++) maps[i].mat[j] = pr[j]; } else { for(j=0; j<16; j++) maps[i].mat[j] = 0.0; for(j=0; j<4; j++) maps[i].mat[j + j*4] = 1.0; } }
static void get_map_file(int i, const mxArray *ptr, MAPTYPE *maps) { int j; mxArray *tmp; double *pr; mwSize dsize = 0; mwSize off; #ifdef SPM_BIGENDIAN int be = 1; #else int be = 0; #endif tmp=mxGetField(ptr,i,"dim"); if (tmp == (mxArray *)0) { free_maps(maps,i); mexErrMsgTxt("Cant find dim."); } if (mxGetM(tmp)*mxGetN(tmp) != 3) { free_maps(maps,i); mexErrMsgTxt("Wrong sized dim."); } pr = mxGetPr(tmp); maps[i].dim[0] = (int)fabs(pr[0]); maps[i].dim[1] = (int)fabs(pr[1]); maps[i].dim[2] = (int)fabs(pr[2]); maps[i].dtype = (int)fabs(pr[3]); maps[i].data = (void **)mxCalloc(maps[i].dim[2],sizeof(void *)); maps[i].scale = (double *)mxCalloc(maps[i].dim[2],sizeof(double)); maps[i].offset = (double *)mxCalloc(maps[i].dim[2],sizeof(double)); tmp=mxGetField(ptr,i,"dt"); if (tmp == (mxArray *)0) { free_maps(maps,i+1); mexErrMsgTxt("Cant find dt."); } if (mxGetM(tmp)*mxGetN(tmp) != 2) { free_maps(maps,i+1); mexErrMsgTxt("Wrong sized dt."); } pr = mxGetPr(tmp); if ((int)(pr[1])==be) { if (pr[0]== 2) {maps[i].dtype = SPM_UNSIGNED_CHAR; dsize = 8;} else if (pr[0]== 256) {maps[i].dtype = SPM_SIGNED_CHAR; dsize = 8;} else if (pr[0]== 4) {maps[i].dtype = SPM_SIGNED_SHORT; dsize = 16;} else if (pr[0]== 512) {maps[i].dtype = SPM_UNSIGNED_SHORT; dsize = 16;} else if (pr[0]== 8) {maps[i].dtype = SPM_SIGNED_INT; dsize = 32;} else if (pr[0]== 768) {maps[i].dtype = SPM_UNSIGNED_INT; dsize = 32;} else if (pr[0]== 16) {maps[i].dtype = SPM_FLOAT; dsize = 32;} else if (pr[0]== 64) {maps[i].dtype = SPM_DOUBLE; dsize = 64;} else {free_maps(maps,i+1);mexErrMsgTxt("Unknown datatype.");} } else { if (pr[0]== 2) {maps[i].dtype = SPM_UNSIGNED_CHAR; dsize = 8;} else if (pr[0]== 256) {maps[i].dtype = SPM_SIGNED_CHAR; dsize = 8;} else if (pr[0]== 4) {maps[i].dtype = SPM_SIGNED_SHORT_S; dsize = 16;} else if (pr[0]== 512) {maps[i].dtype = SPM_UNSIGNED_SHORT_S; dsize = 16;} else if (pr[0]== 8) {maps[i].dtype = SPM_SIGNED_INT_S; dsize = 32;} else if (pr[0]== 768) {maps[i].dtype = SPM_UNSIGNED_INT_S; dsize = 32;} else if (pr[0]== 16) {maps[i].dtype = SPM_FLOAT_S; dsize = 32;} else if (pr[0]== 64) {maps[i].dtype = SPM_DOUBLE_S; dsize = 64;} else {free_maps(maps,i+1);mexErrMsgTxt("Unknown datatype.");} } tmp=mxGetField(ptr,i,"fname"); if (tmp == (mxArray *)0) { free_maps(maps,i+1); mexErrMsgTxt("Cant find fname."); } if (mxIsChar(tmp)) { #ifdef SPM_WIN32 HANDLE hFile, hMapping; #endif char *buf = NULL; int fd; struct stat stbuf; if ((buf = mxArrayToString(tmp)) == NULL) { mxFree(buf); free_maps(maps,i+1); mexErrMsgTxt("Cant get filename."); } if ((fd = open(buf, O_RDONLY)) == -1) { mxFree(buf); free_maps(maps,i+1); mexErrMsgTxt("Cant open image file."); } if (fstat(fd, &stbuf) == -1) { (void)close(fd); mxFree(buf); free_maps(maps,i+1); mexErrMsgTxt("Cant get file size."); } maps[i].len = stbuf.st_size; #ifdef SPM_WIN32 (void)close(fd); /* maps[i].addr = map_file(buf, (caddr_t)0, maps[i].len, * PROT_READ, MAP_SHARED, (off_t)0); */ /* http://msdn.microsoft.com/library/default.asp? url=/library/en-us/fileio/base/createfile.asp */ hFile = CreateFile(buf, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL); mxFree(buf); if (hFile == NULL) mexErrMsgTxt("Cant open file. It may be locked by another program."); /* http://msdn.microsoft.com/library/default.asp? url=/library/en-us/fileio/base/createfilemapping.asp */ hMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL); (void)CloseHandle(hFile); if (hMapping == NULL) mexErrMsgTxt("Cant create file mapping. It may be locked by another program."); /* http://msdn.microsoft.com/library/default.asp? url=/library/en-us/fileio/base/mapviewoffile.asp */ maps[i].addr = (caddr_t)MapViewOfFileEx(hMapping, FILE_MAP_READ, 0, 0, maps[i].len, 0); (void)CloseHandle(hMapping); if (maps[i].addr == NULL) mexErrMsgTxt("Cant map view of file. It may be locked by another program."); #else maps[i].addr = mmap((caddr_t)0, maps[i].len, PROT_READ, MAP_SHARED, fd, (off_t)0); (void)close(fd); if (maps[i].addr == (void *)-1) { (void)perror("Memory Map"); mxFree(buf); free_maps(maps,i+1); mexErrMsgTxt("Cant map image file."); } mxFree(buf); #endif } tmp=mxGetField(ptr,i,"pinfo"); if (tmp != (mxArray *)0) { if (mxGetM(tmp) != 3 || (mxGetN(tmp) != 1 && mxGetN(tmp) != maps[i].dim[2])) { free_maps(maps,i+1); mexErrMsgTxt("Wrong sized pinfo."); } pr = mxGetPr(tmp); if (mxGetN(tmp) == 1) { off = (mwSize)fabs(pr[2]); if (off+maps[i].dim[0]*maps[i].dim[1]*maps[i].dim[2]*(dsize/8) > maps[i].len) { free_maps(maps,i+1); mexErrMsgTxt("File too small."); } for(j=0; j<maps[i].dim[2]; j++) { maps[i].scale[j] = pr[0]; maps[i].offset[j] = pr[1]; maps[i].data[j] = maps[i].addr+off+j*maps[i].dim[0]*maps[i].dim[1]*(dsize/8); } } else { for(j=0; j<maps[i].dim[2]; j++) { maps[i].scale[j] = pr[0+j*3]; maps[i].offset[j] = pr[1+j*3]; off = (mwSize)fabs(pr[2+j*3]); maps[i].data[j] = maps[i].addr+off; if (off+maps[i].dim[0]*maps[i].dim[1]*(dsize/8) > maps[i].len) { free_maps(maps,i+1); mexErrMsgTxt("File too small."); } } } } else { if (maps[i].dim[0]*maps[i].dim[1]*maps[i].dim[2]*(dsize/8) > maps[i].len) { free_maps(maps,i+1); mexErrMsgTxt("File too small."); } for(j=0; j<maps[i].dim[2]; j++) { maps[i].scale[j] = 1.0; maps[i].offset[j] = 0.0; maps[i].data[j] = maps[i].addr+j*maps[i].dim[0]*maps[i].dim[1]*(dsize/8); } } tmp=mxGetField(ptr,i,"mat"); if (tmp != (mxArray *)0) { if (mxGetM(tmp) != 4 || mxGetN(tmp) != 4) { free_maps(maps,i+1); mexErrMsgTxt("Wrong sized mat."); } pr = mxGetPr(tmp); for(j=0; j<16; j++) maps[i].mat[j] = pr[j]; } else { for(j=0; j<16; j++) maps[i].mat[j] = 0.0; for(j=0; j<4; j++) maps[i].mat[j + j*4] = 1.0; } }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) /* void mexFunction(nlhs, plhs, nrhs, prhs) int nlhs, nrhs; mxArray *plhs[]; const mxArray *prhs[]; */ { MAPTYPE *map, *get_maps(); int m,n, k, hold; double background=0.0; if (nrhs != 5 || nlhs > 4) mexErrMsgTxt("Incorrect usage."); map=get_maps(prhs[0], &n); if (n!=1) { free_maps(map, n); mexErrMsgTxt("Bad image handle dimensions."); } for(k=1; k<=3; k++) if (!mxIsNumeric(prhs[k]) || mxIsComplex(prhs[k]) || mxIsSparse(prhs[k]) || !mxIsDouble(prhs[k])) { free_maps(map, 1); mexErrMsgTxt("Coordinates must be numeric, real, full and double."); } m = mxGetM(prhs[1]); n = mxGetN(prhs[1]); if (mxGetM(prhs[2]) != m || mxGetN(prhs[2]) != n || mxGetM(prhs[3]) != m || mxGetN(prhs[3]) != n) mexErrMsgTxt("Coordinates must have compatible dimensions."); if (!mxIsNumeric(prhs[4]) || mxIsComplex(prhs[4]) || mxIsSparse(prhs[4]) || !mxIsDouble(prhs[4]) || (mxGetM(prhs[4])*mxGetN(prhs[4]) != 1 && mxGetM(prhs[4])*mxGetN(prhs[4]) != 2)) { free_maps(map, 1); mexErrMsgTxt("Bad hold & background argument."); } hold = (int)(*(mxGetPr(prhs[4]))); if (abs(hold) > 127) { free_maps(map, 1); mexErrMsgTxt("Bad hold value."); } if (mxGetM(prhs[4])*mxGetN(prhs[4]) > 1) background = mxGetPr(prhs[4])[1]; if (nlhs<=1) { plhs[0] = mxCreateDoubleMatrix(m,n,mxREAL); resample(m*n, map, mxGetPr(plhs[0]), mxGetPr(prhs[1]),mxGetPr(prhs[2]),mxGetPr(prhs[3]), hold, background); } else { if (hold==0) { free_maps(map, 1); mexErrMsgTxt("This wont work for nearest neighbour resampling."); } plhs[0] = mxCreateDoubleMatrix(m,n,mxREAL); plhs[1] = mxCreateDoubleMatrix(m,n,mxREAL); plhs[2] = mxCreateDoubleMatrix(m,n,mxREAL); plhs[3] = mxCreateDoubleMatrix(m,n,mxREAL); resample_d(m*n, map, mxGetPr(plhs[0]),mxGetPr(plhs[1]),mxGetPr(plhs[2]),mxGetPr(plhs[3]), mxGetPr(prhs[1]),mxGetPr(prhs[2]),mxGetPr(prhs[3]), hold, background); } free_maps(map, 1); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int m0, m1, m2, n0, n1, n2, nh, sh; MAPTYPE *vol, *get_maps(); double *B0, *B1, *B2, mx, *f, *Alpha, *Beta, *h; if (nrhs == 4 && nlhs <=2) { mexFunction1(nlhs, plhs, nrhs, prhs); return; } if (nrhs != 6 || nlhs > 5) mexErrMsgTxt("Incorrect usage."); vol = get_maps(prhs[0], &n0); if (n0!=1) { free_maps(vol, n0); mexErrMsgTxt("Inappropriate usage."); } for(n0=1; n0<nrhs; n0++) { if (!mxIsNumeric(prhs[n0]) || mxIsComplex(prhs[n0]) || mxIsSparse(prhs[n0]) || !mxIsDouble(prhs[n0])) { free_maps(vol, 1); mexErrMsgTxt("Arguments must be numeric, real, full and double."); } } n0 = vol->dim[0]; n1 = vol->dim[1]; n2 = vol->dim[2]; m0 = mxGetN(prhs[1]); m1 = mxGetN(prhs[2]); m2 = mxGetN(prhs[3]); if (mxGetM(prhs[1])!=n0 || mxGetM(prhs[2])!=n1 || mxGetM(prhs[3])!=n2 || mxGetM(prhs[4])*mxGetN(prhs[4]) != m0*m1*m2 || mxGetM(prhs[5])*mxGetN(prhs[5])!=2) { free_maps(vol, 1); mexErrMsgTxt("Inappropriate matrix dimensions."); } if (m0>MAXB || m1>MAXB || m2>MAXB) { free_maps(vol, 1); mexErrMsgTxt("Too many basis functions."); } B0 = mxGetPr(prhs[1]); B1 = mxGetPr(prhs[2]); B2 = mxGetPr(prhs[3]); f = mxGetPr(prhs[4]); mx = mxGetPr(prhs[5])[0]; nh = floor(mxGetPr(prhs[5])[1]); if (nh<1 || nh > 10240) { free_maps(vol, 1); mexErrMsgTxt("Inappropriate number of bins in histogram."); } plhs[0] = mxCreateDoubleMatrix(m0*m1*m2,m0*m1*m2, mxREAL); plhs[1] = mxCreateDoubleMatrix(m0*m1*m2,1, mxREAL); plhs[2] = mxCreateDoubleMatrix(1,1, mxREAL); plhs[3] = mxCreateDoubleMatrix(nh,1, mxREAL); plhs[4] = mxCreateDoubleMatrix(1,1, mxREAL); /* Initialised to zero */ Alpha = mxGetPr(plhs[0]); Beta = mxGetPr(plhs[1]); h = mxGetPr(plhs[3]); mxGetPr(plhs[2])[0] = iteration(m0,m1,m2, n0,n1,n2, Alpha,Beta, vol, B0,B1,B2,f,mx, nh,h, &sh); mxGetPr(plhs[4])[0] = (double)sh; free_maps(vol, 1); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { MAPTYPE *map, *get_maps(); int m,n, k, hold, status; double *mat, *ptr, *img, background=0.0; if (nrhs != 4 || nlhs > 1) { mexErrMsgTxt("Incorrect usage."); } map = get_maps(prhs[0], &n); if (n!=1) { free_maps(map, n); mexErrMsgTxt("Bad image handle dimensions."); } for(k=1; k<=3; k++) { if (!mxIsNumeric(prhs[k]) || mxIsComplex(prhs[k]) || mxIsSparse(prhs[k]) || !mxIsDouble(prhs[k])) { free_maps(map, 1); mexErrMsgTxt("Arguments must be numeric, real, full and double."); } } /* get transformation matrix */ if (mxGetM(prhs[1]) != 4 && mxGetN(prhs[1]) != 4) { free_maps(map, 1); mexErrMsgTxt("Transformation matrix must be 4 x 4."); } mat = mxGetPr(prhs[1]); /* get output dimensions */ if (mxGetM(prhs[2]) * mxGetN(prhs[2]) != 2) { free_maps(map, 1); mexErrMsgTxt("Output dimensions must have two elements."); } ptr = mxGetPr(prhs[2]); m = abs((int)ptr[0]); n = abs((int)ptr[1]); plhs[0] = mxCreateDoubleMatrix(m,n,mxREAL); img = mxGetPr(plhs[0]); if (mxGetM(prhs[3])*mxGetN(prhs[3]) != 1 && mxGetM(prhs[3])*mxGetN(prhs[3]) != 2) { free_maps(map, 1); mexErrMsgTxt("Hold & background argument must have one or two element(s)."); } hold = (int)(*(mxGetPr(prhs[3]))); if (abs(hold) > 127) { free_maps(map, 1); mexErrMsgTxt("Bad hold value."); } if (mxGetM(prhs[3])*mxGetN(prhs[3]) > 1) background = mxGetPr(prhs[3])[1]; status = slice(mat, img, m, n, map, hold, background); free_maps(map, 1); if (status) { mexErrMsgTxt("Slicing failed."); } }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { MAPTYPE *map, *get_maps(); mwSize m,n,k; mwIndex i; int nn, E[3], F[3], P, C; double *R, r[3], *img; int *curr, *prev, *tmpp; if (nrhs != 2 || nlhs > 1) { mexErrMsgTxt("Incorrect usage."); } map = get_maps(prhs[0], &nn); if (nn!=1) { free_maps(map, nn); mexErrMsgTxt("Bad image handle dimensions."); } if (!mxIsNumeric(prhs[1]) || mxIsComplex(prhs[1]) || !mxIsDouble(prhs[1])) { free_maps(map, 1); mexErrMsgTxt("Second argument must be numeric, real, full and double."); } if (mxGetM(prhs[1])*mxGetN(prhs[1]) != 3) { free_maps(map, nn); mexErrMsgTxt("Second argument must contain three elements."); } r[0] = 1.0/mxGetPr(prhs[1])[0]; r[1] = 1.0/mxGetPr(prhs[1])[1]; r[2] = 1.0/mxGetPr(prhs[1])[2]; plhs[0] = mxCreateDoubleMatrix(4,1,mxREAL); R = mxGetPr(plhs[0]); m = map->dim[0]; n = map->dim[1]; k = map->dim[2]; curr = (int *)mxCalloc((m+1)*(n+1),sizeof(int)); /* current plane */ prev = (int *)mxCalloc((m+1)*(n+1),sizeof(int)); /* previous plane */ img = (double *)mxCalloc((m+1)*(n+1),sizeof(double)); P = C = E[0] = E[1] = E[2] = F[0] = F[1] = F[2] = 0; for(i=0; i<k; i++) { int i1, j1; static double mat[16] = { 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0}; mat[14] = i+1.0; slice(mat, img, m, n, map, 0, 0); for(i1=0;i1<m; i1++) for(j1=0; j1<n; j1++) if (mxIsFinite(img[i1+m*j1]) && img[i1+m*j1]) curr[i1+1+(m+1)*(j1+1)] = 1; else curr[i1+1+(m+1)*(j1+1)] = 0; /* count edges, faces etc */ resel_fun(curr,prev,m+1,n+1, &P, E, F, &C); /* make current plane previous */ tmpp = prev; prev = curr; curr = tmpp; } (void)mxFree((char *)curr); (void)mxFree((char *)prev); (void)mxFree((char *)img); free_maps(map, 1); R[0] = P - (E[0]+E[1]+E[2])+(F[0]+F[1]+F[2])-C; R[1] = (E[0]-F[0]-F[1]+C)*r[0] + (E[1]-F[0]-F[2]+C)*r[1] + (E[2]-F[1]-F[2]+C)*r[2]; R[2] = (F[0]-C)*r[0]*r[1] + (F[1]-C)*r[0]*r[2] + (F[2]-C)*r[1]*r[2]; R[3] = C*r[0]*r[1]*r[2]; }
/* Performs the core dump */ int do_coredump(int pid, char *core_file) { int ret; /* Initialise members of core process */ init_core(); /* Getting thread information and seizing them */ ret = seize_threads(pid); if (ret) goto cleanup; /* Wait for threads to stop */ ret = wait_for_threads_to_stop(); if (ret) goto cleanup; /* Get VMAS */ ret = get_vmas(pid, &cp); if (ret) goto cleanup; /* Compat Support */ cp.elf_class = ret = get_elf_class(pid, &cp); if (ret == -1) goto cleanup; /* Initialise core file name */ cp.corefile = core_file; /* Do elf_dump */ if (cp.elf_class == ELFCLASS32) ret = do_elf32_coredump(pid, &cp); else ret = do_elf64_coredump(pid, &cp); if (ret) goto cleanup; cleanup: /* Release the threads */ release_threads(); if (cp.t_id) free(cp.t_id); if (cp.vmas) free_maps(cp.vmas); if (cp.elf_hdr) free(cp.elf_hdr); if (cp.notes) free_notes(cp.notes); if (cp.phdrs) free(cp.phdrs); if (cp.phdrs_count) free(cp.shdrs); errno = status; return ret; }