1 #define _CRT_SECURE_NO_WARNINGS
6 #include <QtConcurrentRun>
35 m_DataPath(saver, this,
"dataPath",
"",
"Data Path"),
36 m_DarkImagePath(saver, this,
"darkImagePath",
"",
"Dark Images Path"),
37 m_BadPixelsPath(saver, this,
"badPixelsPath",
"",
"Bad Pixels Path"),
38 m_GainMapPath(saver, this,
"gainMapPath",
"",
"Gain Map Path"),
39 m_MaskPath(saver, this,
"maskPath",
"",
"Mask Path"),
40 m_ScriptPath(saver, this,
"scriptPath",
"",
"Script Path"),
41 m_PerformDarkSubtraction(saver, this,
"performDarkSubtraction", true,
"Perform Dark Subtraction?"),
42 m_SaveRawImages(saver, this,
"saveRawImages", true,
"Save Raw Images?"),
43 m_SaveDarkImages(saver, this,
"saveDarkImages", true,
"Save Dark Images?"),
44 m_PerformBadPixels(saver, this,
"performBadPixels", true,
"Perform Bad Pixel Correction?"),
45 m_PerformGainCorrection(saver, this,
"performGainCorrection", true,
"Perform Gain Correction?"),
46 m_SaveSubtracted(saver, this,
"saveSubtracted", true,
"Save Dark Subtracted Data?"),
47 m_SaveAsText(saver, this,
"saveAsText", false,
"Save as Text Files (warning - Large and Slow!)"),
48 m_SaveAsTextSeparator(saver, this,
"saveAsTextSeparator",
" ",
"Separator for Images Saved as Text"),
49 m_SaveAsTextPerLine(saver, this,
"saveAsTextPerLine",16,
"Pixels per line in Images Saved as Text"),
50 m_SaveOverflowFiles(saver, this,
"saveOverflowFiles",0,
"Save Overflow Pixel Files?"),
51 m_PerformIntegration(saver, this,
"performIntegration", true,
"Perform Circular Integration?"),
52 m_DisplayIntegratedData(saver, this,
"displayIntegratedData", true,
"Display Integrated Data?"),
53 m_SaveIntegratedData(saver, this,
"saveIntegratedData", true,
"Save Integrated Data?"),
54 m_SaveIntegratedPath(saver, this,
"saveIntegratedPath",
"",
"Integrated Data Path"),
55 m_SaveDarkInSubdirectory(saver, this,
"saveDarkInSubdirectory",0,
"Save Dark In Subdirectory?"),
56 m_SaveDarkSubdirectory(saver, this,
"saveDarkSubdirectory",
"",
"Dark Subdirectory"),
57 m_SaveRawInSubdirectory(saver, this,
"saveRawInSubdirectory",0,
"Save Raw in Subdirectory?"),
58 m_SaveRawSubdirectory(saver, this,
"saveRawSubdirectory",
"",
"Raw Subdirectory"),
59 m_SaveSubtractedInSubdirectory(saver, this,
"saveSubtractedInSubdirectory",0,
"Save Subtracted in Subdirectory?"),
60 m_SaveSubtractedSubdirectory(saver, this,
"saveSubtractedSubdirectory",
"",
"Subtracted Subdirectory"),
61 m_SaveIntegratedInSeparateFiles(saver, this,
"saveIntegratedInSeparateFiles",0,
"Save Integrated in Separate Files?"),
62 m_SaveIntegratedInSubdirectory(saver, this,
"saveIntegratedInSubdirectory",0,
"Save Integrated in Subdirectory?"),
63 m_SaveIntegratedSubdirectory(saver, this,
"saveIntegratedSubdirectory",
"",
"Integrated Subdirectory"),
64 m_AccumulateIntegrated2D(saver, this,
"accumulateIntegrated2D", 0,
"Accumulate integrated data in 2-d dataset"),
65 m_AccumulateIntegratedName(saver, this,
"accumulateIntegratedName",
"/accumulated/2d-data",
"Dataset to accumulate to"),
66 m_AccumulateIntegratedDirectory(saver, this,
"accumulateIntegratedDirectory",
"",
"Accumulator save directory"),
67 m_AccumulateIntegratedFileName(saver, this,
"accumulateIntegratedFileName",
"",
"Accumulator save file"),
68 m_AccumulateIntegratedFormat(saver, this,
"accumulateIntegratedFormat",
"",
"Accumulator save format"),
69 m_PerformDarkSubtractionTime(saver, this,
"performDarkSubtractionTime", 0.01,
"Avg Time to Perform Dark Subtraction (in sec)"),
70 m_PerformBadPixelsTime(saver, this,
"performBadPixelsTime", 0.01,
"Avg Time to Perform Bad Pixel Correction (in sec)"),
71 m_PerformGainCorrectionTime(saver, this,
"performGainCorrectionTime", 0.01,
"Avg Time to Perform Gain Correction (in sec)"),
72 m_SaveSubtractedTime(saver, this,
"saveSubtractedTime", 0.1,
"Avg Time to Save Subtracted Data (in sec)"),
73 m_SaveAsTextTime(saver, this,
"saveAsTextTime", 0.1,
"Avg Time to Save Images as Text (in sec)"),
74 m_PerformIntegrationTime(saver, this,
"performIntegrationTime", 0.05,
"Avg Time to Perform Integration (in sec/core)"),
75 m_DisplayIntegratedDataTime(saver, this,
"displayIntegratedDataTime", 0.2,
"Avg Time to Display Integrated Data (in sec)"),
76 m_SaveIntegratedDataTime(saver, this,
"saveIntegratedDataTime", 0.01,
"Avg Time to Save Integrated Data (in sec)"),
77 m_EstimatedProcessingTime(saver, this,
"estimatedProcessingTime", 0.1,
"Overall Estimated Processing Time (in sec/image)"),
78 m_AveragingRatio(saver, this,
"averagingRatio", 0.1,
"Averaging Ratio for Estimated Timing"),
79 m_MaskMinimumValue(saver, this,
"maskMinimumValue", 0,
"Mask Minimum Value"),
80 m_MaskMaximumValue(saver, this,
"maskMaximumValue", 20000,
"Mask Maximum Value"),
81 m_MaskCircleRadius(saver, this,
"maskCircleRadius", 10,
"Mask Circle Radius"),
82 m_MaskSetPixels(saver, this,
"maskSetPixels", true,
"Mask Set Pixels"),
84 m_Average(
QcepSettingsSaverPtr(), this,
"average",0.0,
"Average Value of Acquired Image (per exposure)"),
87 m_CorrectionQueueLength(
QcepSettingsSaverPtr(), this,
"correctionQueueLength", 0,
"Image correction backlog"),
88 m_IntegrationQueueLength(
QcepSettingsSaverPtr(), this,
"integrationQueueLength", 0,
"Image integration backlog"),
90 m_ZingerAlgorithm(saver, this,
"zingerAlgorithm", 0,
"Zinger Detection Algorithm"),
91 m_ZingerMask(saver, this,
"zingerMask", 0,
"Zinger Mask Source"),
92 m_ZingerDestination(saver, this,
"zingerDestination", -1,
"Zinger Destination"),
93 m_ZingerSize1(saver, this,
"zingerSize1", 1,
"Inner Zinger Search Box Size"),
94 m_ZingerSize2(saver, this,
"zingerSize2", 5,
"Outer Zinger Search Box Size"),
95 m_ZingerThreshold(saver, this,
"zingerThreshold", 2.5,
"Zinger Detection Threshold"),
96 m_Mutex(QMutex::Recursive),
100 m_FileSaver(filesaver),
102 m_AcquiredInt16Images(
"acquiredInt16Images"),
103 m_AcquiredInt32Images(
"acquiredInt32Images"),
110 m_CenterFinder(NULL),
112 m_PolarTransform(NULL),
113 m_PolarNormalization(NULL),
114 m_GenerateTestImage(NULL)
121 printf(
"QxrdDataProcessorBase::QxrdDataProcessorBase(%p)\n",
this);
125 printMessage(
"QxrdDataProcessorBase::QxrdDataProcessorBase");
144 printf(
"Deleting processor\n");
148 printf(
"QxrdDataProcessorBase::~QxrdDataProcessorBase(%p)\n",
this);
231 exp->printMessage(msg, ts);
240 exp->criticalMessage(msg, ts);
249 exp->statusMessage(msg, ts);
255 return QDir(dir).filePath(subdir);
268 return exp->get_ExperimentDirectory();
284 return QDir(exp->get_ExperimentDirectory()).filePath(exp->get_DataDirectory());
297 if (get_SaveDarkInSubdirectory()) {
311 if (get_SaveRawInSubdirectory()) {
325 if (get_SaveSubtractedInSubdirectory()) {
339 if (get_SaveIntegratedInSubdirectory()) {
349 width, height,
this);
362 w -> newDataAvailable(
m_Data, overflow);
375 set_DarkImagePath(image->get_FileName());
377 int height = image->get_Height();
378 int width = image->get_Width();
379 int ndrk = image -> get_SummedExposures();
380 int npixels = width*height;
381 if (ndrk <= 0) ndrk = 1;
383 double *dk = image->data();
386 for (
int i=0; i<npixels; i++) {
389 set_AverageDark(avgdark/npixels/ndrk);
391 set_DarkImagePath(
"");
433 set_BadPixelsPath(image->get_FileName());
435 set_BadPixelsPath(
"");
444 set_GainMapPath(image->get_FileName());
455 w -> newMaskAvailable(
mask());
462 QFileInfo fileInfo(fileName);
464 if (fileInfo.exists() && fileInfo.isFile()) {
468 fileName = get_DarkImagePath();
469 fileInfo.setFile(fileName);
471 if (fileInfo.exists() && fileInfo.isFile()) {
475 fileName = get_BadPixelsPath();
476 fileInfo.setFile(fileName);
478 if (fileInfo.exists() && fileInfo.isFile()) {
482 fileName = get_GainMapPath();
483 fileInfo.setFile(fileName);
485 if (fileInfo.exists() && fileInfo.isFile()) {
509 res = dir.entryList(QStringList());
519 res = dir.entryList(QStringList(pattern));
526 if (QThread::currentThread() != thread()) {
527 INVOKE_CHECK(QMetaObject::invokeMethod(
this,
"loadData", Qt::BlockingQueuedConnection, Q_ARG(QString, name)))
531 tr(
"QxrdDataProcessorBase::loadData(%1)").arg(name));
538 if (res && res -> readImage(path)) {
542 res -> loadMetaData();
544 int typ = res->get_DataType();
554 set_DataPath(res -> get_FileName());
563 if (QThread::currentThread() != thread()) {
564 INVOKE_CHECK(QMetaObject::invokeMethod(
this,
"saveData", Qt::BlockingQueuedConnection, Q_ARG(QString, name), Q_ARG(
int, canOverwrite)))
570 set_DataPath(
m_Data -> get_FileName());
576 if (QThread::currentThread() != thread()) {
577 INVOKE_CHECK(QMetaObject::invokeMethod(
this,
"saveData",
578 Qt::BlockingQueuedConnection,
580 Q_ARG(QString, name), Q_ARG(
int, canOverwrite)))
589 printMessage(tr(
"Don't know how to save %1").arg(object->pathName()));
610 if (QThread::currentThread() != thread()) {
611 INVOKE_CHECK(QMetaObject::invokeMethod(
this,
"loadDark", Qt::BlockingQueuedConnection, Q_ARG(QString, name)))
615 tr(
"QxrdDataProcessorBase::loadDark(%1)").arg(name));
622 if (res && res -> readImage(path)) {
626 res -> loadMetaData();
631 set_DarkImagePath(res -> get_FileName());
633 printMessage(tr(
"Loaded Dark Image from %1").arg(path));
642 if (QThread::currentThread() != thread()) {
643 INVOKE_CHECK(QMetaObject::invokeMethod(
this,
"saveDark", Qt::BlockingQueuedConnection, Q_ARG(QString, name), Q_ARG(
int, canOverwrite)))
658 printMessage(tr(
"QxrdDataProcessorBase::loadBadPixels(%1)").arg(name));
665 if (res && res -> readImage(path)) {
669 res -> loadMetaData();
674 set_BadPixelsPath(res -> get_FileName());
692 printMessage(tr(
"QxrdDataProcessorBase::loadGainMap(%1)").arg(name));
699 if (res -> readImage(path)) {
703 res -> loadMetaData();
705 res -> setDefaultValue(1.0);
709 set_GainMapPath(res -> get_FileName());
720 set_GainMapPath(
m_GainMap -> get_FileName());
760 if (pos >= 0 && pos < len) {
762 }
else if (pos < 0 && pos >= -len) {
778 w =
mask()->get_Width();
793 h =
mask()->get_Height();
821 mask()->copyMaskTo(m);
840 }
else if (amount > 1) {
841 for (
int i=0; i<amount; i++) {
844 }
else if (amount < -1) {
845 for (
int i=0; i<(-amount); i++) {
848 }
else if (amount == 1) {
853 }
else if (amount == -1) {
883 }
else if (amount > 1) {
884 for (
int i=0; i<amount; i++) {
887 }
else if (amount < -1) {
888 for (
int i=0; i<(-amount); i++) {
891 }
else if (amount == 1) {
895 }
else if (amount == -1) {
911 if ((p0 >= 0) && (p1 >= 0) && (p0 != p1)) {
927 if ((p0 >= 0) && (p1 >= 0)) {
943 if ((p0 >= 0) && (p1 >= 0)) {
959 if ((p0 >= 0) && (p1 >= 0)) {
975 if ((p0 >= 0) && (p1 >= 0)) {
991 if ((p0 >= 0) && (p1 >= 0)) {
1007 if ((p0 >= 0) && (p1 >= 0)) {
1010 m_Masks[p0] -> xorNotMask(pm);
1087 double min = get_MaskMinimumValue();
1088 double max = get_MaskMaximumValue();
1103 double min = get_MaskMinimumValue();
1104 double max = get_MaskMaximumValue();
1118 printMessage(tr(
"QxrdDataProcessorBase::loadMask(%1)").arg(name));
1125 if (res -> readImage(path)) {
1129 res -> loadMetaData();
1140 set_MaskPath(
mask() -> get_FileName());
1153 set_MaskPath(
mask() -> get_FileName());
1169 f -> saveDoubleData(name, image, overflow, canOverwrite);
1178 f -> saveInt16Data(name, image, overflow, canOverwrite);
1187 f -> saveRaw16Data(name, image, overflow, canOverwrite);
1196 f -> saveInt32Data(name, image, overflow, canOverwrite);
1205 f -> saveRaw32Data(name, image, overflow, canOverwrite);
1214 f -> saveMaskData(name, image, canOverwrite);
1223 f -> saveTextData(name, image, overflow, canOverwrite);
1231 set_DarkImagePath(
"");
1238 set_BadPixelsPath(
"");
1245 set_GainMapPath(
"");
1256 printMessage(tr(
"processing acquired 16 bit image, %1 remaining")
1261 if (get_SaveRawImages()) {
1262 if (img->get_ObjectSaved()) {
1263 printMessage(tr(
"Image \"%1\" is already saved").arg(img->rawFileName()));
1269 corrected -> copyFrom(img);
1270 corrected -> set_DateTime(QDateTime::currentDateTime());
1288 printMessage(tr(
"processing acquired 32 bit image, %1 remaining")
1293 if (get_SaveRawImages()) {
1294 if (img->get_ObjectSaved()) {
1295 printMessage(tr(
"Image \"%1\" is already saved").arg(img->rawFileName()));
1301 corrected -> copyFrom(img);
1302 corrected -> set_DateTime(QDateTime::currentDateTime());
1341 if (processed && img) {
1342 processed->copyFrom(img);
1344 statusMessage(tr(
"Processing Image \"%1\"").arg(processed->get_FileName()));
1349 if (v.length() > 0) {
1350 processed->set_Normalization(v);
1354 printMessage(tr(
"Processing Image \"%1\", image number %2, count %3")
1355 .arg(processed->get_FileName()).arg(processed->get_ImageNumber()).arg(
getAcquiredCount()));
1358 if (get_PerformDarkSubtraction()) {
1360 processed -> set_ObjectSaved(
false);
1362 int subTime = tic.restart();
1367 printMessage(tr(
"Dark subtraction took %1 msec").arg(subTime));
1371 if (get_PerformBadPixels()) {
1373 processed -> set_ObjectSaved(
false);
1375 int badPxlTime = tic.restart();
1380 printMessage(tr(
"Bad Pixel correction took %1 msec").arg(badPxlTime));
1384 if (get_PerformGainCorrection()) {
1386 processed -> set_ObjectSaved(
false);
1388 int gainTime = tic.restart();
1393 printMessage(tr(
"Gain correction took %1 msec").arg(gainTime));
1397 if (get_SaveSubtracted()) {
1398 if (processed->get_ObjectSaved()) {
1399 printMessage(tr(
"Image \"%1\" is already saved").arg(processed->rawFileName()));
1405 if (get_SaveAsText()) {
1414 printMessage(tr(
"Processing took %1 msec").arg(tic.restart()));
1417 statusMessage(tr(
"Completed Processing Image \"%1\"").arg(processed->get_FileName()));
1425 double newVal = prop -> value() * (1.0 - get_AveragingRatio()) + ((
double) msec)/1000.0* get_AveragingRatio();
1427 prop -> setValue(newVal);
1433 if (dark && image) {
1434 if (dark->get_ExposureTime() != image->get_ExposureTime()) {
1435 printMessage(
"Exposure times of acquired data and dark image are different, skipping");
1439 if (dark->get_Width() != image->get_Width() ||
1440 dark->get_Height() != image->get_Height()) {
1441 printMessage(
"Dimensions of acquired data and dark image are different, skipping");
1445 if (dark->get_CameraGain() != image->get_CameraGain()) {
1446 printMessage(
"Gains of acquired data and dark image are different, skipping");
1459 int height = image->get_Height();
1460 int width = image->get_Width();
1461 int nres = image-> get_SummedExposures();
1462 int ndrk = dark -> get_SummedExposures();
1463 int npixels = width*height;
1465 if (nres <= 0) nres = 1;
1467 double ratio = ((double) nres)/((double) ndrk);
1472 double *result = image->data();
1473 double *dk = dark->data();
1477 for (
int i=0; i<npixels; i++) {
1479 avgraw += result[i];
1480 result[i] = result[i]-ratio*dk[i];
1484 set_AverageRaw(avgraw/npixels/nres);
1485 set_Average(get_AverageRaw() - get_AverageDark());
1495 if (dark && image) {
1496 if (dark->get_ExposureTime() != image->get_ExposureTime()) {
1497 printMessage(
"Exposure times of acquired data and dark image are different, skipping");
1501 if (dark->get_Width() != image->get_Width() ||
1502 dark->get_Height() != image->get_Height()) {
1503 printMessage(
"Dimensions of acquired data and dark image are different, skipping");
1507 if (dark->get_CameraGain() != image->get_CameraGain()) {
1508 printMessage(
"Gains of acquired data and dark image are different, skipping");
1521 int height = image->get_Height();
1522 int width = image->get_Width();
1523 int nres = image-> get_SummedExposures();
1524 int ndrk = dark -> get_SummedExposures();
1525 int npixels = width*height;
1527 if (nres <= 0) nres = 1;
1529 double ratio = ((double) nres)/((double) ndrk);
1534 double *result = image->data();
1535 double *dk = dark->data();
1539 for (
int i=0; i<npixels; i++) {
1541 avgraw += result[i];
1542 result[i] = result[i]+ratio*dk[i];
1546 set_AverageRaw(avgraw/npixels/nres);
1547 set_Average(get_AverageRaw() - get_AverageDark());
1564 image -> multiply(gains);
1571 double estSerialTime = 0, estParallelTime = 0;
1575 if (acq && get_SaveRawImages()) {
1576 if (acq -> get_SummedExposures() > 1) {
1577 estSerialTime += acq -> get_Raw32SaveTime();
1579 estSerialTime += acq -> get_Raw16SaveTime();
1583 if (get_PerformDarkSubtraction()) {
1584 estParallelTime += get_PerformDarkSubtractionTime();
1587 if (get_PerformBadPixels()) {
1588 estParallelTime += get_PerformBadPixelsTime();
1591 if (get_PerformGainCorrection()) {
1592 estParallelTime += get_PerformGainCorrectionTime();
1595 if (get_SaveSubtracted()) {
1596 estSerialTime += get_SaveSubtractedTime();
1599 if (get_SaveAsText()) {
1600 estSerialTime += get_SaveAsTextTime();
1603 if (get_PerformIntegration()) {
1604 estParallelTime += get_PerformIntegrationTime();
1607 if (get_DisplayIntegratedData()) {
1608 estSerialTime += get_DisplayIntegratedDataTime();
1611 if (get_SaveIntegratedData()) {
1612 estSerialTime += get_SaveIntegratedDataTime();
1620 return estSerialTime + estParallelTime;
1625 double min = get_MaskMinimumValue();
1626 double max = get_MaskMaximumValue();
1666 double min = get_MaskMinimumValue();
1667 double max = get_MaskMaximumValue();
1720 if ((rect.left() == rect.right()) && (rect.bottom() == rect.top())) {
1721 mask() ->
maskCircle(rect.left(), rect.top(), get_MaskCircleRadius(), get_MaskSetPixels());
1723 double cx = rect.center().x();
1724 double cy = rect.center().y();
1725 double rad = rect.width()/2;
1741 int nRows =
mask() -> get_Height();
1742 int nCols =
mask() -> get_Width();
1744 QImage polyImage(nCols, nRows, QImage::Format_RGB32);
1745 QPainter polyPainter(&polyImage);
1748 foreach(QPointF pt, poly) {
1752 polyPainter.setPen(Qt::white);
1753 polyPainter.fillRect(0,0,nCols,nRows,Qt::black);
1754 polyPainter.setBrush(QBrush(Qt::white, Qt::SolidPattern));
1755 polyPainter.drawPolygon(poly);
1757 bool newval = get_MaskSetPixels();
1759 for (
int j=0; j<nRows; j++) {
1760 for (
int i=0; i<nCols; i++) {
1761 if (qGray(polyImage.pixel(i,j))) {
1762 mask() -> setMaskValue(i, j, newval);
1773 foreach(QPointF pt, poly) {
1774 printMessage(tr(
"Measure pt (%1,%2) = %3").arg(pt.x()).arg(pt.y())
1775 .arg(
m_Data -> value(pt.x(),pt.y())));
1783 foreach(QPointF pt, poly) {
1784 printMessage(tr(
"Measure pt (%1,%2)").arg(pt.x()).arg(pt.y()));
1792 if (poly.size() >= 3) {
1793 double x0 = poly[0].x();
1794 double y0 = poly[0].y();
1795 double x1 = poly[1].x();
1796 double y1 = poly[1].y();
1797 double x2 = poly[2].x();
1798 double y2 = poly[2].y();
1799 double dx1 = x0-x1, dy1 = y0-y1, dx2 = x2-x1, dy2 = y2-y1;
1800 double a1 = atan2(dy1,dx1), a2 = atan2(dy2,dx2);
1802 statusMessage(tr(
"Angle: @ %1,%2, ang %3 deg").arg(x1).arg(y1).arg((a2-a1)/M_PI*180.0));
1803 }
else if (poly.size() == 2) {
1804 double x0 = poly[0].x();
1805 double y0 = poly[0].y();
1806 double x1 = poly[1].x();
1807 double y1 = poly[1].y();
1810 double ang = atan2(dy,dx);
1811 double len = sqrt(dx*dx+dy*dy);
1813 statusMessage(tr(
"Line: %1,%2 - %3,%4 : D %5,%6 : L %7 : Ang %8").
1814 arg(x0).arg(y0).arg(x1).arg(y1).
1815 arg(dx).arg(dy).arg(len).arg(ang/M_PI*180.0));
1817 }
else if (poly.size() == 1) {
1818 statusMessage(tr(
"Point: %1,%2").arg(poly[0].x()).arg(poly[0].y()));
1912 printMessage(
"Problem: QxrdDataProcessorBase::experiment == NULL");
1921 printMessage(
"Problem QxrdDataProcessorBase::centerFinder == NULL");
1930 printMessage(
"Problem QxrdDataProcessorBase::integrator == NULL");
1939 printMessage(
"Problem QxrdDataProcessorBase::polarTransform == NULL");
1948 printMessage(
"Problem QxrdDataProcessorBase::polarNormalization == NULL");
1957 printMessage(
"Problem QxrdDataProcessorBase::distortion == NULL");
1965 m_Data -> resize(ncols, nrows);
1973 int nr =
m_Data -> get_Height();
1974 int nc =
m_Data -> get_Width();
1976 for (
int y=0; y<nr; y++) {
1977 for (
int x=0; x<nc; x++) {
1980 for (
int iy = 0; iy < oversample; iy++) {
1981 double yy = (double) y + ((
double) iy)/((
double) oversample) - cy;
1983 for (
int ix = 0; ix < oversample; ix++) {
1984 double xx = (double) x + ((
double) ix)/((
double) oversample) - cx;
1986 double r = sqrt(yy2 + xx2);
1987 sum += exp(-r/width);
1991 m_Data -> setValue(x, y,
m_Data -> value(x,y) + sum/(oversample*oversample));
2000 int nr =
m_Data -> get_Height();
2001 int nc =
m_Data -> get_Width();
2003 for (
int y=0; y<nr; y++) {
2004 for (
int x=0; x<nc; x++) {
2007 for (
int iy = 0; iy < oversample; iy++) {
2008 double yy = (double) y + ((
double) iy)/((
double) oversample) - cy;
2010 for (
int ix = 0; ix < oversample; ix++) {
2011 double xx = (double) x + ((
double) ix)/((
double) oversample) - cx;
2013 double r = sqrt(yy2 + xx2);
2018 m_Data -> setValue(x, y,
m_Data -> value(x,y) + sum/(oversample*oversample));
2027 int nr =
m_Data -> get_Height();
2028 int nc =
m_Data -> get_Width();
2030 for (
int y=0; y<nr; y++) {
2031 for (
int x=0; x<nc; x++) {
2034 for (
int iy = 0; iy < oversample; iy++) {
2035 double yy = (double) y + ((
double) iy)/((
double) oversample) - cy;
2037 for (
int ix = 0; ix < oversample; ix++) {
2038 double xx = (double) x + ((
double) ix)/((
double) oversample) - cx;
2040 double r = sqrt(yy2 + xx2);
2042 double ndr = (r - radius)/width;
2044 if (fabs(ndr) < 6) {
2045 double val = strength*exp(-2*ndr*ndr)/width*sqrt(2.0/M_PI);
2051 m_Data -> setValue(x, y,
m_Data -> value(x,y) + sum/(oversample*oversample));
2060 int nr =
m_Data -> get_Height();
2061 int nc =
m_Data -> get_Width();
2063 for (
int y=0; y<nr; y++) {
2064 for (
int x=0; x<nc; x++) {
2067 for (
int iy = 0; iy < oversample; iy++) {
2068 double yy = (double) y + ((
double) iy)/((
double) oversample) - cy;
2070 for (
int ix = 0; ix < oversample; ix++) {
2071 double xx = (double) x + ((
double) ix)/((
double) oversample) - cx;
2073 double r = sqrt(yy2 + xx2);
2074 double th = atan2(yy,xx);
2075 double elr = a*(1-e*e)/(1 - e*cos(th - ang));
2076 double ndr = (elr - r)/width;
2078 if (fabs(ndr) < 6) {
2079 double val = strength*exp(-2*ndr*ndr)/width*sqrt(2.0/M_PI);
2085 m_Data -> setValue(x, y,
m_Data -> value(x,y) + sum/(oversample*oversample));
2097 if (this->get_SaveIntegratedData()) {
2101 expt->openScanFile();
2102 f->writeOutputScan(expt->scanFile(),
data);
2106 if (this->get_SaveIntegratedInSeparateFiles()) {
2114 if (this->get_DisplayIntegratedData()) {
2122 quint32 *buff =
new quint32[sz];
2128 for (
int i=0; i<10; i++) {
2129 QString
fileName = path+tr(
"%1.junk").arg(i,5,10,QChar(
'0'));
2131 FILE *f = fopen(qPrintable(fileName),
"w");
2134 fwrite(buff, sz,
sizeof(quint32), f);
2137 int dt = tic.restart();
2139 printMessage(tr(
"file %1 written in %2 msec").arg(fileName).arg(dt));
2144 .arg(((
double) sz)*40.0*1000.0/(1e6*((
double) totalt))));
2154 double *res =
new double[65536];
2155 long npixels = (
m_Data -> get_Height()) * (
m_Data -> get_Width());
2159 for (
int i=0; i<65536; i++) {
2163 for (
long i=0; i<npixels; i++) {
2165 short bin = maskp[i];
2170 int dt = tic.restart();
2184 double *res =
new double[65536];
2185 long npixels =
m_Data -> get_Height() *
m_Data -> get_Width();
2189 double minVal = *
data;
2190 double maxVal = minVal;
2192 for (
long i=0; i<npixels; i++) {
2194 if (v < minVal) minVal = v;
2195 if (v > maxVal) maxVal = v;
2198 for (
int i=0; i<65536; i++) {
2202 for (
long i=0; i<npixels; i++) {
2204 short bin = maskp[i];
2208 int dt = tic.restart();
2210 printMessage(tr(
"Histogram calculated in %1 msec").arg(dt));
2260 for (
int y=y0; y<y1; y++) {
2261 for (
int x=x0; x<x1; x++) {
2262 if (msk->value(x,y)) {
2263 sum += dat->value(x,y);
2269 for (
int y=y0; y<y1; y++) {
2270 for (
int x=x0; x<x1; x++) {
2271 sum += dat->value(x,y);
2277 printMessage(tr(
"integrateRectange(\"%1\",%2,%3,%4,%5)=[%6,%7]=%8")
2278 .arg(dat->get_FileName())
2279 .arg(x0).arg(y0).arg(x1).arg(y1).arg(sum).arg(npx).arg(sum/npx));
2282 res << tr(
"%1").arg(sum/npx);
2287 res << tr(
"%1").arg(sum);
2288 res << tr(
"%1").arg(npx);
2289 res << dat->get_FileName();
2315 int wid = dat->get_Width();
2316 int ht = dat->get_Height();
2318 for (
int y=0; y<ht; y++) {
2319 for (
int x=0; x<wid; x++) {
2320 dat->setValue(x, y, dat->value(x, y) * scalar);
2329 int wid = dat->get_Width();
2330 int ht = dat->get_Height();
2332 for (
int y=0; y<ht; y++) {
2333 for (
int x=0; x<wid; x++) {
2334 dat->setValue(x, y, dat->value(x, y) + offset);
2349 mask = masks->value(get_ZingerMask());
2352 int wid =
m_Data->get_Width();
2353 int ht =
m_Data->get_Height();
2354 int sz1 = get_ZingerSize1();
2355 int sz2 = get_ZingerSize2();
2356 double thr = get_ZingerThreshold();
2361 for (
int y=0; y<ht; y++) {
2362 for (
int x=0; x<wid; x++) {
2363 if (mask==NULL || mask->value(x,y)) {
2364 double sum = 0, n = 0;
2367 for (
int dy=-sz2; dy<=sz2; dy++) {
2368 for (
int dx=-sz2; dx<=sz2; dx++) {
2369 if (mask==NULL || mask->value(x+dx, y+dy)) {
2370 if (dx == 0 && dy == 0) {
2371 val =
m_Data->value(x+dx, y+dy);
2373 sum +=
m_Data->value(x+dx, y+dy);
2380 if (n > 0 && fabs(val-sum/n) >= thr) {
2381 dest->setValue(x,y,0);
2388 for (
int i=0; i<sz1; i++) {
2394 for (
int y=0; y<ht; y++) {
2395 for (
int x=0; x<wid; x++) {
2396 if (mask->value(x,y) == 0) {
2397 dest->setValue(x,y,0);
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
QxrdPolarTransformPtr polarTransform() const
QSharedPointer< QxrdCenterFinder > QxrdCenterFinderPtr
QSharedPointer< QxrdWindow > QxrdWindowPtr
void multiplyData(double scalar)
void calculateHistogram()
QcepMaskDataPtr mask() const
QxrdMaskStackPtr maskStack()
QcepDoubleImageDataPtr m_BadPixels
void powderRing(double cx, double cy, double radius, double width, double strength, int oversample)
QString experimentDirectory() const
static QcepIntegratedDataPtr newIntegratedData(AllocationStrategy strat, QcepDoubleImageDataPtr image, QcepObject *parent)
void orNotMaskStack(int pos)
void newBadPixelsImage(QcepDoubleImageDataPtr image)
qint64 qcepDebug(int cond)
void subtractDarkImage(QcepDoubleImageDataPtr image, QcepDoubleImageDataPtr dark)
void showMaskAllStack(int pos)
QcepDoubleImageDataPtr m_GainMap
QxrdPolarNormalizationPtr m_PolarNormalization
QSharedPointer< QxrdAcquisition > QxrdAcquisitionPtr
virtual void readSettings(QSettings *set, QString section)
void loadData(QString name)
QcepMaskDataPtr m_Overflow
QcepDoubleImageDataPtr darkImage() const
void invertMaskStack(int pos)
QString rawOutputDirectory() const
QxrdCenterFinderPtr m_CenterFinder
void newDarkImage(QcepInt16ImageDataPtr image)
void saveOutputScan(QString fileName)
QxrdAcquisitionWPtr m_Acquisition
QcepDoubleImageDataPtr processAcquiredImage(QcepDoubleImageDataPtr processed, QcepDoubleImageDataPtr dimg, QcepDoubleImageDataPtr dark, QcepMaskDataPtr mask, QcepMaskDataPtr overflow, QcepDoubleList v=QcepDoubleList())
void saveNamedImageDataAsText(QString name, QcepDoubleImageDataPtr image, QcepMaskDataPtr overflow, int canOverwrite=NoOverwrite)
QcepDoubleImageDataPtr takeNextFreeImage(int width, int height)
void criticalMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
QString filePathInSubtractedOutputDirectory(QString name) const
QxrdDistortionCorrectionPtr distortionCorrection() const
void appendToOutputScan(double x, double y)
QxrdGenerateTestImageWPtr generateTestImage() const
void xorNotMaskStack(int pos)
void hideMaskAllStack(int pos)
QString filePathInExperimentDirectory(QString name) const
void saveDark(QString name, int canOverwrite=NoOverwrite)
void newData(QcepDoubleImageDataPtr image, QcepMaskDataPtr overflow)
JSON Parse a string as a JSON object
void newOutputScan(QString title)
void setWindow(QxrdWindowWPtr win)
QWeakPointer< QxrdExperiment > QxrdExperimentWPtr
void statusMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
void newImage(int ncols, int nrows)
QSharedPointer< QcepIntegratedData > QcepIntegratedDataPtr
void popMaskStack(int amount=1)
QxrdGenerateTestImagePtr m_GenerateTestImage
int incrementAcquiredCount()
void saveCachedIntensity(QString name)
void updateEstimatedTime(QcepDoubleProperty *prop, int msec)
QxrdDataProcessorBase(QcepSettingsSaverWPtr saver, QxrdExperimentWPtr doc, QxrdAcquisitionWPtr acq, QxrdFileSaverWPtr filesaver)
void saveData(QString name, int canOverwrite=NoOverwrite)
void ellipse(double cx, double cy, double a, double e, double ang, double width, double strength, int oversample)
void readSettings(QSettings *settings, QString section)
void newGainMapImage(QcepDoubleImageDataPtr image)
void writeSettings(QSettings *settings, QString section)
void maskCircle(QRectF pt)
int newMaskHeight() const
QcepDoubleImageDataPtr m_DarkFrame
void maskPolygon(QVector< QPointF > poly)
QcepDoubleImageDataPtr gainMap() const
void createMaskIfNeeded()
static QcepDoubleImageDataPtr newDoubleImage(AllocationStrategy strat, int width, int height, QcepObject *parent)
#define INVOKE_CHECK(res)
QxrdIntegratorPtr integrator() const
void printMeasuredPolygon(QVector< QPointF > poly)
void updateEstimatedProcessingTime()
void exchangeMaskStack(int pos)
QcepDoubleImageDataPtr badPixels() const
QWeakPointer< QxrdWindow > QxrdWindowWPtr
QSharedPointer< QxrdGenerateTestImage > QxrdGenerateTestImagePtr
QAtomicInt m_AcquiredCount
void saveGainMap(QString name, int canOverwrite=NoOverwrite)
void newIntegrationAvailable(QcepIntegratedDataPtr data)
QString existingOutputDirectory(QString dir, QString subdir) const
int decrementAcquiredCount()
bool displayIntegratedData
void showMaskRangeStack(int pos)
void hideMaskRangeStack(int pos)
QcepDoubleImageDataPtr data() const
int maskStackPosition(int pos)
void loadBadPixels(QString name)
QSharedPointer< QxrdPolarNormalization > QxrdPolarNormalizationPtr
void saveCachedGeometry(QString name)
void measurePolygon(QVector< QPointF > poly)
QWeakPointer< QxrdFileSaver > QxrdFileSaverWPtr
QString filePathInDarkOutputDirectory(QString name) const
QStringList integrateRectangle(int x0, int y0, int x1, int y1)
QWeakPointer< QxrdGenerateTestImage > QxrdGenerateTestImageWPtr
QList< double > QcepDoubleList
QxrdExperimentWPtr m_Experiment
QcepIntegratedDataPtr m_OutputScan
void correctBadPixels(QcepDoubleImageDataPtr image)
QcepDoubleImageDataPtr m_Data
void xorMaskStack(int pos)
QSharedPointer< QxrdIntegrator > QxrdIntegratorPtr
QSharedPointer< QcepSettingsSaver > QcepSettingsSaverPtr
void summarizeMeasuredPolygon(QVector< QPointF > poly)
QxrdIntegratorPtr m_Integrator
QcepDoubleImageDataPtr processAcquiredDoubleImage(QcepDoubleImageDataPtr processed, QcepDoubleImageDataPtr image, QcepDoubleImageDataPtr dark, QcepMaskDataPtr mask, QcepMaskDataPtr overflow)
void writeOutputScan(QcepIntegratedDataPtr d)
void pushMaskStack(QcepMaskDataPtr mask=QcepMaskDataPtr())
QxrdPolarTransformPtr m_PolarTransform
void saveNamedMaskData(QString name, QcepMaskDataPtr mask, int canOverwrite=NoOverwrite)
void loadMask(QString name)
void offsetData(double offset)
virtual void writeSettings(QSettings *set, QString section)
void setAcquisition(QxrdAcquisitionWPtr acq)
QSharedPointer< QcepDataObject > QcepDataObjectPtr
void shrinkMaskStack(int pos)
QcepDoubleImageDataPtr m_LiveData
QString subtractedOutputDirectory() const
void unsubtractDarkImage(QcepDoubleImageDataPtr image, QcepDoubleImageDataPtr dark)
QxrdPolarNormalizationPtr polarNormalization() const
QWeakPointer< QxrdAcquisition > QxrdAcquisitionWPtr
QSharedPointer< QcepInt32ImageData > QcepInt32ImageDataPtr
QcepDoubleImageDataPtr processAcquiredInt16Image(QcepDoubleImageDataPtr processed, QcepInt16ImageDataPtr image, QcepDoubleImageDataPtr dark, QcepMaskDataPtr mask, QcepMaskDataPtr overflow)
QSharedPointer< QxrdFileSaver > QxrdFileSaverPtr
double estimatedProcessingTime
void growMaskStack(int pos)
void orMaskStack(int pos)
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
QxrdDistortionCorrectionPtr m_DistortionCorrection
QWaitCondition m_ProcessWaiting
void andNotMaskStack(int pos)
QString darkOutputDirectory() const
void valueChanged(double val, int index)
QString filePathInDataDirectory(QString name) const
void saveNamedImageData(QString name, QcepDoubleImageDataPtr image, QcepMaskDataPtr overflow, int canOverwrite=NoOverwrite)
QxrdCenterFinderPtr centerFinder() const
void reciprocalTail(double cx, double cy, double strength, int oversample)
void loadDark(QString name)
void rollMaskStack(int amount)
QxrdExperimentPtr experiment() const
void loadGainMap(QString name)
virtual ~QxrdDataProcessorBase()
static QcepMaskDataPtr newMask(AllocationStrategy strat, int width, int height, int def, QcepObject *parent)
QString filePathInIntegratedOutputDirectory(QString name) const
void valueChanged(int val, int index)
QcepDoubleImageDataPtr processAcquiredInt32Image(QcepDoubleImageDataPtr processed, QcepInt32ImageDataPtr image, QcepDoubleImageDataPtr dark, QcepMaskDataPtr mask, QcepMaskDataPtr overflow)
QSharedPointer< QcepInt16ImageData > QcepInt16ImageDataPtr
void fileWriteTest(int dim, QString path)
QSharedPointer< QcepMaskData > QcepMaskDataPtr
QxrdFileSaverWPtr m_FileSaver
QcepMaskDataPtr overflow() const
QcepDoubleImageDataPtr liveData() const
QSharedPointer< QxrdDistortionCorrection > QxrdDistortionCorrectionPtr
void saveMask(QString name, int canOverwrite=NoOverwrite)
void exponentialTail(double cx, double cy, double width, int oversample)
void valueChanged(bool val, int index)
QWeakPointer< QcepSettingsSaver > QcepSettingsSaverWPtr
QString dataDirectory() const
QString filePathInRawOutputDirectory(QString name) const
void andMaskStack(int pos)
void saveNamedRawImageData(QString name, QcepInt16ImageDataPtr image, QcepMaskDataPtr overflow, int canOverwrite=NoOverwrite)
void correctImageGains(QcepDoubleImageDataPtr image)
void saveBadPixels(QString name, int canOverwrite=NoOverwrite)
QSharedPointer< QcepDoubleImageData > QcepDoubleImageDataPtr
QString integratedOutputDirectory() const