[Kst] branches/work/kst/portto4/kst/src

Mike Fenton mike at staikos.net
Tue May 13 20:24:50 CEST 2008


SVN commit 807372 by fenton:

Add Matrix/Scalar handling to update cycle.  Optimizations and bug fixes.


 M  +9 -0      libkst/matrix.cpp  
 M  +5 -0      libkst/matrix.h  
 M  +8 -0      libkst/scalar.cpp  
 M  +3 -0      libkst/scalar.h  
 M  +9 -0      libkstmath/csd.cpp  
 M  +8 -1      libkstmath/dataobject.cpp  
 M  +1 -1      libkstmath/dataobject.h  
 M  +10 -2     libkstmath/equation.cpp  
 M  +1 -3      libkstmath/histogram.cpp  
 M  +66 -36    libkstmath/image.cpp  
 M  +3 -0      libkstmath/image.h  
 M  +1 -3      libkstmath/psd.cpp  


--- branches/work/kst/portto4/kst/src/libkst/matrix.cpp #807371:807372
@@ -31,6 +31,7 @@
 #include "math_kst.h"
 #include "datacollection.h"
 #include "objectstore.h"
+#include "updatemanager.h"
 
 
 // used for resizing; set to 1 for loop zeroing, 2 to use memset
@@ -618,5 +619,13 @@
   setDirty();
 }
 
+
+void Matrix::triggerUpdateSignal(ObjectPtr object) {
+#if DEBUG_UPDATE_CYCLE > 1
+  qDebug() << "UP - Matrix" << shortName() << "has been updated as part of update of" << object->shortName() << "informing dependents";
+#endif
+  emit matrixUpdated(object);
 }
+
+}
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkst/matrix.h #807371:807372
@@ -138,6 +138,11 @@
 
     virtual void deleteDependents();
 
+    void triggerUpdateSignal(ObjectPtr object);
+
+  Q_SIGNALS:
+    void matrixUpdated(ObjectPtr object);
+
   protected:
     int _NS;
     int _NRealS; // number of samples with real values
--- branches/work/kst/portto4/kst/src/libkst/scalar.cpp #807371:807372
@@ -181,5 +181,13 @@
 }
 
 
+void Scalar::triggerUpdateSignal(ObjectPtr object) {
+#if DEBUG_UPDATE_CYCLE > 1
+  qDebug() << "UP - Scalar" << shortName() << "has been updated as part of update of" << object->shortName() << "informing dependents";
+#endif
+  emit scalarUpdated(object);
 }
+
+
+}
 // vim: et ts=2 sw=2
--- branches/work/kst/portto4/kst/src/libkst/scalar.h #807371:807372
@@ -64,6 +64,8 @@
 
     Scalar& operator=(double v);
 
+    void triggerUpdateSignal(ObjectPtr object);
+
   public slots:
     double value() const;
 
@@ -81,6 +83,7 @@
 
   signals:
     void trigger();
+    void scalarUpdated(ObjectPtr object);
 
   private:
     double _value;
--- branches/work/kst/portto4/kst/src/libkstmath/csd.cpp #807371:807372
@@ -122,6 +122,11 @@
     int in_windowSize, int in_length, double in_gaussianSigma,
     PSDType in_outputType, const QString& in_vectorUnits,
     const QString& in_rateUnits) {
+
+  if (_inputVectors[INVECTOR]) {
+    disconnect(_inputVectors[INVECTOR], SIGNAL(vectorUpdated(ObjectPtr)));
+  }
+
   _inputVectors[INVECTOR] = in_V;
   QString vecName = in_V ? in_V->tag().displayString() : QString::null;
   _frequency = in_freq;
@@ -155,6 +160,8 @@
   setDirty();
   _shortName = "G"+QString::number(_csdnum++);
 
+  connect(_inputVectors[INVECTOR], SIGNAL(vectorUpdated(ObjectPtr)), this, SLOT(inputObjectUpdated(ObjectPtr)));
+
 }
 
 void CSD::commonConstructor(ObjectStore *store, VectorPtr in_V,
@@ -193,6 +200,8 @@
 
   updateMatrixLabels();
   _outMatrix->setDirty();
+
+  connect(_inputVectors[INVECTOR], SIGNAL(vectorUpdated(ObjectPtr)), this, SLOT(inputObjectUpdated(ObjectPtr)));
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstmath/dataobject.cpp #807371:807372
@@ -166,7 +166,7 @@
 }
 
 
