File indexing completed on 2025-07-13 04:09:18
0001 /*************************************************************************** 0002 * * 0003 * copyright : (C) 2007 The University of Toronto * 0004 * netterfield@astro.utoronto.ca * 0005 * copyright : (C) 2005 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 DATAMATRIX_H 0016 #define DATAMATRIX_H 0017 0018 #include "kst_export.h" 0019 #include "dataprimitive.h" 0020 #include "matrix.h" 0021 0022 namespace Kst { 0023 0024 class MatrixData { 0025 public: 0026 double xMin; 0027 double yMin; 0028 double xStepSize; 0029 double yStepSize; 0030 double *z; // the data 0031 }; 0032 0033 class KSTCORE_EXPORT DataMatrix : public Matrix, public DataPrimitive 0034 { 0035 Q_OBJECT 0036 0037 public: 0038 0039 /** Read the specified sub-range of the matrix, flat-packed in z in row-major order 0040 xStart - starting x column 0041 yStart - starting y row 0042 xNumSteps - number of columns to read in x direction; 0043 yNumSteps - number of rows to read in y direction; 0044 Will skip according to the parameter, but it may not be implemented. If return value is -9999, 0045 use the non-skip version instead. 0046 The suggested scaling and translation is returned in xMin, yMin, xStepSize, and yStepSize 0047 Returns the number of *samples* read 0048 **/ 0049 struct KSTCORE_EXPORT ReadInfo { 0050 MatrixData* data; 0051 int xStart; 0052 int yStart; 0053 int xNumSteps; 0054 int yNumSteps; 0055 int skip; 0056 int frame; // only used for image streams 0057 }; 0058 0059 0060 struct KSTCORE_EXPORT DataInfo 0061 { 0062 DataInfo(); 0063 0064 int xSize; 0065 int ySize; 0066 bool invertXHint; 0067 bool invertYHint; 0068 int frameCount; // only used for image streams 0069 }; 0070 0071 0072 virtual const QString& typeString() const; 0073 static const QString staticTypeString; 0074 static const QString staticTypeTag; 0075 0076 // save DataMatrix 0077 virtual void save(QXmlStreamWriter &xml); 0078 0079 // change properties of DataMatrix 0080 void change(DataSourcePtr file, const QString &field, 0081 int xStart, int yStart, 0082 int xNumSteps, int yNumSteps, 0083 bool doAve, bool doSkip, int skip, int frame, 0084 double minX, double minY, double stepX, double stepY); 0085 void changeFrames(int xStart, int yStart, 0086 int xNumSteps, int yNumSteps, 0087 bool doAve, bool doSkip, int skip, int frame, 0088 double minX, double minY, double stepX, double stepY); 0089 0090 // return properties of DataMatrix 0091 int reqXStart() const; 0092 int reqYStart() const; 0093 int reqXNumSteps() const; 0094 int reqYNumSteps() const; 0095 //QString filename() const; 0096 const QString& field() const; 0097 bool xReadToEnd() const; 0098 bool yReadToEnd() const; 0099 bool xCountFromEnd() const; 0100 bool yCountFromEnd() const; 0101 bool doSkip() const; 0102 bool doAverage() const; 0103 int skip() const; 0104 0105 // for image streams 0106 int frame() const {return _frame;} 0107 void setFrame(int f) {_frame = f;} 0108 bool isStream(); 0109 0110 // labels for this matrix 0111 virtual QString label() const; 0112 0113 // returns true if the file and field is valid; false otherwise 0114 bool isValid() const; 0115 0116 // reload contents of DataMatrix from file 0117 void reload(); 0118 virtual void reset(); 0119 0120 // change the datasource for this matrix 0121 void changeFile(DataSourcePtr file); 0122 0123 virtual QString descriptionTip() const; 0124 0125 virtual QString propertyString() const; 0126 virtual void internalUpdate(); 0127 0128 virtual LabelInfo xLabelInfo() const; 0129 virtual LabelInfo yLabelInfo() const; 0130 virtual LabelInfo titleInfo() const; 0131 0132 virtual ScriptInterface* createScriptInterface(); 0133 0134 int fileLength() const; 0135 0136 protected: 0137 DataMatrix(ObjectStore *store); 0138 virtual ~DataMatrix(); 0139 0140 // update DataMatrix 0141 virtual qint64 minInputSerial() const; 0142 virtual qint64 maxInputSerialOfLastChange() const; 0143 0144 friend class ObjectStore; 0145 0146 virtual QString _automaticDescriptiveName() const; 0147 0148 virtual void _resetFieldMetadata(); 0149 0150 private: 0151 void commonConstructor(DataSourcePtr file, const QString &field, 0152 int reqXStart, int reqYStart, int reqNX, int reqNY, 0153 bool doAve, bool doSkip, int skip, int frame, 0154 double minX, double minY, double stepX, double stepY); 0155 0156 void doUpdateSkip(int realXStart, int realYStart, int frame); 0157 void doUpdateNoSkip(int realXStart, int realYStart, int frame); 0158 0159 virtual void _resetFieldScalars(); 0160 virtual void _resetFieldStrings(); 0161 0162 0163 // values requested; may be different from actual matrix range 0164 int _reqXStart, _reqYStart, _reqNX, _reqNY; 0165 0166 // matrix params since last update - used to determine if update is needed 0167 int _lastXStart, _lastYStart, _lastNX, _lastNY; 0168 bool _lastDoAve : 1; 0169 bool _lastDoSkip : 1; 0170 int _lastSkip; 0171 0172 double* _aveReadBuffer; // buffer used when performing boxcar filter 0173 int _aveReadBufferSize; 0174 0175 DataSourcePtr _file; 0176 QString _field; // field to read from _file 0177 bool _doAve : 1; 0178 bool _doSkip : 1; 0179 int _skip; 0180 int _frame; 0181 0182 int readMatrix(MatrixData* data, const QString& matrix, int xStart, int yStart, int xNumSteps, int yNumSteps, int skip, int frame); 0183 0184 QHash<QString, ScalarPtr> _fieldScalars; 0185 QHash<QString, StringPtr> _fieldStrings; 0186 0187 // make a "copy" of this DataMatrix 0188 virtual PrimitivePtr makeDuplicate() const; 0189 virtual bool checkValidity(const DataSourcePtr& ds) const; 0190 0191 0192 }; 0193 0194 typedef SharedPtr<DataMatrix> DataMatrixPtr; 0195 typedef ObjectList<DataMatrix> DataMatrixList; 0196 0197 } 0198 #endif 0199 // vim: ts=2 sw=2 et