void KstCSD::commonConstructor(const QString& in_tag, KstVectorPtr in_V, double in_freq, bool in_average, bool in_removeMean, bool in_apodize, int in_apodizeFxn, int in_windowSize, int in_length, double in_gaussianSigma, const QString& in_vectorUnits, const QString& in_rateUnits, const QString& vecName) { _typeString = i18n("Cumulative Spectral Decay"); _inputVectors[INVECTOR] = in_V; setTagName(in_tag); _frequency = in_freq; _average = in_average; _apodize = in_apodize; _windowSize = in_windowSize; _apodizeFxn = in_apodizeFxn; _gaussianSigma = in_gaussianSigma; _removeMean = in_removeMean; _length = in_length; _vectorUnits = in_vectorUnits; _rateUnits = in_rateUnits; if (!_average) { _length = int(ceil(log(_windowSize)/log(2.0))); } if (_length < 2) { _length = 2; } if (_length > KSTCSDMAXLEN) { _length = KSTCSDMAXLEN; } if (_frequency <= 0.0) { _frequency = 1.0; } int psdLength = int(pow(2.0, (double)(_length-1))); KstMatrixPtr outMatrix = new KstMatrix(in_tag+"-csd", psdLength, 1); outMatrix->setLabel(i18n("Power [%1/%2^{1/2}]").arg(_vectorUnits).arg(_rateUnits)); outMatrix->setXLabel(i18n("%1 [%2]").arg(vecName).arg(_vectorUnits)); outMatrix->setYLabel(i18n("Frequency [%1]").arg(_rateUnits)); if (outMatrix->sampleCount() != psdLength) { _length = 1; KstDebug::self()->log(i18n("Attempted to create a CSD that used all memory."), KstDebug::Error); } outMatrix->setProvider(this); _outMatrix = _outputMatrices.insert(OUTMATRIX, outMatrix); KST::addMatrixToList(outMatrix); (*_outMatrix)->setDirty(); }
KstCPlugin::KstCPlugin(const QDomElement& pluginElement) : KstDataObject(pluginElement) { QString pluginName; _inStringCnt = 0; _outStringCnt = 0; commonConstructor(); QDomNode n = pluginElement.firstChild(); while (!n.isNull()) { QDomElement e = n.toElement(); if (!e.isNull()) { if (e.tagName() == "tag") { setTagName(KstObjectTag::fromString(e.text())); } else if (e.tagName() == "name") { pluginName = e.text(); } else if (e.tagName() == "ivector") { _inputVectorLoadQueue.append(qMakePair(e.attribute("name"), e.text())); } else if (e.tagName() == "iscalar") { _inputScalarLoadQueue.append(qMakePair(e.attribute("name"), e.text())); } else if (e.tagName() == "istring") { _inputStringLoadQueue.append(qMakePair(e.attribute("name"), e.text())); } else if (e.tagName() == "ovector") { KstWriteLocker blockVectorUpdates(&KST::vectorList.lock()); KstVectorPtr v; if (e.attribute("scalarList", "0").toInt()) { v = new KstVector(KstObjectTag(e.text(), tag()), 0, this, true); } else { v = new KstVector(KstObjectTag(e.text(), tag()), 0, this, false); } _outputVectors.insert(e.attribute("name"), v); } else if (e.tagName() == "oscalar") { KstWriteLocker blockScalarUpdates(&KST::scalarList.lock()); KstScalarPtr sp = new KstScalar(KstObjectTag(e.text(), tag()), this); _outputScalars.insert(e.attribute("name"), sp); } else if (e.tagName() == "ostring") { KstWriteLocker blockStringUpdates(&KST::stringList.lock()); KstStringPtr sp = new KstString(KstObjectTag(e.text(), tag()), this); _outputStrings.insert(e.attribute("name"), sp); } } n = n.nextSibling(); } _plugin = PluginCollection::self()->plugin(pluginName); if (!_plugin.data()) { KstDebug::self()->log(i18n("Unable to load plugin %1 for \"%2\".").arg(pluginName).arg(tagName()), KstDebug::Warning); } else { Plugin::countScalarsVectorsAndStrings(_plugin->data()._inputs, _inScalarCnt, _inArrayCnt, _inStringCnt, _inPid); const QValueList<Plugin::Data::IOValue>& otable = _plugin->data()._outputs; for (QValueList<Plugin::Data::IOValue>::ConstIterator it = otable.begin(); it != otable.end(); ++it) { // FIXME: i18n? if ((*it)._type == Plugin::Data::IOValue::TableType) { _outArrayCnt++; if (!_outputVectors.contains((*it)._name)) { KstWriteLocker blockVectorUpdates(&KST::vectorList.lock()); KstVectorPtr v; if ((*it)._subType == Plugin::Data::IOValue::FloatNonVectorSubType) { v = new KstVector(KstObjectTag(tagName() + " vector - " + (*it)._name, tag()), 0, this, true); // FIXME: tag name? } else { v = new KstVector(KstObjectTag(tagName() + " vector - " + (*it)._name, tag()), 0, this, false); // FIXME: tag name? } _outputVectors.insert((*it)._name, v); } } else if ((*it)._type == Plugin::Data::IOValue::MatrixType) { abort(); // FIXME: #if 0 _outArrayCnt += 2; if (!_outputMatrices.contains((*it)._name)) { KstWriteLocker blockMatrixUpdates(&KST::matrixList.lock()); KstMatrixPtr m; if ((*it)._subType == Plugin::Data::IOValue::FloatNonVectorSubType) { m = new KstMatrix(KstObjectTag(tagName() + " matrix - " + (*it)._name, tag()), 0, this, true); // FIXME: tag name? } else { m = new KstMatrix(KstObjectTag(tagName() + " matrix - " + (*it)._name, tag()), 0, this, false); // FIXME: tag name? } m->setProvider(this); _outputMatrices.insert((*it)._name, m); } #endif } else if ((*it)._type == Plugin::Data::IOValue::FloatType) { _outScalarCnt++; if (!_outputScalars.contains((*it)._name)) { KstScalarPtr s = new KstScalar(KstObjectTag(tagName() + " scalar - " + (*it)._name, tag()), this); // FIXME: tag name? _outputScalars.insert((*it)._name, s); } } else if ((*it)._type == Plugin::Data::IOValue::StringType) { _outStringCnt++; if (!_outputStrings.contains((*it)._name)) { KstStringPtr s = new KstString(KstObjectTag(tagName() + " string - " + (*it)._name, tag()), this); // FIXME: tag name? _outputStrings.insert((*it)._name, s); } } } allocateParameters(); } }