Vector3 BezierCurve::newPoint(float t, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3){ Vector3 result; float c0 = getScalar(0, t); float c1 = getScalar(1, t); float c2 = getScalar(2, t); float c3 = getScalar(3, t); result = (p0) * c0 + (p1) * c1 + (p2) * c2 + (p3) * c3; return result; }
Vector3 BezierCurve::newPoint(float t){ Vector3 result; float c0 = getScalar(0, t); float c1 = getScalar(1, t); float c2 = getScalar(2, t); float c3 = getScalar(3, t); result = (this->p0) * c0 + (this->p1) * c1 + (this->p2) * c2 + (this->p3) * c3; return result; }
Vector4f ImageAccess::getVector(VectorXi position) const { Vector4f result; for(uchar i = 0; i < mImage->getNrOfComponents(); ++i) { result[i] = getScalar(position, i); } return result; }
bool faForceEquation<T>::getMask(DynamicList<label> &cellIDs,const word &psi) { parse(maskExpression_); if(!resultIsLogical()) { FatalErrorIn("faForceEquation<scalar>::operator()(faMatrix<T> &)") << "Result of " << maskExpression_ << " is not a logical expression" << endl << abort(FatalError); } const areaScalarField &cond=getScalar(); forAll(cond,cellI) { if(cond[cellI]!=0) { cellIDs.append(cellI); } } cellIDs.shrink(); label size=cellIDs.size(); reduce(size,plusOp<label>()); if(size==0) { if(verbose_) { Info << "No cells fixed for field " << psi << endl; } return false; } if(verbose_) { Info << size << " cells fixed for field " << psi << endl; } return true; }
bool SqlDatabase::tableExists(const char* szTable) { char szSQL[128]; sprintf(szSQL, "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='%s'", szTable); int nRet = getScalar(szSQL); return (nRet > 0); }
void SFVec3f::normalize() { float scale = getScalar(); if (scale != 0.0f) { mValue[0] /= scale; mValue[1] /= scale; mValue[2] /= scale; } }
SkScalar SkAnimator::getScalar(const char* id, const char* fieldID) { const SkDisplayable* element = getElement(id); if (element == nullptr) return SK_ScalarNaN; const SkMemberInfo* field = getField(element, fieldID); if (field == nullptr) return SK_ScalarNaN; return getScalar(element, field); }
void ScalarField::show(const std::string title){ std::cout << std::endl << "--- " << title << " ---" << std::endl; for (int k = 0; k < _size_z; k++){ for (int j = _size_y-1; j > -1; j--){ for (int i = 0; i < _size_x; i++){ std::cout << getScalar(i,j,k) << "\t"; } std::cout << std::endl; } std::cout << std::endl; } }
tmp<areaScalarField> faForceEquation<T>::getMask() { clearVariables(); parse(maskExpression_); return tmp<areaScalarField> ( new areaScalarField ( getScalar() ) ); }
int32_t VMMemory::getArrayElement(unsigned arrayDSTOC, unsigned arrayIndex) { if (arrayDSTOC >= programData->getDSTOCCount()) throw std::range_error("Not a DSTOC entry"); // Check element type. RXEFile::dstocType elementType = programData->getTypeAtDSTOCIndex(arrayDSTOC + 1); if (elementType == RXEFile::TC_VOID || elementType == RXEFile::TC_CLUSTER) return -1; // Get dope vector int32_t dopeVector = getScalarValue(arrayDSTOC); if (arrayIndex >= SwapU16LittleToHost(dopeVectors[dopeVector].elementCount)) throw std::range_error("Array element not in range"); // Get size of an element. unsigned size = SwapU16LittleToHost(dopeVectors[dopeVector].elementSize); return getScalar(elementType, &(arrays[dopeVector][size*arrayIndex])); }
void PolyDDV::computeHull(PolyDDV& ddv) { if (ddv.getSize() != _types.size()) return; int i; for (i = 0; i < ddv.getSize(); ++i) { if (ddv.isPlus(i)) { if (isEq(i) || isScalar(i)) setPlus(i); else if (isMinus(i)) setStar(i); } else if (ddv.isMinus(i)) { if (isEq(i) || isScalar(i)) setMinus(i); else if (isPlus(i)) setStar(i); } else if (ddv.isStar(i)) setStar(i); else if (ddv.isScalar(i) && ! isStar(i)) { int s1 = ddv.getScalar(i); if (isScalar(i) || isEq(i)) { int s2 = 0; if (isScalar(i)) s2 = getScalar(i); if (s1 > 0 && s2 < 0 || s1 < 0 && s2 > 0) setStar(i); else if (s1 > 0 && s1 != s2) setPlus(i); else if (s1 < 0 && s1 != s2) setMinus(i); } else { if (s1 > 0 && isMinus(i) || s1 < 0 && isPlus(i)) setStar(i); } } } }
void faForceEquation<scalar>::operator()(faMatrix<scalar> &eq) { clearVariables(); DynamicList<label> cellIDs; if(!getMask(cellIDs,eq.psi().name())) { return; } Field<scalar> values(cellIDs.size()); parse(valueExpression_); const areaScalarField &calculated=getScalar(); forAll(cellIDs,i) { values[i]=calculated[cellIDs[i]]; } eq.setValues(cellIDs,values); }
bool PolyDDV::isIdenticalVector(PolyDDV& ddv) { if (ddv.getSize() != _types.size()) return false; int i; for (i = 0; i < ddv.getSize(); ++i) { if (ddv.isPlus(i) && ! isPlus(i)) return false; else if (ddv.isMinus(i) && ! isMinus(i)) return false; else if (ddv.isStar(i) && ! isStar(i)) return false; else if (ddv.isEq(i) && ! isEq(i)) return false; else if (ddv.isScalar(i)) { if (! isScalar(i) || getScalar(i) != ddv.getScalar(i)) return false; } } return true; }
void VertexScalar::saveScalars() { if (!mi) return; SurfaceMesh *mesh = mi->getMesh(); if (!mesh) return; SurfaceMesh::VertexIter v_it = mesh->vertices_begin(); for (unsigned int i = 0; i < ps->size(); i++) { if (v_it == mesh->vertices_end()) { mesh->add_vertex(MyMesh::Point()); } else { SurfaceMesh::TexCoord2D tc = mesh->texcoord2D(v_it); tc[0] = (SurfaceMesh::Scalar) getScalar(i); mesh->set_texcoord2D(v_it, tc); ++v_it; } } while (v_it != mesh->vertices_end()) { SurfaceMesh::VertexIter extra = v_it; ++v_it; // could do this above but may be confusing mesh->delete_vertex(extra); } }
options_t* getOptions(const mxArray *array) { options_t* options = (options_t*)malloc(sizeof(options_t)); mxArray* tmp; double* ptr; options->model_posterior = getScalar(array, "model_posterior"); options->kl_psi = getScalar(array, "kl_psi"); options->kl_multibin = getScalar(array, "kl_multibin"); options->effective_counts = getScalar(array, "effective_counts"); options->effective_posterior_counts = getScalar(array, "effective_posterior_counts"); options->bprob = getScalar(array, "bprob"); options->density = getScalar(array, "density"); options->density_step = getScalar(array, "density_step"); tmp = mxGetField(array, 0, "density_range"); if (tmp == 0) invalidOptions("density_range"); ptr = mxGetPr(tmp); options->density_range.from = ptr[0]; options->density_range.to = ptr[1]; options->n_moments = getScalar(array, "n_moments"); options->n_density = (int)floor(1.0/options->density_step) + 1; options->epsilon = getScalar(array, "epsilon"); options->verbose = 0; options->prombsTest = 0; options->threads = getScalar(array, "threads"); options->stacksize = getScalar(array, "stacksize"); options->algorithm = getScalar(array, "algorithm"); options->which = getScalar(array, "which"); options->hmm = getScalar(array, "hmm"); options->rho = getScalar(array, "rho"); tmp = mxGetField(array, 0, "samples"); if (tmp == 0) invalidOptions("samples"); ptr = mxGetPr(tmp); options->samples[0] = ptr[0]; options->samples[1] = ptr[1]; return options; }
float ImageAccess::getScalar(Vector2i position, uchar channel) const { Vector3i position3D(position.x(), position.y(), 0); return getScalar(position3D, channel); }
double& LOCA::TurningPoint::MooreSpence::ExtendedVector::getBifParam() { return getScalar(0); }
double& LOCA::PhaseTransition::ExtendedVector::PTP() { return getScalar(0); }
static void abv_init(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[], bool isStructInit) { int result; char *bv_hostname = 0; struct RDA_MessageStart *pMsgStart; mxArray* OUT_STATE; /* copy the params to the out state */ if(isStructInit) { // init with struct OUT_STATE = mxDuplicateArray(prhs[1]); } else { // init with property list int dims[2] = {1,1}; OUT_STATE = mxCreateStructArray(2, dims, 0, NULL); // arguments have beed checked in mexFunction for(int i = 1; i < nrhs; i = i + 2) { addField(OUT_STATE, prhs[i], prhs[i + 1]); } } /* check for the needed fields values * if they don't exist we will set the default values */ checkString(OUT_STATE,FIELD_HOST, "127.0.0.1"); /* Get server name (or use default "brainamp") */ bv_hostname = getString(OUT_STATE, FIELD_HOST); /* open connection */ result = initConnection(bv_hostname,&pMsgStart); free(bv_hostname); if (result == IC_OKAY) { /* construct connection state structure */ int nChans, lag, n; double orig_fs; mxArray *pArray; char *pChannelName; double *chan_sel; double *filter_buffer_sub; double *filter_buffer_a; double *filter_buffer_b; int iirFilterSize; nChans = pMsgStart->nChannels; orig_fs = 1000000.0 / ((double) pMsgStart->dSamplingInterval); /* Check fs */ checkScalar(OUT_STATE,FIELD_FS,orig_fs); lag = (int) (orig_fs / getScalar(OUT_STATE, FIELD_FS)); abv_assert(lag * (int)getScalar(OUT_STATE,FIELD_FS) == (int)orig_fs,"bbci_acquire_bv: The base frequency has to be a multiple of the requested frequency."); /* Overwrite the following fields */ setScalar(OUT_STATE,FIELD_ORIG_FS, orig_fs); setScalar(OUT_STATE,FIELD_LAG, lag); setScalar(OUT_STATE,FIELD_BLOCK_NO, -1.0); /* this odd hack is because pMsgStart contains several variably sized arrays, and this is the way to get the channel names */ setStringCell(OUT_STATE, FIELD_CLAB,(char *) ((double*) pMsgStart->dResolutions + nChans), 1, nChans); /* Check the following fields */ checkString(OUT_STATE,FIELD_MARKER_FORMAT, "numeric"); abv_assert(1 == checkScalar(OUT_STATE, FIELD_RECONNECT, 1), "bbci_acquire_bv: Reconnect is no scalar."); abv_assert(1 == checkArray(OUT_STATE, FIELD_SCALE, 1, nChans, pMsgStart->dResolutions), "bbci_acquire_bv: Scale is no array or has wrong size."); chan_sel = (double *) malloc(nChans*sizeof(double)); for (n = 0;n<nChans;n++) { chan_sel[n] = n+1; } abv_assert(1 == checkArray(OUT_STATE, FIELD_CHAN_SEL, 1, -nChans, chan_sel), "bbci_acquire_bv: chan_sel is no array."); free(chan_sel); /* Create the default filters */ filter_buffer_sub = (double *) malloc(lag*sizeof(double)); for(n = 0; n < lag; ++n) { filter_buffer_sub[n] = 1.0 / (double)lag; } filter_buffer_a = (double *) malloc(sizeof(double)); filter_buffer_a[0] = 1.0; filter_buffer_b = (double *) malloc(sizeof(double)); filter_buffer_b[0] = 1.0; /* check the filters */ abv_assert(1 == checkArray(OUT_STATE, FIELD_FILT_SUBSAMPLE, 1, lag, filter_buffer_sub), "bbci_acquire_bv: Subsample filter is no array or has the wrong size."); abv_assert(1 == checkArray(OUT_STATE, FIELD_FILT_A, 1, -1, filter_buffer_a), "bbci_acquire_bv: IIR filter aSubsample filter has the wrong size."); abv_assert(1 == checkArray(OUT_STATE, FIELD_FILT_B, 1, -1, filter_buffer_b), "bbci_acquire_bv: Subsample filter has the wrong size."); /* free the default filters */ free(filter_buffer_sub); free(filter_buffer_a); free(filter_buffer_b); /* check if the iir filters have the same size */ iirFilterSize = getArrayN(OUT_STATE, FIELD_FILT_A); abv_assert(getArrayN(OUT_STATE, FIELD_FILT_B) == iirFilterSize, "bbci_acquire_bv: bFilter and aFilter must have the same size."); /* get the arrays for the filters and create the filters */ filter_buffer_sub = getArray(OUT_STATE, FIELD_FILT_SUBSAMPLE); filter_buffer_a = getArray(OUT_STATE, FIELD_FILT_A); filter_buffer_b = getArray(OUT_STATE, FIELD_FILT_B); filterFIRCreate(filter_buffer_sub, lag,nChans); filterIIRCreate(filter_buffer_a, filter_buffer_b, iirFilterSize, nChans); connected = 1; } plhs[0] = OUT_STATE; free(pMsgStart); }
static void abv_getdata(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int result; /* return values for called function */ mxArray *pArray; /* generic pointer to a matlab array */ int lastBlock; /* the last block which we have seen */ int nChannels; /* number of channels */ int blocksize; /* the size of blocks */ int ElementSize; /* size of one data point. 2 if int16, 4 if int32, etc */ int reconnect; /* if we reconnect on connection loss */ char *bv_hostname = 0; /* if we reconnect wi need the hostname */ struct RDA_MessageData *pMsgData; struct RDA_MessageStart *pMsgStart; /* init the input and output values */ const mxArray* IN_STATE = prhs[0]; mxArray* OUT_DATA = NULL; mxArray* OUT_MRK_TIME = NULL; mxArray* OUT_MRK_DESCR = NULL; mxArray* OUT_STATE = NULL; /* get the information from the state and obtain the data */ lastBlock = (int)getScalar(IN_STATE, FIELD_BLOCK_NO); nChannels = getArrayN(IN_STATE, FIELD_CLAB); result = getData(&pMsgData, &blocksize, lastBlock, nChannels, &ElementSize); /* If everything is okay, construct the appropriate output. Else * return empty arrays. */ if (result != -1) { int n; int nChans_orig, lag, nPoints, nChans_sel, nMarkers, pDstPosition; double *chan_sel, *scale, *pDst0, *pMrkPos, *pSrcDouble; struct RDA_Marker *pMarker; char *pszType, *pszDesc; char* outputTypeDef; int outputType; double *pMrkToe; /* get necessary information from the current state */ nChans_orig = getArrayN(IN_STATE, FIELD_CLAB); lag = (int) getScalar(IN_STATE,FIELD_LAG); nPoints = (getFIRPos() + pMsgData->nPoints)/lag; chan_sel = getArray(IN_STATE, FIELD_CHAN_SEL); nChans_sel = getArrayN(IN_STATE, FIELD_CHAN_SEL); /* check for the new resample filter */ abv_assert(checkArray(IN_STATE, FIELD_FILT_SUBSAMPLE, 1, lag), "bbci_acquire_bv: Resample filter has to be a vector. Resample filter has to correspondent with the sampling rate."); filterFIRSet(getArray(IN_STATE, FIELD_FILT_SUBSAMPLE)); /* construct the data output matrix. */ OUT_DATA = mxCreateDoubleMatrix(nPoints, nChans_sel, mxREAL); pArray = mxGetField(IN_STATE, 0, "scale"); scale = mxGetPr(pArray); pDst0= mxGetPr(OUT_DATA); pDstPosition = 0; /* convert the source data to double format */ pSrcDouble = (double*)malloc(pMsgData->nPoints * nChans_orig * sizeof(double)); if (ElementSize==2) { int16_t *pSrc = pMsgData->nData; for(n = 0; n != pMsgData->nPoints * nChans_orig; ++n) { pSrcDouble[n] = (double)pSrc[n]; } } else if (ElementSize==4) { int32_t *pSrc = (int32_t*) pMsgData->nData; for(n = 0; n != pMsgData->nPoints * nChans_orig; ++n) { pSrcDouble[n] = (double)pSrc[n]; } } else { mexErrMsgTxt("bbci_acquire_bv: Unknown element size"); } /* filter the data with the filters */ filterData(pSrcDouble,pMsgData->nPoints ,pDst0,nPoints, chan_sel, nChans_sel, scale); free(pSrcDouble); /* if markers are also requested, construct the appropriate output matrices */ if (nlhs >= 2) { nMarkers = pMsgData->nMarkers; if (nMarkers > 0) { /* if markers existed, collect them */ OUT_MRK_TIME = mxCreateDoubleMatrix(1, nMarkers, mxREAL); pMrkPos = mxGetPr(OUT_MRK_TIME); outputTypeDef = getString(IN_STATE, FIELD_MARKER_FORMAT); if(0 == strcmp ("numeric", outputTypeDef)) { outputType = 1; } else if(0 == strcmp ("string", outputTypeDef)) { outputType = 2; } else { mexErrMsgTxt("bbci_acquire_bv: Unknown ouput type."); } free(outputTypeDef); if (nlhs >= 3) { if(1 == outputType) { /* numeric */ OUT_MRK_DESCR = mxCreateDoubleMatrix(1, nMarkers, mxREAL); pMrkToe = mxGetPr(OUT_MRK_DESCR); } else if(2 == outputType) {/* string */ OUT_MRK_DESCR = mxCreateCellMatrix(1,nMarkers); } else { mexErrMsgTxt("bbci_acquire_bv: Unknown ouput type for output."); } } pMarker = (struct RDA_Marker*)((char*)pMsgData->nData + pMsgData->nPoints * nChans_orig * ElementSize); double origFs = getScalar(IN_STATE, FIELD_ORIG_FS); for (n = 0; n < nMarkers; n++) { pMrkPos[n]= ((double)pMarker->nPosition+1.0) * 1000.0 /origFs; pszType = pMarker->sTypeDesc; pszDesc = pszType + strlen(pszType) + 1; if (nlhs >= 3) { if(1 == outputType) { /* numeric */ pMrkToe[n]= ((*pszDesc =='R') ? -1 : 1) * atoi(pszDesc+1); } else if(2 == outputType) {/* string */ mxSetCell(OUT_MRK_DESCR, n, mxCreateString(pszDesc)); } else { mexErrMsgTxt("bbci_acquire_bv: Unknown ouput type for output."); } } pMarker = (struct RDA_Marker*)((char*)pMarker + pMarker->nSize); } } else { /* no markers -> return empty matrix */ OUT_MRK_TIME = mxCreateDoubleMatrix(0, 0, mxREAL); if (nlhs >= 3) { OUT_MRK_DESCR = mxCreateDoubleMatrix(0, 0, mxREAL); } } } /* end constructing marker outputs */ } else { int nChans_sel; reconnect = (int) getScalar(IN_STATE, FIELD_RECONNECT); if(1 == reconnect) { printf("bbci_acquire_bv: getData didn't work, reconnecting "); /* only close the connection */ closeConnection(); connected = 0; bv_hostname = (char *) malloc(MAX_CHARS); /* getting the hostname for the new connection */ pArray = mxGetField(IN_STATE, 0, "hostname"); mxGetString(pArray, bv_hostname, MAX_CHARS); free(pMsgData); /* try reconnecting till we get a new connection */ while(IC_OKAY != (result = initConnection(bv_hostname, &pMsgStart))){ printf("bbci_acquire_bv: connecting failed, trying again\n"); free(pMsgData); } /* cleaning things up */ free(bv_hostname); free(pMsgStart); connected = 1; } else { printf("bbci_acquire_bv: getData didn't work, closing connection, returning -2\n "); /* close the connection and clean everything up */ abv_close(); } /* We have an error in the data transmition return an empty datablock. */ pArray = mxGetField(IN_STATE, 0, "chan_sel"); nChans_sel = mxGetN(pArray); OUT_DATA = mxCreateDoubleMatrix(0, nChans_sel, mxREAL); if (nlhs >= 2){OUT_MRK_TIME = mxCreateDoubleMatrix(0,0, mxREAL);}; if (nlhs >= 3){OUT_MRK_DESCR = mxCreateDoubleMatrix(0,0, mxREAL);}; } /* clone the state */ if(nlhs >= 4) {OUT_STATE = mxDuplicateArray(IN_STATE);}; plhs[0] = OUT_DATA; if(nlhs >=2) { plhs[1] = OUT_MRK_TIME; } if(nlhs >=3) { plhs[2] = OUT_MRK_DESCR; } if(nlhs >=4) { plhs[3] = OUT_STATE; } free(pMsgData); }
extern "C" FREObject RigidBodygetAngularDamping(FREContext ctx, void *funcData, uint32_t argc, FREObject argv[]) { return getScalar(argv[0], &btRigidBody::getAngularDamping); }
double& LOCA::Pitchfork::MooreSpence::ExtendedVector::getSlack() { return getScalar(0); }
int32_t VMMemory::getScalarValue(unsigned entry) const throw(std::range_error, std::invalid_argument) { if (entry >= programData->getDSTOCCount()) throw std::range_error("Not a DSTOC entry"); RXEFile::dstocType type = programData->getTypeAtDSTOCIndex(entry); return getScalar(type, memory + programData->getDataDescriptorAtDSTOCIndex(entry)); }
double LOCA::Hopf::MooreSpence::ExtendedVector::getBifParam() const { return getScalar(1); }
double& LOCA::Hopf::MooreSpence::ExtendedVector::getFrequency() { return getScalar(0); }
double& LOCA::Pitchfork::MooreSpence::ExtendedVector::getBifParam() { return getScalar(1); }
void MatrixArchive::getScalar(std::string const & scalarName, double & outScalar) const { outScalar = getScalar(scalarName); }