File indexing completed on 2025-07-13 04:09:57

0001 /***************************************************************************
0002  *                                                                         *
0003  *   copyright : (C) 2007 The University of Toronto                        *
0004  *                   netterfield@astro.utoronto.ca                         *
0005  *   copyright : (C) 2005 by University of British Columbia
0006  *                   dscott@phas.ubc.ca                                    *
0007  *                                                                         *
0008  *   This program is free software; you can redistribute it and/or modify  *
0009  *   it under the terms of the GNU General Public License as published by  *
0010  *   the Free Software Foundation; either version 2 of the License, or     *
0011  *   (at your option) any later version.                                   *
0012  *                                                                         *
0013  ***************************************************************************/
0014 
0015 #ifndef IMAGE_H
0016 #define IMAGE_H
0017 
0018 #include "matrix.h"
0019 #include "relation.h"
0020 #include "kstmath_export.h"
0021 #include "palette.h"
0022 #include "labelinfo.h"
0023 
0024 #include <QHash>
0025 
0026 namespace Kst {
0027 
0028 class ObjectStore;
0029 
0030 class CoutourLineDetails {
0031   public:
0032     CoutourLineDetails() { }
0033     CoutourLineDetails(QLine line, int width) { _line = line; _lineWidth = width; }
0034 
0035   QLine _line;
0036   int _lineWidth;
0037 };
0038 
0039 /**A class for handling images for Kst
0040  *@author University of British Columbia
0041  */
0042 class KSTMATH_EXPORT Image : public Relation {
0043   Q_OBJECT
0044 
0045   public:
0046     static const QString staticTypeString;
0047     const QString& typeString() const { return staticTypeString; }
0048     static const QString staticTypeTag;
0049 
0050     virtual void showNewDialog();
0051     virtual void showEditDialog();
0052     virtual void save(QXmlStreamWriter &s);
0053     virtual void internalUpdate();
0054     virtual QString propertyString() const;
0055 
0056     virtual bool getNearestZ(double x, double y, double& z, QPointF &matchedPoint);
0057     virtual QColor getMappedColor(double z);
0058     virtual void setPalette(const QString &palname);
0059     virtual void setUpperThreshold(double z);
0060     virtual void setLowerThreshold(double z);
0061     virtual void setAutoThreshold(bool yes);
0062     virtual void setThresholdToSpikeInsensitive(double per = 0.005);
0063 
0064 
0065     virtual double upperThreshold() const { return _zUpper; }
0066     virtual double lowerThreshold() const { return _zLower; }
0067     virtual bool autoThreshold() const { return _autoThreshold; }
0068 
0069     virtual void setMatrix(MatrixPtr in_matrix);
0070     virtual MatrixPtr matrix() const;
0071     virtual QString paletteName() const;
0072     virtual const Palette &palette() const { return _pal; }
0073 
0074     virtual void matrixDimensions(double &x, double &y, double &width, double &height);
0075 
0076     virtual void changeToColorOnly(MatrixPtr in_matrix,
0077         double lowerZ, double upperZ, bool autoThreshold, const QString &paletteName);
0078     virtual void changeToContourOnly(MatrixPtr in_matrix,
0079         int numContours, const QColor& contourColor, int contourWeight);
0080     virtual void changeToColorAndContour(MatrixPtr in_matrix,
0081         double lowerZ, double upperZ, bool autoThreshold, const QString &paletteName,
0082         int numContours, const QColor& contourColor, int contourWeight);
0083 
0084     //contour lines
0085     virtual int numContourLines() const { return _numContourLines; }
0086     virtual QList<double> contourLines() const { return _contourLines; }
0087     virtual bool addContourLine(double line);
0088     virtual bool removeContourLine(double line);
0089     virtual void clearContourLines();
0090     virtual const QColor& contourColor() const { return _contourColor; }
0091     virtual int contourWeight() const { return _contourWeight; } // a contour weight of -1 means variable weight
0092 
0093     //other properties
0094     virtual bool hasContourMap() const { return _hasContourMap; }
0095     virtual bool hasColorMap() const { return _hasColorMap; }
0096 
0097     // labels for plots
0098     virtual LabelInfo xLabelInfo() const;
0099     virtual LabelInfo yLabelInfo() const;
0100     virtual LabelInfo titleInfo() const;
0101 
0102     virtual RelationPtr makeDuplicate() const;
0103 
0104     // see KstRelation::distanceToPoint
0105     virtual double distanceToPoint(double xpos, double dx, double ypos) const;
0106 
0107     // see KstRelation::paint
0108     void paintObjects(const CurveRenderContext& context);
0109 
0110     // Update the curve details.
0111     void updatePaintObjects(const CurveRenderContext& context);
0112 
0113     // see KstRelation::yRange
0114     virtual void yRange(double xFrom, double xTo, double* yMin, double* yMax);
0115 
0116     // see KstRelation::paintLegendSymbol
0117     virtual QSize legendSymbolSize(QPainter *p);
0118     virtual void paintLegendSymbol(QPainter *p, const QSize &size);
0119     virtual bool symbolLabelOnTop() {return true;}
0120 
0121     virtual QString descriptionTip() const;
0122 
0123     virtual bool invertXHint() const;
0124     virtual bool invertYHint() const;
0125 
0126     virtual ScriptInterface* createScriptInterface();
0127 
0128     virtual double ns_maxX(int)    const { return _ns_maxx; }
0129     virtual double ns_minX(int)    const { return _ns_minx; }
0130     virtual double ns_maxY(int)    const { return _ns_maxy; }
0131     virtual double ns_minY(int)    const { return _ns_miny; }
0132 
0133   protected:
0134     Image(ObjectStore *store);
0135     virtual ~Image();
0136 
0137     friend class ObjectStore;
0138 
0139     virtual QString _automaticDescriptiveName() const;
0140     virtual void _initializeShortName();
0141 
0142   private:
0143     //use these to set defaults when either is not used.
0144     void setColorDefaults();
0145     void setContourDefaults();
0146     Palette _pal;
0147     //upper and lower thresholds
0148     double _zUpper;
0149     double _zLower;
0150     bool _autoThreshold;
0151 
0152     bool _hasColorMap;
0153     bool _hasContourMap;
0154 
0155     int _numContourLines;
0156     QList<double> _contourLines;
0157     QColor _contourColor;
0158     int _contourWeight; //_contourWeight = -1 means variable weight
0159 
0160     QVector<CoutourLineDetails> _lines;
0161     QImage _image;
0162     QPoint _imageLocation;
0163 
0164     double _ns_maxx;
0165     double _ns_minx;
0166     double _ns_maxy;
0167     double _ns_miny;
0168 
0169 };
0170 
0171 
0172 typedef SharedPtr<Image> ImagePtr;
0173 typedef ObjectList<Image> ImageList;
0174 
0175 }
0176 
0177 #endif
0178 // vim: ts=2 sw=2 et