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 "QmitkVtkHistogramWidget.h"
00019
00020 #include "mitkHistogramGenerator.h"
00021
00022 #include <qlabel.h>
00023 #include <qpen.h>
00024 #include <qgroupbox.h>
00025
00026
00027 #include <vtkQtChartArea.h>
00028 #include <vtkQtChartTableSeriesModel.h>
00029 #include <vtkQtChartStyleManager.h>
00030 #include <vtkQtChartColorStyleGenerator.h>
00031
00032 #include <vtkQtChartMouseSelection.h>
00033 #include <vtkQtChartInteractorSetup.h>
00034 #include <vtkQtChartSeriesSelectionHandler.h>
00035 #include <vtkQtChartAxisLayer.h>
00036 #include <vtkQtChartAxis.h>
00037 #include <vtkQtChartAxisOptions.h>
00038 #include <vtkQtChartLegend.h>
00039 #include <vtkQtChartLegendManager.h>
00040
00041
00042
00043 QmitkVtkHistogramWidget::QmitkVtkHistogramWidget( QWidget * )
00044 : m_HistogramMode( HISTOGRAM_MODE_ENTIREIMAGE )
00045 {
00046
00047
00048
00049 m_ChartWidget = new vtkQtChartWidget( this );
00050
00051 QBoxLayout *layout = new QVBoxLayout( this );
00052 layout->addWidget( m_ChartWidget );
00053 layout->setSpacing( 10 );
00054
00055 vtkQtChartArea *area = m_ChartWidget->getChartArea();
00056
00057
00058 m_BarChart = new vtkQtBarChart();
00059 area->insertLayer( area->getAxisLayerIndex(), m_BarChart );
00060
00061
00062 vtkQtChartMouseSelection *selector =
00063 vtkQtChartInteractorSetup::createDefault( area );
00064 vtkQtChartSeriesSelectionHandler *handler =
00065 new vtkQtChartSeriesSelectionHandler( selector );
00066 handler->setModeNames( "Bar Chart - Series", "Bar Chart - Bars" );
00067 handler->setMousePressModifiers( Qt::ControlModifier, Qt::ControlModifier );
00068 handler->setLayer( m_BarChart );
00069 selector->addHandler( handler );
00070 selector->setSelectionMode("Bar Chart - Bars");
00071
00072
00073 vtkQtChartAxisLayer *axisLayer = area->getAxisLayer();
00074 vtkQtChartAxis *xAxis = axisLayer->getAxis(vtkQtChartAxis::Bottom);
00075 xAxis->getOptions()->setGridVisible(false);
00076 xAxis->getOptions()->setPrecision( 0 );
00077 xAxis->getOptions()->setNotation( vtkQtChartAxisOptions::Standard );
00078
00079 vtkQtChartAxis *yAxis = axisLayer->getAxis(vtkQtChartAxis::Left);
00080 yAxis->getOptions()->setPrecision( 0 );
00081 yAxis->getOptions()->setNotation( vtkQtChartAxisOptions::Standard );
00082
00083
00084 m_ItemModel = new QStandardItemModel( m_BarChart );
00085 m_ItemModel->setItemPrototype( new QStandardItem() );
00086 }
00087
00088
00089
00090 QmitkVtkHistogramWidget::~QmitkVtkHistogramWidget()
00091 {
00092 }
00093
00094
00095 void QmitkVtkHistogramWidget::SetHistogramModeToDirectHistogram()
00096 {
00097 if ( m_HistogramMode != HISTOGRAM_MODE_DIRECT )
00098 {
00099 m_HistogramMode = HISTOGRAM_MODE_DIRECT;
00100 }
00101 }
00102
00103
00104 void QmitkVtkHistogramWidget::SetHistogramModeToEntireImage()
00105 {
00106 if ( m_HistogramMode != HISTOGRAM_MODE_ENTIREIMAGE )
00107 {
00108 m_HistogramMode = HISTOGRAM_MODE_ENTIREIMAGE;
00109 }
00110 }
00111
00112
00113 void QmitkVtkHistogramWidget::SetHistogramModeToMaskedImage()
00114 {
00115 if ( m_HistogramMode != HISTOGRAM_MODE_MASKEDIMAGE )
00116 {
00117 m_HistogramMode = HISTOGRAM_MODE_MASKEDIMAGE;
00118 }
00119 }
00120
00121
00122 void QmitkVtkHistogramWidget::SetHistogramModeToImageRegion()
00123 {
00124 if ( m_HistogramMode != HISTOGRAM_MODE_IMAGEREGION )
00125 {
00126 m_HistogramMode = HISTOGRAM_MODE_IMAGEREGION;
00127 }
00128 }
00129
00130 void QmitkVtkHistogramWidget::SetHistogramModeToPlanarFigureRegion()
00131 {
00132 if ( m_HistogramMode != HISTOGRAM_MODE_PLANARFIGUREREGION )
00133 {
00134 m_HistogramMode = HISTOGRAM_MODE_PLANARFIGUREREGION;
00135 }
00136 }
00137
00138
00139 void QmitkVtkHistogramWidget::UpdateItemModelFromHistogram()
00140 {
00141 this->ComputeHistogram();
00142
00143 if ( m_DerivedHistogram.IsNull() )
00144 {
00145 return;
00146 }
00147
00148
00149 unsigned int startIndex = 0, endIndex = 0, i = 0;
00150 HistogramConstIteratorType startIt = m_DerivedHistogram->End();
00151 HistogramConstIteratorType endIt = m_DerivedHistogram->End();
00152 HistogramConstIteratorType it;
00153 bool firstNonEmptyBinFound = false;
00154 for ( it = m_DerivedHistogram->Begin(); it != m_DerivedHistogram->End(); ++it, ++i )
00155 {
00156 if ( it.GetFrequency() > 0.0 )
00157 {
00158 endIt = it;
00159 endIndex = i;
00160 if ( !firstNonEmptyBinFound )
00161 {
00162 firstNonEmptyBinFound = true;
00163 startIt = it;
00164 startIndex = i;
00165 }
00166 }
00167 }
00168 ++endIt;
00169
00170
00171 if ( startIt == m_DerivedHistogram->End() )
00172 {
00173 this->ClearItemModel();
00174 return;
00175 }
00176
00177
00178 m_ItemModel->setRowCount( endIndex + 1 - startIndex );
00179 m_ItemModel->setColumnCount( 1 );
00180
00181
00182 for ( it = startIt, i = 0; it != endIt; ++it, ++i )
00183 {
00184 const double &frequency = it.GetFrequency();
00185 const double &measurement = it.GetMeasurementVector()[0];
00186
00187 m_ItemModel->setVerticalHeaderItem( i, new QStandardItem() );
00188 m_ItemModel->verticalHeaderItem( i )->setData(
00189 QVariant( measurement ), Qt::DisplayRole );
00190
00191 m_ItemModel->setItem( i, 0, new QStandardItem() );
00192 m_ItemModel->item( i, 0 )->setData( QVariant( frequency ), Qt::DisplayRole );
00193 }
00194
00195 vtkQtChartTableSeriesModel *table =
00196 new vtkQtChartTableSeriesModel( m_ItemModel, m_BarChart );
00197 m_BarChart->setModel( table );
00198
00199 m_ChartWidget->show();
00200 }
00201
00202
00203 void QmitkVtkHistogramWidget::ClearItemModel()
00204 {
00205 m_ItemModel->clear();
00206 }
00207
00208
00209 void QmitkVtkHistogramWidget::ComputeHistogram()
00210 {
00211 switch ( m_HistogramMode )
00212 {
00213 case HISTOGRAM_MODE_DIRECT:
00214 {
00215 m_DerivedHistogram = m_Histogram;
00216 break;
00217 }
00218
00219 case HISTOGRAM_MODE_ENTIREIMAGE:
00220 {
00221 mitk::HistogramGenerator::Pointer histogramGenerator = mitk::HistogramGenerator::New();
00222 histogramGenerator->SetImage( m_Image );
00223 histogramGenerator->ComputeHistogram();
00224 m_DerivedHistogram = histogramGenerator->GetHistogram();
00225 break;
00226 }
00227
00228 case HISTOGRAM_MODE_MASKEDIMAGE:
00229 {
00230 break;
00231 }
00232
00233 case HISTOGRAM_MODE_IMAGEREGION:
00234 {
00235 break;
00236 }
00237
00238 case HISTOGRAM_MODE_PLANARFIGUREREGION:
00239 {
00240 break;
00241 }
00242 }
00243 }
00244
00245 void QmitkVtkHistogramWidget::SetHistogram(const HistogramType* histogram )
00246 {
00247 m_Histogram = histogram;
00248 }
00249
00250 void QmitkVtkHistogramWidget::SetImage(const mitk::Image* image )
00251 {
00252 m_Image = image;
00253 }
00254
00255 void QmitkVtkHistogramWidget::SetImageMask(const mitk::Image* imageMask )
00256 {
00257 m_ImageMask = imageMask;
00258 }
00259
00260 void QmitkVtkHistogramWidget::SetImageRegion( const RegionType imageRegion )
00261 {
00262 m_ImageRegion = imageRegion;
00263 }
00264
00265 void QmitkVtkHistogramWidget::SetPlanarFigure(const mitk::PlanarFigure* planarFigure )
00266 {
00267 m_PlanarFigure = planarFigure;
00268 }
00269
00270 void QmitkVtkHistogramWidget::SetHistogramMode( unsigned int histogramMode )
00271 {
00272 m_HistogramMode = histogramMode;
00273 }
00274
00275 unsigned int QmitkVtkHistogramWidget::GetHistogramMode()
00276 {
00277 return m_HistogramMode;
00278 }