//TODO Could use some templates perhaps... bool BasicPlugin::inputsExist() const { //First, check the inputVectors... QStringList iv = inputVectorList(); QStringList::ConstIterator ivI = iv.begin(); for (; ivI != iv.end(); ++ivI) { if (!inputVector(*ivI)) return false; } //Now, check the inputScalars... QStringList is = inputScalarList(); QStringList::ConstIterator isI = is.begin(); for (; isI != is.end(); ++isI) { if (!inputScalar(*isI)) return false; } //Finally, check the inputStrings... QStringList istr = inputStringList(); QStringList::ConstIterator istrI = istr.begin(); for (; istrI != istr.end(); ++istrI) { if (!inputString(*istrI)) return false; } return true; }
// Remove some elements from the vector starting from vector[0] bool Trim::algorithm() { KstVectorPtr input = inputVector(INPUT); KstScalarPtr remove = inputScalar(REMOVE); KstVectorPtr cut = outputVector(CUT); bool rc = false; if (input->length() > remove->value()) { int cutSize = (int)input->length() - (int)remove->value(); cut->resize( cutSize, false ); for (int j=0; j<cutSize; j++) { cut->value()[j] = input->value()[(int)remove->value()+j]; } rc = true; } return rc; }
bool CumulativeSum::algorithm() { KstVectorPtr inputvector = inputVector(INPUTVECTOR); KstScalarPtr scale_factor = inputScalar(SCALE_FACTOR); KstVectorPtr cumulative_sum = outputVector(CUMULATIVE_SUM); /* Memory allocation */ if (cumulative_sum->length() != inputvector->length()) { cumulative_sum->resize(inputvector->length()+1, true); } cumulative_sum->value()[0] = 0.0; for (int i = 0; i < inputvector->length(); i++) { cumulative_sum->value()[i+1] = inputvector->value()[i]*scale_factor->value() + cumulative_sum->value()[i]; } return true; }
bool Differentiation::algorithm() { KstVectorPtr inputvector = inputVector(INPUTVECTOR); KstScalarPtr time_step = inputScalar(TIME_STEP); KstVectorPtr derivative = outputVector(DERIVATIVE); /* Memory allocation */ if (derivative->length() != inputvector->length()) { derivative->resize(inputvector->length(), true); } derivative->value()[0] = (inputvector->value()[1] - inputvector->value()[0]) / time_step->value(); int i = 1; for (; i < inputvector->length()-1; i++) { derivative->value()[i] = (inputvector->value()[i+1] - inputvector->value()[i-1])/(2*time_step->value()); } derivative->value()[i] = (inputvector->value()[i] - inputvector->value()[i-1]) / time_step->value(); return true; }
bool NoiseAddition::algorithm() { KstVectorPtr array = inputVector(ARRAY); KstScalarPtr sigma = inputScalar(SIGMA); KstVectorPtr output = outputVector(OUTPUT); const gsl_rng_type* pGeneratorType; gsl_rng* pRandomNumberGenerator; double* pResult[1]; int iRetVal = false; int iLength = array->length(); pResult[0] = 0L; if (iLength > 0) { if (output->length() != iLength) { output->resize(iLength, false); pResult[0] = (double*)realloc( output->value(), iLength * sizeof( double ) ); } else { pResult[0] = output->value(); } } pGeneratorType = gsl_rng_default; pRandomNumberGenerator = gsl_rng_alloc( pGeneratorType ); if (pRandomNumberGenerator != NULL) { if (pResult[0] != NULL) { for (int i=0; i<iLength; i++) { output->value()[i] = array->value()[i] + gsl_ran_gaussian( pRandomNumberGenerator, sigma->value() ); } iRetVal = true; } gsl_rng_free( pRandomNumberGenerator ); } return iRetVal; }
bool Phase::algorithm() { KstVectorPtr time = inputVector(TIME); KstVectorPtr data_i = inputVector(DATA_I); KstScalarPtr period = inputScalar(PERIOD); KstScalarPtr zero = inputScalar(ZERO); KstVectorPtr phase = outputVector(PHASE); KstVectorPtr data_o = outputVector(DATA_O); double* pResult[2]; double dPhasePeriod = period->value(); double dPhaseZero = zero->value(); int iLength; bool iRetVal = false; if (dPhasePeriod > 0.0) { if (time->length() == data_i->length()) { iLength = time->length(); if (phase->length() != iLength) { phase->resize(iLength, true); pResult[0] = (double*)realloc( phase->value(), iLength * sizeof( double ) ); } else { pResult[0] = phase->value(); } if (data_o->length() != iLength) { data_o->resize(iLength, true); pResult[1] = (double*)realloc( data_o->value(), iLength * sizeof( double ) ); } else { pResult[1] = data_o->value(); } if (pResult[0] != NULL && pResult[1] != NULL) { for (int i = 0; i < phase->length(); ++i) { phase->value()[i] = pResult[0][i]; } for (int i = 0; i < data_o->length(); ++i) { data_o->value()[i] = pResult[1][i]; } /* determine the phase... */ for (int i=0; i<iLength; i++) { phase->value()[i] = fmod( ( time->value()[i] - dPhaseZero ) / dPhasePeriod, 1.0 ); } /* sort by phase... */ memcpy( data_o->value(), data_i->value(), iLength * sizeof( double ) ); double* sort[2]; sort[0] = phase->value(); sort[1] = data_o->value(); quicksort( sort, 0, iLength-1 ); iRetVal = true; } } } return iRetVal; }