-void DataObject::vectorUpdated(ObjectPtr object) {
+void DataObject::inputObjectUpdated(ObjectPtr object) {
 #if DEBUG_UPDATE_CYCLE > 1
   qDebug() << "UP - Vector update required by DataObject " << shortName() << "for update of" << object->shortName();
 #endif
@@ -179,6 +179,13 @@
     foreach (VectorPtr vector, _outputVectors) {
       vector->triggerUpdateSignal(object);
     }
+    foreach (MatrixPtr matrix, _outputMatrices) {
+      qDebug() << "loop updating matrix" << matrix->shortName();
+      matrix->triggerUpdateSignal(object);
+    }
+    foreach (ScalarPtr scalar, _outputScalars) {
+      scalar->triggerUpdateSignal(object);
+    }
   }
   UpdateManager::self()->updateFinished(object, this);
   unlock();
--- branches/work/kst/portto4/kst/src/libkstmath/dataobject.h #807371:807372
@@ -122,7 +122,7 @@
     void showDialog(bool isNew = true);
 
   public Q_SLOTS:
-    void vectorUpdated(ObjectPtr object);
+    void inputObjectUpdated(ObjectPtr object);
 
   protected slots:
     virtual void showNewDialog() = 0;
--- branches/work/kst/portto4/kst/src/libkstmath/equation.cpp #807371:807372
@@ -173,7 +173,6 @@
   if (rc == UPDATE) {
     v->setDirty();
   }
-  v->update();
 
   unlockInputsAndOutputs();
 
@@ -261,6 +260,15 @@
     }
   }
   _isValid = _pe != 0L;
+
+  if (_isValid) {
+    foreach (VectorPtr vector, VectorsUsed) {
+      connect(vector, SIGNAL(vectorUpdated(ObjectPtr)), this, SLOT(inputObjectUpdated(ObjectPtr)));
+    }
+    foreach (ScalarPtr scalar, ScalarsUsed) {
+      connect(scalar, SIGNAL(scalarUpdated(ObjectPtr)), this, SLOT(inputObjectUpdated(ObjectPtr)));
+    }
+  }
 }
 
 
@@ -276,7 +284,7 @@
   _xInVector = in_xv;
   _inputVectors.insert(XINVECTOR, in_xv);
 
-  connect(in_xv, SIGNAL(vectorUpdated(ObjectPtr)), this, SLOT(vectorUpdated(ObjectPtr)));
+  connect(in_xv, SIGNAL(vectorUpdated(ObjectPtr)), this, SLOT(inputObjectUpdated(ObjectPtr)));
 
   _ns = 2; // reset the updating
   _doInterp = do_interp;
--- branches/work/kst/portto4/kst/src/libkstmath/histogram.cpp #807371:807372
@@ -264,9 +264,7 @@
   }
 
   _bVector->setDirty();
-  _bVector->update();
   _hVector->setDirty();
-  _hVector->update();
 
   unlockInputsAndOutputs();
 
@@ -325,7 +323,7 @@
 
 void Histogram::setVector(VectorPtr new_v) {
   if (new_v) {
-    connect(new_v, SIGNAL(vectorUpdated(ObjectPtr)), this, SLOT(vectorUpdated(ObjectPtr)));
+    connect(new_v, SIGNAL(vectorUpdated(ObjectPtr)), this, SLOT(inputObjectUpdated(ObjectPtr)));
     _inputVectors[RAWVECTOR] = new_v;
   }
 }
--- branches/work/kst/portto4/kst/src/libkstmath/image.cpp #807371:807372
@@ -16,6 +16,7 @@
 #include "image.h"
 #include "math_kst.h"
 #include "objectstore.h"
