QXRD  0.11.16
qcepintegrateddata.cpp
Go to the documentation of this file.
1 #include "qcepintegrateddata.h"
2 #include "qcepsettingssaver.h"
3 #include "qcepallocator.h"
4 #include <QScriptEngine>
5 
7  QString name,
8  QcepDoubleImageDataPtr image, int maxSize, QcepObject *parent) :
9  QcepDataObject(saver, name, 2*maxSize*sizeof(double), parent),
10  m_Title(saver, this, "title", "", "Integrated Data Title"),
11  m_Image(image),
12  m_MaxSize(maxSize),
13  m_Size(0),
14  m_AllocStep(1024),
15  m_X(maxSize),
16  m_Y(maxSize),
17  m_cx(0),
18  m_cy(0),
19  m_XUnitsLabel("TTH"),
20  m_Oversample(1)
21 {
22  set_Type("Integrated Data");
23 
24  QcepAllocator::allocate(sizeof(double), 2, m_MaxSize);
25 }
26 
28 {
29  QcepAllocator::deallocate(sizeof(double), 2, m_MaxSize);
30 }
31 
33 {
34  return tr("%1 Rows").arg(m_Size);
35 }
36 
38  QcepSettingsSaverWPtr saver, QString name, int sz, QcepObject *parent)
39 {
40  QcepIntegratedDataPtr res(new QcepIntegratedData(saver, name, QcepDoubleImageDataPtr(), sz, parent));
41 
42  return res;
43 }
44 
46 {
47  if (n >= m_MaxSize) {
48  int newSize = (n/m_AllocStep+1)*m_AllocStep;
49  m_X.resize(newSize);
50  m_Y.resize(newSize);
51 
52  QcepAllocator::allocate(sizeof(double), 2, newSize-m_MaxSize);
53 
54  set_ByteSize(2*newSize*sizeof(double));
55 
56  m_MaxSize = newSize;
57  }
58 
59  m_Size = n;
60 }
61 
63 {
64  return m_Size;
65 }
66 
67 const double* QcepIntegratedData::x() const
68 {
69  return m_X.data();
70 }
71 
72 const double* QcepIntegratedData::y() const
73 {
74  return m_Y.data();
75 }
76 
77 double QcepIntegratedData::x(int i) const
78 {
79  return m_X.value(i);
80 }
81 
82 double QcepIntegratedData::y(int i) const
83 {
84  return m_Y.value(i);
85 }
86 
87 void QcepIntegratedData::set_Center(double cx, double cy)
88 {
89  m_cx = cx;
90  m_cy = cy;
91 }
92 
93 double QcepIntegratedData::cx() const
94 {
95  return m_cx;
96 }
97 
98 double QcepIntegratedData::cy() const
99 {
100  return m_cy;
101 }
102 
103 void QcepIntegratedData::append(double x, double y)
104 {
105  resize(size()+1);
106 
107  m_X[size()-1] = x;
108  m_Y[size()-1] = y;
109 }
110 
111 void QcepIntegratedData::setValue(int n, double x, double y)
112 {
113  m_X.replace(n, x);
114  m_Y.replace(n, y);
115 }
116 
117 void QcepIntegratedData::selfNormalize(double minx, double maxx)
118 {
119  double sumn = 0, sumv = 0;
120 
121  for (int i=0; i<m_Size; i++) {
122  double x = m_X.value(i);
123  double y = m_Y.value(i);
124 
125  if (x == x && y == y) {
126  if (x >= minx && x <= maxx) {
127  sumn += 1;
128  sumv += y;
129  }
130  }
131  }
132 
133  if (sumn >= 5) {
134  double norm = sumn/sumv;
135 
136  for (int i=0; i<m_Size; i++) {
137  double x = m_X.value(i);
138  double y = m_Y.value(i);
139 
140  if (x == x && y == y) {
141  m_Y[i] = y*norm;
142  }
143  }
144  }
145 }
146 
148 {
149  m_Image = image;
150 }
151 
153 {
154  return m_Image;
155 }
156 
158 {
159  return m_XUnitsLabel;
160 }
161 
163 {
164  m_XUnitsLabel = units;
165 }
166 
168 {
169  return m_Oversample;
170 }
171 
173 {
174  m_Oversample = ovs;
175 }
176 
177 QScriptValue QcepIntegratedData::toIntegratedDataScriptValue(QScriptEngine *engine, const QcepIntegratedDataPtr &data)
178 {
179  return engine->newQObject(data.data());
180 }
181 
183 {
184  QObject *qobj = obj.toQObject();
185 
186  if (qobj) {
187  QcepIntegratedData *qdobj = qobject_cast<QcepIntegratedData*>(qobj);
188 
189  if (qdobj) {
190  QcepDataObjectPtr p = qdobj->sharedFromThis();
191 
192  if (p) {
193  QcepIntegratedDataPtr cs = qSharedPointerDynamicCast<QcepIntegratedData>(p);
194 
195  if (cs) {
196  data = cs;
197  }
198  }
199  }
200  }
201 }
QcepDoubleImageDataPtr m_Image
static void deallocate(int sz, int width, int height)
virtual QString description() const
const double * y() const
void append(double x, double y)
void setValue(int n, double x, double y)
static void fromIntegratedDataScriptValue(const QScriptValue &obj, QcepIntegratedDataPtr &data)
QSharedPointer< QcepIntegratedData > QcepIntegratedDataPtr
QString get_XUnitsLabel() const
QcepDoubleImageDataPtr get_Image() const
void set_Image(QcepDoubleImageDataPtr image)
QVector< double > m_X
void set_XUnitsLabel(QString units)
const double * x() const
void set_Center(double cx, double cy)
QVector< double > m_Y
void selfNormalize(double minx, double maxx)
static QcepIntegratedDataPtr newIntegratedData(QcepSettingsSaverWPtr saver, QString name, int sz, QcepObject *parent)
static void allocate(int sz, int width, int height)
QSharedPointer< QcepDataObject > QcepDataObjectPtr
QcepIntegratedData(QcepSettingsSaverWPtr saver, QString name, QcepDoubleImageDataPtr data, int maxSize, QcepObject *parent)
QString name
Definition: qcepobject.h:49
static QScriptValue toIntegratedDataScriptValue(QScriptEngine *engine, const QcepIntegratedDataPtr &data)
void set_Oversample(int ovs)
QWeakPointer< QcepSettingsSaver > QcepSettingsSaverWPtr
QcepSettingsSaverWPtr saver()
QSharedPointer< QcepDoubleImageData > QcepDoubleImageDataPtr