14 #include <qwt_plot_rescaler.h>
15 #include <qwt_plot_marker.h>
16 #include <qwt_legend.h>
17 #include <qwt_legend_label.h>
18 #include <qwt_plot_spectrogram.h>
19 #include <qwt_scale_widget.h>
20 #include <qwt_symbol.h>
21 #include <qwt_picker_machine.h>
24 #include <QContextMenuEvent>
47 m_ColorMap(new QwtLinearColorMap(Qt::black, Qt::white)),
78 m_Zoomer -> setStateMachine(
new QwtPickerDragRectMachine());
79 m_Zoomer -> setTrackerMode(QwtPicker::AlwaysOn);
80 m_Zoomer -> setRubberBand(QwtPicker::RectRubberBand);
82 m_Zoomer -> setMousePattern(QwtEventPattern::MouseSelect2,
83 Qt::LeftButton, Qt::ControlModifier | Qt::ShiftModifier);
84 m_Zoomer -> setMousePattern(QwtEventPattern::MouseSelect3,
85 Qt::LeftButton, Qt::ControlModifier);
89 m_Rescaler =
new QwtPlotRescaler(canvas(), QwtPlot::yLeft, QwtPlotRescaler::Expanding);
91 m_Rescaler -> setExpandingDirection(QwtPlotRescaler::ExpandBoth);
102 m_Legend -> setFrameStyle(QFrame::Box|QFrame::Sunken);
103 m_Legend -> setDefaultItemMode(QwtLegendData::Checkable);
238 set->set_DisplayMinimumPct(0);
239 set->set_DisplayMaximumPct(5);
248 set->set_DisplayMinimumPct(0);
249 set->set_DisplayMaximumPct(10);
258 set->set_DisplayMinimumPct(0);
259 set->set_DisplayMaximumPct(100);
268 double mindis, maxdis;
273 double del = maxv-minv;
275 mindis = minv+del*set->get_DisplayMinimumPct()/100.0;
276 maxdis = minv+del*set->get_DisplayMaximumPct()/100.0;
280 mindis = range.minValue();
281 maxdis = range.maxValue();
283 mindis = set->get_DisplayMinimumVal();
284 maxdis = set->get_DisplayMaximumVal();
372 m_ColorMap->setColorInterval(startColor, endColor);
379 if (set && set->get_DisplayLog()) {
380 int n1 = int(value1*100);
381 int n2 = int(value2*100);
382 double r1 = color1.redF();
383 double r2 = color2.redF();
384 double g1 = color1.greenF();
385 double g2 = color2.greenF();
386 double b1 = color1.blueF();
387 double b2 = color2.blueF();
389 for (
int n=n1; n<n2; n++) {
390 double pos = double(n)/100.0;
391 double val = (pow(10.0, pos) - 1.0)/9.0;
392 double interp = (pos-value1)/(value2-value1);
394 QColor col = QColor::fromRgbF(r1 + (r2-r1)*interp, g1 + (g2 - g1)*interp, b1 + (b2 - b1)*interp);
532 set->set_ImageShown(shown);
535 m_DataImage -> setAlpha(set->get_ImageShown() ? 255 : 0);
558 set->set_MaskShown(shown);
584 set->set_OverflowShown(shown);
610 set->set_DisplayROI(shown);
630 set->set_DisplayLog(isLog);
706 if (overflow == NULL) {
714 setTitle(image -> get_Title());
748 setTitle(image -> get_Title());
900 centerFinder = processor->centerFinder();
903 QString res = tr(
"%1, %2").arg(pos.x()).arg(pos.y());
908 set->set_XMouse(pos.x());
909 set->set_YMouse(pos.y());
913 double val = ras->
value(pos.x(),pos.y());
914 res += tr(
", %1").arg(val);
917 set->set_ValMouse(val);
923 res += tr(
", %1").arg(mask);
926 set->set_MaskMouse(mask);
931 double tth = centerFinder->getTTH(pos);
932 res += tr(
"\nTTH %1").arg(tth);
935 set->set_TTHMouse(tth);
938 double q = centerFinder->getQ(pos);
939 res += tr(
", Q %1").arg(q);
945 double r = centerFinder->getR(pos);
946 res += tr(
", R %1").arg(r);
952 double chi = centerFinder->getChi(pos);
953 res += tr(
", Chi %1").arg(chi);
957 res += tr(
"\nPtx %1, Pty %2").arg(rpt.x()).arg(rpt.y());
980 QMenu plotMenu(NULL, NULL);
982 QAction *auSc = plotMenu.addAction(
"Autoscale");
983 QAction *prGr = plotMenu.addAction(
"Print Graph...");
985 plotMenu.addSeparator();
993 QwtScaleMap xMap = canvasMap(QwtPlot::xBottom);
994 QwtScaleMap yMap = canvasMap(QwtPlot::yLeft);
996 QWidget *canv = canvas();
998 QPoint evlocal = canv->mapFromParent(event->pos());
1000 double x = xMap.invTransform(evlocal.x());
1001 double y = yMap.invTransform(evlocal.y());
1005 QAction *fitCircle = plotMenu.addAction(tr(
"Fit Circle Center from Points on Ring %1").arg(nearest.
n1()));
1006 QAction *fitEllipse = plotMenu.addAction(tr(
"Fit Ellipse from Points on Ring %1").arg(nearest.
n1()));
1007 QAction *fitEllipses = plotMenu.addAction(tr(
"Fit Ellipses to all powder rings"));
1009 QAction *adjustEnergy = plotMenu.addAction(tr(
"Adjust Energy to match Calibrant Ring %1").arg(nearest.
n1()));
1010 QAction *adjustDistance = plotMenu.addAction(tr(
"Adjust Detector Distance to match Calibrant Ring %1").arg(nearest.
n1()));
1012 QAction *adjustFit = plotMenu.addAction(tr(
"Fit to nearby peak when adding powder points?"));
1013 adjustFit->setCheckable(
true); adjustFit->setChecked(cf->get_FitPowderPointPosition());
1014 QAction *addPoint = plotMenu.addAction(tr(
"Add point at (%1,%2)").arg(x).arg(y));
1015 QAction *delPoint = plotMenu.addAction(tr(
"Delete point at (%1,%2)").arg(nearest.
x()).arg(nearest.
y()));
1016 QAction *delRing = plotMenu.addAction(tr(
"Delete Ring %1").arg(nearest.
n1()));
1017 QAction *deleteAllPoints = plotMenu.addAction(tr(
"Delete all Rings"));
1018 QAction *disableRing = plotMenu.addAction(tr(
"Disable Ring %1").arg(nearest.
n1()));
1019 QAction *enableRing = plotMenu.addAction(tr(
"Enable Ring %1").arg(nearest.
n1()));
1020 QAction *normalizeRings = plotMenu.addAction(tr(
"Normalize Powder Rings"));
1021 QAction *fitPeakNear = plotMenu.addAction(tr(
"Fit Diffracted Peak near (%1,%2) [%3,%4]").arg(x).arg(y).arg(event->x()).arg(event->y()));
1022 QAction *fitRingNear = plotMenu.addAction(tr(
"Fit Point on Diffracted Ring near (%1,%2) [%3,%4]").arg(x).arg(y).arg(event->x()).arg(event->y()));
1023 QAction *traceRingClockwise = plotMenu.addAction(tr(
"Trace Diffracted Ring starting at (%1,%2) [%3,%4]").arg(x).arg(y).arg(event->x()).arg(event->y()));
1024 QAction *missingRing = plotMenu.addAction(tr(
"Missing Diffracted Ring near (%1,%2)").arg(x).arg(y));
1026 QAction *
zapPixel = plotMenu.addAction(tr(
"Zap (replace with avg of neighboring values) pixel [%1,%2]").arg((
int)x).arg(
int(y)));
1028 QAction *action = plotMenu.exec(event->globalPos());
1030 if (action == auSc) {
1032 }
else if (action == prGr) {
1034 }
else if (action == fitCircle) {
1035 cf->fitPowderCircle(nearest.
n1());
1036 }
else if (action == fitEllipse) {
1037 cf->fitPowderEllipse(nearest.
n1());
1038 }
else if (action == fitEllipses) {
1039 cf->fitPowderEllipses();
1040 }
else if (action == adjustEnergy) {
1041 cf->adjustEnergy(nearest.
n1());
1042 }
else if (action == adjustDistance) {
1043 cf->adjustDistance(nearest.
n1());
1044 }
else if (action == adjustFit) {
1045 cf->toggle_FitPowderPointPosition();
1046 }
else if (action == addPoint) {
1047 cf->appendPowderPoint(x,y);
1048 }
else if (action == delPoint) {
1049 cf->deletePowderPointNear(x,y);
1050 }
else if (action == delRing) {
1051 cf->deletePowderRing(nearest.
n1());
1052 }
else if (action == deleteAllPoints) {
1053 cf->deletePowderPoints();
1054 }
else if (action == enableRing) {
1055 cf->enablePowderRing(nearest.
n1());
1056 }
else if (action == disableRing) {
1057 cf->disablePowderRing(nearest.
n1());
1058 }
else if (action == normalizeRings) {
1059 cf->normalizePowderRings();
1060 }
else if (action == fitPeakNear) {
1061 QMetaObject::invokeMethod(cf.data(),
"fitPeakNear",
1064 }
else if (action == fitRingNear) {
1065 QMetaObject::invokeMethod(cf.data(),
"fitRingNear",
1068 }
else if (action == traceRingClockwise) {
1069 QMetaObject::invokeMethod(cf.data(),
"traceRingNear",
1072 Q_ARG(
double,25.0));
1073 }
else if (action == missingRing) {
1074 cf->missingRingNear(x,y);
1083 }
else if (action == zapPixel) {
1084 this->
zapPixel(qRound(x),qRound(y));
1101 for (
int ix = x-1; ix <= x+1; ix++) {
1102 for (
int iy = y-1; iy <= y+1; iy++) {
1103 sum +=
m_Data->getImageData(ix, iy);
1108 sum -=
m_Data->getImageData(x,y);
1111 m_Data->setImageData(x,y, sum/npx);
1133 int nrgs = cf->countPowderRings();
1134 int npts = cf->countPowderRingPoints();
1136 for (
int r=0; r<nrgs; r++) {
1137 QVector<double> x,y;
1139 for (
int i=0; i<npts; i++) {
1148 if (x.count() > 0) {
1149 QwtPlotCurve *pc =
new QwtPlotCurve(tr(
"Ring %1").arg(r));
1152 pc -> setSamples(x, y);
1153 pc -> setStyle(QwtPlotCurve::NoCurve);
1154 pc -> setLegendAttribute(QwtPlotCurve::LegendShowSymbol,
true);
1181 set->set_DisplayROI(enable);
1231 int nROI =
m_ROIModel->rowCount(QModelIndex());
1233 for (
int i=0; i<nROI; i++) {
1237 QVector<QPointF> pts = roi->markerCoords();
1243 bool on =
m_ROISelection->rowIntersectsSelection(i, QModelIndex());
1246 QPen pen = pc->pen();
1247 const QwtSymbol *oldsym = pc->symbol();
1248 QwtSymbol *sym = NULL;
1251 sym =
new QwtSymbol(oldsym->style(), oldsym->brush(), oldsym->pen(), oldsym->size());
1271 pc->setSamples(pts);
1285 QwtPlotItem *item = infoToItem(itemInfo);
1288 QwtPlotCurve *pc =
dynamic_cast<QwtPlotCurve*
>(item);
1296 QItemSelectionModel::Select | QItemSelectionModel::Rows);
1299 QItemSelectionModel::Deselect | QItemSelectionModel::Rows);
1313 QPen pen = pc->pen();
1314 const QwtSymbol *oldsym = pc->symbol();
1315 QwtSymbol *sym = NULL;
1318 sym =
new QwtSymbol(oldsym->style(), oldsym->brush(), oldsym->pen(), oldsym->size());
1341 const QVariant itemInfo = itemToInfo(
m_ROICurves.value(i));
1343 QwtLegendLabel *legendLabel =
1344 qobject_cast<QwtLegendLabel*>(
1348 legendLabel->setChecked(on);
1353 const QItemSelection &selected,
1354 const QItemSelection &deselected)
1359 for (
int i=0; i<n; i++) {
1360 bool sel =
m_ROISelection->rowIntersectsSelection(i, QModelIndex());
1375 for (
int i=0; i<n; i++) {
void changeMaskShown(bool shown)
QSharedPointer< QxrdCenterFinder > QxrdCenterFinderPtr
void changeOverflowShown(bool shown)
virtual void criticalMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())=0
QxrdROICoordinatesListModelPtr m_ROIModel
QWeakPointer< QxrdDataProcessor > QxrdDataProcessorWPtr
QwtPlotSpectrogram * m_DataImage
void changeImageShown(bool shown)
qint64 qcepDebug(int cond)
void setDisplayedRange(double min, double max)
QwtPlotMarker * m_CenterMarker
QxrdPlotSlicer * m_Slicer
QSharedPointer< QxrdROICoordinates > QxrdROICoordinatesPtr
void selectHistogram(QRectF rect)
QcepObjectNamer m_ObjectNamer
QwtLinearColorMap * m_ColorMap
void setInverseGrayscale()
void contextMenuEvent(QContextMenuEvent *event)
void moveSelectedROICenter(double x, double y)
QSharedPointer< QxrdDataProcessor > QxrdDataProcessorPtr
void toggleShowOverflow()
QVector< QwtPlotCurve * > m_PowderPointCurves
void onImageScaleChanged()
QxrdImagePlotSettingsWPtr imagePlotSettings()
void setROISelection(QItemSelectionModel *select)
void onDarkImageAvailable(QcepImageDataBasePtr image)
void setMask(QxrdMaskRasterData *data)
void setPlotCurveStyle(int index, QwtPlotCurve *curve)
QwtInterval percentileRange(double lowpct, double highpct)
QwtPlotSpectrogram * m_OverflowImage
void valueChanged(QxrdPowderPointVector val, int index)
QWeakPointer< QxrdImagePlotSettings > QxrdImagePlotSettingsWPtr
QxrdImagePlotSettingsWPtr m_ImagePlotSettings
QxrdDataProcessorWPtr processor() const
void colorMapRange(double value1, QColor color1, double value2, QColor color2)
void maskCircle(QRectF pt)
void onPointSelected(QPointF pt)
void maskPolygon(QVector< QPointF > poly)
void setProcessor(QxrdDataProcessorWPtr proc)
const QxrdRasterData * raster() const
void zapPixel(int x, int y)
void updateROISelection(const QItemSelection &selected, const QItemSelection &deselected)
void onCenterYChanged(double cy)
const QxrdMaskRasterData * maskRaster() const
QxrdMaskRasterData * m_MaskRaster
void onCenterChanged(QPointF c)
QwtPlotSpectrogram * m_MaskImage
void init(QxrdImagePlotSettingsWPtr settings)
QwtPlotRescaler * m_Rescaler
A class which draws piecewise curves.
QxrdMaskColorMap * m_MaskColorMap
void init(QcepPlotSettingsWPtr settings)
QxrdImagePlotMeasurer * m_Measurer
void measurePolygon(QVector< QPointF > poly)
QxrdMaskRasterData * m_OverflowRaster
QxrdMaskPicker * m_Polygons
void setColorMap(int index)
void slicePolygon(QVector< QPointF > poly)
QxrdImagePlot(QWidget *parent=0)
void changeROIShown(bool shown)
virtual void onLegendChecked(const QVariant &itemInfo, bool on, int index)
void recalculateDisplayedRange()
void enablePowderPoints()
double value(double x, double y) const
void onCenterChanged(QPointF pt)
QxrdMaskPicker * m_Circles
QSharedPointer< QxrdImagePlotSettings > QxrdImagePlotSettingsPtr
void clearPowderMarkers()
void onMarkedPointsChanged()
QxrdHistogramSelector * m_HistogramSelector
void setTrackerPen(const QPen &pen)
QcepMaskDataPtr m_Overflow
void onMaintainAspectChanged(bool interp)
QItemSelectionModel * m_ROISelection
QxrdMaskColorMap * m_OverflowColorMap
void onMaskedImageAvailable(QcepImageDataBasePtr image, QcepMaskDataPtr mask)
QxrdRasterData * m_DataRaster
void displayPowderMarkers()
void selectROIItem(int n, bool selected)
QPointF optimizePeakPosition(QPointF pt) const
bool m_ContextMenuEnabled
virtual void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())=0
double value(double x, double y) const
void onProcessedImageAvailable(QcepImageDataBasePtr image, QcepMaskDataPtr overflow)
QcepApplication * g_Application
void enableMaskPolygons()
virtual void onLegendChecked(const QVariant &itemInfo, bool on, int index)
void selectROILabel(int i, bool on)
void valueChanged(double val, int index)
void setOverflows(QxrdMaskRasterData *overflow)
void changeLogDisplay(bool isLog)
QxrdDataProcessorWPtr m_DataProcessor
void valueChanged(int val, int index)
QSharedPointer< QcepImageDataBase > QcepImageDataBasePtr
QSharedPointer< QcepMaskData > QcepMaskDataPtr
void setROIModel(QxrdROICoordinatesListModelPtr model)
virtual QwtText trackerTextF(const QPointF &pos)
void setImage(QxrdRasterData *data)
void disableContextMenu()
QSharedPointer< QxrdROICoordinatesListModel > QxrdROICoordinatesListModelPtr
void valueChanged(bool val, int index)
void onCenterXChanged(double cx)
QxrdCenterFinderPicker * m_CenterFinderPicker
QVector< QwtPlotCurve * > m_ROICurves
QcepImageDataBasePtr m_Data
void enableROIDisplay(bool enable)
QxrdPowderPointPicker * m_PowderPointPicker
void onInterpolateChanged(bool interp)
void colorMapStart(QColor startColor, QColor endColor)
void setInterpolate(int interp)