void btWorldFactory::createBoxesFloor(QVariantList &shapesList, double areaX, double areaZ, btVector3 pos, btVector3 boxMin, btVector3 boxMax) { // Boxes Floor double sizeX = Tools::random((double)boxMin.x(), (double)boxMax.x()); double sizeZ = Tools::random((double)boxMin.z(), (double)boxMax.z()); btVector3 recal(sizeX,0,sizeZ); pos = pos + recal; int nbBoxesX = areaX / sizeX; int nbBoxesZ = areaZ / sizeZ; for(int i=0;i<nbBoxesX;++i){ for(int j=0;j<nbBoxesZ;++j){ double sizeY = Tools::random((double)boxMin.y(), (double)boxMax.y()); createBox(shapesList, btVector3(sizeX,sizeY,sizeZ), btVector3(i*sizeX - areaX*0.5 + pos.x(),sizeY/2.0 + pos.y(),j*sizeZ - areaZ*0.5 + pos.z()), btVector3(0,0,0),0); } } }
//************************************************************************* void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int mrows, ncols; double *image; double **newimage; double *outputimage; double *transform; double *finalbounds; int *bounds; int ntransform; int i,j,s; //srand (time(NULL)); /* Check for proper number of arguments. */ if (nrhs != 1 && nrhs != 2) { mexErrMsgTxt("1 or 2 input required."); } else if (nlhs > 3) { mexErrMsgTxt("Too many output arguments"); } mrows = (int) mxGetM(prhs[0]); ncols = (int) mxGetN(prhs[0]); if (nrhs == 1) ntransform=1; else ntransform = (int) mxGetScalar(prhs[1]); if ( mxIsComplex(prhs[0]) || !mxIsDouble(prhs[0])) { mexErrMsgTxt("Input 1 must be a noncomplex double matrix."); } image = mxGetPr(prhs[0]); if(nlhs >= 2) { plhs[1] = mxCreateDoubleMatrix(ntransform, ncols, mxREAL); transform=mxGetPr(plhs[1]); } else transform=mxGetPr(mxCreateDoubleMatrix(ntransform, ncols, mxREAL)); if(nlhs >= 3) { plhs[2] = mxCreateDoubleMatrix(1, 2, mxREAL); finalbounds=mxGetPr(plhs[2]); } else finalbounds=mxGetPr(mxCreateDoubleMatrix(1, 2, mxREAL)); newimage=(double **) malloc(ncols*sizeof(double*)); bounds=(int *) malloc(ncols*2*sizeof(int)); for(i=0;i<ncols;i++) { newimage[i]=(double *) malloc(mrows*sizeof(double*)); for(j=0;j<mrows;j++) { newimage[i][j]=image[i*mrows+j]; } bounds[2*i]=0; bounds[2*i+1]=mrows; } /*int b[2]; b[0]=-8; b[1]=492-8; bounds[10]=-16; bounds[11]=492-16; double cc=cost(newimage,newimage[50], bounds, b, ncols, 50); mexPrintf("C : %lf \n", cc);*/ //findbestcorr(newimage, ncols, bounds, 80, newimage[80],mrows,transform+80, ntransform); //mexPrintf("C : %lf \n", transform[80*ntransform]); recal(image, newimage, mrows, ncols, bounds, transform, ntransform); finalbounds[1]=mrows; for(i=0;i<ncols;i++) { if(bounds[2*i]>finalbounds[0]) finalbounds[0]=bounds[2*i]; if(bounds[2*i+1]<finalbounds[1]) finalbounds[1]=bounds[2*i+1]; } s=(int) (finalbounds[1]-finalbounds[0]); plhs[0] = mxCreateDoubleMatrix(s, ncols, mxREAL); outputimage=mxGetPr(plhs[0]); for(i=0;i<ncols;i++) { for(j=(int) finalbounds[0];j<finalbounds[1];j++) { outputimage[(int) (i*s+j-finalbounds[0])]=newimage[i][j-bounds[2*i]]; } free(newimage[i]); } finalbounds[1]++; finalbounds[0]++; free(newimage); free(bounds); }