Shows a histogram in a Qwt_Plot and a report (selectable) in a QTextEdit Makes the data Values from a itk::histogram suitable for a Qwt_Plot. Offers zoom possibility. A marker can be set and shows the frequency at his position. More...
#include <QmitkHistogramWidget.h>
Public Types | |
typedef mitk::Image::HistogramType | HistogramType |
Public Member Functions | |
QmitkHistogramWidget (QWidget *parent=0, bool showreport=false) | |
virtual | ~QmitkHistogramWidget () |
void | SetHistogram (HistogramType::ConstPointer histogram) |
void | SetHistogram (mitk::Image *mitkImage) |
void | SetReport (std::string report) |
double | GetMarkerPosition () |
Protected Slots | |
void | OnSelect (const QwtDoublePoint &pos) |
Protected Member Functions | |
double | Round (double val) |
void | InitializeMarker () |
void | InitializeZoomer () |
Protected Attributes | |
QwtPlot * | m_Plot |
QTextEdit * | m_Textedit |
QwtPlotMarker * | m_Marker |
QwtPlotPicker * | m_Picker |
QwtPlotZoomer * | m_Zoomer |
QmitkHistogram * | m_Histogram |
Shows a histogram in a Qwt_Plot and a report (selectable) in a QTextEdit Makes the data Values from a itk::histogram suitable for a Qwt_Plot. Offers zoom possibility. A marker can be set and shows the frequency at his position.
Definition at line 41 of file QmitkHistogramWidget.h.
Definition at line 51 of file QmitkHistogramWidget.h.
QmitkHistogramWidget::QmitkHistogramWidget | ( | QWidget * | parent = 0 , |
bool | showreport = false |
||
) |
Definition at line 33 of file QmitkHistogramWidget.cpp.
References QwtPicker::AlwaysOn, QwtPlotItem::attach(), QwtPlot::canvas(), QwtPlotGrid::enableXMin(), QwtPlotGrid::enableYMin(), m_Picker, m_Plot, m_Textedit, QwtPicker::NoRubberBand, OnSelect(), QwtPicker::PointSelection, QwtPlot::setCanvasBackground(), QwtText::setFont(), QwtPlotGrid::setMajPen(), QwtPlotGrid::setMinPen(), QwtPlot::setTitle(), QwtTextLabel::text(), QwtPlot::titleLabel(), QwtPlot::xBottom, and QwtPlot::yLeft.
{ QBoxLayout *layout = new QVBoxLayout(this); //***histogram*** QGroupBox *hgroupbox = new QGroupBox("", this); hgroupbox->setMinimumSize(900, 400); m_Plot = new QwtPlot(hgroupbox); m_Plot->setCanvasBackground(QColor(Qt::white)); m_Plot->setTitle("Histogram"); QwtText text = m_Plot->titleLabel()->text(); text.setFont(QFont("Helvetica", 12, QFont::Normal)); QwtPlotGrid *grid = new QwtPlotGrid; grid->enableXMin(true); grid->enableYMin(true); grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine)); grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine)); grid->attach(m_Plot); layout->addWidget(hgroupbox); layout->setSpacing(20); if (showreport == true) { //***report*** QGroupBox *rgroupbox = new QGroupBox("", this); rgroupbox->setMinimumSize(900, 400); QLabel *label = new QLabel("Gray Value Analysis", rgroupbox); label->setAlignment(Qt::AlignHCenter); label->setFont(QFont("Helvetica", 14, QFont::Bold)); m_Textedit = new QTextEdit(rgroupbox); m_Textedit->setFont(QFont("Helvetica", 12, QFont::Normal)); m_Textedit->setReadOnly(true); layout->addWidget(rgroupbox); } m_Picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft, QwtPicker::PointSelection, QwtPlotPicker::NoRubberBand, QwtPicker::AlwaysOn, m_Plot->canvas()); connect(m_Picker, SIGNAL(selected(const QwtDoublePoint &)), SLOT(OnSelect(const QwtDoublePoint &))); }
QmitkHistogramWidget::~QmitkHistogramWidget | ( | ) | [virtual] |
Definition at line 87 of file QmitkHistogramWidget.cpp.
{ }
double QmitkHistogramWidget::GetMarkerPosition | ( | ) |
Definition at line 174 of file QmitkHistogramWidget.cpp.
References m_Marker, and QwtPlotMarker::xValue().
void QmitkHistogramWidget::InitializeMarker | ( | ) | [protected] |
Definition at line 140 of file QmitkHistogramWidget.cpp.
References QwtPlotItem::attach(), QwtSymbol::Diamond, m_Marker, m_Plot, QwtPlotMarker::setLabelAlignment(), QwtPlotMarker::setLinePen(), QwtPlotMarker::setLineStyle(), QwtPlotMarker::setSymbol(), QwtPlotMarker::setXValue(), and QwtPlotMarker::VLine.
Referenced by SetHistogram().
{ m_Marker = new QwtPlotMarker(); m_Marker->setXValue(0.); m_Marker->setLineStyle(QwtPlotMarker::VLine); m_Marker->setLabelAlignment(Qt::AlignHCenter | Qt::AlignRight); m_Marker->setLinePen(QPen(QColor(200,150,0), 3, Qt::SolidLine)); m_Marker->setSymbol( QwtSymbol(QwtSymbol::Diamond, QColor(Qt::red), QColor(Qt::red), QSize(10,10))); m_Marker->attach(m_Plot); }
void QmitkHistogramWidget::InitializeZoomer | ( | ) | [protected] |
Definition at line 153 of file QmitkHistogramWidget.cpp.
References QwtPlot::canvas(), m_Plot, m_Zoomer, QwtPicker::RectSelection, QwtPicker::setRubberBandPen(), QwtPlotZoomer::setSelectionFlags(), QwtPicker::setTrackerPen(), QwtPlot::xBottom, and QwtPlot::yLeft.
Referenced by SetHistogram().
{ m_Zoomer = new QwtPlotZoomer(m_Plot->xBottom, m_Plot->yLeft, m_Plot->canvas()); m_Zoomer->setRubberBandPen(QPen(Qt::red, 2, Qt::DotLine)); m_Zoomer->setTrackerPen(QPen(Qt::red)); m_Zoomer->setSelectionFlags(QwtPlotZoomer::RectSelection); }
void QmitkHistogramWidget::OnSelect | ( | const QwtDoublePoint & | pos ) | [protected, slot] |
Definition at line 161 of file QmitkHistogramWidget.cpp.
References m_Marker, m_Plot, QwtPlot::replot(), Round(), QwtText::setBackgroundBrush(), QwtText::setFont(), QwtPlotMarker::setLabel(), QwtPlotMarker::setXValue(), and QwtDoublePoint::x().
Referenced by QmitkHistogramWidget().
{ m_Marker->setXValue( this->Round(pos.x()) ); //unsigned int count = (unsigned int)(m_Histogram->data().value(pos.x())); QString str = QString( "%1" ) .arg( (int)(this->Round(pos.x())), 0, 10 ); QwtText text(str); text.setBackgroundBrush(QColor(200,150,0)); text.setFont(QFont("Helvetica", 14, QFont::Bold)); m_Marker->setLabel(text); m_Plot->replot(); }
double QmitkHistogramWidget::Round | ( | double | val ) | [protected] |
Definition at line 179 of file QmitkHistogramWidget.cpp.
Referenced by OnSelect(), and SetHistogram().
{ double ival = (double)(int)val; if( (val - ival) > 0.5) return ival+1; else return ival; }
void QmitkHistogramWidget::SetHistogram | ( | mitk::Image * | mitkImage ) |
Definition at line 130 of file QmitkHistogramWidget.cpp.
References mitk::Image::GetScalarHistogram(), and SetHistogram().
{ this->SetHistogram(mitkImage->GetScalarHistogram()); }
void QmitkHistogramWidget::SetHistogram | ( | HistogramType::ConstPointer | histogram ) |
Definition at line 92 of file QmitkHistogramWidget.cpp.
References QwtPlotItem::attach(), QwtPlot::clear(), InitializeMarker(), InitializeZoomer(), m_Histogram, m_Plot, QwtPlot::replot(), Round(), QmitkHistogram::setColor(), and QmitkHistogram::setData().
Referenced by SetHistogram().
{ HistogramType::SizeType size = itkHistogram->GetSize(); HistogramType::IndexType index; HistogramType::MeasurementVectorType currentMeasurementVector; QwtArray<QwtDoubleInterval> xValues(size[0]); QwtArray<double> yValues(size[0]); for (unsigned int i = 0; i < size[0]; ++i) { #if !defined(ITK_USE_REVIEW_STATISTICS) index[0] = static_cast<HistogramType::IndexType::IndexValueType> (i); #else index[0] = static_cast<HistogramType::IndexValueType> (i); #endif currentMeasurementVector = itkHistogram->GetMeasurementVector(index); if (currentMeasurementVector[0] != 0.0) { xValues[i] = QwtDoubleInterval(Round(currentMeasurementVector[0]-1), Round(currentMeasurementVector[0])); yValues[i] = static_cast<double> (itkHistogram->GetFrequency(index)); } } // rebuild the plot m_Plot->clear(); m_Histogram = new QmitkHistogram(); m_Histogram->setColor(Qt::darkCyan); m_Histogram->setData(QwtIntervalData(xValues, yValues)); m_Histogram->attach(m_Plot); this->InitializeMarker(); this->InitializeZoomer(); m_Plot->replot(); }
void QmitkHistogramWidget::SetReport | ( | std::string | report ) |
Definition at line 135 of file QmitkHistogramWidget.cpp.
References m_Textedit.
{ m_Textedit->setText(report.c_str()); }
QmitkHistogram* QmitkHistogramWidget::m_Histogram [protected] |
Definition at line 82 of file QmitkHistogramWidget.h.
Referenced by SetHistogram().
QwtPlotMarker* QmitkHistogramWidget::m_Marker [protected] |
Definition at line 79 of file QmitkHistogramWidget.h.
Referenced by GetMarkerPosition(), InitializeMarker(), and OnSelect().
QwtPlotPicker* QmitkHistogramWidget::m_Picker [protected] |
Definition at line 80 of file QmitkHistogramWidget.h.
Referenced by QmitkHistogramWidget().
QwtPlot* QmitkHistogramWidget::m_Plot [protected] |
Definition at line 77 of file QmitkHistogramWidget.h.
Referenced by InitializeMarker(), InitializeZoomer(), OnSelect(), QmitkHistogramWidget(), and SetHistogram().
QTextEdit* QmitkHistogramWidget::m_Textedit [protected] |
Definition at line 78 of file QmitkHistogramWidget.h.
Referenced by QmitkHistogramWidget(), and SetReport().
QwtPlotZoomer* QmitkHistogramWidget::m_Zoomer [protected] |
Definition at line 81 of file QmitkHistogramWidget.h.
Referenced by InitializeZoomer().