Public Types | Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes

QmitkHistogramWidget Class Reference

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>

Collaboration diagram for QmitkHistogramWidget:
Collaboration graph
[legend]

List of all members.

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

QwtPlotm_Plot
QTextEdit * m_Textedit
QwtPlotMarkerm_Marker
QwtPlotPickerm_Picker
QwtPlotZoomerm_Zoomer
QmitkHistogramm_Histogram

Detailed Description

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.


Member Typedef Documentation

Definition at line 51 of file QmitkHistogramWidget.h.


Constructor & Destructor Documentation

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.

{

}

Member Function Documentation

double QmitkHistogramWidget::GetMarkerPosition (  )

Definition at line 174 of file QmitkHistogramWidget.cpp.

References m_Marker, and QwtPlotMarker::xValue().

{
  return m_Marker->xValue();
}
void QmitkHistogramWidget::InitializeMarker (  ) [protected]
void QmitkHistogramWidget::InitializeZoomer (  ) [protected]
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 )
  • gets the data values from either a itk histogram or a mitk image
  • copies them into data arrays suitable for qwt
  • creates a plot dialog, fill it with the data and shows it

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());
}

Member Data Documentation

Definition at line 82 of file QmitkHistogramWidget.h.

Referenced by SetHistogram().

Definition at line 79 of file QmitkHistogramWidget.h.

Referenced by GetMarkerPosition(), InitializeMarker(), and OnSelect().

Definition at line 80 of file QmitkHistogramWidget.h.

Referenced by QmitkHistogramWidget().

QTextEdit* QmitkHistogramWidget::m_Textedit [protected]

Definition at line 78 of file QmitkHistogramWidget.h.

Referenced by QmitkHistogramWidget(), and SetReport().

Definition at line 81 of file QmitkHistogramWidget.h.

Referenced by InitializeZoomer().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines