16 #include <QtConcurrentRun>
19 #define _USE_MATH_DEFINES
25 m_Oversample(saver, this,
"oversample", 1,
"Oversampling for Integration"),
26 m_IntegrationStep(saver, this,
"integrationStep", 0.001,
"Integration Step Size"),
27 m_IntegrationNSteps(saver, this,
"integrationNSteps", 0,
"Integration Number of Steps"),
28 m_IntegrationMinimum(saver, this,
"integrationMinimum", 0,
"Integration Minimum"),
29 m_IntegrationMaximum(saver, this,
"integrationMaximum", 100000,
"Integration Maximum"),
30 m_IntegrationXUnits(saver, this,
"integrationXUnits",
RadialIntegrateTTH,
"X Units for Integration (0 = TTH, 1 = Q, 2 = R)"),
31 m_EnableGeometricCorrections(saver, this,
"enableGeometricCorrections", false,
"Enable Geometric Corrections (tilt and distance) in Integration"),
32 m_EnablePolarizationCorrections(saver, this,
"enablePolarizationCorrections", false,
"Enable Polarization Corrections in Integration"),
33 m_Polarization(saver, this,
"polarization", 1.0,
"Beam Polarization Factor"),
34 m_EnableAbsorptionCorrections(saver, this,
"enableAbsorptionCorrections", false,
"Enable Absorption Correction in Integration"),
35 m_AttenuationLength(saver, this,
"attenuationLength", 0,
"Attenuation Length (mm)"),
36 m_EnableUserGeometry(saver, this,
"enableUserGeometry", 0,
"Apply user-defined geometry function in integration"),
37 m_UserGeometryScript(saver, this,
"userGeometryScript",
defaultUserGeometryScript(),
"Script to define user defined geometry functions"),
38 m_UserGeometryFunction(saver, this,
"userGeometryFunction",
"userGeometry",
"Name of user defined geometry function"),
39 m_EnableUserAbsorption(saver, this,
"enableUserAbsorption", 0,
"Apply user-defined geometry function in integration"),
40 m_UserAbsorptionScript(saver, this,
"userAbsorptionScript",
defaultUserAbsorptionScript(),
"Script to define user defined absorption functions"),
41 m_UserAbsorptionFunction(saver, this,
"userAbsorptionFunction",
"userAbsorb1",
"Name of user defined absorption function"),
42 m_ScalingFactor(saver, this,
"scalingFactor", 1.0,
"Scaling factor for integrated intensity"),
43 m_SelfNormalization(saver, this,
"selfNormalization", false,
"Normalize result based on average value within specified range"),
44 m_SelfNormalizationMinimum(saver, this,
"selfNormalizationMinimum", 0,
"Self Normalization Range Minimum"),
45 m_SelfNormalizationMaximum(saver, this,
"selfNormalizationMaximum", 0,
"Self Normalization Range Maximum"),
52 printf(
"QxrdIntegrator::QxrdIntegrator(%p)\n",
this);
91 printf(
"Deleting integrator\n");
95 printf(
"QxrdIntegrator::~QxrdIntegrator(%p)\n",
this);
104 return expt->dataProcessor();
121 expt->printMessage(
"Integration parameters changed");
145 expt->printMessage(tr(
"QxrdIntegrator::performIntegration(\"%1\")")
146 .arg(dimg->get_FileName()));
150 QThread::currentThread()->setObjectName(
"performIntegration");
155 dimg->get_Width() != cache->get_NCols() ||
156 dimg->get_Height() != cache->get_NRows()) {
167 cache->performIntegration(integ, dimg, mask,
true);
174 return XValue(pt.x(), pt.y());
184 switch(get_IntegrationXUnits()) {
186 xVal = cf->getTTH(x,y);
190 xVal = cf->getQ(x,y);
194 xVal = cf->getR(x,y);
204 double xc,
double yc,
205 double dst,
double nrg,
206 double pxl,
double pxh,
207 double rot,
double cosr,
double sinr,
208 double cosb,
double sinb,
209 double cosa,
double sina
217 xVal = cf->getTwoTheta(xc,yc,dst,x,y,pxl,pxh,cosb,sinb,cosr,sinr);
221 cf->getQChi(xc,yc,dst,nrg,x,y,pxl,pxh,rot,cosb,sinb,cosa,sina,cosr,sinr,&xVal, &junk);
225 xVal = cf->getRadius(xc,yc,dst,x,y,pxl,pxh,cosb,sinb,cosr,sinr);
236 switch(get_IntegrationXUnits()) {
238 label =
"2 Theta (deg)";
256 QVector<QPointF> poly;
257 poly.append(QPointF(x0,y0));
258 poly.append(QPointF(x1,y1));
267 expt->printMessage(
"QxrdIntegrator::sliceLine failed");
276 QThread::currentThread()->setObjectName(
"slicePolygon");
278 if (integ && image) {
281 if (poly.size() >= 2) {
282 QPointF p0 = poly[0];
284 for (
int i=1; i<poly.size(); i++) {
285 QPointF p1 = poly[i];
286 double dx = p1.x() - p0.x();
287 double dy = p1.y() - p0.y();
288 length += sqrt(dx*dx + dy*dy);
299 for (
int i=1; i<poly.size(); i++) {
300 QPointF p1 = poly[i];
301 double dx = p1.x() - p0.x();
302 double dy = p1.y() - p0.y();
303 double len = sqrt(dx*dx + dy*dy);
306 for (; r<len; r+=1) {
307 double x = p0.x() + r*dx/len;
308 double y = p0.y() + r*dy/len;
310 integ -> append(r+r0, image->value((
int) x, (
int) y));
325 expt->printMessage(
"QxrdIntegrator::slicePolygon failed");
367 QFile def(
":/qxrdexampleusergeometry.js");
369 if (def.open(QFile::ReadOnly)) {
370 return def.readAll();
372 return "Couldn't open resource file";
378 QFile def(
":/qxrdexampleuserabsorption.js");
380 if (def.open(QFile::ReadOnly)) {
381 return def.readAll();
383 return "Couldn't open resource file";
398 data = ds->newImage(resPath);
404 printMessage(tr(
"Unable to accumulate integrated data into %1").arg(resPath));
421 data = ds->newImage(resPath);
441 int width = res->get_Width();
442 int ht = res->get_Height();
443 int npts = integ->size();
445 res->resize(npts, ht+1);
447 for (
int i=0; i<npts; i++) {
448 res->setValue(i, ht, integ->y(i));
451 emit res->dataObjectChanged();
466 data = ds->newImage(resPath);
487 data = ds->newImage(resPath);
508 data -> saveData(fileName, filter);
516 return engine->newQObject(proc.data());
521 QObject *qobj = obj.toQObject();
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
QcepIntegratedDataPtr slicePolygon(QcepIntegratedDataPtr integ, QcepDoubleImageDataPtr dimg, QVector< QPointF > poly, double width)
void saveAccumulator(QString resPath, QString &fileName, QString filter)
QSharedPointer< QxrdCenterFinder > QxrdCenterFinderPtr
QxrdDataProcessorWPtr dataProcessor() const
QxrdExperimentWPtr m_Experiment
QWeakPointer< QxrdDataProcessor > QxrdDataProcessorWPtr
static QcepIntegratedDataPtr newIntegratedData(AllocationStrategy strat, QcepDoubleImageDataPtr image, QcepObject *parent)
QSharedPointer< QxrdIntegratorCache > QxrdIntegratorCachePtr
qint64 qcepDebug(int cond)
void valueChanged(QString val, int index)
QcepInt32ImageDataPtr cachedGeometry()
QWeakPointer< QxrdCenterFinder > QxrdCenterFinderWPtr
QcepIntegratedDataPtr performIntegration(QcepIntegratedDataPtr integ, QcepDoubleImageDataPtr dimg, QcepMaskDataPtr mask)
QxrdExperimentWPtr experiment() const
static void fromScriptValue(const QScriptValue &obj, QxrdIntegratorPtr &proc)
QWeakPointer< QxrdExperiment > QxrdExperimentWPtr
QSharedPointer< QcepIntegratedData > QcepIntegratedDataPtr
QcepDoubleImageDataPtr cachedIntensity()
void onIntegrationParametersChanged()
double XValue(double x, double y) const
QString defaultUserGeometryScript()
QxrdCenterFinderWPtr m_CenterFinder
QxrdIntegrator(QcepSettingsSaverWPtr saver, QxrdExperimentWPtr exp, QxrdCenterFinderWPtr cfw)
QSharedPointer< QxrdIntegrator > QxrdIntegratorPtr
void clearAccumulator(QString resPath)
void appendIntegration(QString resPath, QcepDoubleImageDataPtr dimg, QcepMaskDataPtr mask=QcepMaskDataPtr())
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime()) const
QWeakPointer< QxrdIntegrator > QxrdIntegratorWPtr
void completeAccumulator(QString path)
QSharedPointer< QcepInt32ImageData > QcepInt32ImageDataPtr
QcepSettingsSaverWPtr m_Saver
static QScriptValue toScriptValue(QScriptEngine *engine, const QxrdIntegratorPtr &proc)
void valueChanged(double val, int index)
void valueChanged(int val, int index)
QSharedPointer< QcepMaskData > QcepMaskDataPtr
virtual ~QxrdIntegrator()
QString defaultUserAbsorptionScript()
QSharedPointer< QcepDatasetModel > QcepDatasetModelPtr
void prepareAccumulator(QString resPath, int nImages)
QxrdIntegratorCachePtr m_IntegratorCache
void valueChanged(bool val, int index)
QWeakPointer< QcepSettingsSaver > QcepSettingsSaverWPtr
QcepIntegratedDataPtr sliceLine(QcepIntegratedDataPtr integ, QcepDoubleImageDataPtr dimg, double x0, double y0, double x1, double y1, double width)
QSharedPointer< QcepDoubleImageData > QcepDoubleImageDataPtr