Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "QmitkHistogramWidget.h"
00019
00020 #include <qlabel.h>
00021 #include <qpen.h>
00022 #include <qgroupbox.h>
00023
00024 #include <qwt_plot_grid.h>
00025 #include <qwt_interval_data.h>
00026 #include <qwt_array.h>
00027 #include <qwt_text_label.h>
00028 #include <qwt_text.h>
00029 #include <qwt_symbol.h>
00030
00031
00032
00033 QmitkHistogramWidget::QmitkHistogramWidget(QWidget * , bool showreport)
00034 {
00035 QBoxLayout *layout = new QVBoxLayout(this);
00036
00037
00038
00039 QGroupBox *hgroupbox = new QGroupBox("", this);
00040
00041 hgroupbox->setMinimumSize(900, 400);
00042
00043 m_Plot = new QwtPlot(hgroupbox);
00044 m_Plot->setCanvasBackground(QColor(Qt::white));
00045 m_Plot->setTitle("Histogram");
00046 QwtText text = m_Plot->titleLabel()->text();
00047 text.setFont(QFont("Helvetica", 12, QFont::Normal));
00048
00049 QwtPlotGrid *grid = new QwtPlotGrid;
00050 grid->enableXMin(true);
00051 grid->enableYMin(true);
00052 grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
00053 grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine));
00054 grid->attach(m_Plot);
00055
00056 layout->addWidget(hgroupbox);
00057
00058 layout->setSpacing(20);
00059
00060 if (showreport == true)
00061 {
00062
00063 QGroupBox *rgroupbox = new QGroupBox("", this);
00064
00065 rgroupbox->setMinimumSize(900, 400);
00066
00067 QLabel *label = new QLabel("Gray Value Analysis", rgroupbox);
00068 label->setAlignment(Qt::AlignHCenter);
00069 label->setFont(QFont("Helvetica", 14, QFont::Bold));
00070
00071 m_Textedit = new QTextEdit(rgroupbox);
00072 m_Textedit->setFont(QFont("Helvetica", 12, QFont::Normal));
00073 m_Textedit->setReadOnly(true);
00074
00075 layout->addWidget(rgroupbox);
00076 }
00077
00078 m_Picker = new QwtPlotPicker(QwtPlot::xBottom, QwtPlot::yLeft,
00079 QwtPicker::PointSelection,
00080 QwtPlotPicker::NoRubberBand, QwtPicker::AlwaysOn,
00081 m_Plot->canvas());
00082
00083 connect(m_Picker, SIGNAL(selected(const QwtDoublePoint &)),
00084 SLOT(OnSelect(const QwtDoublePoint &)));
00085 }
00086
00087 QmitkHistogramWidget::~QmitkHistogramWidget()
00088 {
00089
00090 }
00091
00092 void QmitkHistogramWidget::SetHistogram(HistogramType::ConstPointer itkHistogram)
00093 {
00094 HistogramType::SizeType size = itkHistogram->GetSize();
00095 HistogramType::IndexType index;
00096 HistogramType::MeasurementVectorType currentMeasurementVector;
00097
00098 QwtArray<QwtDoubleInterval> xValues(size[0]);
00099 QwtArray<double> yValues(size[0]);
00100
00101 for (unsigned int i = 0; i < size[0]; ++i)
00102 {
00103 #if !defined(ITK_USE_REVIEW_STATISTICS)
00104 index[0] = static_cast<HistogramType::IndexType::IndexValueType> (i);
00105 #else
00106 index[0] = static_cast<HistogramType::IndexValueType> (i);
00107 #endif
00108 currentMeasurementVector = itkHistogram->GetMeasurementVector(index);
00109 if (currentMeasurementVector[0] != 0.0)
00110 {
00111 xValues[i] = QwtDoubleInterval(Round(currentMeasurementVector[0]-1), Round(currentMeasurementVector[0]));
00112 yValues[i] = static_cast<double> (itkHistogram->GetFrequency(index));
00113 }
00114 }
00115
00116
00117 m_Plot->clear();
00118
00119 m_Histogram = new QmitkHistogram();
00120 m_Histogram->setColor(Qt::darkCyan);
00121 m_Histogram->setData(QwtIntervalData(xValues, yValues));
00122 m_Histogram->attach(m_Plot);
00123
00124 this->InitializeMarker();
00125 this->InitializeZoomer();
00126
00127 m_Plot->replot();
00128 }
00129
00130 void QmitkHistogramWidget::SetHistogram( mitk::Image* mitkImage )
00131 {
00132 this->SetHistogram(mitkImage->GetScalarHistogram());
00133 }
00134
00135 void QmitkHistogramWidget::SetReport(std::string report)
00136 {
00137 m_Textedit->setText(report.c_str());
00138 }
00139
00140 void QmitkHistogramWidget::InitializeMarker()
00141 {
00142 m_Marker = new QwtPlotMarker();
00143 m_Marker->setXValue(0.);
00144 m_Marker->setLineStyle(QwtPlotMarker::VLine);
00145 m_Marker->setLabelAlignment(Qt::AlignHCenter | Qt::AlignRight);
00146 m_Marker->setLinePen(QPen(QColor(200,150,0), 3, Qt::SolidLine));
00147 m_Marker->setSymbol( QwtSymbol(QwtSymbol::Diamond,
00148 QColor(Qt::red), QColor(Qt::red), QSize(10,10)));
00149 m_Marker->attach(m_Plot);
00150 }
00151
00152
00153 void QmitkHistogramWidget::InitializeZoomer()
00154 {
00155 m_Zoomer = new QwtPlotZoomer(m_Plot->xBottom, m_Plot->yLeft, m_Plot->canvas());
00156 m_Zoomer->setRubberBandPen(QPen(Qt::red, 2, Qt::DotLine));
00157 m_Zoomer->setTrackerPen(QPen(Qt::red));
00158 m_Zoomer->setSelectionFlags(QwtPlotZoomer::RectSelection);
00159 }
00160
00161 void QmitkHistogramWidget::OnSelect( const QwtDoublePoint& pos )
00162 {
00163 m_Marker->setXValue( this->Round(pos.x()) );
00164
00165 QString str = QString( "%1" )
00166 .arg( (int)(this->Round(pos.x())), 0, 10 );
00167 QwtText text(str);
00168 text.setBackgroundBrush(QColor(200,150,0));
00169 text.setFont(QFont("Helvetica", 14, QFont::Bold));
00170 m_Marker->setLabel(text);
00171 m_Plot->replot();
00172 }
00173
00174 double QmitkHistogramWidget::GetMarkerPosition()
00175 {
00176 return m_Marker->xValue();
00177 }
00178
00179 double QmitkHistogramWidget::Round(double val)
00180 {
00181 double ival = (double)(int)val;
00182 if( (val - ival) > 0.5)
00183 return ival+1;
00184 else
00185 return ival;
00186 }