22 m_DetectorDisplayMode(saver, this,
"detectorDisplayMode",
ImageDisplayMode,
"Detector Display Mode"),
23 m_PerformDarkSubtraction(saver, this,
"performDarkSubtraction", true,
"Perform Dark Subtraction?"),
24 m_SaveRawImages(saver, this,
"saveRawImages", true,
"Save Raw Images?"),
25 m_SaveDarkImages(saver, this,
"saveDarkImages", true,
"Save Dark Images?"),
26 m_PerformBadPixels(saver, this,
"performBadPixels", true,
"Perform Bad Pixel Correction?"),
27 m_PerformGainCorrection(saver, this,
"performGainCorrection", true,
"Perform Gain Correction?"),
28 m_SaveSubtracted(saver, this,
"saveSubtracted", true,
"Save Dark Subtracted Data?"),
29 m_DarkImagePath(saver, this,
"darkImagePath",
"",
"Dark Images Path"),
30 m_RawDataSubdir(saver, this,
"rawDataSubdir",
"",
"Raw Data Subdirectory"),
31 m_DarkDataSubdir(saver, this,
"darkDataSubdir",
"",
"Dark Data Subdirectory"),
32 m_BadPixelsPath(saver, this,
"badPixelsPath",
"",
"Bad Pixels Path"),
33 m_GainMapPath(saver, this,
"gainMapPath",
"",
"Gain Map Path"),
34 m_SubtractedSubdir(saver, this,
"subtractedSubdir",
"",
"Subtracted Data Subdirectory"),
35 m_MaskPath(saver, this,
"maskPath",
"",
"Mask Path"),
37 m_PerformIntegration(saver, this,
"performIntegration", true,
"Perform Circular Integration?"),
38 m_DisplayIntegratedData(saver, this,
"displayIntegratedData", true,
"Display Integrated Data?"),
39 m_SaveIntegratedData(saver, this,
"saveIntegratedData", true,
"Save Integrated Data?"),
40 m_IntegratedDataFile(saver, this,
"integratedDataFile",
"",
"Integrated Data File"),
41 m_SaveIntegratedDataSeparate(saver, this,
"saveIntegratedDataSeparate", false,
"Save Integrated Data in Separate Files?"),
42 m_IntegratedDataSubdir(saver, this,
"integratedDataSubdir",
"",
"Integrated Data Subdir"),
44 m_AccumulateIntegrated2D(saver, this,
"accumulateIntegrated2D", 0,
"Accumulate integrated data in 2-d dataset"),
45 m_AccumulateIntegratedName(saver, this,
"accumulateIntegratedName",
"",
"Dataset name for accumulated data"),
47 m_CalculateROICounts(saver, this,
"calculateROICounts", true,
"Calculate ROI Counts"),
48 m_DisplayROIBorders(saver, this,
"displayROIBorders", true,
"Display ROIs in image"),
62 printf(
"QxrdDetectorProcessor::QxrdDetectorProcessor(%p)\n",
this);
78 printf(
"QxrdDetectorProcessor::~QxrdDetectorProcessor(%p)\n",
this);
98 m_Integrator->readSettings(settings, section+
"/integrator");
121 m_Integrator->writeSettings(settings, section+
"/integrator");
135 return engine->newQObject(proc.data());
140 QObject *qobj = obj.toQObject();
208 QDateTime now = QDateTime::currentDateTime();
211 image -> set_Title (image -> get_FileBase());
212 image -> set_ExposureTime (acq -> get_ExposureTime());
213 image -> set_DateTime (now);
214 image -> set_TimeStamp (msec);
215 image -> set_HBinning (det -> get_HBinning());
216 image -> set_VBinning (det -> get_VBinning());
220 image -> set_UserComment1 (acq -> get_UserComment1());
221 image -> set_UserComment2 (acq -> get_UserComment2());
222 image -> set_UserComment3 (acq -> get_UserComment3());
223 image -> set_UserComment4 (acq -> get_UserComment4());
224 image -> set_ObjectSaved (
false);
225 image -> set_Triggered (trig);
226 image -> set_Normalization (acq -> get_Normalization());
228 image -> set_ImageNumber (fileIndex);
229 image -> set_PhaseNumber (phase);
230 image -> set_NPhases (nPhases);
232 acq -> copyDynamicProperties(image.data());
244 if (QThread::currentThread() != thread()) {
245 QMetaObject::invokeMethod(
this,
"processAcquiredImage",
248 Q_ARG(
int, fileIndex),
262 printMessage(tr(
"QxrdDetectorProcessor::processAcquiredImage(\"%1\",...)")
263 .arg(img->get_FileName()));
273 if (get_SaveRawImages()) {
276 int saveTime = tic.restart();
283 if (img && get_PerformDarkSubtraction()) {
286 int subTime = tic.restart();
289 printMessage(tr(
"Subtraction took %1 msec").arg(subTime));
293 if (img && get_PerformBadPixels()) {
296 int pxlTime = tic.restart();
299 printMessage(tr(
"Bd pixels took %1 msec").arg(pxlTime));
303 if (img && get_PerformGainCorrection()) {
306 int gainTime = tic.restart();
309 printMessage(tr(
"Gain correction took %1 msec").arg(gainTime));
314 ctrl->displayNewData(img, overflow);
316 int displayTime = tic.restart();
319 printMessage(tr(
"Display took %1 msec").arg(displayTime));
323 if (img && get_CalculateROICounts()) {
328 set_RoiCounts(scalers);
330 int roiTime = tic.restart();
333 printMessage(tr(
"ROI calculation took %1 msec").arg(roiTime));
337 if (img && get_SaveSubtracted()) {
340 int saveTime = tic.restart();
343 printMessage(tr(
"Save Subtracted took %1 msec").arg(saveTime));
374 if (QThread::currentThread() != thread()) {
375 QMetaObject::invokeMethod(
this,
"processDarkImage",
378 Q_ARG(
int, fileIndex));
382 printMessage(tr(
"QxrdDetectorProcessor::processDarkImage(\"%1\",...)")
383 .arg(image->get_FileName()));
388 if (get_SaveDarkImages()) {
391 set_DarkImagePath(image->get_FileName());
401 if (QThread::currentThread() != thread()) {
402 QMetaObject::invokeMethod(
this,
"processIdleImage",
411 if (acq && acq->get_LiveViewAtIdle()) {
417 printMessage(tr(
"QxrdDetectorProcessor::processIdleImage(\"%1\")")
418 .arg(image->get_FileName()));
428 if (img && get_PerformDarkSubtraction()) {
431 int subTime = tic.restart();
434 printMessage(tr(
"Subtraction took %1 msec").arg(subTime));
438 if (img && get_PerformBadPixels()) {
441 int pxlTime = tic.restart();
444 printMessage(tr(
"Bd pixels took %1 msec").arg(pxlTime));
448 if (img && get_PerformGainCorrection()) {
451 int gainTime = tic.restart();
454 printMessage(tr(
"Gain correction took %1 msec").arg(gainTime));
461 int displayTime = tic.restart();
464 printMessage(tr(
"Display took %1 msec").arg(displayTime));
468 if (img && get_CalculateROICounts()) {
473 set_RoiCounts(scalers);
475 int roiTime = tic.restart();
478 printMessage(tr(
"ROI calculation took %1 msec").arg(roiTime));
498 if (img->get_ExposureTime() != dark->get_ExposureTime()) {
499 printMessage(
"Exposure times of acquired data and dark image are different, skipping");
503 if (img->get_Width() != dark->get_Width() ||
504 img->get_Height() != dark->get_Height()) {
505 printMessage(
"Dimensions of acquired data and dark image are different, skipping");
509 if (img->get_CameraGain() != dark->get_CameraGain()) {
510 printMessage(
"Gains of acquired data and dark image are different, skipping");
514 int height = img->get_Height();
515 int width = img->get_Width();
516 int nres = img -> get_SummedExposures();
517 int ndrk = dark -> get_SummedExposures();
518 int npixels = width*height;
520 if (nres <= 0) nres = 1;
523 double ratio = ((double) nres)/((double) ndrk);
528 result->copyPropertiesFrom(img);
530 double sumraw = 0, sumdark = 0;
532 double *resptr = result->data();
533 quint32 *drkptr = dark->data();
538 quint16 *imgptr = i16->data();
540 for (
int i=0; i<npixels; i++) {
541 double valraw = imgptr[i];
542 double valdark = drkptr[i];
547 resptr[i] = valraw - ratio*valdark;
553 quint32 *imgptr = i32->data();
555 for (
int i=0; i<npixels; i++) {
556 double valraw = imgptr[i];
557 double valdark = drkptr[i];
562 resptr[i] = valraw - ratio*valdark;
567 for (
int row=0; row<height; row++) {
568 for (
int col=0; col<width; col++) {
569 double valraw = img -> getImageData(col, row);
570 double valdark = dark -> getImageData(col, row);
571 if (valraw == valraw && valdark == valdark) {
572 sumraw += valraw; sumdark += valdark;
574 double resval = valraw - ratio*valdark;
576 result->setImageData(col, row, resval);
592 printMessage(
"Bad Pixel Correction not yet implemented");
615 for (
int i=0; i<res.count(); i++) {
617 s.append(tr(
"%1").arg(res.value(i)));
619 s.append(tr(
", %1").arg(res.value(i)));
636 if (fsav && expt && img) {
648 if (fsav && expt && img) {
660 if (fsav && expt && img) {
672 return QDir(expt->get_ExperimentDirectory()).filePath(expt->get_DataDirectory());
680 return QDir(dir).filePath(subdir);
725 if (newPath.length() == 0) {
733 if (mask && mask->readImage(newPath)) {
739 ctl->displayNewMask(
m_Mask);
747 if (newPath.length() == 0) {
751 printMessage(tr(
"Load Dark Image from %1").arg(newPath));
755 if (dark && dark -> readImage(newPath)) {
763 if (newPath.length() == 0) {
767 printMessage(tr(
"Load Bad Pixels from %1").arg(newPath));
771 if (bad && bad->readImage(newPath)) {
779 if (newPath.length() == 0) {
QSharedPointer< QxrdDetectorControlWindow > QxrdDetectorControlWindowPtr
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
void processAcquiredImage(QcepInt32ImageDataPtr image, QcepMaskDataPtr overflow, int fileIndex, int phase, int nPhases, bool trig)
QSharedPointer< QxrdCenterFinder > QxrdCenterFinderPtr
QString darkOutputDirectory() const
void onBadPixelsPathChanged(QString newPath)
QxrdDetectorProcessor(QcepSettingsSaverWPtr saver, QxrdExperimentWPtr doc, QxrdFileSaverWPtr fsav, QxrdDetectorWPtr det)
QcepDoubleImageDataPtr badPixels()
qint64 qcepDebug(int cond)
void valueChanged(QString val, int index)
static void fromScriptValue(const QScriptValue &obj, QxrdDetectorProcessorPtr &proc)
QxrdDetectorControlWindowWPtr m_ControlWindow
QcepImageDataBasePtr doGainCorrection(QcepImageDataBasePtr img)
QSharedPointer< QxrdAcquisition > QxrdAcquisitionPtr
virtual void readSettings(QSettings *set, QString section)
virtual ~QxrdDetectorProcessor()
QcepDoubleImageDataPtr m_BadPixels
QWeakPointer< QxrdDetectorControlWindow > QxrdDetectorControlWindowWPtr
void onDarkImagePathChanged(QString newPath)
void processIdleImage(QcepImageDataBasePtr image)
QString integratedOutputDirectory() const
static QScriptValue toScriptValue(QScriptEngine *engine, const QxrdDetectorProcessorPtr &proc)
QString filePathInDarkOutputDirectory(QString fileName) const
QWeakPointer< QcepMaskData > QcepMaskDataWPtr
QSharedPointer< QxrdROICalculator > QxrdROICalculatorPtr
QcepDoubleImageDataPtr gainCorrection()
void doSaveSubtractedImage(QcepImageDataBasePtr img, QcepMaskDataPtr ovf)
QxrdROICalculatorPtr roiCalculator()
QWeakPointer< QxrdExperiment > QxrdExperimentWPtr
QxrdIntegratorPtr m_Integrator
QxrdIntegratorPtr integrator()
QWeakPointer< QxrdImagePlotSettings > QxrdImagePlotSettingsWPtr
QxrdDetectorWPtr m_Detector
QVector< double > QcepDoubleVector
QxrdExperimentWPtr m_Experiment
QxrdImagePlotSettingsPtr m_ImagePlotSettings
static QcepDoubleImageDataPtr newDoubleImage(AllocationStrategy strat, int width, int height, QcepObject *parent)
QcepMaskDataPtr m_Overflow
void onMaskPathChanged(QString newPath)
QString subtractedOutputDirectory() const
QxrdImagePlotSettingsWPtr imagePlotSettings()
QString filePathInRawOutputDirectory(QString fileName) const
QcepMaskDataPtr overflow()
void setControlWindow(QxrdDetectorControlWindowWPtr ctrl)
QcepImageDataBasePtr doBadPixels(QcepImageDataBasePtr img)
QString existingOutputDirectory(QString dir, QString subdir) const
void doSaveDarkImage(QcepImageDataBasePtr img, QcepMaskDataPtr ovf)
QcepSettingsSaverWPtr m_Saver
QWeakPointer< QxrdFileSaver > QxrdFileSaverWPtr
void readSettings(QSettings *settings, QString section)
QSharedPointer< QxrdDetectorProcessor > QxrdDetectorProcessorPtr
QWeakPointer< QxrdDetector > QxrdDetectorWPtr
QSharedPointer< QxrdIntegrator > QxrdIntegratorPtr
void writeSettings(QSettings *settings, QString section)
QxrdROICalculatorPtr m_ROICalculator
QString dataDirectory() const
QcepImageDataBasePtr m_Data
QcepDoubleImageDataPtr m_GainMap
void doSaveRawImage(QcepImageDataBasePtr img, QcepMaskDataPtr ovf)
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime()) const
void setAcquiredImageProperties(QcepImageDataBasePtr image, int fileIndex, int phase, int nPhases, bool trig)
QcepImageDataBasePtr doDarkSubtraction(QcepImageDataBasePtr img)
virtual void writeSettings(QSettings *set, QString section)
QcepInt32ImageDataPtr dark()
QSharedPointer< QcepInt32ImageData > QcepInt32ImageDataPtr
QSharedPointer< QxrdFileSaver > QxrdFileSaverPtr
void processDarkImage(QcepInt32ImageDataPtr image, QcepMaskDataPtr overflow, int fileIndex)
QcepDoubleVector doCalculateROICounts(QcepImageDataBasePtr img)
QSharedPointer< QxrdDetector > QxrdDetectorPtr
QxrdCenterFinderPtr m_CenterFinder
QString filePathInSubtractedOutputDirectory(QString fileName) const
QxrdFileSaverWPtr m_FileSaver
static QcepMaskDataPtr newMask(AllocationStrategy strat, int width, int height, int def, QcepObject *parent)
void onGainMapPathChanged(QString newPath)
QSharedPointer< QcepImageDataBase > QcepImageDataBasePtr
QSharedPointer< QcepInt16ImageData > QcepInt16ImageDataPtr
QSharedPointer< QcepMaskData > QcepMaskDataPtr
QString filePathInIntegratedOutputDirectory(QString fileName) const
QcepImageDataBasePtr data()
static QcepInt32ImageDataPtr newInt32Image(AllocationStrategy strat, int width, int height, QcepObject *parent)
QcepInt32ImageDataPtr m_DarkImage
static double secondsSinceEpoch()
QWeakPointer< QcepSettingsSaver > QcepSettingsSaverWPtr
QxrdCenterFinderPtr centerFinder()
QString rawOutputDirectory() const
QSharedPointer< QcepDoubleImageData > QcepDoubleImageDataPtr