void KstHistogram::AutoBin(KstVectorPtr V, int *n, double *max, double *min) { double m; *max = V->max(); *min = V->min(); *n = V->sampleCount(); if (*max < *min) { m = *max; *max = *min; *min = m; } if (*max == *min) { *max += 1; *min -= 1; } // we can do a better job auto-ranging using the tick rules from plot... // this has not been done yet, you will notice... *n /= 50; if (*n < 6) *n = 6; if (*n > 60) *n = 60; m = (*max - *min)/(100.0*double(*n)); *max += m; *min -= m; }
KstObject::UpdateType KstPSDCurve::update(int update_counter) { int i_subset, i_samp; int n_subsets; int v_len; int copyLen; double mean; double y; bool force = false; KstVectorPtr iv = _inputVectors[INVECTOR]; double *psd; if (KstObject::checkUpdateCounter(update_counter)) return NO_CHANGE; if (update_counter <= 0) { force = true; } else { iv->update(update_counter); } v_len = iv->sampleCount(); n_subsets = v_len/PSDLen+1; last_n_new += iv->numNew(); if ((last_n_new < PSDLen/16) && (n_subsets - last_n_subsets < 1) && !force) { return NO_CHANGE; } psd = (*_sVector)->value(); for (i_samp = 0; i_samp < PSDLen; i_samp++) { psd[i_samp] = 0; } for (i_subset = 0; i_subset < n_subsets; i_subset++) { /* copy each chunk into a[] and find mean */ if (i_subset*PSDLen + ALen <= v_len) { copyLen = ALen; } else { copyLen = v_len - i_subset*PSDLen; } mean = 0; for (i_samp = 0; i_samp < copyLen; i_samp++) { mean += ( a[i_samp] = iv->interpolate(i_samp + i_subset*PSDLen, v_len) ); } if (copyLen>1) mean/=(double)copyLen; /* Remove Mean and apodize */ if (removeMean() && appodize()) { for (i_samp=0; i_samp<copyLen; i_samp++) { a[i_samp]= (a[i_samp]-mean)*w[i_samp]; } } else if (removeMean()) { for (i_samp=0; i_samp<copyLen; i_samp++) { a[i_samp] -= mean; } } else if (appodize()) { for (i_samp=0; i_samp<copyLen; i_samp++) { a[i_samp] *= w[i_samp]; } } for (;i_samp < ALen; i_samp++) a[i_samp] = 0.0; /* fft a */ rdft(ALen, 1, a); /* sum each bin into psd[] */ psd[0]+=a[0]; psd[PSDLen-1] += a[1]; for (i_samp=1; i_samp<PSDLen-1; i_samp++) { psd[i_samp]+= cabs(a[i_samp*2], a[i_samp*2+1]); } } last_f0 = 0; last_n_subsets = n_subsets; last_n_new = 0; norm_factor = 1.0/(sqrt(double(Freq)*double(PSDLen))*double(n_subsets)); psd[0]*=norm_factor; MaxY = MinY = mean = psd[0]; if (psd[0]>0) MinPosY = psd[0]; else (MinPosY = 1.0e300); /* normalize psd */ for (i_samp=1; i_samp<PSDLen; i_samp++) { y = (psd[i_samp]*=norm_factor); if (y>MaxY) MaxY=y; if (y<MinY) MinY=y; if ((y>0) && (y<MinPosY)) MinPosY = y; mean +=y; } if (PSDLen > 0) MeanY = mean/PSDLen; else MeanY = 0; // should never ever happen... NS = PSDLen; if (Freq <= 0) Freq = 1.0; MaxX = Freq/2.0; MinX = 0; MinPosX = 1.0/double(NS) * MaxX; MeanX = MaxX/2.0; double *f = (*_fVector)->value(); f[0] = 0; f[1] = Freq/2.0; (*_sVector)->update(update_counter); (*_fVector)->update(update_counter); return UPDATE; }
void KstObjectItem::update(bool recursive) { switch (_rtti) { case RTTI_OBJ_DATA_VECTOR: { KstVectorPtr px = *KST::vectorList.findTag(_name); assert(px.data()); assert(dynamic_cast<KstRVector*>(px.data())); KstRVectorPtr x = static_cast<KstRVector*>(px.data()); setText(2, QString::number(x->getUsage() - 3)); // caller has a ptr setText(3, QString::number(x->sampleCount())); setText(4, i18n("%3: %4 [%1..%2]").arg(x->reqStartFrame()) .arg(x->reqStartFrame() + x->reqNumFrames()) .arg(x->getFilename()) .arg(x->getField())); _removable = x->getUsage() == 3; break; } case RTTI_OBJ_VECTOR: { KstVectorPtr x = *KST::vectorList.findTag(_name); assert(x.data()); setText(2, QString::number(x->getUsage() - 2)); //caller also points setText(3, QString::number(x->sampleCount())); setText(4, i18n("[%1..%2]").arg(x->min()).arg(x->max())); _removable = false; break; } case RTTI_OBJ_OBJECT: { KstDataObjectPtr x = *KST::dataObjectList.findTag(_name); assert(x.data()); setText(1, x->typeString()); setText(2, QString::number(x->getUsage() - 1)); // our pointer setText(3, QString::number(x->sampleCount())); setText(4, x->propertyString()); if (recursive) { QPtrStack<QListViewItem> trash; for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) { KstObjectItem *oi = static_cast<KstObjectItem*>(i); if (x->outputVectors().findTag(oi->tagName()) == x->outputVectors().end()) { trash.push(i); } } trash.setAutoDelete(true); trash.clear(); for (KstVectorMap::Iterator p = x->outputVectors().begin(); p != x->outputVectors().end(); ++p) { bool found = false; for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) { KstObjectItem *oi = static_cast<KstObjectItem*>(i); if (oi->tagName() == p.data()->tagName()) { oi->update(); found = true; break; } } if (!found) { new KstObjectItem(this, p.data(), _dm); } } } _removable = x->getUsage() == 1; break; } default: assert(0); } }