Пример #1
0
QString KstIfaceImpl::loadMatrix(const QString& name, const QString& file, const QString& field,
                                int xStart, int yStart, int xNumSteps, int yNumSteps, 
                                int skipFrames, bool boxcarFilter) {
  KstDataSourcePtr src;
  /* generate or find the kstfile */
  KST::dataSourceList.lock().writeLock();
  KstDataSourceList::Iterator it = KST::dataSourceList.findReusableFileName(file);

  if (it == KST::dataSourceList.end()) {
    src = KstDataSource::loadSource(file);
    if (!src || !src->isValid()) {
      KST::dataSourceList.lock().unlock();
      return QString::null;
    }
    if (src->isEmpty()) {
      KST::dataSourceList.lock().unlock();
      return QString::null;
    }
    KST::dataSourceList.append(src);
  } else {
    src = *it;
  }
  src->writeLock();
  KST::dataSourceList.lock().unlock();

  // make sure field is valid
  if (!src->isValidMatrix(field)) {
    src->unlock();
    return QString::null;  
  }
  
  // make sure name is unique, else generate a unique one
  KST::matrixList.lock().readLock();
 
  QString matrixName;
  if (name.isEmpty()) {
    matrixName = "M" + QString::number(KST::matrixList.count() + 1); 
  } else {
    matrixName = name;  
  }

  while (KstData::self()->matrixTagNameNotUnique(matrixName, false)) {
    matrixName = "M" + QString::number(KST::matrixList.count() + 1);
  }
  KST::matrixList.lock().unlock();

  KstMatrixPtr p = new KstRMatrix(src, field, matrixName, xStart, yStart, xNumSteps, yNumSteps, 
                                  boxcarFilter, skipFrames > 0, skipFrames);
  KST::addMatrixToList(p);

  src->unlock();

  if (p) {
    _doc->forceUpdate();
    _doc->setModified();
    return p->tagName();
  }

  return QString::null;
}
Пример #2
0
QString KstIfaceImpl::createGradient(const QString& name, bool xDirection, double zAtMin, double zAtMax, 
                                     int xNumSteps, int yNumSteps, double xMin, double yMin, 
                                     double xStepSize, double yStepSize) {
  // make sure tag name is unique
  // make sure name is unique, else generate a unique one
  KST::matrixList.lock().readLock();

  QString matrixName;
  if (name.isEmpty()) {
    matrixName = "M" + QString::number(KST::matrixList.count() + 1); 
  } else {
    matrixName = name;  
  }

  while (KstData::self()->matrixTagNameNotUnique(matrixName, false)) {
    matrixName = "M" + QString::number(KST::matrixList.count() + 1);
  }
  KST::matrixList.lock().unlock();
  
  // create the gradient matrix
  KstMatrixPtr p = new KstSMatrix(matrixName, xNumSteps, yNumSteps, xMin, yMin, xStepSize, yStepSize, 
                                  zAtMin, zAtMax, xDirection);
  
  KST::addMatrixToList(p);

  if (p) {
    _doc->forceUpdate();
    _doc->setModified();
    return p->tagName();
  }

  return QString::null;
}
Пример #3
0
QString BinnedMap::hitsMapTag() const {
  KstMatrixPtr m = hitsMap();
  if (m) {
    return m->tagName();
  }
  return QString::null;
}
Пример #4
0
void KstMatrixTable::paintCell( QPainter* painter, int row, int col, const QRect& cr, bool selected, const QColorGroup& cg ) {
  KstMatrixList matrices = KST::matrixList;
  KstMatrixPtr matrix = *matrices.findTag(_strMatrix);
  QString str;
  double value;
  
  painter->eraseRect( 0, 0, cr.width(), cr.height() );
  if (selected) {
    painter->fillRect( 0, 0, cr.width(), cr.height(), cg.highlight() );
    painter->setPen(cg.highlightedText());
  } else {
    painter->fillRect( 0, 0, cr.width(), cr.height(), cg.base() );
    painter->setPen(cg.text());
  }

  if (matrix) {
    bool ok;
    value = matrix->valueRaw(col, row, &ok);
    if (ok) {
      str.setNum(value, 'g', 16);
    }
  }

  painter->drawText(0, 0, cr.width(), cr.height(), AlignLeft, str);
}
Пример #5
0
void KstMatrixTable::paintCell( QPainter* painter, int row, int col, const QRect& cr, bool selected, const QPalette &palette ) {
  KstMatrixPtr matrix = *KST::matrixList.findTag(_strMatrix);
  QString str;
  double value;

  painter->eraseRect( 0, 0, cr.width(), cr.height() );
  if (selected) {
    painter->fillRect( 0, 0, cr.width(), cr.height(), palette.highlight() );
    painter->setPen(palette.highlightedText().color());
  } else {
    painter->fillRect( 0, 0, cr.width(), cr.height(), palette.base() );
    painter->setPen(palette.text().color());
  }

  if (matrix) {
    bool ok;
    value = matrix->valueRaw(col, row, &ok);
    if (ok) {
      str.setNum(value, 'g', 16);
    } else {
      str = "-";
    }
  }

  painter->drawText(0, 0, cr.width(), cr.height(), Qt::AlignLeft, str);
}
Пример #6
0
void KstCSD::commonConstructor(const QString& in_tag, KstVectorPtr in_V,
                               double in_freq, bool in_average, bool in_removeMean, bool in_apodize, 
                               ApodizeFunction in_apodizeFxn, int in_windowSize, int in_averageLength, 
                               double in_gaussianSigma, const QString& in_vectorUnits, 
                               const QString& in_rateUnits, PSDType in_outputType, 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;
  _averageLength = in_averageLength;
  _vectorUnits = in_vectorUnits;
  _rateUnits = in_rateUnits;
  _outputType = in_outputType;

  if (_frequency <= 0.0) {
    _frequency = 1.0;
  }
  
  KstMatrixPtr outMatrix = new KstMatrix(in_tag+"-csd", this, 1, 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));
  _outMatrix = _outputMatrices.insert(OUTMATRIX, outMatrix);
  KST::addMatrixToList(outMatrix);

  updateMatrixLabels();
  (*_outMatrix)->setDirty();
}
Пример #7
0
KstObjectItem::KstObjectItem(QListViewItem *parent, KstMatrixPtr x, KstDataManagerI *dm, int localUseCount) 
: QObject(), QListViewItem(parent), _rtti(RTTI_OBJ_MATRIX), _tag(x->tag()), _dm(dm) {
  assert(x);
  _inUse = false;
  setText(0, x->tag().tag());
  setText(1, i18n("Slave Matrix"));
  x = 0L; // keep the counts in sync
  update(true, localUseCount);
}
Пример #8
0
void MatrixSelector::newMatrixCreated( KstMatrixPtr v ) {
  QString name;

  v->readLock();
  name = v->tagName();
  v->unlock();
  v = 0L; // deref

  emit newMatrixCreated(name);
}
Пример #9
0
void EventMonitorEntry::replaceDependency(KstMatrixPtr oldMatrix, KstMatrixPtr newMatrix) {
  QString newExp = _event;

  // also replace all occurences of scalar stats for the oldMatrix
  QHashIterator<QString, KstScalar*> scalarDictIter(oldMatrix->scalars());
  while (scalarDictIter.hasNext()) {
    const QString oldTag = scalarDictIter.next().value()->tagName();
    const QString newTag = newMatrix->scalars()[scalarDictIter.key()]->tagName();
    newExp = newExp.replace("[" + oldTag + "]", "[" + newTag + "]");
  }

  setEvent(newExp);
  setDirty();
}
Пример #10
0
void KstEquation::replaceDependency(KstMatrixPtr oldMatrix, KstMatrixPtr newMatrix) {

  QString newExp = _equation;
  
  // also replace all occurences of scalar stats for the oldMatrix
  QDictIterator<KstScalar> scalarDictIter(oldMatrix->scalars());
  for (; scalarDictIter.current(); ++scalarDictIter) {
    QString oldTag = scalarDictIter.current()->tagName();
    QString newTag = ((newMatrix->scalars())[scalarDictIter.currentKey()])->tagName();
    newExp = newExp.replace("[" + oldTag + "]", "[" + newTag + "]"); 
  }
  
  setEquation(newExp);
}
Пример #11
0
void KstImageDialogI::calcAutoThreshold() {
  //make sure an matrix is selected
  if (!_w->_matrix->selectedMatrix().isEmpty()){
    KST::matrixList.lock().readLock();
    KstMatrixPtr matrix = *KST::matrixList.findTag(_w->_matrix->selectedMatrix());
    KST::matrixList.lock().unlock();
    if (matrix) {
      matrix->readLock();
      _w->_lowerZ->setText(QString::number(matrix->minValue()));
      _w->_upperZ->setText(QString::number(matrix->maxValue()));
      matrix->unlock();
    }
  }
}
Пример #12
0
void EventMonitorEntry::replaceDependency(KstMatrixPtr oldMatrix, KstMatrixPtr newMatrix) {
  QString newExp = _event;

  // also replace all occurences of scalar stats for the oldMatrix
  QDictIterator<KstScalar> scalarDictIter(oldMatrix->scalars());
  for (; scalarDictIter.current(); ++scalarDictIter) {
    const QString oldTag = scalarDictIter.current()->tagName();
    const QString newTag = newMatrix->scalars()[scalarDictIter.currentKey()]->tagName();
    newExp = newExp.replace("[" + oldTag + "]", "[" + newTag + "]");
  }

  setEvent(newExp);
  setDirty();
}
Пример #13
0
void KstMatrixDialog::fillFieldsForEdit() {
  KstMatrixPtr mp;

  mp = kst_cast<KstMatrix>(_dp);
  if (mp) {
    KstRMatrixPtr rmp;

    mp->readLock();
    _tagName->setText(mp->tagName());
    _w->_minX->setText(QString::number(mp->minX()));
    _w->_minY->setText(QString::number(mp->minY()));
    _w->_xStep->setText(QString::number(mp->xStepSize()));
    _w->_yStep->setText(QString::number(mp->yStepSize()));
    mp->unlock();
  
    _w->_sourceGroup->hide();
  
    rmp = kst_cast<KstRMatrix>(mp);
    if (rmp) {
      fillFieldsForRMatrixEdit();
    } else {
      fillFieldsForSMatrixEdit();
    }
  
    updateEnables();
  
    adjustSize();
    resize(minimumSizeHint());
    setFixedHeight(height());
  }
}
Пример #14
0
void KstDataObject::replaceDependency(KstMatrixPtr oldMatrix, KstMatrixPtr newMatrix) {
  KstMatrixMap::Iterator j;

  for (j = _inputMatrices.begin(); j != _inputMatrices.end(); ++j) {
    if (*j == oldMatrix) {
      _inputMatrices[j.key()] = newMatrix;
    }
  }

  ScalarCollection::const_iterator it;
  
  for (KstScalarMap::Iterator j = _inputScalars.begin(); j != _inputScalars.end(); ++j) {
    for (it =oldMatrix->scalars().begin(); it != oldMatrix->scalars().end(); ++it) {
      if ((*it) == (*j)) {
        _inputScalars[j.key()] = (newMatrix->scalars())[it.key()];
      }
    }
  }
}
Пример #15
0
void MatrixSelector::editMatrix() {
  KstDataObjectPtr pro;
  KstMatrixPtr matrix;
  
  KST::matrixList.lock().readLock();
  matrix = *KST::matrixList.findTag(_matrix->currentText());
  KST::matrixList.lock().unlock();

  if (matrix) {
    pro = kst_cast<KstDataObject>(matrix->provider());
  }

  if (pro) {
    pro->readLock();
    pro->showDialog(false);
    pro->unlock();
  } else {
// xxx    KstDialogs::self()->showMatrixDialog(_matrix->currentText(), true);
  }
}
Пример #16
0
void KstViewMatricesDialogI::updateViewMatricesDialog(const QString& matrixName) {
  int needed = 0;
  
  KST::matrixList.lock().readLock();
  KstMatrixPtr matrix = *KST::matrixList.findTag(matrixName);
  KST::matrixList.lock().unlock();
  if (matrix) {
    matrix->readLock();
    
    needed = matrix->xNumSteps();
    if (needed != _tableMatrices->numCols()) {
      _tableMatrices->setNumCols(needed);
    }    
    
    needed = matrix->yNumSteps();
    if (needed != _tableMatrices->numRows()) {
      _tableMatrices->setNumRows(needed);
    }  
        
    matrix->unlock();
  }
}
Пример #17
0
void KstCSD::commonConstructor(const QString& in_tag, KstVectorPtr in_V, double in_freq, bool in_average, 
                                bool in_removeMean, bool in_apodize, ApodizeFunction in_apodizeFxn, int in_windowSize, 
                                int in_averageLength, double in_gaussianSigma, const QString& in_vectorUnits,
                                const QString& in_rateUnits, PSDType in_outputType, bool in_interpolateHoles,
                                const QString& vecName) {
  _typeString = i18n("Spectrogram");
  _type = "Spectrogram";
  _inputVectors[INVECTOR] = in_V;
  setTagName(KstObjectTag::fromString(in_tag));
  _frequency = in_freq;
  _average = in_average;
  _apodize = in_apodize;
  _windowSize = in_windowSize;
  _apodizeFxn = in_apodizeFxn;
  _gaussianSigma = in_gaussianSigma;
  _removeMean = in_removeMean;
  _averageLength = in_averageLength;
  _vectorUnits = in_vectorUnits;
  _rateUnits = in_rateUnits;
  _outputType = in_outputType;
  _interpolateHoles = in_interpolateHoles;

  if (_frequency <= 0.0) {
    _frequency = 1.0;
  }

  {
    KstWriteLocker blockMatrixUpdates(&KST::matrixList.lock());

    KstMatrixPtr outMatrix = new KstMatrix(KstObjectTag("csd", tag()), this, 1, 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));
    _outMatrix = _outputMatrices.insert(OUTMATRIX, outMatrix);
  }

  updateMatrixLabels();
  (*_outMatrix)->setDirty();
}
Пример #18
0
void KstViewMatricesDialog::updateViewMatricesDialog(const QString& matrixName) {
  KstMatrixPtr matrix;

  KST::matrixList.lock().readLock();
  matrix = *KST::matrixList.findTag(matrixName);
  KST::matrixList.lock().unlock();
  if (matrix) {
    bool updated = false;
    int xneeded = 0;
    int yneeded = 0;

    matrix->readLock();
    xneeded = matrix->xNumSteps();
    yneeded = matrix->yNumSteps();
    matrix->unlock();

    if (xneeded != _tableMatrices->columnCount()) {
      _tableMatrices->setColumnCount(xneeded);
      updated = true;
    }

    if (yneeded != _tableMatrices->rowCount()) {
      _tableMatrices->setRowCount(yneeded);
      updated = true;
    }

    if (!updated) {
      //
      // following two lines appear to be necessary to ensure a full update...
      //

      _tableMatrices->hide();
      _tableMatrices->show();

      _tableMatrices->update();
    }
  }
}
Пример #19
0
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();
}
Пример #20
0
// This should use a smart (percentile based) algorithm to
// calculate the thresholds.  It will be expensive.
void KstImageDialogI::calcSmartThreshold() {
  //make sure an matrix is selected
  if (!_w->_matrix->selectedMatrix().isEmpty()){
    KST::matrixList.lock().readLock();
    KstMatrixPtr matrix = *KST::matrixList.findTag(_w->_matrix->selectedMatrix());
    KST::matrixList.lock().unlock();
    if (matrix) {
      matrix->readLock();
      double per = _w->_smartThresholdValue->value()/100.0;

      matrix->calcNoSpikeRange(per);
      _w->_lowerZ->setText(QString::number(matrix->minValueNoSpike()));
      _w->_upperZ->setText(QString::number(matrix->maxValueNoSpike()));
      matrix->unlock();
    }
  }
}
Пример #21
0
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);
  }
}
Пример #22
0
bool KstMatrixDialogI::editObject() {
  // if editing multiple objects, edit each one
  if (_editMultipleMode) {
    _fileNameDirty = !_w->_fileName->url().isEmpty();
    _gradientZAtMinDirty = !_w->_gradientZAtMin->text().isEmpty();
    _gradientZAtMaxDirty = !_w->_gradientZAtMax->text().isEmpty();
    _minXDirty = !_w->_minX->text().isEmpty();
    _minYDirty = !_w->_minY->text().isEmpty();
    _yStepDirty = !_w->_yStep->text().isEmpty();
    _xStepDirty = !_w->_xStep->text().isEmpty();

    _xStartDirty = _w->_xStart->text() != " ";
    _yStartDirty = _w->_yStart->text() != " ";
    _xNumStepsDirty = _w->_xNumSteps->text() != " ";
    _yNumStepsDirty = _w->_yNumSteps->text() != " ";

    _skipDirty = _w->_skip->text() != " ";
    _nXDirty = _w->_nX->text() != " ";
    _nYDirty = _w->_nY->text() != " ";

    bool didEdit = false;
    for (uint i = 0; i < _editMultipleWidget->_objectList->count(); i++) {
      if (_editMultipleWidget->_objectList->isSelected(i)) {
        // get the pointer to the object
        KST::matrixList.lock().readLock();
        KstMatrixPtr mxPtr = *KST::matrixList.findTag(_editMultipleWidget->_objectList->text(i));
        KST::matrixList.lock().unlock();
        if (!mxPtr) {
          return false;
        }

        if (!editSingleObject(mxPtr)) {
          return false;
        }
        didEdit = true;
      }
    }
    if (!didEdit) {
      KMessageBox::sorry(this, i18n("Select one or more objects to edit."));
      return false;
    }
  } else {
    KstMatrixPtr mp = kst_cast<KstMatrix>(_dp);
    // verify that the curve name is unique
    QString tag_name = _tagName->text();
    if (!mp || (tag_name != mp->tagName() && KstData::self()->dataTagNameNotUnique(tag_name))) {
      _tagName->setFocus();
      return false;
    }

    mp->writeLock();
    mp->setTagName(tag_name);
    mp->unlock();

    // then edit the object
    _fileNameDirty = true;
    _fieldDirty = true;
    _xStartDirty = true;
    _xStartCountFromEndDirty = true;
    _yStartDirty = true;
    _yStartCountFromEndDirty = true;
    _xNumStepsDirty = true;
    _xNumStepsReadToEndDirty = true;
    _yNumStepsDirty = true;
    _yNumStepsReadToEndDirty = true;
    _gradientXDirty = true;
    _gradientYDirty = true;
    _gradientZAtMinDirty = true;
    _gradientZAtMaxDirty = true;
    _minXDirty = true;
    _minYDirty = true;
    _xStepDirty = true;
    _yStepDirty = true;
    _doSkipDirty = true;
    _skipDirty = true;
    _doAveDirty = true;
    _nXDirty = true;
    _nYDirty = true;
    if (!editSingleObject(mp)) {
      return false;
    }
  }
  emit modified();
  return true;
}
Пример #23
0
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);
        n = hitsMap->value(x0, y0)+1;
        hitsMap->setValue(x0, y0, n);
    }

    for (int i=0; i<_nx; i++) {
        for (int j=0; j<_ny; j++) {
            p = map->valueRaw(i, j);
            n = hitsMap->valueRaw(i, j);
            if (n>0) {
                map->setValueRaw(i, j, p/n);
            } else {
                map->setValueRaw(i, j, KST::NOPOINT);
            }
        }
    }
}
Пример #24
0
QString KstIfaceImpl::createImage(const QString &name,
                                  const QString &in_matrix,
                                  double lowerZ,
                                  double upperZ,
                                  const QString &paletteName,
                                  int numContours,
                                  const QColor& contourColor,
                                  uint imageType) {
  //get the matrix
  KstMatrixList matrices = kstObjectSubList<KstDataObject, KstMatrix>(KST::dataObjectList);
  KstMatrixPtr matrix = *matrices.findTag(in_matrix);
  if (!matrix) {
    return QString::null;
  }

  //make a name if necessary
  QString imgtag;
  if (name.isEmpty()) {
    imgtag = KST::suggestImageName(in_matrix);
  } else {
    QString imgtag_end = QString(name);
    //count number of data objects and make a unique name
    int i = KST::dataObjectList.count() + 1;
    imgtag = QString::number(i) + "-" + imgtag_end;
  }
  while (KstData::self()->dataTagNameNotUnique(imgtag, false)) {
    imgtag += "\'";
  }

  //determine the image type
  KstImagePtr image;
  if (imageType == 0) {
    //need a colormap
    if (lowerZ > upperZ) {
      return QString::null;
    }
    KPalette* pal = new KPalette(paletteName);
    matrix->readLock();
    image = new KstImage(imgtag, matrix, lowerZ, upperZ, false, pal);
    matrix->unlock();
  } else if (imageType == 1) {
    //need a contourmap
    if (numContours < 1) {
      return QString::null;
    }
    matrix->readLock();
    image = new KstImage(imgtag, matrix, numContours, contourColor.isValid() ? contourColor : QColor("darkBlue"), 0);
    matrix->unlock();
  } else if (imageType == 2) {
    //need both contourmap and colormap
    if (lowerZ > upperZ) {
      return QString::null;
    }
    if (numContours < 1) {
      return QString::null;
    }
    KPalette* pal = new KPalette(paletteName);
    matrix->readLock();
    image = new KstImage(imgtag, matrix, lowerZ, upperZ, false, pal,
                         numContours, contourColor.isValid() ? contourColor : QColor("darkBlue"), 0);
    matrix->unlock();
  } else {
    return QString::null;
  }

  KST::dataObjectList.lock().writeLock();
  KST::dataObjectList.append(KstDataObjectPtr(image));
  KST::dataObjectList.lock().unlock();

  _doc->forceUpdate();
  _doc->setModified();

  return imgtag;

}
Пример #25
0
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();
  }
}
Пример #26
0
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);

  if (autoBin()) {
    AutoSize(X(),Y(), &_nx, &_xMin, &_xMax, &_ny, &_yMin, &_yMax);
  }
  
  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);
    n = hitsMap->value(x0, y0)+1;
    hitsMap->setValue(x0, y0, n);
  }

  for (int i=0; i<_nx; i++) {
    for (int j=0; j<_ny; j++) {
      p = map->valueRaw(i,j);
      n = hitsMap->valueRaw(i,j);
      if (n>0) {
	map->setValueRaw(i,j,p/n);
      } else {
	map->setValueRaw(i,j,KST::NOPOINT);
      }
    }
  }

  //calculate here...
}
Пример #27
0
void MatrixSelector::setSelection( KstMatrixPtr v ) {
  v->readLock();
  setSelection(v->tagName());
  v->unlock();
}
Пример #28
0
bool KstImageDialogI::newObject() {
  //if matrixCombo is empty then display an error message
  if (_w->_matrix->selectedMatrix().isEmpty()){
    KMessageBox::sorry(this, i18n("Matrix is a 2D grid of numbers, used to create image", "New image not made: define matrix first."));
    return false;
  }

  //do some checks on the inputs
  double lowerZDouble, upperZDouble;
  if (!checkParameters(lowerZDouble, upperZDouble)) {
    return false;
  }

  KST::matrixList.lock().readLock();
  KstMatrixPtr matrix = *KST::matrixList.findTag(_w->_matrix->selectedMatrix());
  KST::matrixList.lock().unlock();
  if (!matrix) {
    KMessageBox::sorry(this, i18n("Matrix is a 2D grid of numbers, used to create image", "Could not find matrix."));
    return false;
  }
  KST::dataObjectList.lock().readLock();
  matrix->readLock();

  //create a unique name
  QString tag_name = KST::suggestImageName(matrix->tag());
  if (KstData::self()->dataTagNameNotUnique(tag_name)) {
    _tagName->setFocus();
    matrix->unlock();
    KST::dataObjectList.lock().unlock();
    return false;
  }

  KstImagePtr image;
  if (_w->_contourOnly->isChecked()) {
    //need a contour map only
    QColor tempColor = _w->_contourColor->color();
    image = new KstImage(tag_name, matrix, _w->_numContourLines->text().toInt(), tempColor,
                         _w->_useVariableWeight->isChecked() ? -1 : _w->_contourWeight->value());
  } else if (_w->_colorOnly->isChecked()) {
    //need a color map only
    KPalette* newPal = new KPalette(_w->_colorPalette->selectedPalette());
    image = new KstImage(tag_name, matrix, lowerZDouble, upperZDouble,
                         _w->_realTimeAutoThreshold->isChecked(), newPal);
  } else {
    //need both a contour map and colour map
    QColor tempColor = _w->_contourColor->color();
    KPalette* newPal = new KPalette(_w->_colorPalette->selectedPalette());
    image = new KstImage(tag_name, matrix, lowerZDouble, upperZDouble,
                         _w->_realTimeAutoThreshold->isChecked(), newPal,
                         _w->_numContourLines->text().toInt(), tempColor,
                         _w->_useVariableWeight->isChecked() ? -1 : _w->_contourWeight->value());
  }
  matrix->unlock();
  KST::dataObjectList.lock().unlock();
  placeInPlot(image);
  KST::dataObjectList.lock().writeLock();
  KST::dataObjectList.append(image.data());
  KST::dataObjectList.lock().unlock();
  image = 0L; // drop the reference
  emit modified();
  return true;
}
Пример #29
0
bool KstMatrixDialog::editObject() {
  //
  // if editing multiple objects, edit each one...
  //

  if (_editMultipleMode) {
// xxx    _fileNameDirty = !_w->_fileName->url().isEmpty();
    _gradientZAtMinDirty = !_w->_gradientZAtMin->text().isEmpty();
    _gradientZAtMaxDirty = !_w->_gradientZAtMax->text().isEmpty();
    _minXDirty = !_w->_minX->text().isEmpty();
    _minYDirty = !_w->_minY->text().isEmpty();
    _yStepDirty = !_w->_yStep->text().isEmpty();
    _xStepDirty = !_w->_xStep->text().isEmpty();

    _xStartDirty = _w->_xStart->text() != " ";
    _yStartDirty = _w->_yStart->text() != " ";
    _xNumStepsDirty = _w->_xNumSteps->text() != " ";
    _yNumStepsDirty = _w->_yNumSteps->text() != " ";

    _skipDirty = _w->_skip->text() != " ";
    _nXDirty = _w->_nX->text() != " ";
    _nYDirty = _w->_nY->text() != " ";

    bool didEdit = false;
    int i;

    for (i = 0; i < _editMultipleWidget->_objectList->count(); i++) {
      if (_editMultipleWidget->_objectList->item(i)->isSelected()) {
        KstMatrixPtr mxPtr;

        //
        // get the pointer to the object...
        //

        KST::matrixList.lock().readLock();
        mxPtr = *KST::matrixList.findTag(_editMultipleWidget->_objectList->item(i)->text());
        KST::matrixList.lock().unlock();
        
        if (!mxPtr) {
          return false;
        }

        if (!editSingleObject(mxPtr)) {
          return false;
        }

        didEdit = true;
      }
    }

    if (!didEdit) {
      QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("Select one or more objects to edit."));

      return false;
    }
  } else {
    KstMatrixPtr mp;
    QString tagName;

    mp = kst_cast<KstMatrix>(_dp);
    tagName = _tagName->text();
    if (!mp || (tagName != mp->tagName() && KstData::self()->dataTagNameNotUnique(tagName))) {
      _tagName->setFocus();

      return false;
    }

    mp->writeLock();
    mp->setTag(KstObjectTag(tagName, mp->tag().context())); // FIXME: can't change tag context
    mp->unlock();

    //
    // then edit the object...
    //

    _fileNameDirty = true;
    _fieldDirty = true;
    _xStartDirty = true;
    _xStartCountFromEndDirty = true;
    _yStartDirty = true;
    _yStartCountFromEndDirty = true;
    _xNumStepsDirty = true;
    _xNumStepsReadToEndDirty = true;
    _yNumStepsDirty = true;
    _yNumStepsReadToEndDirty = true;
    _gradientXDirty = true;
    _gradientYDirty = true;
    _gradientZAtMinDirty = true;
    _gradientZAtMaxDirty = true;
    _minXDirty = true;
    _minYDirty = true;
    _xStepDirty = true;
    _yStepDirty = true;
    _doSkipDirty = true;
    _skipDirty = true;
    _doAveDirty = true;
    _nXDirty = true;
    _nYDirty = true;

    if (!editSingleObject(mp)) {
      return false;
    }
  }

  emit modified();

  return true;
}
Пример #30
0
void doTests() {
  bool ok = true;

  //basic default constructor values
  KstMatrixPtr m1 = new KstMatrix(KstObjectTag(QString::null));
  doTest(m1->tagName().startsWith("Anonymous"));
  doTest(m1->sampleCount() == 0);
  doTest(m1->minValue() == 0);
  doTest(m1->maxValue() == 0);
  doTest(m1->value(0, 0, &ok) == 0);
  doTest(!ok);
  doTest(m1->value(10, 10, &ok) == 0); //should be outside the boundaries.
  doTest(!ok);
  doTest(m1->sampleCount() == 0);
  doTest(m1->meanValue() != m1->meanValue()); // NaN

  //basic symetrical matrix
  KstMatrixPtr m2 = new KstMatrix(KstObjectTag("Symetrical"), 0L, 3, 3);
  doTest(m2->tagName() == "Symetrical");

  doTest(m2->resize(3, 3, true));

  doTest(!m2->editable());
  m2->setEditable(true);

  doTest(m2->editable());

  doTest(m2->xNumSteps() == 3);
  doTest(m2->yNumSteps() == 3);
  doTest(m2->minX() == 0);
  doTest(m2->minY() == 0);
  doTest(m2->xStepSize() == 1);
  doTest(m2->yStepSize() == 1);
  doTest(m2->sampleCount() == 9);

  doTest(m2->setValueRaw(1, 1, 5));
  ok = true;
  doTest(m2->value(1, 1, &ok) == 5);
  doTest(ok);

  m2->blank();

  m2->change(m2->tag(), 3, 3, 0, 0, 0, 0); //should not be legal
  doTest(m2->xNumSteps() == 3);
  doTest(m2->yNumSteps() == 3);
  doTest(m2->minX() == 0);
  doTest(m2->minY() == 0);
  doTest(m2->xStepSize() == 0);
  doTest(m2->yStepSize() == 0);
  doTest(m2->sampleCount() == 9);

  doTest(!m2->setValue(0, 0, 1.0));
  ok = true;
  doTest(m2->value(0, 0, &ok) == 0.0);
  doTest(!ok);

  doTest(!m2->setValue(1, 1, 5.0));
  doTest(m2->value(1, 1) != 5.0);
  doTest(m2->setValueRaw(2, 2, 6.0)); //fails

  KstMatrixPtr um1 = new KstMatrix(KstObjectTag("Unity"), 0L, 3, 3, 0, 0, 1, 1);
  um1->setEditable(true);
  um1->zero();
  doTest(!um1->setValue(0, 0, 1.0));
  doTest(!um1->setValue(1, 1, 1.0));
  doTest(!um1->setValue(2, 2, 1.0));

  doTest(um1->resize(3, 3, false));
  um1->zero();
  doTest(um1->setValue(0, 0, 1.0));
  doTest(um1->setValue(1, 1, 1.0));
  doTest(um1->setValue(2, 2, 1.0));

  // calling resize on a matrix does not retain the correct values
  // for matrix entries. i.e. taking a 3x3 matrix and resizing
  // to a 2x2 matrix does not mean matrix[0][0], matrix[0][1],
  // matrix[1][0], matrix[1][1] are the same before and after the resize.
  // The resulting values should properly be undefined...
  doTest(um1->resize(2, 2, true));
  doTest(um1->sampleCount() == 4); 

  doTest(um1->value(0, 0, &ok) == 1.0);
  doTest(ok);
  doTest(um1->value(0, 1, &ok) == 0);
  doTest(ok);
  doTest(um1->value(0, 2, &ok) == 0);
  doTest(!ok);
  doTest(um1->value(1, 0, &ok) == 0);
  doTest(ok);
  doTest(um1->value(1, 1, &ok) == 0);
  doTest(ok);
  doTest(um1->value(1, 2, &ok) == 0);
  doTest(!ok);

  doTest(um1->resize(4, 4, false));
  doTest(um1->value(0, 0, &ok) == 1.0);
  doTest(ok);
  doTest(um1->value(0, 1, &ok) == 0);
  doTest(ok);
  doTest(um1->value(0, 2, &ok) == 0);
  doTest(ok);
  doTest(um1->value(1, 0, &ok) == 0);
  doTest(ok);
  doTest(um1->value(1, 1, &ok) == 0);
  doTest(ok);
  doTest(um1->value(1, 2, &ok) == 0);
  doTest(ok);

  doTest(um1->resize(3, 3, true));
  doTest(um1->setValue(0, 0, 1.716299));
  doTest(um1->setValue(0, 1, -0.485527));
  doTest(um1->setValue(0, 2, -0.288690));
  doTest(um1->setValue(1, 0, 1.716299));
  doTest(um1->setValue(1, 1, NAN));
  doTest(um1->setValue(1, 2, -0.274957));
  doTest(um1->setValue(2, 0, 1.711721));
  doTest(um1->setValue(2, 1, -0.485527));
  doTest(um1->setValue(2, 2, -0.293267));

  doTest(um1->value(0, 0) == 1.716299);
  doTest(um1->value(0, 1) ==  -0.485527);
  doTest(um1->value(0, 2) == -0.288690);
  doTest(um1->value(1, 0) == 1.716299);
  doTest(um1->value(1, 1) == 0);
  doTest(um1->value(1, 2) == -0.274957);
  doTest(um1->value(2, 0) == 1.711721);
  doTest(um1->value(2, 1) == -0.485527);
  doTest(um1->value(2, 2) == -0.293267);

  doTest(um1->minValue() == 0);
  doTest(um1->maxValue() == 0);

  KstMatrixPtr sm = new KstMatrix(KstObjectTag("Spike"), 0L, 2, 2, 0, 0, 1, 1);

  sm->setEditable(true);
  doTest(sm->resize(2, 2, false));
  doTest(sm->xNumSteps() == 2);
  doTest(sm->yNumSteps() == 2);

  doTest(sm->setValueRaw(0, 0, 0.0));
  doTest(sm->setValueRaw(0, 1, 0.1));
  doTest(sm->setValueRaw(1, 0, 1.0));
  doTest(sm->setValueRaw(1, 1, 1.1));

  sm->calcNoSpikeRange(0);
  doTest(sm->minValueNoSpike() == 0.0);
  doTest(sm->maxValueNoSpike() == 0.0);

  sm->calcNoSpikeRange(-100);
  doTest(sm->minValueNoSpike() == 0.0);
  doTest(sm->maxValueNoSpike() == 0.0);

  sm->calcNoSpikeRange(0.9);
  doTest(sm->minValueNoSpike() >= 1E+300 );
  doTest(sm->maxValueNoSpike() <= -1E+300);
}