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(); }
void KstObjectItem::update(bool recursive, int localUseCount) { switch (_rtti) { case RTTI_OBJ_DATA_VECTOR: { KST::vectorList.lock().readLock(); KstRVectorPtr x = kst_cast<KstRVector>(*KST::vectorList.findTag(_tag)); KST::vectorList.lock().unlock(); if (x) { x->readLock(); // getUsage: subtract 1 for KstRVectorPtr x bool inUse = (x->getUsage() - 1 - localUseCount) > 0; if (inUse != _inUse) { _inUse = inUse; setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap()); } QString field; if (inUse) { field = QString::number(x->length()); } else { field = "-"; } if (text(3) != field) { setText(3, field); } field = i18n("%3: %4 [%1..%2]").arg(x->reqStartFrame()) .arg(x->reqStartFrame() + x->reqNumFrames()) .arg(x->filename()) .arg(x->field()); if (text(4) != field) { setText(4, field); } _removable = x->getUsage() == 2; x->unlock(); } // Hmmm what happens if this if() fails?? We become inconsistent? break; } case RTTI_OBJ_STATIC_VECTOR: { KST::vectorList.lock().readLock(); KstSVectorPtr x = kst_cast<KstSVector>(*KST::vectorList.findTag(_tag)); KST::vectorList.lock().unlock(); if (x) { x->readLock(); // getUsage: subtract 1 for KstRVectorPtr x bool inUse = (x->getUsage() - 1 - localUseCount) > 0; if (inUse != _inUse) { _inUse = inUse; setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap()); } QString field; if (inUse) { field = QString::number(x->length()); } else { field = "-"; } if (text(3) != field) { setText(3, field); } field = i18n("%1 to %2").arg(x->min()).arg(x->max()); if (text(4) != field) { setText(4, field); } _removable = x->getUsage() == 2; x->unlock(); } // Hmmm what happens if this if() fails?? We become inconsistent? break; } case RTTI_OBJ_VECTOR: { KST::vectorList.lock().readLock(); KstVectorPtr x = *KST::vectorList.findTag(_tag); KST::vectorList.lock().unlock(); if (x) { x->readLock(); // getUsage: // subtract 1 for KstVectorPtr x bool inUse = (x->getUsage() - 1 - localUseCount) > 0; if (inUse != _inUse) { _inUse = inUse; setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap()); } QString field = QString::number(x->length()); if (text(3) != field) { setText(3, field); } field = i18n("[%1..%2]").arg(x->min()).arg(x->max()); if (text(4) != field) { setText(4, field); } x->unlock(); _removable = false; } break; } case RTTI_OBJ_OBJECT: { KST::dataObjectList.lock().readLock(); KstDataObjectPtr x = *KST::dataObjectList.findTag(_tag.tag()); KST::dataObjectList.lock().unlock(); if (x) { x->readLock(); QString field = x->typeString(); if (text(1) != field) { setText(1, field); } // getUsage: // subtract 1 for KstDataObjectPtr x bool inUse = (x->getUsage() - 1 - localUseCount) > 0; if (inUse != _inUse) { _inUse = inUse; setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap()); } if (x->sampleCount() > 0) { field = QString::number(x->sampleCount()); if (text(3) != field) { setText(3, field); } } else { if (text(3) != "-") { setText(3, "-"); } } field = x->propertyString(); if (text(4) != field) { setText(4, field); } if (recursive) { QPtrStack<QListViewItem> trash; KstVectorMap vl = x->outputVectors(); KstVectorMap::Iterator vlEnd = vl.end(); for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) { KstObjectItem *oi = static_cast<KstObjectItem*>(i); if (vl.findTag(oi->tag().tag()) == vlEnd) { trash.push(i); } } trash.setAutoDelete(true); trash.clear(); // get the output vectors for (KstVectorMap::Iterator p = vl.begin(); p != vlEnd; ++p) { bool found = false; QString tn = p.data()->tag().tag(); for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) { KstObjectItem *oi = static_cast<KstObjectItem*>(i); if (oi->tag().tag() == tn) { oi->update(); found = true; break; } } if (!found) { KstObjectItem *item = new KstObjectItem(this, p.data(), _dm); connect(item, SIGNAL(updated()), this, SIGNAL(updated())); } } KstMatrixMap ml = x->outputMatrices(); KstMatrixMap::Iterator mlEnd = ml.end(); // also get the output matrices for (KstMatrixMap::Iterator p = ml.begin(); p != mlEnd; ++p) { bool found = false; QString tn = p.data()->tag().tag(); for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) { KstObjectItem *oi = static_cast<KstObjectItem*>(i); if (oi->tag().tag() == tn) { oi->update(); found = true; break; } } if (!found) { KstObjectItem *item = new KstObjectItem(this, p.data(), _dm); connect(item, SIGNAL(updated()), this, SIGNAL(updated())); } } } _removable = x->getUsage() == 1; x->unlock(); } break; } case RTTI_OBJ_DATA_MATRIX: { KST::matrixList.lock().readLock(); KstRMatrixPtr x = kst_cast<KstRMatrix>(*KST::matrixList.findTag(_tag)); KST::matrixList.lock().unlock(); if (x) { x->readLock(); // getUsage: subtract 1 for KstRMatrixPtr x bool inUse = (x->getUsage() - 1 - localUseCount) > 0; if (inUse != _inUse) { _inUse = inUse; setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap()); } QString field = QString::number(x->sampleCount()); if (text(3) != field) { setText(3, field); } field = i18n("%1: %2 (%3 by %4)").arg(x->filename()).arg(x->field()) .arg(x->xNumSteps()) .arg(x->yNumSteps()); if (text(4) != field) { setText(4, field); } _removable = x->getUsage() == 2; x->unlock(); } break; } case RTTI_OBJ_STATIC_MATRIX: { KST::matrixList.lock().readLock(); KstSMatrixPtr x = kst_cast<KstSMatrix>(*KST::matrixList.findTag(_tag)); KST::matrixList.lock().unlock(); if (x) { x->readLock(); // getUsage: subtract 1 for KstRMatrixPtr x bool inUse = (x->getUsage() - 1 - localUseCount) > 0; if (inUse != _inUse) { _inUse = inUse; setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap()); } QString field = QString::number(x->sampleCount()); if (text(3) != field) { setText(3, field); } field = i18n("%1 to %2").arg(x->gradZMin()).arg(x->gradZMax()); if (text(4) != field) { setText(4, field); } _removable = x->getUsage() == 2; x->unlock(); } break; } case RTTI_OBJ_MATRIX: { KST::matrixList.lock().readLock(); KstMatrixPtr x = *KST::matrixList.findTag(_tag); KST::matrixList.lock().unlock(); if (x) { x->readLock(); // getUsage: // subtract 1 for KstVectorPtr x bool inUse = (x->getUsage() - 1 - localUseCount) > 0; if (inUse != _inUse) { _inUse = inUse; setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap()); } QString field = QString::number(x->sampleCount()); if (text(3) != field) { setText(3, field); } field = i18n("[%1..%2]").arg(x->minValue()).arg(x->maxValue()); if (text(4) != field) { setText(4, field); } x->unlock(); _removable = false; } break; } default: assert(0); } }