25 #include <QtConcurrentRun>
33 m_ThreadCount(QThreadPool::globalInstance()->maxThreadCount()),
83 printf(
"QxrdIntegratorCache::QxrdIntegratorCache(%p)\n",
this);
89 if (integp == NULL && xformp) {
90 integp = xformp->integrator();
161 printf(
"QxrdIntegratorCache::~QxrdIntegratorCache(%p)\n",
this);
183 cos(beta), sin(beta), cos(rot), sin(rot));
193 double tth =
getTTH(x, y)*M_PI/180.0;
208 rot, cos(beta), sin(beta), 1.0, 0.0, cos(rot), sin(rot),
214 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0,
231 rot, cos(beta), sin(beta), 1.0, 0.0, cos(rot), sin(rot),
237 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0,
246 double tth =
getTTH(x, y);
295 double tth =
getTTH(x,y)*M_PI/180.0;
296 double chi =
getChi(x,y)*M_PI/180.0;
345 QThread::usleep(usec);
350 QThread::msleep(msec);
414 int rowStart = strideSize*i;
415 int rowEnd = rowStart + strideSize;
423 double halfOversampleStep = oversampleStep/2.0;
425 double rMin=0, rMax=0, cMin=0, cMax=0;
426 bool rFirst=
true, cFirst=
true;
428 for(
int y = rowStart; y<rowEnd; y++) {
429 for (
int x = 0; x <
m_NCols; x++) {
430 for (
int oversampley = 0; oversampley < noversample; oversampley++) {
431 double yy = y+oversampley*oversampleStep+halfOversampleStep;
432 int iy = y*noversample+oversampley;
433 for (
int oversamplex = 0; oversamplex < noversample; oversamplex++) {
434 double xx = x+oversamplex*oversampleStep+halfOversampleStep;
435 int ix = x*noversample+oversamplex;
437 double r =
XValue(xx, yy);
444 }
else if (r > rMax) {
446 }
else if (r < rMin) {
454 double c =
YValue(xx, yy);
461 }
else if (c > cMax) {
463 }
else if (c < cMin) {
475 if (rFirst ==
false || cFirst ==
false) {
478 if (rFirst ==
false) {
501 if (cFirst ==
false) {
534 int rowStart = strideSize*i;
535 int rowEnd = rowStart + strideSize;
543 double halfOversampleStep = oversampleStep/2.0;
545 for(
int y = rowStart; y<rowEnd; y++) {
546 for (
int x = 0; x <
m_NCols; x++) {
547 for (
int oversampley = 0; oversampley < noversample; oversampley++) {
548 double yy = y+oversampley*oversampleStep+halfOversampleStep;
549 int iy = y*noversample+oversampley;
550 for (
int oversamplex = 0; oversamplex < noversample; oversamplex++) {
551 double xx = x+oversamplex*oversampleStep+halfOversampleStep;
552 int ix = x*noversample+oversamplex;
602 int rowStart = strideSize*i;
603 int rowEnd = rowStart + strideSize;
611 double halfOversampleStep = oversampleStep/2.0;
615 for(
int y = rowStart; y<rowEnd; y++) {
616 for (
int x = 0; x <
m_NCols; x++) {
617 if ((mask == NULL) || (mask->value(x, y))) {
618 double val = dimg->value(x,y);
619 for (
int oversampley = 0; oversampley < noversample; oversampley++) {
620 int iy = y*noversample+oversampley;
621 for (
int oversamplex = 0; oversamplex < noversample; oversamplex++) {
622 int ix = x*noversample+oversamplex;
640 integral[bin] += val*norm;
653 double *s2 = sumValue.data();
655 double *v2 = integral.data();
679 expt->printMessage(tr(
"QxrdIntegratorCache::performIntegration"));
688 double halfOversampleStep = oversampleStep/2.0;
700 if (norm.length()>=1) {
706 expt->printMessage(tr(
"QxrdIntegratorCache::performIntegration - fill cache"));
713 m_NRows*m_Oversample, expt.data());
717 m_NRows*m_Oversample, expt.data());
721 m_NRows*m_Oversample, expt.data());
726 m_NRows*m_Oversample, expt.data());
730 m_NRows*m_Oversample, expt.data());
735 m_CachedNormalization -> clear();
746 expt->printMessage(tr(
"Threaded integration disabled because of user supplied functions"));
762 QVector< QFuture<void> > res;
769 res[i].waitForFinished();
804 expt->printMessage(tr(
"1st stage complete after %1 msec").arg(tic.elapsed()));
813 QVector< QFuture<void> > res;
820 res[i].waitForFinished();
831 expt->printMessage(tr(
"2nd stage complete after %1 msec").arg(tic.elapsed()));
842 expt->printMessage(tr(
"QxrdIntegratorCache::performIntegration - cache finished"));
848 expt->printMessage(tr(
"QxrdIntegratorCache::performIntegration - waiting for cache [%1,%2]")
857 expt->printMessage(tr(
"QxrdIntegratorCache::performIntegration - anomalous cache [%1,%2]")
862 expt->printMessage(tr(
"QxrdIntegratorCache::performIntegration - use cache"));
871 QVector< QFuture<void> > res;
875 i, m_ThreadCount, dimg, mask, normalize));
879 res[i].waitForFinished();
884 expt->printMessage(tr(
"Stage 3 complete after %1 msec").arg(tic.elapsed()));
890 double nsum = 0, ninteg = 0;
905 if ((nsum > 0) && (ninteg != 0)) {
920 img->set_HLabel(
XLabel());
921 img->set_HUnits(
XUnits());
922 img->set_VLabel(
YLabel());
923 img->set_VUnits(
YUnits());
925 img->set_Title(dimg->get_Title());
929 int bin = y*m_NRSteps + x;
935 img->setValue(x,y, scalingFactor*normVal*v/sv);
937 img->setValue(x,y, qQNaN());
942 img->dataObjectChanged();
957 integ -> append(xv, scalingFactor*normVal*
m_Integral[ir]/sv);
959 integ -> append(xv, scalingFactor*normVal*
m_Integral[ir]/sv*(ir*oversampleStep+halfOversampleStep));
964 integ->set_XUnitsLabel(
XLabel());
965 integ->set_Oversample(m_Oversample);
971 expt->printMessage(tr(
"Integration of %1 took %2 msec")
972 .arg(dimg->get_Title())
973 .arg(tic.restart()));
975 expt->printMessage(tr(
"QxrdIntegratorCache::performIntegration - integration failed"));
1042 exp->printMessage(tr(
"User Geometry Function Completed"));
1046 exp->printMessage(tr(
"User Absorption Function Completed"));
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
QSharedPointer< QxrdCenterFinder > QxrdCenterFinderPtr
QString m_UserAbsorptionFunction
double m_DetectorDistance
void releaseScriptEngine()
QcepDoubleImageDataPtr m_CachedRadialValues
QAtomicInt m_CacheFillLevel
QString m_UserAbsorptionScript
qint64 qcepDebug(int cond)
double m_DetectorYPixelSize
QxrdIntegratorCache(QxrdExperimentWPtr exp, QxrdIntegratorWPtr integ, QxrdPolarTransformWPtr xform, QxrdCenterFinderWPtr cf)
QWeakPointer< QxrdCenterFinder > QxrdCenterFinderWPtr
QcepInt32ImageDataPtr m_CachedPolarBinNumbers
void performIntegration(QcepDataObjectPtr res, QcepDoubleImageDataPtr dimg, QcepMaskDataPtr mask, int normalize)
QSharedPointer< QxrdScriptEngine > QxrdScriptEnginePtr
QScriptValue m_UserGeometryFunctionValue
double m_AttenuationLength
QcepDoubleImageDataPtr m_CachedPolarValues
static void getQChi(double xCenter, double yCenter, double distance, double energy, double xPixel, double yPixel, double pixelLength, double pixelHeight, double rotation, double cos_beta, double sin_beta, double cos_alpha, double sin_alpha, double cos_rotation, double sin_rotation, double *q, double *chi)
virtual ~QxrdIntegratorCache()
void partialIntegrationStep3(int i, int n, QcepDoubleImageDataPtr dimg, QcepMaskDataPtr mask, int normalize)
QWeakPointer< QxrdExperiment > QxrdExperimentWPtr
double getR(double x, double y)
QSharedPointer< QcepIntegratedData > QcepIntegratedDataPtr
QString m_UserGeometryScript
QAtomicInt m_CacheFullLevel
double getChi(double x, double y)
bool m_EnablePolarization
double m_TiltPlaneRotation
static QcepDoubleImageDataPtr newDoubleImage(AllocationStrategy strat, int width, int height, QcepObject *parent)
double XValue(double x, double y)
void partialIntegrationStep1(int i, int n)
double m_DetectorXPixelSize
QVector< double > m_Integral
static void msleep(int msec)
QcepDoubleImageDataPtr m_CachedNormalization
double NormValue(double x, double y)
static double getTwoTheta(double xCenter, double yCenter, double distance, double xPixel, double yPixel, double pixelLength, double pixelHeight, double cos_beta, double sin_beta, double cos_rotation, double sin_rotation)
QList< double > QcepDoubleList
QcepInt32ImageDataPtr m_CachedRadialBinNumbers
QcepInt32ImageDataPtr cachedGeometry()
QVector< double > m_SumValue
double YValue(double x, double y)
QSharedPointer< QxrdIntegrator > QxrdIntegratorPtr
QxrdIntegratorWPtr m_Integrator
QString m_UserGeometryFunction
static void usleep(int usec)
QScriptValue m_UserAbsorptionFunctionValue
QcepDoubleImageDataPtr cachedIntensity()
QWeakPointer< QxrdIntegrator > QxrdIntegratorWPtr
QSharedPointer< QcepDataObject > QcepDataObjectPtr
QSharedPointer< QcepInt32ImageData > QcepInt32ImageDataPtr
int m_EnableUserAbsorption
QxrdCenterFinderWPtr m_CenterFinder
QSharedPointer< QcepMaskData > QcepMaskDataPtr
double getTTH(double x, double y)
double m_SelfNormalizationMinimum
QxrdPolarTransformWPtr m_PolarTransform
double getQ(double x, double y)
static QcepInt32ImageDataPtr newInt32Image(AllocationStrategy strat, int width, int height, QcepObject *parent)
QxrdExperimentWPtr m_Experiment
double m_SelfNormalizationMaximum
double getDistance(double x, double y)
void partialIntegrationStep2(int i, int n)
QSharedPointer< QcepDoubleImageData > QcepDoubleImageDataPtr
static void sleep(int sec)