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

Mike Fenton mike at staikos.net
Fri Oct 19 20:59:50 CEST 2007


SVN commit 727091 by fenton:

Add creation of CSD object and image creation.


 M  +68 -2     libkstapp/csddialog.cpp  
 M  +3 -0      libkstapp/csddialog.h  
 M  +7 -7      libkstmath/image.cpp  
 M  +8 -9      libkstmath/image.h  
 M  +3 -0      libkstmath/palette.cpp  
 M  +5 -2      libkstmath/palette.h  


--- branches/work/kst/portto4/kst/src/libkstapp/csddialog.cpp #727090:727091
@@ -22,6 +22,8 @@
 #include "application.h"
 #include "plotrenderitem.h"
 #include "curve.h"
+#include "palette.h"
+#include "image.h"
 
 #include "defaultnames.h"
 #include "datacollection.h"
@@ -57,6 +59,15 @@
 }
 
 
+ColorPalette* CSDTab::colorPalette() const {
+  return _colorPalette;
+}
+
+
+int CSDTab::windowSize() const {
+  return _windowSize->value();
+}
+
 CSDDialog::CSDDialog(ObjectPtr dataObject, QWidget *parent)
   : DataDialog(dataObject, parent) {
 
@@ -82,8 +93,63 @@
 
 
 ObjectPtr CSDDialog::createNewDataObject() const {
-  qDebug() << "createNewDataObject" << endl;
-  return 0;
+
+  CSDPtr csd = new CSD(tagName(),
+                                     _CSDTab->vector(),
+                                     _CSDTab->FFTOptionsWidget()->sampleRate(),
+                                     _CSDTab->FFTOptionsWidget()->interleavedAverage(),
+                                     _CSDTab->FFTOptionsWidget()->removeMean(),
+                                     _CSDTab->FFTOptionsWidget()->apodize(),
+                                     _CSDTab->FFTOptionsWidget()->apodizeFunction(),
+                                     _CSDTab->windowSize(),
+                                     _CSDTab->FFTOptionsWidget()->FFTLength(),
+                                     _CSDTab->FFTOptionsWidget()->sigma(),
+                                     _CSDTab->FFTOptionsWidget()->output(),
+                                     _CSDTab->FFTOptionsWidget()->vectorUnits(),
+                                     _CSDTab->FFTOptionsWidget()->rateUnits());
+
+  csd->writeLock();
+  csd->update(0);
+  csd->unlock();
+
+  Palette* newPalette = new Palette(_CSDTab->colorPalette()->selectedPalette());
+  csd->readLock();
+  ImagePtr image = new Image(csd->tagName()+"-I", csd->outputMatrix(), 0, 1, true, newPalette->paletteData());
+  csd->unlock();
+
+  image->writeLock();
+  image->update(0);
+  image->unlock();
+
+  PlotItem *plotItem = 0;
+  switch (_CSDTab->curvePlacement()->place()) {
+  case CurvePlacement::NoPlot:
+    break;
+  case CurvePlacement::ExistingPlot:
+    {
+      plotItem = static_cast<PlotItem*>(_CSDTab->curvePlacement()->existingPlot());
+      break;
+    }
+  case CurvePlacement::NewPlot:
+    {
+      CreatePlotForCurve *cmd = new CreatePlotForCurve(
+        _CSDTab->curvePlacement()->createLayout(),
+        _CSDTab->curvePlacement()->appendToLayout());
+      cmd->createItem();
+
+      plotItem = static_cast<PlotItem*>(cmd->item());
+      break;
+    }
+  default:
+    break;
+  }
+
+  PlotRenderItem *renderItem = plotItem->renderItem(PlotRenderItem::Cartesian);
+  //TODO  Adam, is this the correct way to draw an image?  It runs very slow.
+  renderItem->addRelation(kst_cast<Relation>(image));
+  plotItem->update();
+
+  return ObjectPtr(image.data());
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/csddialog.h #727090:727091
@@ -34,8 +34,11 @@
     VectorPtr vector() const;
     CurvePlacement* curvePlacement() const;
     FFTOptions* FFTOptionsWidget() const;
+    ColorPalette* colorPalette() const;
 
+    int windowSize() const;
 
+
   private Q_SLOTS:
   private:
 };
--- branches/work/kst/portto4/kst/src/libkstmath/image.cpp #727090:727091
@@ -79,12 +79,12 @@
   _zUpper = in_zUpper;
 
   if (_hasColorMap) {
-    Palette in_pal;
+    PaletteData in_pal;
     //maybe the palette doesn't exist anymore.  Generate a grayscale palette then.
     for (int i = 0; i < 256; i++) {
       in_pal.insert(i, QColor(i,i,i));
     }
-    Debug::self()->log(i18n("Unable to find palette %1.  Using a 256 color grayscale palette instead.").arg(in_paletteName), Debug::Warning);
+    Debug::self()->log(i18n("Unable to find PaletteData %1.  Using a 256 color grayscale palette instead.").arg(in_paletteName), Debug::Warning);
     _pal = in_pal;
   }
 
@@ -98,7 +98,7 @@
 
 
 //constructor for colormap only
-Image::Image(const QString &in_tag, MatrixPtr in_matrix, double lowerZ, double upperZ, bool autoThreshold, const Palette &pal) : Relation(){
+Image::Image(const QString &in_tag, MatrixPtr in_matrix, double lowerZ, double upperZ, bool autoThreshold, const PaletteData &pal) : Relation(){
 
   _inputMatrices[THEMATRIX] = in_matrix;
   setTagName(ObjectTag(in_tag, ObjectTag::globalTagContext));  // FIXME: always top-level?
@@ -140,7 +140,7 @@
                    double lowerZ,
                    double upperZ,
                    bool autoThreshold,
-                   const Palette &pal,
+                   const PaletteData &pal,
                    int numContours,
                    const QColor& contourColor,
                    int contourWeight) {
@@ -288,7 +288,7 @@
 }
 
 
-void Image::setPalette(const Palette &pal) {
+void Image::setPalette(const PaletteData &pal) {
   _pal = pal;
 }
 
@@ -329,7 +329,7 @@
 
 
 void Image::changeToColorOnly(const QString &in_tag, MatrixPtr in_matrix,
-                                     double lowerZ, double upperZ, bool autoThreshold, const Palette &pal) {
+                                     double lowerZ, double upperZ, bool autoThreshold, const PaletteData &pal) {
   setTagName(ObjectTag(in_tag, ObjectTag::globalTagContext));  // FIXME: always top-level?
   if (_inputMatrices.contains(THEMATRIX)) {
     _inputMatrices[THEMATRIX] = in_matrix;
@@ -370,7 +370,7 @@
 
 
 void Image::changeToColorAndContour(const QString &in_tag, MatrixPtr in_matrix,
-                                               double lowerZ, double upperZ, bool autoThreshold, const Palette &pal,
+                                               double lowerZ, double upperZ, bool autoThreshold, const PaletteData &pal,
                                                int numContours, const QColor& contourColor, int contourWeight) {
   setTagName(ObjectTag(in_tag, ObjectTag::globalTagContext));  // FIXME: always top-level?
   if (_inputMatrices.contains(THEMATRIX)) {
--- branches/work/kst/portto4/kst/src/libkstmath/image.h #727090:727091
@@ -16,20 +16,19 @@
 #include "matrix.h"
 #include "relation.h"
 #include "kst_export.h"
+#include "palette.h"
 
 #include <QHash>
 
 namespace Kst {
 
-typedef QHash<int, QColor> Palette;
-
 /**A class for handling images for Kst
  *@author University of British Columbia
  */
 class KST_EXPORT Image : public Relation {
   public:
     //constructor for colormap only
-    Image(const QString &in_tag, MatrixPtr in_matrix, double lowerZ, double upperZ, bool autoThreshold, const Palette &pal);
+    Image(const QString &in_tag, MatrixPtr in_matrix, double lowerZ, double upperZ, bool autoThreshold, const PaletteData &pal);
     //constructor for contour map only
     Image(const QString &in_tag, MatrixPtr in_matrix, int numContours, const QColor& contourColor, int contourWeight);
     //constructor for both colormap and contour map
@@ -38,7 +37,7 @@
         double lowerZ,
         double upperZ,
         bool autoThreshold,
-        const Palette &pal,
+        const PaletteData &pal,
         int numContours,
         const QColor& contourColor,
         int contourWeight);
@@ -56,7 +55,7 @@
 
     virtual bool getNearestZ(double x, double y, double& z);
     virtual QColor getMappedColor(double x, double y);
-    virtual void setPalette(const Palette &pal);
+    virtual void setPalette(const PaletteData &pal);
     virtual void setUpperThreshold(double z);
     virtual void setLowerThreshold(double z);
     virtual void setAutoThreshold(bool yes);
@@ -70,16 +69,16 @@
     virtual QString matrixTag() const;
     virtual MatrixPtr matrix() const;
     virtual QString paletteName() const;
-    virtual const Palette &palette() const { return _pal; }
+    virtual const PaletteData &palette() const { return _pal; }
 
     virtual void matrixDimensions(double &x, double &y, double &width, double &height);
 
     virtual void changeToColorOnly(const QString &in_tag, MatrixPtr in_matrix,
-        double lowerZ, double upperZ, bool autoThreshold, const Palette &pal);
+        double lowerZ, double upperZ, bool autoThreshold, const PaletteData &pal);
     virtual void changeToContourOnly(const QString &in_tag, MatrixPtr in_matrix,
         int numContours, const QColor& contourColor, int contourWeight);
     virtual void changeToColorAndContour(const QString &in_tag, MatrixPtr in_matrix,
-        double lowerZ, double upperZ, bool autoThreshold, const Palette &pal,
+        double lowerZ, double upperZ, bool autoThreshold, const PaletteData &pal,
         int numContours, const QColor& contourColor, int contourWeight);
 
     //contour lines
@@ -123,7 +122,7 @@
     //use these to set defaults when either is not used.
     void setColorDefaults();
     void setContourDefaults();
-    Palette _pal;
+    PaletteData _pal;
     //upper and lower thresholds
     double _zUpper;
     double _zLower;
--- branches/work/kst/portto4/kst/src/libkstmath/palette.cpp #727090:727091
@@ -68,6 +68,9 @@
   return _count;
 }
 
+PaletteData Palette::paletteData() const {
+  return _palette;
+}
 
 QColor Palette::color(const int colorId) const {
   return _palette[colorId];
--- branches/work/kst/portto4/kst/src/libkstmath/palette.h #727090:727091
@@ -18,6 +18,8 @@
 
 namespace Kst {
 
+typedef QHash<int, QColor> PaletteData;
+
 class Palette {
   public:
     static QStringList getPaletteList();
@@ -29,12 +31,13 @@
 
     QString paletteName() const;
     int colorCount() const;
-    QColor color(const int colorId) const ;
+    QColor color(const int colorId) const;
+    PaletteData paletteData() const;
 
   private:
     void createPalette();
 
-    QHash<int, QColor> _palette;
+    PaletteData _palette;
     QString _paletteName;
     int _count;
 };


More information about the Kst mailing list