-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlw_data.h
195 lines (161 loc) · 6.32 KB
/
lw_data.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// *****************************************************************************
// NICOS, the Networked Instrument Control System of the FRM-II
// Copyright (c) 2009-2014 by the NICOS contributors (see AUTHORS)
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// Module authors:
// Tobias Weber <[email protected]>
// Georg Brandl <[email protected]>
//
// *****************************************************************************
#ifndef LW_DATA_H
#define LW_DATA_H
#include <stdint.h>
#include <qwt_plot_spectrogram.h>
#include "lw_common.h"
// undefine to remove timing console messages
// #define CLOCKING
// data type used for single pixel count values
typedef uint32_t data_t;
class LWData
{
private:
virtual void updateRange();
virtual void initFromBuffer(const void *data, std::string format);
void _dummyInit();
bool _readFits(const char *filename);
bool _readRaw(const char *filename);
bool _readTiff(const char *filename);
protected:
// concerning the data
data_t *m_data; // processed data
data_t *m_clone; // original data without filters/processing applied
bool m_data_owned;
int m_width, m_height, m_depth;
double m_min, m_max;
// concerning the display
int m_cur_z;
bool m_log10;
bool m_custom_range;
double m_range_min, m_range_max;
// image filtering and processing
bool m_normalized;
bool m_darkfieldsubtracted;
bool m_despeckled;
LWImageFilters m_filter;
LWImageOperations m_operation;
float m_despecklevalue;
QString m_darkfieldfile;
QString m_normalizefile;
void clampedCopyFloatVals(float* pdata);
data_t data(int x, int y, int z) const;
int size() const { return m_width * m_height * m_depth; }
public:
LWData();
LWData(int width, int height, int depth, const char *data);
LWData(int width, int height, int depth, const char *format, const char *data);
LWData(const char* filename);
LWData(const LWData &other);
virtual ~LWData();
const data_t *buffer() const { return m_data; }
const data_t *buffer_clone() const { return m_clone; }
int width() const { return m_width; }
int height() const { return m_height; }
int depth() const { return m_depth; }
double min() const { return m_min; }
double max() const { return m_max; }
int currentZ() const { return m_cur_z; }
virtual void setCurrentZ(int val);
bool isLog10() const { return m_log10; }
virtual void setLog10(bool val);
bool isNormalized() const { return m_normalized; }
QString getNormalizeFile() const { return m_normalizefile; }
virtual void setNormalized(bool val);
virtual void setNormalizeFile(QString val);
bool isDarkfieldSubtracted() const { return m_darkfieldsubtracted; }
QString getDarkfieldFile() const { return m_darkfieldfile; }
virtual void setDarkfieldSubtracted(bool val);
virtual void setDarkfieldFile(QString val);
bool isDespeckled() const { return m_despeckled; }
int getDespeckleValue() const { return m_despecklevalue; }
virtual void setDespeckled(bool val);
virtual void setDespeckleValue(float value);
LWImageFilters isImageFilter() const { return m_filter; }
virtual void setImageFilter(LWImageFilters which);
LWImageOperations isImageOperation() const { return m_operation; }
virtual void setImageOperation(LWImageOperations which);
void saveAsFitsImage(float *data, char *fits_filename);
std::string getStringFromFitsHeader(const char *filename, const char *headerEntry);
float getFloatFromFitsHeader(const char *filename, const char *headerEntry) ;
bool hasCustomRange() const { return m_custom_range; }
double customRangeMin() const;
double customRangeMax() const;
virtual void setCustomRange(double lower, double upper);
/// Get current presentation value at the specified point.
virtual double value(double x, double y) const;
/// Get raw value without regard to presentation settings (like log10).
virtual double valueRaw(int x, int y) const;
/// Same, but also specifying the layer.
virtual double valueRaw(int x, int y, int z) const;
/// Create a histogram of the current layer. Caller must allocate
/// the xs and ys arrays with a length of "bins".
virtual void histogram(int bins, double *xs, double *ys) const;
/// Same, but creates QVectors of doubles (callable from Python).
virtual void histogram(int bins, QVector<double> **xs,
QVector<double> **ys) const;
};
class LWRasterData : public QwtRasterData
{
private:
const LWData *m_data;
public:
LWRasterData() :
QwtRasterData(QwtDoubleRect(0, 1, 0, 1)),
m_data(new LWData()) {
}
LWRasterData(const LWData *data) :
QwtRasterData(QwtDoubleRect(0, data->width(), 0, data->height())),
m_data(data) {
}
LWRasterData(const LWRasterData &other) :
QwtRasterData(other), m_data(other.m_data) {
}
// QwtRasterData overridables
virtual QwtRasterData *copy() const {
return new LWRasterData(*this);
}
virtual QwtDoubleInterval range() const {
if (m_data->hasCustomRange()) {
return QwtDoubleInterval(m_data->customRangeMin(),
m_data->customRangeMax());
} else {
return QwtDoubleInterval(m_data->min(), m_data->max());
}
}
virtual double value(double x, double y) const {
return m_data->value(x, y);
}
virtual double valueRaw(double x, double y) const {
return m_data->valueRaw(x, y);
}
int width() {
return m_data->width();
}
int height() {
return m_data->height();
}
};
#endif