本文整理汇总了C++中KstScalarPtr类的典型用法代码示例。如果您正苦于以下问题:C++ KstScalarPtr类的具体用法?C++ KstScalarPtr怎么用?C++ KstScalarPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KstScalarPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: i18n
// FIXME: KstPlugin should not know about fit scalars!!
void KstPlugin::createFitScalars() {
if (_plugin->data()._isFit && _outputVectors.contains("Parameters")) {
KstVectorPtr vectorParam = _outputVectors["Parameters"];
if (vectorParam) {
QString paramName;
int i = 0;
int length = vectorParam->length();
for (paramName = _plugin->parameterName(i);
!paramName.isEmpty() && i < length;
paramName = _plugin->parameterName(++i)) {
double scalarValue = vectorParam->value(i);
if (!_outputScalars.contains(paramName)) {
QString scalarName = i18n("%1-%2").arg(tagName()).arg(paramName);
KstScalarPtr s = new KstScalar(scalarName, scalarValue);
s->writeLock();
s->setProvider(this);
s->writeUnlock();
_outputScalars.insert(paramName, s);
} else {
_outputScalars[paramName]->setValue(scalarValue);
}
}
}
}
}
示例2: sample
QString CrossPowerSpectrum::sampleTag() const {
KstScalarPtr s = sample();
if (s) {
return s->tagName();
}
return QString::null;
}
示例3: KstScalar
const QString& KstIfaceImpl::generateScalar(const QString& name, double value) {
KstScalarPtr s = new KstScalar(name, 0L, value);
KstReadLocker rl(s);
s->setOrphan(true);
s->setEditable(true);
return s->tagName();
}
示例4: makeDuplicate
KstDataObjectPtr KstPlugin::makeDuplicate(KstDataObjectDataObjectMap& duplicatedMap) {
KstPluginPtr plugin = new KstPlugin;
// use same inputs
for (KstVectorMap::ConstIterator iter = _inputVectors.begin(); iter != _inputVectors.end(); ++iter) {
plugin->inputVectors().insert(iter.key(), iter.data());
}
for (KstScalarMap::ConstIterator iter = _inputScalars.begin(); iter != _inputScalars.end(); ++iter) {
plugin->inputScalars().insert(iter.key(), iter.data());
}
for (KstStringMap::ConstIterator iter = _inputStrings.begin(); iter != _inputStrings.end(); ++iter) {
plugin->inputStrings().insert(iter.key(), iter.data());
}
// create new outputs
for (KstVectorMap::ConstIterator iter = outputVectors().begin(); iter != outputVectors().end(); ++iter) {
KstVectorPtr v = new KstVector;
v->writeLock();
plugin->outputVectors().insert(iter.key(), v);
v->setTagName(iter.data()->tagName() + "'");
v->setProvider(plugin.data());
KST::addVectorToList(v);
v->writeUnlock();
}
for (KstScalarMap::ConstIterator iter = outputScalars().begin(); iter != outputScalars().end(); ++iter) {
KstScalarPtr s = new KstScalar;
s->writeLock();
plugin->outputScalars().insert(iter.key(), s);
s->setTagName(iter.data()->tagName() + "'");
s->setProvider(plugin.data());
s->writeUnlock();
}
for (KstStringMap::ConstIterator iter = outputStrings().begin(); iter != outputStrings().end(); ++iter) {
KstStringPtr s = new KstString;
s->writeLock();
plugin->outputStrings().insert(iter.key(), s);
s->setTagName(iter.data()->tagName() + "'");
s->setProvider(plugin.data());
s->writeUnlock();
}
// set the same plugin
plugin->setPlugin(_plugin);
plugin->setTagName(tagName() + "'");
duplicatedMap.insert(this, KstDataObjectPtr(plugin));
return KstDataObjectPtr(plugin);
}
示例5: inputVector
// 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;
}
示例6: i18n
QString KstCPlugin::label(int precision) const {
QString label;
label = i18n("%1: %2").arg(plugin()->data()._readableName).arg(tagName());
if ((outputVectors())["Parameters"]) {
QString strParamName;
QString strValue;
int length = (outputVectors())["Parameters"]->length();
int i = 0;
for (strParamName = plugin()->parameterName(0);
!strParamName.isEmpty() && i < length;
strParamName = plugin()->parameterName(++i)) {
KstScalarPtr scalar = outputScalars()[strParamName];
if (scalar) {
strValue = QString::number(scalar->value(), 'g', precision);
label += i18n("\n%1: %2").arg(strParamName).arg(strValue);
}
}
}
return label;
}
示例7: Q_ASSERT
KstObject::UpdateType KstCPlugin::update(int update_counter) {
Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
if (!isValid()) {
return setLastUpdateResult(NO_CHANGE);
}
if (recursed()) {
return setLastUpdateResult(NO_CHANGE);
}
bool force = dirty();
setDirty(false);
if (KstObject::checkUpdateCounter(update_counter) && !force) {
return lastUpdateResult();
}
#define CLEANUP() do {\
for (unsigned i = 0; i < _outStringCnt; ++i) { \
if (_outStrings[i]) { \
free(_outStrings[i]); \
_outStrings[i] = 0L; \
} \
} \
for (unsigned i = 0; i < _inStringCnt; ++i) { \
if (_inStrings[i]) { \
free(_inStrings[i]); \
_inStrings[i] = 0L; \
} \
} \
} while(0)
writeLockInputsAndOutputs();
const QValueList<Plugin::Data::IOValue>& itable = _plugin->data()._inputs;
const QValueList<Plugin::Data::IOValue>& otable = _plugin->data()._outputs;
int itcnt = 0, vitcnt = 0, sitcnt = 0;
bool doUpdate = force;
// Populate the input scalars and vectors
for (QValueList<Plugin::Data::IOValue>::ConstIterator it = itable.begin(); it != itable.end(); ++it) {
if ((*it)._type == Plugin::Data::IOValue::TableType) {
if (!_inputVectors.contains((*it)._name)) {
KstDebug::self()->log(i18n("Input vector [%1] for plugin %2 not found. Unable to continue.").arg((*it)._name).arg(tagName()), KstDebug::Error);
CLEANUP();
return setLastUpdateResult(NO_CHANGE);
}
KstVectorPtr iv = _inputVectors[(*it)._name];
if (!iv) {
kstdFatal() << "Input vector \"" << (*it)._name << "\" for plugin " << tag().displayString() << " is invalid." << endl;
}
doUpdate = (UPDATE == iv->update(update_counter)) || doUpdate;
_inVectors[vitcnt] = iv->value();
_inArrayLens[vitcnt++] = iv->length();
} else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
KstScalarPtr is = _inputScalars[(*it)._name];
if (!is) {
kstdFatal() << "Input scalar \"" << (*it)._name << "\" for plugin " << tag().displayString() << " is invalid." << endl;
}
doUpdate = (UPDATE == is->update(update_counter)) || doUpdate;
_inScalars[itcnt++] = is->value();
} else if ((*it)._type == Plugin::Data::IOValue::StringType) {
KstStringPtr is = _inputStrings[(*it)._name];
if (!is) {
kstdFatal() << "Input string \"" << (*it)._name << "\" for plugin " << tag().displayString() << " is invalid." << endl;
}
doUpdate = (UPDATE == is->update(update_counter)) || doUpdate;
// Maybe we should use UTF-8 instead?
_inStrings[sitcnt++] = strdup(is->value().latin1());
} else if ((*it)._type == Plugin::Data::IOValue::PidType) {
_inScalars[itcnt++] = getpid();
}
}
if (!doUpdate) {
CLEANUP();
unlockInputsAndOutputs();
return setLastUpdateResult(NO_CHANGE);
}
vitcnt = 0;
// Populate the output vectors
for (QValueList<Plugin::Data::IOValue>::ConstIterator it = otable.begin();
it != otable.end();
++it) {
if ((*it)._type == Plugin::Data::IOValue::TableType) {
if (!_outputVectors.contains((*it)._name)) {
KstDebug::self()->log(i18n("Output vector [%1] for plugin %2 not found. Unable to continue.").arg((*it)._name).arg(tagName()), KstDebug::Error);
CLEANUP();
unlockInputsAndOutputs();
return setLastUpdateResult(NO_CHANGE);
}
_outVectors[vitcnt] = _outputVectors[(*it)._name]->value();
_outArrayLens[vitcnt++] = _outputVectors[(*it)._name]->length();
}
}
if (_outStringCnt > 0) {
//.........这里部分代码省略.........
示例8: blockVectorUpdates
bool KstPluginDialogI::saveOutputs(KstCPluginPtr plugin, KstSharedPtr<Plugin> p) {
const QValueList<Plugin::Data::IOValue>& otable = p->data()._outputs;
for (QValueList<Plugin::Data::IOValue>::ConstIterator it = otable.begin(); it != otable.end(); ++it) {
QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "QLineEdit");
if (!field) {
continue; // Some are unsupported
}
QLineEdit *li = static_cast<QLineEdit*>(field);
if (li->text().isEmpty()) {
li->setText((*it)._name);
}
QString nt = li->text();
if ((*it)._type == Plugin::Data::IOValue::TableType) {
if (!KstData::self()->vectorTagNameNotUnique(nt, false)) {
// Implicitly creates it if it doesn't exist
KstVectorPtr v = plugin->outputVectors()[(*it)._name];
if (!v) {
KstWriteLocker blockVectorUpdates(&KST::vectorList.lock());
v = new KstVector(KstObjectTag(nt, plugin->tag()), 0, plugin.data());
plugin->outputVectors().insert((*it)._name, v);
}
v->setTagName(KstObjectTag(nt, plugin->tag()));
} else if (plugin->outputVectors()[(*it)._name]->tagName() != nt) {
while (KstData::self()->vectorTagNameNotUnique(nt, false)) {
nt += "'";
}
KstVectorPtr v;
if (plugin->outputVectors().contains((*it)._name)) {
v = plugin->outputVectors()[(*it)._name];
} else {
KstWriteLocker blockVectorUpdates(&KST::vectorList.lock());
v = new KstVector(KstObjectTag(nt, plugin->tag()), 0, plugin.data());
plugin->outputVectors().insert((*it)._name, v);
}
v->setTagName(KstObjectTag(nt, plugin->tag()));
}
} else if ((*it)._type == Plugin::Data::IOValue::StringType) {
if (!KstData::self()->vectorTagNameNotUnique(nt, false)) {
KstStringPtr s;
if (plugin->outputStrings().contains((*it)._name)) {
s = plugin->outputStrings()[(*it)._name];
} else {
KstWriteLocker blockStringUpdates(&KST::stringList.lock());
s = new KstString(KstObjectTag(nt, plugin->tag()), plugin.data());
plugin->outputStrings().insert((*it)._name, s);
}
s->setTagName(KstObjectTag(nt, plugin->tag()));
} else if (plugin->outputStrings()[(*it)._name]->tagName() != nt) {
while (KstData::self()->vectorTagNameNotUnique(nt, false)) {
nt += "'";
}
KstStringPtr s;
if (plugin->outputStrings().contains((*it)._name)) {
s = plugin->outputStrings()[(*it)._name];
} else {
KstWriteLocker blockStringUpdates(&KST::stringList.lock());
s = new KstString(KstObjectTag(nt, plugin->tag()), plugin.data());
plugin->outputStrings().insert((*it)._name, s);
}
s->setTagName(KstObjectTag(nt, plugin->tag()));
}
} else if ((*it)._type == Plugin::Data::IOValue::PidType) {
// Nothing
} else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
if (!KstData::self()->vectorTagNameNotUnique(nt, false)) {
KstScalarPtr s;
if (plugin->outputScalars().contains((*it)._name)) {
s = plugin->outputScalars()[(*it)._name];
} else {
KstWriteLocker blockScalarUpdates(&KST::scalarList.lock());
s = new KstScalar(KstObjectTag(nt, plugin->tag()), plugin.data());
plugin->outputScalars().insert((*it)._name, s);
}
s->setTagName(KstObjectTag(nt, plugin->tag()));
} else if (plugin->outputScalars()[(*it)._name]->tagName() != nt) {
while (KstData::self()->vectorTagNameNotUnique(nt, false)) {
nt += "'";
}
KstScalarPtr s;
if (plugin->outputScalars().contains((*it)._name)) {
s = plugin->outputScalars()[(*it)._name];
} else {
KstWriteLocker blockScalarUpdates(&KST::scalarList.lock());
s = new KstScalar(KstObjectTag(nt, plugin->tag()), plugin.data());
plugin->outputScalars().insert((*it)._name, s);
}
s->setTagName(KstObjectTag(nt, plugin->tag()));
}
}
}
return true;
}
示例9: i18n
void KstPluginDialogI::generateEntries(bool input, int& cnt, QWidget *parent, QGridLayout *grid, const QValueList<Plugin::Data::IOValue>& table) {
QString scalarLabelTemplate, vectorLabelTemplate, stringLabelTemplate;
if (input) {
stringLabelTemplate = i18n("Input string - %1:");
scalarLabelTemplate = i18n("Input scalar - %1:");
vectorLabelTemplate = i18n("Input vector - %1:");
} else {
stringLabelTemplate = i18n("Output string - %1:");
scalarLabelTemplate = i18n("Output scalar - %1:");
vectorLabelTemplate = i18n("Output vector - %1:");
}
for (QValueList<Plugin::Data::IOValue>::ConstIterator it = table.begin(); it != table.end(); ++it) {
QString labellabel;
bool scalar = false;
bool string = false;
switch ((*it)._type) {
case Plugin::Data::IOValue::PidType:
continue;
case Plugin::Data::IOValue::StringType:
labellabel = stringLabelTemplate.arg((*it)._name);
string = true;
break;
case Plugin::Data::IOValue::FloatType:
labellabel = scalarLabelTemplate.arg((*it)._name);
scalar = true;
break;
case Plugin::Data::IOValue::TableType:
if ((*it)._subType == Plugin::Data::IOValue::FloatSubType ||
(*it)._subType == Plugin::Data::IOValue::FloatNonVectorSubType) {
labellabel = vectorLabelTemplate.arg((*it)._name);
} else {
// unsupported
continue;
}
break;
default:
// unsupported
continue;
}
QLabel *label = new QLabel(labellabel, parent, input ? "Input label" : "Output label");
QWidget *widget = 0L;
if (input) {
if (scalar) {
ScalarSelector *w = new ScalarSelector(parent, (*it)._name.latin1());
widget = w;
connect(w->_scalar, SIGNAL(activated(const QString&)), this, SLOT(updateScalarTooltip(const QString&)));
connect(widget, SIGNAL(newScalarCreated()), this, SIGNAL(modified()));
if (!(*it)._default.isEmpty()) {
w->_scalar->insertItem((*it)._default);
w->_scalar->setCurrentText((*it)._default);
}
KstScalarPtr p = *KST::scalarList.findTag(w->_scalar->currentText());
w->allowDirectEntry(true);
if (p) {
p->readLock();
QToolTip::remove(w->_scalar);
QToolTip::add(w->_scalar, QString::number(p->value()));
p->unlock();
}
} else if (string) {
StringSelector *w = new StringSelector(parent, (*it)._name.latin1());
widget = w;
connect(w->_string, SIGNAL(activated(const QString&)), this, SLOT(updateStringTooltip(const QString&)));
connect(widget, SIGNAL(newStringCreated()), this, SIGNAL(modified()));
if (!(*it)._default.isEmpty()) {
w->_string->insertItem((*it)._default);
w->_string->setCurrentText((*it)._default);
}
KstStringPtr p = *KST::stringList.findTag(w->_string->currentText());
w->allowDirectEntry(true);
if (p) {
p->readLock();
QToolTip::remove(w->_string);
QToolTip::add(w->_string, p->value());
p->unlock();
}
} else {
widget = new VectorSelector(parent, (*it)._name.latin1());
connect(widget, SIGNAL(newVectorCreated(const QString&)), this, SIGNAL(modified()));
}
} else {
示例10: assert
bool KstPluginDialogI::saveInputs(KstCPluginPtr plugin, KstSharedPtr<Plugin> p) {
bool rc = true;
KST::vectorList.lock().readLock();
KST::scalarList.lock().readLock();
KST::stringList.lock().readLock();
const QValueList<Plugin::Data::IOValue>& itable = p->data()._inputs;
for (QValueList<Plugin::Data::IOValue>::ConstIterator it = itable.begin(); it != itable.end(); ++it) {
if ((*it)._type == Plugin::Data::IOValue::TableType) {
QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "VectorSelector");
assert(field);
VectorSelector *vs = static_cast<VectorSelector*>(field);
KstVectorPtr v = *KST::vectorList.findTag(vs->selectedVector());
if (v) {
v->writeLock(); // to match with plugin->writeLock()
if (plugin->inputVectors().contains((*it)._name) && plugin->inputVectors()[(*it)._name] != v) {
plugin->inputVectors()[(*it)._name]->unlock();
}
plugin->inputVectors().insert((*it)._name, v);
} else if (plugin->inputVectors().contains((*it)._name)) {
plugin->inputVectors().erase((*it)._name);
rc = false;
}
} else if ((*it)._type == Plugin::Data::IOValue::StringType) {
QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "StringSelector");
assert(field);
StringSelector *ss = static_cast<StringSelector*>(field);
KstStringPtr s = *KST::stringList.findTag(ss->selectedString());
if (s == *KST::stringList.end()) {
QString val = ss->_string->currentText();
KstStringPtr newString = new KstString(ss->_string->currentText(), 0L, val, true, false);
newString->writeLock(); // to match with plugin->writeLock()
if (plugin->inputStrings().contains((*it)._name) && plugin->inputStrings()[(*it)._name] != s) {
plugin->inputStrings()[(*it)._name]->unlock();
}
plugin->inputStrings().insert((*it)._name, newString);
} else {
s->writeLock(); // to match with plugin->writeLock()
if (plugin->inputStrings().contains((*it)._name) && plugin->inputStrings()[(*it)._name] != s) {
plugin->inputStrings()[(*it)._name]->unlock();
}
plugin->inputStrings().insert((*it)._name, s);
}
} else if ((*it)._type == Plugin::Data::IOValue::PidType) {
// Nothing
} else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "ScalarSelector");
assert(field);
ScalarSelector *ss = static_cast<ScalarSelector*>(field);
KstScalarPtr s = *KST::scalarList.findTag(ss->selectedScalar());
if (s == *KST::scalarList.end()) {
bool ok;
double val = ss->_scalar->currentText().toDouble(&ok);
if (ok) {
KstScalarPtr newScalar = new KstScalar(ss->_scalar->currentText(), 0L, val, true, false, false);
newScalar->writeLock(); // to match with plugin->writeLock()
if (plugin->inputScalars().contains((*it)._name) && plugin->inputScalars()[(*it)._name] != s) {
plugin->inputScalars()[(*it)._name]->unlock();
}
plugin->inputScalars().insert((*it)._name, newScalar);
} else {
s->writeLock(); // to match with plugin->writeLock()
if (plugin->inputScalars().contains((*it)._name) && plugin->inputScalars()[(*it)._name] != s) {
plugin->inputScalars()[(*it)._name]->unlock();
}
plugin->inputScalars().insert((*it)._name, s);
}
} else {
s->writeLock(); // to match with plugin->writeLock()
if (plugin->inputScalars().contains((*it)._name) && plugin->inputScalars()[(*it)._name] != s) {
plugin->inputScalars()[(*it)._name]->unlock();
}
plugin->inputScalars().insert((*it)._name, s);
}
} else {
}
}
KST::stringList.lock().unlock();
KST::scalarList.lock().unlock();
KST::vectorList.lock().unlock();
return rc;
}
示例11: crossspectrum
void CrossPowerSpectrum::crossspectrum() {
KstVectorPtr v1 = *_inputVectors.find(VECTOR_ONE);
KstVectorPtr v2 = *_inputVectors.find(VECTOR_TWO);
KstScalarPtr fft = *_inputScalars.find(FFT_LENGTH);
KstScalarPtr sample = *_inputScalars.find(SAMPLE_RATE);
KstVectorPtr real = *_outputVectors.find(REAL);
KstVectorPtr imaginary = *_outputVectors.find(IMAGINARY);
KstVectorPtr frequency = *_outputVectors.find(FREQUENCY);
double SR = sample->value(); // sample rate
double df;
int i, xps_len;
double *a, *b;
double mean_a, mean_b;
int dv0, dv1, v_len;
int i_subset, n_subsets;
int i_samp, copyLen;
double norm_factor;
/* parse fft length */
xps_len = int( fft->value() - 0.99);
if ( xps_len > KSTPSDMAXLEN ) xps_len = KSTPSDMAXLEN;
if ( xps_len<2 ) xps_len = 2;
xps_len = int ( pow( 2, xps_len ) );
/* input vector lengths */
v_len = ( ( v1->length() < v2->length() ) ?
v1->length() : v2->length() );
dv0 = v_len/v1->length();
dv1 = v_len/v2->length();
while ( xps_len > v_len ) xps_len/=2;
// allocate the lengths
if ( real->length() != xps_len ) {
real->resize( xps_len, false );
imaginary->resize( xps_len, false );
frequency->resize( xps_len, false );
}
/* Fill the frequency and zero the xps */
df = SR/( 2.0*double( xps_len-1 ) );
for ( i=0; i<xps_len; i++ ) {
frequency->value()[i] = double( i ) * df;
real->value()[i] = 0.0;
imaginary->value()[i] = 0.0;
}
/* allocate input arrays */
int ALen = xps_len * 2;
a = new double[ALen];
b = new double[ALen];
/* do the fft's */
n_subsets = v_len/xps_len + 1;
for ( i_subset=0; i_subset<n_subsets; i_subset++ ) {
/* copy each chunk into a[] and find mean */
if (i_subset*xps_len + ALen <= v_len) {
copyLen = ALen;
} else {
copyLen = v_len - i_subset*xps_len;
}
mean_b = mean_a = 0;
for (i_samp = 0; i_samp < copyLen; i_samp++) {
i = ( i_samp + i_subset*xps_len )/dv0;
mean_a += (
a[i_samp] = v1->value()[i]
);
i = ( i_samp + i_subset*xps_len )/dv1;
mean_b += (
b[i_samp] = v2->value()[i]
);
}
if (copyLen>1) {
mean_a/=(double)copyLen;
mean_b/=(double)copyLen;
}
/* Remove Mean and apodize */
for (i_samp=0; i_samp<copyLen; i_samp++) {
a[i_samp] -= mean_a;
b[i_samp] -= mean_b;
}
for (;i_samp < ALen; i_samp++) {
a[i_samp] = 0.0;
b[i_samp] = 0.0;
}
/* fft */
rdft(ALen, 1, a);
rdft(ALen, 1, b);
/* sum each bin into psd[] */
real->value()[0] += ( a[0]*b[0] );
real->value()[xps_len-1] += ( a[1]*b[1] );
for (i_samp=1; i_samp<xps_len-1; i_samp++) {
//.........这里部分代码省略.........
示例12: doTests
void doTests() {
KstScalarPtr sp = new KstScalar;
doTest(!sp->tagName().isEmpty());
doTest(sp->value() == 0.0);
*sp = 3.1415;
doTest(sp->displayable());
doTest(sp->value() == 3.1415);
sp->setValue(2.1415);
doTest(sp->value() == 2.1415);
sp->setValue(NOPOINT);
doTest(sp->value() != sp->value());
sp->setValue(INF);
doTest(sp->value() == INF);
doTest((*sp = 2.0).value() == 2.0);
SListener *listener = new SListener;
sp->connect(sp, SIGNAL(trigger()), listener, SLOT(trigger()));
*sp = 3.1415;
doTest(listener->_trigger == 1);
sp->setValue(3.1415);
doTest(listener->_trigger == 2);
*sp = 1.1415;
doTest(listener->_trigger == 3);
KstScalarPtr sp2 = new KstScalar(sp->tagName());
doTest(sp2->tagName() == sp->tagName() + "'");
doTest(sp->isGlobal());
doTest(sp2->isGlobal());
doTest(sp->displayable());
doTest(sp2->displayable());
QDomNode n;
QDomElement e;
n = makeDOM1("load1", "2.14159265").firstChild();
e = n.toElement();
KstScalarPtr sp3 = new KstScalar(e);
doTest(sp3->orphan() == false);
doTest(sp3->value() == 2.14159265);
doTest(sp3->tagName() == "load1");
doTest(sp3->isGlobal());
doTest(sp3->displayable());
n = makeDOM1("55.4232", "55.4232", true).firstChild();
e = n.toElement();
KstScalarPtr sp4 = new KstScalar(e);
doTest(sp4->orphan());
doTest(sp4->value() == 55.4232);
doTest(sp4->tagName() == "55.4232");
doTest(sp4->isGlobal());
doTest(!sp4->displayable());
n = makeDOM1("load2", "NAN").firstChild();
e = n.toElement();
sp4 = new KstScalar(e);
doTest(sp4->value() != sp4->value());
n = makeDOM1("load3", "INF").firstChild();
e = n.toElement();
sp4 = new KstScalar(e);
doTest(sp4->value() == INF);
n = makeDOM1("load4", "-INF").firstChild();
e = n.toElement();
sp4 = new KstScalar(e);
doTest(sp4->value() == -INF);
delete listener;
}
示例13: autoSize
void BinnedMap::binnedmap() {
KstVectorPtr x = *_inputVectors.find(VECTOR_X);
KstVectorPtr y = *_inputVectors.find(VECTOR_Y);
KstVectorPtr z = *_inputVectors.find(VECTOR_Z);
KstMatrixPtr map = *_outputMatrices.find(MAP);
KstMatrixPtr hitsMap = *_outputMatrices.find(HITSMAP);
KstScalarPtr autobin = *_inputScalars.find(AUTOBIN);
if (autobin) {
if (autobin->value() != 0.0) {
_autoBin = true;
} else {
_autoBin = false;
}
}
if (_autoBin) {
double minx, miny, maxx, maxy;
int nx, ny;
autoSize(X(), Y(), &nx, &minx, &maxx, &ny, &miny, &maxy);
setNX(nx);
setNY(ny);
setXMin(minx);
setXMax(maxx);
setYMin(miny);
setYMax(maxy);
} else {
KstScalarPtr xmin = *_inputScalars.find(XMIN);
KstScalarPtr xmax = *_inputScalars.find(XMAX);
KstScalarPtr ymin = *_inputScalars.find(YMIN);
KstScalarPtr ymax = *_inputScalars.find(YMAX);
KstScalarPtr nx = *_inputScalars.find(NX);
KstScalarPtr ny = *_inputScalars.find(NY);
if (xmin) {
_xMin = xmin->value();
}
if (xmax) {
_xMax = xmax->value();
}
if (ymin) {
_yMin = ymin->value();
}
if (ymax) {
_yMax = ymax->value();
}
if (nx) {
_nx = (int)nx->value();
}
if (ny) {
_ny = (int)ny->value();
}
}
bool needsresize = false;
if (_nx < 2) {
_nx = 2;
needsresize = true;
}
if (_ny < 2) {
_ny = 2;
needsresize = true;
}
if ((map->xNumSteps() != _nx) || (map->yNumSteps() != _ny) ||
(map->minX() != _xMin) || (map->minY() != _yMin)) {
needsresize = true;
}
if (map->xStepSize() != (_xMax - _xMin)/double(_nx-1)) {
needsresize = true;
}
if (map->yStepSize() != (_yMax - _yMin)/double(_ny-1)) {
needsresize = true;
}
if (needsresize) {
map->change(map->tag(), _nx, _ny, _xMin, _yMin,
(_xMax - _xMin)/double(_nx-1), (_yMax - _yMin)/double(_ny-1));
map->resize(_nx, _ny);
hitsMap->change(hitsMap->tag(), _nx, _ny, _xMin, _yMin,
(_xMax - _xMin)/double(_nx-1), (_yMax - _yMin)/double(_ny-1));
hitsMap->resize(_nx, _ny);
}
map->zero();
hitsMap->zero();
int ns = z->length(); // the z vector defines the number of points.
double n,p, x0, y0, z0;
for (int i=0; i<ns; i++) {
x0 = x->interpolate(i, ns);
y0 = y->interpolate(i, ns);
z0 = z->interpolate(i, ns);
p = map->value(x0, y0)+z0;
map->setValue(x0, y0, p);
//.........这里部分代码省略.........
示例14: switch
void KstViewLabel::DataCache::update() {
for (QValueVector<DataRef>::ConstIterator i = data.begin(); valid && i != data.end(); ++i) {
switch ((*i).type) {
case DataRef::DataRef::DRScalar:
{
KST::scalarList.lock().readLock();
KstScalarPtr p = *KST::scalarList.findTag((*i).name);
KST::scalarList.lock().unlock();
if (p) {
p->readLock();
if (QVariant(p->value()) != (*i).value) {
valid = false;
}
p->unlock();
}
}
break;
case DataRef::DRString:
{
KST::stringList.lock().readLock();
KstStringPtr p = *KST::stringList.findTag((*i).name);
KST::stringList.lock().unlock();
if (p) {
p->readLock();
if (QVariant(p->value()) != (*i).value) {
valid = false;
}
p->unlock();
}
}
break;
case DataRef::DRExpression:
{
bool ok = false;
const double val = Equation::interpret((*i).name.latin1(), &ok, (*i).name.length());
if (QVariant(val) != (*i).value) {
valid = false;
}
}
break;
case DataRef::DRVector:
{
bool ok = false;
const double idx = Equation::interpret((*i).index.latin1(), &ok, (*i).index.length());
if (idx != (*i).indexValue) {
valid = false;
break;
}
KST::vectorList.lock().readLock();
KstVectorPtr p = *KST::vectorList.findTag((*i).name);
KST::vectorList.lock().unlock();
if (p) {
p->readLock();
if (QVariant(p->value(int((*i).indexValue))) != (*i).value) {
valid = false;
}
p->unlock();
}
}
break;
case DataRef::DataRef::DRFit:
{
KST::dataObjectList.lock().readLock();
KstDataObjectList::Iterator oi = KST::dataObjectList.findTag((*i).name);
KST::dataObjectList.lock().unlock();
if (oi != KST::dataObjectList.end()) {
KstCPluginPtr fit = kst_cast<KstCPlugin>(*oi);
if (fit) {
fit->readLock();
if (fit->label((int)((*i).indexValue)) != (*i).index) {
valid = false;
}
fit->unlock();
}
}
}
break;
}
}
}
示例15: qDebug
//.........这里部分代码省略.........
qDebug() << "updating curve: " << (void*)bcp << " - " << bcp->tagName() << endl;
#endif
KstObject::UpdateType ut = bcp->update(_updateCounter);
bcp->unlock();
if (ut == KstObject::UPDATE) { // HACK
_updatedCurves.append(bcp);
}
if (U != KstObject::UPDATE) {
U = ut;
if (U == KstObject::UPDATE) {
#if UPDATEDEBUG > 0
qDebug() << "Curve " << bcp->tagName() << " said UPDATE" << endl;
#endif
}
}
if (_done || (_paused && !force)) {
#if UPDATEDEBUG > 1
qDebug() << "5 Returning from scan with U=" << (int)U << endl;
#endif
return U == KstObject::UPDATE;
}
}
// Update all data objects
for (uint i = 0; i < dol.count(); ++i) {
KstDataObjectPtr dp = dol[i];
dp->writeLock();
assert(dp.data());
#if UPDATEDEBUG > 1
qDebug() << "updating data object: " << (void*)dp << " - " << dp->tagName() << endl;
#endif
dp->update(_updateCounter);
dp->unlock();
if (_done || (_paused && !force)) {
#if UPDATEDEBUG > 1
qDebug() << "5 Returning from scan with U=" << (int)U << endl;
#endif
return U == KstObject::UPDATE;
}
}
}
// Update the files
if (!_paused) { // don't update even if paused && force
KST::dataSourceList.lock().readLock();
unsigned cnt = KST::dataSourceList.count();
for (uint i = 0; i < cnt; ++i) {
KstDataSourcePtr dsp = KST::dataSourceList[i];
dsp->writeLock();
dsp->update(_updateCounter);
dsp->unlock();
if (_done) {
KST::dataSourceList.lock().unlock();
return false;
}
}
KST::dataSourceList.lock().unlock();
}
if (KstScalar::scalarsDirty()) {
KstScalar::clearScalarsDirty(); // Must do this first and take a risk of
// falling slightly behind
KST::scalarList.lock().readLock();
KstScalarList sl = Q3DeepCopy<KstScalarList>(KST::scalarList.list()); // avoid deadlock on exit
KST::scalarList.lock().unlock();
for (KstScalarList::ConstIterator i = sl.begin(); i != sl.end(); ++i) {
KstScalarPtr sp = *i;
sp->writeLock();
KstObject::UpdateType ut = sp->update(_updateCounter);
sp->unlock();
if (ut == KstObject::UPDATE) {
U = KstObject::UPDATE;
}
if (_done) {
return false;
}
}
}
if (U == KstObject::UPDATE) {
qDebug() << "Update plots" << endl;
if (gotData) { // FIXME: do we need to consider all the other exit points?
*gotData = true;
}
}
#if UPDATEDEBUG > 1
qDebug() << "6 Returning from scan with U=" << (int)U << endl;
#endif
return U == KstObject::UPDATE;
}