QXRD  0.11.16
qxrdrasterdata.cpp
Go to the documentation of this file.
1 #include "qxrddebug.h"
2 #include "qxrdrasterdata.h"
3 #include "qxrdapplication.h"
4 #include <QString>
5 
7  : QwtRasterData(),
8  m_Data(img),
9  m_NRows((img ? img->get_Height(): 0)),
10  m_NCols((img ? img->get_Width() : 0)),
11  m_Range(range),
12  m_Interpolate(interp)
13 {
14  if (qcepDebug(DEBUG_IMAGES)) {
15  if (g_Application) {
16  g_Application->printMessage(QObject::tr("QxrdRasterData::QxrdRasterData(%1,%2) [%3]")
17  .HEXARG(img.data()).arg(interp).HEXARG(this));
18  }
19  }
20 
21  setInterval(Qt::XAxis, QwtInterval(0.0, m_NCols));
22  setInterval(Qt::YAxis, QwtInterval(0.0, m_NRows));
23  setInterval(Qt::ZAxis, range);
24 }
25 
27 {
28 // printf("%p->QxrdRasterData::setInterpolate(%d)\n", this, interp);
29 
31 }
32 
34 {
35  return m_Interpolate;
36 }
37 
38 double QxrdRasterData::value(double x, double y) const
39 {
40  if (m_Data) {
41  if (x < 0 || x > m_NCols) return 0;
42  if (y < 0 || y > m_NRows) return 0;
43 
44  if (m_Interpolate) {
45  int ix = ((int) x), iy = ((int) y);
46  double dx = x-ix, dy = y-iy;
47 
48  double f00 = m_Data->getImageData((ix) , (iy));
49  double f10 = m_Data->getImageData((ix+1) , (iy));
50  double f01 = m_Data->getImageData((ix) , (iy+1));
51  double f11 = m_Data->getImageData((ix+1) , (iy+1));
52 
53  double f0 = f00*(1-dx)+f10*dx;
54  double f1 = f01*(1-dx)+f11*dx;
55 
56  double f = f0*(1-dy)+f1*dy;
57 
58  return f;
59  } else {
60  return m_Data->getImageData(((int) qRound(x)) , ((int) qRound(y)));
61  }
62  } else {
63  return 0;
64  }
65 }
66 
67 QwtInterval QxrdRasterData::range() const
68 {
69  return m_Range;
70 }
71 
72 void QxrdRasterData::setDisplayedRange(double min, double max)
73 {
74  m_Range = QwtInterval(min, max);
75 
76  setInterval(Qt::ZAxis, m_Range);
77 }
78 
80 {
81  if (m_Data) {
82  return m_Data->minValue();
83  } else {
84  return 0;
85  }
86 }
87 
89 {
90  if (m_Data) {
91  return m_Data->maxValue();
92  } else {
93  return 0;
94  }
95 }
96 
97 QwtInterval QxrdRasterData::percentileRange(double lowpct, double highpct)
98 {
99  QwtInterval res;
100 
101  if (m_Data) {
102  QPointF r = m_Data->percentileRange(lowpct, highpct);
103 
104  res.setMinValue(r.x());
105  res.setMaxValue(r.y());
106  }
107 
108  return res;
109 }
110 
112 {
113  return m_NCols;
114 }
115 
117 {
118  return m_NRows;
119 }
120 
121 QPointF QxrdRasterData::optimizePeakPosition(QPointF pt) const
122 {
123  int rad = 10;
124  int ix = pt.x();
125  int iy = pt.y();
126  int first = 1;
127 
128  double max;
129  int maxx = 0, maxy = 0;
130 
131  for (int j=iy-rad; j<iy+rad; j++) {
132  for (int i=ix-rad; i<ix+rad; i++) {
133  double val=value(i,j);
134 
135  if (first) {
136  max = val; maxx = i; maxy = j;
137  first = 0;
138  } else if (val > max) {
139  max = val; maxx = i; maxy = j;
140  }
141  }
142  }
143 
144  return QPointF(maxx, maxy);
145 }
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
void setDisplayedRange(double min, double max)
QwtInterval range() const
int width() const
QwtInterval percentileRange(double lowpct, double highpct)
int interp() const
QcepImageDataBasePtr m_Data
double value(double x, double y) const
#define HEXARG(a)
Definition: qcepdebug.h:50
QwtInterval m_Range
QPointF optimizePeakPosition(QPointF pt) const
virtual void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())=0
QcepApplication * g_Application
int height() const
QSharedPointer< QcepImageDataBase > QcepImageDataBasePtr
QxrdRasterData(QcepImageDataBasePtr img=QcepImageDataBasePtr(), int interp=1, QwtInterval range=QwtInterval(0, 40000))
void setInterpolate(int interp)