1 /*************************************************************************** 2 * * 3 * copyright : (C) 2007 The University of Toronto * 4 * netterfield@astro.utoronto.ca * 5 * copyright : (C) 2004 University of British Columbia * 6 * dscott@phas.ubc.ca * 7 * * 8 * This program is free software; you can redistribute it and/or modify * 9 * it under the terms of the GNU General Public License as published by * 10 * the Free Software Foundation; either version 2 of the License, or * 11 * (at your option) any later version. * 12 * * 13 ***************************************************************************/ 14 15 #ifndef MATRIX_H 16 #define MATRIX_H 17 18 #include "scalar.h" 19 #include "vector.h" 20 #include "primitive.h" 21 22 class QXmlStreamWriter; 23 24 namespace Kst { 25 26 class Matrix; 27 typedef SharedPtr<Matrix> MatrixPtr; 28 29 class KSTCORE_EXPORT Matrix : public Primitive 30 { 31 Q_OBJECT 32 33 public: 34 virtual const QString& typeString() const; 35 static const QString staticTypeString; 36 37 virtual QString descriptionTip() const; 38 39 protected: 40 Matrix(ObjectStore *store); 41 virtual ~Matrix(); 42 43 friend class ObjectStore; 44 virtual void _initializeShortName(); 45 46 public: 47 void change(uint nX, uint nY, double minX=0, double minY=0, 48 double stepX=1, double stepY=1); 49 50 void change(QByteArray& data, uint nX, uint nY, double minX=0, double minY=0, 51 double stepX=1, double stepY=1); 52 53 // Return the sample count (x times y) of the matrix 54 virtual int sampleCount() const; 55 56 // return the z value of the rectangle in which the specified point lies 57 // ok is false if the point is out of bounds 58 double value(double x, double y, bool *ok = 0L) const; 59 double value(double x, double y, QPointF &matchedPoint, bool *ok = 0L) const; 60 61 // set the z value of the rectangle in which the specified point lies 62 // return false if the point is out of bounds 63 bool setValue(double x, double y, double z); 64 65 // return the value of the specified rectangle 66 // ok is false if the rectangle does not exist 67 double valueRaw(int x, int y, bool *ok = 0L) const; 68 69 // set the value of the specified rectangle 70 // return false if the rectangle does not exist 71 virtual bool setValueRaw(int x, int y, double z); 72 73 // return some stats on the z values 74 double minValue() const; 75 double maxValue() const; 76 77 // spike insensitive values 78 void calcNoSpikeRange(double per = 0.005); 79 double maxValueNoSpike() const; 80 double minValueNoSpike() const; 81 82 // return mean of the z values 83 double meanValue() const; 84 85 // return least positive z value 86 double minValuePositive() const; 87 88 // number of new samples in the matrix since last resetNumNew() 89 int numNew() const; 90 91 // reset numNew to 0 92 void resetNumNew(); 93 94 // labels for plots 95 virtual void setXLabelInfo(const LabelInfo &label_info); 96 virtual void setYLabelInfo(const LabelInfo &label_info); 97 virtual void setTitleInfo(const LabelInfo &label_info); 98 virtual LabelInfo xLabelInfo() const; 99 virtual LabelInfo yLabelInfo() const; 100 virtual LabelInfo titleInfo() const; 101 102 void zero(); 103 104 // clear out the matrix 105 void blank(); 106 107 // get usage of this matrix by other objects 108 virtual int getUsage() const; 109 110 // save the matrix 111 virtual void save(QXmlStreamWriter &s); 112 113 // set the labels for this matrix 114 void setLabel(const QString& newLabel); 115 116 // whether or not this matrix can be edited 117 bool editable() const; 118 119 void setEditable(bool editable); 120 121 // whether or not this matrix can be saved 122 bool saveable() const; 123 124 // matrix dimensions xNumSteps()125 int xNumSteps() const { return _nX; } yNumSteps()126 int yNumSteps() const { return _nY; } xStepSize()127 double xStepSize() const { return _stepX; } yStepSize()128 double yStepSize() const { return _stepY; } invertXHint()129 virtual bool invertXHint() const {return _invertXHint; } invertYHint()130 virtual bool invertYHint() const {return _invertYHint; } 131 minX()132 double minX() const { return _minX; } minY()133 double minY() const { return _minY; } 134 135 virtual bool resize(int xSize, int ySize, bool reinit = true); 136 137 virtual void deleteDependents(); 138 139 virtual QString sizeString() const; 140 141 virtual void internalUpdate(); 142 Z(int i)143 double Z(int i) const {return _z[i];} 144 145 // output primitives: statistics scalars, etc. vectors()146 VectorMap vectors() const {return _vectors;} scalars()147 ScalarMap scalars() const {return _scalars;} strings()148 StringMap strings() const {return _strings;} 149 150 virtual PrimitiveMap metas() const; 151 152 virtual ObjectList<Primitive> outputPrimitives() const; 153 154 QByteArray getBinaryArray() const; 155 156 /** dump the matrix values to a raw binary file */ 157 bool saveToTmpFile(QFile &fp); 158 159 protected: 160 int _NS; 161 int _NRealS; // number of samples with real values 162 int _nX; //this can be 0 163 int _nY; //this should never be 0 164 double _minX; 165 double _minY; 166 double _stepX; 167 double _stepY; 168 bool _invertXHint; 169 bool _invertYHint; 170 171 int _numNew; // number of new samples 172 173 bool _editable : 1; 174 bool _saveable : 1; 175 176 double _minNoSpike; 177 double _maxNoSpike; 178 179 // labels for this matrix 180 LabelInfo _xLabelInfo; 181 LabelInfo _yLabelInfo; 182 LabelInfo _titleInfo; 183 184 void createScalars(ObjectStore *store); 185 void renameScalars(); 186 void updateScalars(); 187 188 // the flat-packed array in row-major order 189 double *_z; 190 int _zSize; // internally keep track of real _z size 191 192 // for resizing the internal array _z only 193 virtual bool resizeZ(int sz, bool reinit = true); 194 195 // returns -1 if (x,y) is out of bounds 196 int zIndex(int x, int y) const; 197 198 ObjectMap<Scalar> _scalars; 199 ObjectMap<Vector> _vectors; 200 ObjectMap<String> _strings; 201 202 203 }; 204 205 typedef ObjectList<Matrix> MatrixList; 206 typedef ObjectMap<Matrix> MatrixMap; 207 208 } 209 210 Q_DECLARE_METATYPE(Kst::Matrix*) 211 212 #endif 213 // vim: ts=2 sw=2 et 214