void ReplaceMaterialParam(const Palleon::MaterialPtr& material, const char* paramName, float newParamValue) { auto param = material->GetEffectParameter(paramName); float paramValue = param.GetScalar(); paramValue = (newParamValue == 1000.f) ? paramValue : newParamValue; param.SetScalar(paramValue); material->SetEffectParameter(paramName, param); }
Token* Tokenizer::GetNext() { Token* T = NULL; // First check to see if there is an UnGetToken. If there is, use it. if (UnGetToken != NULL) { T = UnGetToken; UnGetToken = NULL; return T; } // Otherwise, crank up the scanner and get a new token. // Get rid of any whitespace SkipWhiteSpace(); // test for end of file if (buffer.isEOF()) { T = new Token(EOFSYM); } else { // Save the starting position of the symbol in a variable, // so that nicer error messages can be produced. TokenColumn = buffer.CurColumn(); // Check kind of current character // Note that _'s are now allowed in identifiers. if (isalpha(CurrentCh) || '_' == CurrentCh) { // grab identifier or reserved word T = GetIdent(); } else if ( '"' == CurrentCh) { T = GetQuotedIdent(); } else if (isdigit(CurrentCh) || '-' == CurrentCh || '.' == CurrentCh) { T = GetScalar(); } else { // // Check for other tokens // T = GetPunct(); } } if (T == NULL) { throw ParserFatalException("didn't get a token"); } if (_printTokens) { std::cout << "Token read: "; T->Print(); std::cout << std::endl; } return T; }
/* entrance point for mex file */ void mexFunction( int nlhs, // Number of left hand side (output) arguments mxArray *plhs[], // Array of left hand side arguments int nrhs, // Number of right hand side (input) arguments const mxArray *prhs[] // Array of right hand side arguments ) { /* no inputs - one output : give data regarding the class */ if ( nlhs == 1 && nrhs == 0 ) { plhs[0] = mxCreateNumericMatrix(1, 1, mxCOORD_CLASS, mxREAL); ANNcoord * tmp = (ANNcoord*)mxGetData(plhs[0]); *tmp = 0; return; } /* regular modes */ if ( nrhs < 2 ) mexErrMsgIdAndTxt("annmex:inputs","too few input arguments"); /* first argument - mode of operation */ ann_mex_mode_t mode; int tmpi(0); int * iptr = NULL; GetScalar(prhs[0], tmpi); mode = (ann_mex_mode_t)tmpi; /* special treatment for opening */ if ( mode == OPEN ) { if ( nlhs != 1 ) mexErrMsgIdAndTxt("annmex:open","wrong number of outputs - must be one"); ann_mex_t * annp = new ann_mex_t(prhs[1]); /* convert the pointer and return it as pointer_type */ plhs[0] = mxCreateNumericMatrix(1, 1, mxPOINTER_CLASS, mxREAL); pointer_t * ptr = (pointer_t*)mxGetData(plhs[0]); *ptr = (pointer_t)annp; return; } /* for all pther modes - second argument is the ann_mex_t pointer */ /* extract pointer */ pointer_t * ptr = (pointer_t*)mxGetData(prhs[1]); ann_mex_t * annp = (ann_mex_t*)(*ptr); if ( ! annp->IsGood() ) mexErrMsgIdAndTxt("annmex:pointer","internal data structure is faulty - possible wrong handle"); if ( mode == CLOSE ) { delete annp; return; } /* for the search operations - extract the parameters */ if ( nrhs < 3 ) mexErrMsgIdAndTxt("annmex:inputs","must have at least 3 inputs"); int k = 1; if ( nrhs >= 4 ) GetScalar(prhs[3], k); double eps = 0.0; if ( nrhs >= 5 ) GetScalar(prhs[4], eps); if ( mode == FRSEARCH ) { if ( nrhs != 6 ) mexErrMsgIdAndTxt("annmex:FRSEARCH_inputs","must have 6 inputs"); } switch (mode) { case KSEARCH: if ( nlhs != 2 ) mexErrMsgIdAndTxt("annmex:outputs","must have two output arguments"); annp->annkSearch(prhs[2], k, &plhs[0], &plhs[1], eps); return; case PRISEARCH: if ( nlhs != 2 ) mexErrMsgIdAndTxt("annmex:outputs","must have two output arguments"); annp->annkPriSearch(prhs[2], k, &plhs[0], &plhs[1], eps); return; case FRSEARCH: if ( nlhs != 3 ) mexErrMsgIdAndTxt("annmex:outputs","must have three output arguments"); annp->annkFRSearch(prhs[2], prhs[5], k, &plhs[0], &plhs[1], &plhs[2], eps); return; default: mexErrMsgIdAndTxt("annmex:mode","unrecognized mode"); } }
/* * main enterance point */ void mexFunction( int nlhs, /* number of expected outputs */ mxArray *plhs[], /* mxArray output pointer array */ int nrhs, /* number of inputs */ const mxArray *prhs[] /* mxArray input pointer array */ ) { if ( nrhs != 3 ) mexErrMsgIdAndTxt("edison_wraper:main","Must have three inputs"); if ( mxGetClassID(prhs[0]) != mxSINGLE_CLASS ) mexErrMsgIdAndTxt("edison_wraper:main","fim must be of type single"); if ( mxGetClassID(prhs[1]) != mxUINT8_CLASS ) mexErrMsgIdAndTxt("edison_wraper:main","rgbim must be of type uint8"); if ( mxGetClassID(prhs[2]) != mxSTRUCT_CLASS ) mexErrMsgIdAndTxt("edison_wraper:main","parameters argument must be a structure"); /* first argument - the image in whatever feature space it is given in */ float * fimage = (float*)mxGetData(prhs[0]); const int* image_dims = mxGetDimensions(prhs[0]); int image_ndim = mxGetNumberOfDimensions(prhs[0]); unsigned int w = image_dims[1]; unsigned int h = image_dims[2]; unsigned int N = image_dims[0]; int ii; unsigned char * rgbim = (unsigned char*)mxGetData(prhs[1]); const int * rgb_dims = mxGetDimensions(prhs[1]); if ( rgb_dims[1] != w || rgb_dims[2] != h ) mexErrMsgIdAndTxt("edison_wraper:main","size of fim and rgbim do not match"); /* second input - parameters structure */ // 'steps' - What steps the algorithm should perform: // 1 - only mean shift filtering // 2 - filtering and region fusion // 3 - full segmentation process [default] int steps; GetScalar(mxGetField(prhs[2], 0, "steps"), steps); // 'synergistic' - perform synergistic segmentation [true]|false bool syn; GetScalar(mxGetField(prhs[2], 0, "synergistic"), syn); // 'SpatialBandWidth' - segmentation spatial radius (integer) [7] unsigned int spBW; GetScalar(mxGetField(prhs[2], 0, "SpatialBandWidth"), spBW); // 'RangeBandWidth' - segmentation feature space radius (float) [6.5] float fsBW; GetScalar(mxGetField(prhs[2], 0, "RangeBandWidth"), fsBW); // 'MinimumRegionArea'- minimum segment area (integer) [20] unsigned int minArea; GetScalar(mxGetField(prhs[2], 0, "MinimumRegionArea"), minArea); // 'SpeedUp' - algorithm speed up {0,1,2} [1] int SpeedUp; enum SpeedUpLevel sul; GetScalar(mxGetField(prhs[2], 0, "SpeedUp"), SpeedUp); switch (SpeedUp) { case 1: sul = NO_SPEEDUP; break; case 2: sul = MED_SPEEDUP; break; case 3: sul = HIGH_SPEEDUP; break; default: mexErrMsgIdAndTxt("edison_wraper:main","wrong speedup value"); } // 'GradientWindowRadius' - synergistic parameters (integer) [2] unsigned int grWin; GetScalar(mxGetField(prhs[2], 0, "GradientWindowRadius"), grWin); // 'MixtureParameter' - synergistic parameter (float 0,1) [.3] float aij; GetScalar(mxGetField(prhs[2], 0, "MixtureParameter"), aij); // 'EdgeStrengthThreshold'- synergistic parameter (float 0,1) [.3] float edgeThr; GetScalar(mxGetField(prhs[2], 0, "EdgeStrengthThreshold"), edgeThr); msImageProcessor ms; ms.DefineLInput(fimage, h, w, N); // image array should be after permute if (ms.ErrorStatus) mexErrMsgIdAndTxt("edison_wraper:edison","Mean shift define latice input: %s", ms.ErrorMessage); kernelType k[2] = {DefualtKernelType, DefualtKernelType}; int P[2] = {DefualtSpatialDimensionality, N}; float tempH[2] = {1.0, 1.0}; ms.DefineKernel(k, tempH, P, 2); if (ms.ErrorStatus) mexErrMsgIdAndTxt("edison_wraper:edison","Mean shift define kernel: %s", ms.ErrorMessage); mxArray * mxconf = NULL; float * conf = NULL; mxArray * mxgrad = NULL; float * grad = NULL; mxArray * mxwght = NULL; float * wght = NULL; if (syn) { /* perform synergistic segmentation */ int maps_dim[2] = {w*h, 1}; /* allcate memory for confidence and gradient maps */ mxconf = mxCreateNumericArray(2, maps_dim, mxSINGLE_CLASS, mxREAL); conf = (float*)mxGetData(mxconf); mxgrad = mxCreateNumericArray(2, maps_dim, mxSINGLE_CLASS, mxREAL); grad = (float*)mxGetData(mxgrad); BgImage rgbIm; rgbIm.SetImage(rgbim, w, h, rgb_dims[0] == 3); BgEdgeDetect edgeDetector(grWin); edgeDetector.ComputeEdgeInfo(&rgbIm, conf, grad); mxwght = mxCreateNumericArray(2, maps_dim, mxSINGLE_CLASS, mxREAL); wght = (float*)mxGetData(mxgrad); for ( ii = 0 ; ii < w*h; ii++ ) { wght[ii] = (grad[ii] > .002) ? aij*grad[ii]+(1-aij)*conf[ii] : 0; } ms.SetWeightMap(wght, edgeThr); if (ms.ErrorStatus) mexErrMsgIdAndTxt("edison_wraper:edison","Mean shift set weights: %s", ms.ErrorMessage); } ms.Filter(spBW, fsBW, sul); if (ms.ErrorStatus) mexErrMsgIdAndTxt("edison_wraper:edison","Mean shift filter: %s", ms.ErrorMessage); if (steps == 2) { ms.FuseRegions(fsBW, minArea); if (ms.ErrorStatus) mexErrMsgIdAndTxt("edison_wraper:edison","Mean shift fuse: %s", ms.ErrorMessage); } if ( nlhs >= 1 ) { // first output - the feture space raw image plhs[0] = mxCreateNumericArray(image_ndim, image_dims, mxSINGLE_CLASS, mxREAL); fimage = (float*)mxGetData(plhs[0]); ms.GetRawData(fimage); } int* labels; float* modes; int* count; int RegionCount = ms.GetRegions(&labels, &modes, &count); if ( nlhs >= 2 ) { // second output - labeled image plhs[1] = mxCreateNumericArray(2, image_dims+1, mxINT32_CLASS, mxREAL); int* plabels = (int*)mxGetData(plhs[1]); for (ii=0; ii< w*h; ii++) plabels[ii] = labels[ii]; } delete [] labels; int arr_dims[2]; if ( nlhs >= 3 ) { // third output - the modes arr_dims[0] = N; arr_dims[1] = RegionCount; plhs[2] = mxCreateNumericArray(2, arr_dims, mxSINGLE_CLASS, mxREAL); fimage = (float*)mxGetData(plhs[2]); for (ii=0;ii<N*RegionCount; ii++) fimage[ii] = modes[ii]; } delete [] modes; if ( nlhs >= 4 ) { // fourth output - region sizes (# of pixels) arr_dims[0] = 1; arr_dims[1] = RegionCount; plhs[3] = mxCreateNumericArray(2, arr_dims, mxINT32_CLASS, mxREAL); int * pc = (int*)mxGetData(plhs[3]); for (ii=0;ii<RegionCount; ii++) pc[ii] = count[ii]; } delete [] count; if ( !syn ) return; if ( nlhs >= 5) // fifth output - gradient map plhs[4] = mxgrad; else mxDestroyArray(mxgrad); if ( nlhs >= 6) plhs[5] = mxconf; else mxDestroyArray(mxconf); }