+#include "updatemanager.h"
 
 #include "kst_i18n.h"
 
@@ -121,6 +122,7 @@
   setContourDefaults();
   setDirty();
   _shortName = "I"+QString::number(_inum++);
+  connect(in_matrix, SIGNAL(matrixUpdated(ObjectPtr)), this, SLOT(matrixUpdated(ObjectPtr)));
 }
 
 
@@ -139,6 +141,7 @@
   setDirty();
 
   _shortName = "I"+QString::number(_inum++);
+  connect(in_matrix, SIGNAL(matrixUpdated(ObjectPtr)), this, SLOT(matrixUpdated(ObjectPtr)));
 }
 
 
@@ -167,6 +170,7 @@
   _pal = Palette(paletteName);
   setDirty();
   _shortName = "I"+QString::number(_inum++);
+  connect(in_matrix, SIGNAL(matrixUpdated(ObjectPtr)), this, SLOT(matrixUpdated(ObjectPtr)));
 }
 
 
@@ -201,58 +205,63 @@
 }
 
 
+void Image::matrixUpdated(ObjectPtr object) {
+#if DEBUG_UPDATE_CYCLE > 1
+    qDebug() << "UP - Image update ready for" << object->shortName();
+#endif
+    UpdateManager::self()->requestUpdate(object, this);
+}
+
+
 Object::UpdateType Image::update() {
   Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
 
-  bool force = dirty();
   setDirty(false);
 
   writeLockInputsAndOutputs();
 
   if (_inputMatrices.contains(THEMATRIX)) {
+
     MatrixPtr mp = _inputMatrices[THEMATRIX];
-    bool updated = UPDATE == mp->update();
 
-    if (updated || force) {
-      // stats
-      NS = mp->sampleCount();
-      MinX = mp->minX();
-      int xNumSteps = mp->xNumSteps();
-      double xStepSize = mp->xStepSize();
-      MaxX = xNumSteps*xStepSize + MinX;
-      MinY = mp->minY();
-      int yNumSteps = mp->yNumSteps();
-      double yStepSize = mp->yStepSize();
-      MaxY = yNumSteps*yStepSize + MinY;
-      _ns_maxx = MaxX;
-      _ns_minx = MinX;
-      _ns_maxy = MaxY;
-      _ns_miny = MinY;
-      MinPosY = MinY > 0 ? MinY : 0;
-      MinPosX = MinX > 0 ? MinX : 0;
+    // stats
+    NS = mp->sampleCount();
+    MinX = mp->minX();
+    int xNumSteps = mp->xNumSteps();
+    double xStepSize = mp->xStepSize();
+    MaxX = xNumSteps*xStepSize + MinX;
+    MinY = mp->minY();
+    int yNumSteps = mp->yNumSteps();
+    double yStepSize = mp->yStepSize();
+    MaxY = yNumSteps*yStepSize + MinY;
+    _ns_maxx = MaxX;
+    _ns_minx = MinX;
+    _ns_maxy = MaxY;
+    _ns_miny = MinY;
+    MinPosY = MinY > 0 ? MinY : 0;
+    MinPosX = MinX > 0 ? MinX : 0;
 
 
-      //recalculate the thresholds if necessary
-      if (_autoThreshold) {
-        _zLower = mp->minValue();
-        _zUpper = mp->maxValue();
-      }
+    //recalculate the thresholds if necessary
+    if (_autoThreshold) {
+      _zLower = mp->minValue();
+      _zUpper = mp->maxValue();
+    }
 
-      //update the contour lines
-      if (hasContourMap()) {
-        double min = mp->minValue(), max = mp->maxValue();
-          double contourStep  = (max - min) / (double)(_numContourLines + 1);
-        if (contourStep > 0) {
-          _contourLines.clear();
-          for (int i = 0; i < _numContourLines; i++) {
-            _contourLines.append(min + (i+1) * contourStep);
-          }
+    //update the contour lines
+    if (hasContourMap()) {
+      double min = mp->minValue(), max = mp->maxValue();
+        double contourStep  = (max - min) / (double)(_numContourLines + 1);
+      if (contourStep > 0) {
+        _contourLines.clear();
+        for (int i = 0; i < _numContourLines; i++) {
+          _contourLines.append(min + (i+1) * contourStep);
         }
       }
+    }
 
-      unlockInputsAndOutputs();
-      return UPDATE;
-    }
+    unlockInputsAndOutputs();
+    return UPDATE;
   }
 
   unlockInputsAndOutputs();
@@ -335,6 +344,10 @@
 void Image::changeToColorOnly(MatrixPtr in_matrix, double lowerZ,
     double upperZ, bool autoThreshold, const QString &paletteName) {
 
+  if (_inputMatrices[THEMATRIX]) {
+    disconnect(_inputMatrices[THEMATRIX], SIGNAL(matrixUpdated(ObjectPtr)));
+  }
+
   _inputMatrices[THEMATRIX] = in_matrix;
 
   _zLower = lowerZ;
@@ -345,12 +358,20 @@
   }
   _hasColorMap = true;
   _hasContourMap = false;
+
+  connect(in_matrix, SIGNAL(matrixUpdated(ObjectPtr)), this, SLOT(matrixUpdated(ObjectPtr)));
+
   setDirty();
 }
 
 
 void Image::changeToContourOnly(MatrixPtr in_matrix, int numContours,
     const QColor& contourColor, int contourWeight) {
+
+  if (_inputMatrices[THEMATRIX]) {
+    disconnect(_inputMatrices[THEMATRIX], SIGNAL(matrixUpdated(ObjectPtr)));
+  }
+
   _inputMatrices[THEMATRIX] = in_matrix;
   _numContourLines = numContours;
   _contourWeight = contourWeight;
@@ -358,6 +379,8 @@
   _hasColorMap = false;
   _hasContourMap = true;
 
+  connect(in_matrix, SIGNAL(matrixUpdated(ObjectPtr)), this, SLOT(matrixUpdated(ObjectPtr)));
+
   setDirty();
 }
 
@@ -366,6 +389,10 @@
     double lowerZ, double upperZ, bool autoThreshold, const QString &paletteName,
     int numContours, const QColor& contourColor, int contourWeight) {
 
+  if (_inputMatrices[THEMATRIX]) {
+    disconnect(_inputMatrices[THEMATRIX], SIGNAL(matrixUpdated(ObjectPtr)));
+  }
+
   _inputMatrices[THEMATRIX] = in_matrix;
 
   _zLower = lowerZ;
@@ -379,6 +406,9 @@
   _contourColor = contourColor;
   _hasColorMap = true;
   _hasContourMap = true;
+
+  connect(in_matrix, SIGNAL(matrixUpdated(ObjectPtr)), this, SLOT(matrixUpdated(ObjectPtr)));
+
   setDirty();
 }
 
--- branches/work/kst/portto4/kst/src/libkstmath/image.h #807371:807372
@@ -106,6 +106,9 @@
     // see KstRelation::paintLegendSymbol
     virtual void paintLegendSymbol(Painter *p, const QRect& bound);
 
+  public Q_SLOTS:
+    void matrixUpdated(ObjectPtr object);
+
   protected:
     Image(ObjectStore *store, const ObjectTag &in_tag);
     //constructor for colormap only
--- branches/work/kst/portto4/kst/src/libkstmath/psd.cpp #807371:807372
@@ -252,9 +252,7 @@
 
   updateVectorLabels();
   _sVector->setDirty();
-  _sVector->update();
   _fVector->setDirty();
-  _fVector->update();
 
   unlockInputsAndOutputs();
 
@@ -399,7 +397,7 @@
   _inputVectors.remove(INVECTOR);
   new_v->writeLock();
   _inputVectors[INVECTOR] = new_v;
-  connect(new_v, SIGNAL(vectorUpdated(ObjectPtr)), this, SLOT(vectorUpdated(ObjectPtr)));
+  connect(new_v, SIGNAL(vectorUpdated(ObjectPtr)), this, SLOT(inputObjectUpdated(ObjectPtr)));
   setDirty();
 }
 


More information about the Kst mailing list