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 "QmitkVtkLineProfileWidget.h"
00019
00020 #include "mitkGeometry2D.h"
00021
00022
00023 #include <qlabel.h>
00024 #include <qpen.h>
00025 #include <qgroupbox.h>
00026 #include <QBrush>
00027
00028
00029 #include <vtkQtChartArea.h>
00030 #include <vtkQtChartTableSeriesModel.h>
00031 #include <vtkQtChartStyleManager.h>
00032 #include <vtkQtChartColorStyleGenerator.h>
00033
00034 #include <vtkQtChartMouseSelection.h>
00035 #include <vtkQtChartInteractorSetup.h>
00036 #include <vtkQtChartSeriesSelectionHandler.h>
00037 #include <vtkQtChartAxisLayer.h>
00038 #include <vtkQtChartAxis.h>
00039 #include <vtkQtChartAxisOptions.h>
00040 #include <vtkQtBarChartOptions.h>
00041 #include <vtkQtChartSeriesOptions.h>
00042 #include <vtkQtChartColors.h>
00043 #include <vtkConfigure.h>
00044
00045 #if ((VTK_MAJOR_VERSION<=5) && (VTK_MINOR_VERSION<=4) )
00046 #include <vtkQtChartPenBrushGenerator.h>
00047 #endif
00048
00049 #if ((VTK_MAJOR_VERSION>=5) && (VTK_MINOR_VERSION>=6) )
00050 #include <vtkQtChartPenGenerator.h>
00051 #include <vtkQtChartBasicStyleManager.h>
00052 #endif
00053
00054
00055
00056 QmitkVtkLineProfileWidget::QmitkVtkLineProfileWidget( QWidget * )
00057 : m_PathMode( PATH_MODE_DIRECT )
00058 {
00059 m_ChartWidget = new vtkQtChartWidget( this );
00060
00061 QBoxLayout *layout = new QVBoxLayout( this );
00062 layout->addWidget( m_ChartWidget );
00063 layout->setSpacing( 10 );
00064
00065 vtkQtChartArea *area = m_ChartWidget->getChartArea();
00066
00067
00068 m_LineChart = new vtkQtLineChart();
00069 area->insertLayer( area->getAxisLayerIndex(), m_LineChart );
00070
00071
00072
00073 vtkQtChartMouseSelection *selector =
00074 vtkQtChartInteractorSetup::createDefault( area );
00075 vtkQtChartSeriesSelectionHandler *handler =
00076 new vtkQtChartSeriesSelectionHandler( selector );
00077 handler->setModeNames( "Bar Chart - Series", "Bar Chart - Bars" );
00078 handler->setMousePressModifiers( Qt::ControlModifier, Qt::ControlModifier );
00079 handler->setLayer( m_LineChart );
00080 selector->addHandler( handler );
00081 selector->setSelectionMode("Bar Chart - Bars");
00082
00083
00084 vtkQtChartAxisLayer *axisLayer = area->getAxisLayer();
00085 vtkQtChartAxis *xAxis = axisLayer->getAxis(vtkQtChartAxis::Bottom);
00086 xAxis->getOptions()->setGridVisible(false);
00087 xAxis->getOptions()->setPrecision( 1 );
00088 xAxis->getOptions()->setNotation( vtkQtChartAxisOptions::Standard );
00089
00090 vtkQtChartAxis *yAxis = axisLayer->getAxis(vtkQtChartAxis::Left);
00091 yAxis->getOptions()->setPrecision( 0 );
00092 yAxis->getOptions()->setNotation( vtkQtChartAxisOptions::Standard );
00093
00094
00095 m_ItemModel = new QStandardItemModel( m_LineChart );
00096 m_ItemModel->setItemPrototype( new QStandardItem() );
00097 m_ItemModel->setHorizontalHeaderItem( 0, new QStandardItem("Intensity profile") );
00098
00099 #if ((VTK_MAJOR_VERSION<=5) && (VTK_MINOR_VERSION<=4) )
00100 vtkQtChartStyleManager *styleManager = area->getStyleManager();
00101 vtkQtChartPenBrushGenerator *pen = new vtkQtChartPenBrushGenerator();
00102 pen->setPen(0,QPen(Qt::SolidLine));
00103 pen->addPens(vtkQtChartColors::WildFlower);
00104 styleManager->setGenerator(pen);
00105 #endif
00106
00107 #if ((VTK_MAJOR_VERSION>=5) && (VTK_MINOR_VERSION>=6) )
00108
00109 vtkQtChartBasicStyleManager *styleManager =
00110 qobject_cast<vtkQtChartBasicStyleManager *>(area->getStyleManager());
00111
00112 vtkQtChartPenGenerator *pen = new vtkQtChartPenGenerator();
00113 pen->setPen(0,QPen(Qt::SolidLine));
00114 pen->addPens(vtkQtChartColors::WildFlower);
00115 styleManager->setGenerator("Pen",pen);
00116
00117 #endif
00118
00119
00120
00121
00122 m_ParametricPath = ParametricPathType::New();
00123 }
00124
00125
00126
00127 QmitkVtkLineProfileWidget::~QmitkVtkLineProfileWidget()
00128 {
00129 }
00130
00131
00132 void QmitkVtkLineProfileWidget::SetPathModeToDirectPath()
00133 {
00134 if ( m_PathMode != PATH_MODE_DIRECT )
00135 {
00136 m_PathMode = PATH_MODE_DIRECT;
00137 }
00138 }
00139
00140
00141 void QmitkVtkLineProfileWidget::SetPathModeToPlanarFigure()
00142 {
00143 if ( m_PathMode != PATH_MODE_PLANARFIGURE )
00144 {
00145 m_PathMode = PATH_MODE_PLANARFIGURE;
00146 }
00147 }
00148
00149
00150 void QmitkVtkLineProfileWidget::UpdateItemModelFromPath()
00151 {
00152 this->ComputePath();
00153
00154 if ( m_DerivedPath.IsNull() )
00155 {
00156 throw std::invalid_argument("QmitkVtkLineProfileWidget: no path set");
00157 }
00158
00159
00160
00162 m_ItemModel->clear();
00163
00164 MITK_INFO << "Intensity profile (t)";
00165 MITK_INFO << "Start: " << m_DerivedPath->StartOfInput();
00166 MITK_INFO << "End: " << m_DerivedPath->EndOfInput();
00167
00168
00169 mitk::Geometry3D *imageGeometry = m_Image->GetGeometry();
00170
00171
00172 double distance = 0.0;
00173 mitk::Point3D currentWorldPoint;
00174
00175 double t;
00176 unsigned int i = 0;
00177 int t_tmp = 0;
00178 QStandardItemModel *tmp_ItemModel = new QStandardItemModel();
00179 vtkQtChartTableSeriesModel *table;
00180 vtkQtChartArea* area = m_ChartWidget->getChartArea();
00181 for(unsigned int j = 0; j < m_VectorLineCharts.size(); j++)
00182 {
00183 area->removeLayer(m_VectorLineCharts[j]);
00184 m_VectorLineCharts[j]->getModel()->deleteLater();
00185 m_VectorLineCharts[j]->deleteLater();
00186 }
00187 m_VectorLineCharts.clear();
00188
00189 int k = 0;
00190 for ( i = 0, t = m_DerivedPath->StartOfInput(); ;++i )
00191 {
00192 const PathType::OutputType &continuousIndex = m_DerivedPath->Evaluate( t );
00193
00194 mitk::Point3D worldPoint;
00195 imageGeometry->IndexToWorld( continuousIndex, worldPoint );
00196
00197 if ( i == 0 )
00198 {
00199 currentWorldPoint = worldPoint;
00200 }
00201
00202 distance += currentWorldPoint.EuclideanDistanceTo( worldPoint );
00203
00204 mitk::Index3D indexPoint;
00205 imageGeometry->WorldToIndex( worldPoint, indexPoint );
00206 double intensity = m_Image->GetPixelValueByIndex( indexPoint );
00207
00208 MITK_INFO << t << "/" << distance << ": " << indexPoint << " (" << intensity << ")";
00209
00210 m_ItemModel->setVerticalHeaderItem( i, new QStandardItem() );
00211 m_ItemModel->verticalHeaderItem( i )->setData(
00212 QVariant( distance ), Qt::DisplayRole );
00213
00214 m_ItemModel->setItem( i, 0, new QStandardItem() );
00215 m_ItemModel->item( i, 0 )->setData( intensity, Qt::DisplayRole );
00216
00217 tmp_ItemModel->setVerticalHeaderItem( k, new QStandardItem() );
00218 tmp_ItemModel->verticalHeaderItem( k )->setData(
00219 QVariant( distance ), Qt::DisplayRole );
00220
00221 tmp_ItemModel->setItem( k, 0, new QStandardItem() );
00222 tmp_ItemModel->item( k, 0 )->setData( intensity, Qt::DisplayRole );
00223
00224 if ((int)t > t_tmp){
00225 t_tmp = (int)t;
00226
00227 vtkQtLineChart *tmp_LineChart = new vtkQtLineChart();
00228 table = new vtkQtChartTableSeriesModel( tmp_ItemModel, tmp_LineChart );
00229 tmp_LineChart->setModel( table );
00230
00231 m_VectorLineCharts.push_back(tmp_LineChart);
00232
00233 tmp_ItemModel = new QStandardItemModel();
00234
00235 k = 0;
00236
00237 tmp_ItemModel->setVerticalHeaderItem( k, new QStandardItem() );
00238 tmp_ItemModel->verticalHeaderItem( k )->setData(
00239 QVariant( distance ), Qt::DisplayRole );
00240
00241 tmp_ItemModel->setItem( k, 0, new QStandardItem() );
00242 tmp_ItemModel->item( k, 0 )->setData( intensity, Qt::DisplayRole );
00243 }
00244 k++;
00245
00246
00247 PathType::OffsetType offset = m_DerivedPath->IncrementInput( t );
00248 if ( !(offset[0] || offset[1] || offset[2]) )
00249 {
00250 break;
00251 }
00252
00253 currentWorldPoint = worldPoint;
00254 }
00255 for(unsigned int j = 0; j < m_VectorLineCharts.size() ; j++)
00256 {
00257
00258
00259
00260
00261
00262 area->insertLayer(area->getAxisLayerIndex() + j +1, m_VectorLineCharts[j]);
00263 }
00264
00265 table =
00266 new vtkQtChartTableSeriesModel( m_ItemModel, m_LineChart );
00267
00268 }
00269
00270
00271 void QmitkVtkLineProfileWidget::ClearItemModel()
00272 {
00273 m_ItemModel->clear();
00274 }
00275
00276
00277 void QmitkVtkLineProfileWidget::CreatePathFromPlanarFigure()
00278 {
00279 m_ParametricPath->Initialize();
00280
00281 if ( m_PlanarFigure.IsNull() )
00282 {
00283 throw std::invalid_argument("QmitkVtkLineProfileWidget: PlanarFigure not set!" );
00284 }
00285
00286 if ( m_Image.IsNull() )
00287 {
00288 throw std::invalid_argument("QmitkVtkLineProfileWidget: Image not set -- needed to calculate path from PlanarFigure!" );
00289 }
00290
00291
00292 mitk::Geometry2D *planarFigureGeometry2D =
00293 dynamic_cast< mitk::Geometry2D * >( m_PlanarFigure->GetGeometry( 0 ) );
00294 if ( planarFigureGeometry2D == NULL )
00295 {
00296 throw std::invalid_argument("QmitkVtkLineProfileWidget: PlanarFigure has no valid geometry!" );
00297 }
00298
00299
00300 mitk::Geometry3D *imageGeometry = m_Image->GetGeometry( 0 );
00301 if ( imageGeometry == NULL )
00302 {
00303 throw std::invalid_argument("QmitkVtkLineProfileWidget: Image has no valid geometry!" );
00304 }
00305
00306
00307
00308 typedef mitk::PlanarFigure::VertexContainerType VertexContainerType;
00309 const VertexContainerType *vertexContainer = m_PlanarFigure->GetPolyLine( 0 );
00310
00311 MITK_INFO << "WorldToIndex:";
00312
00313 VertexContainerType::ConstIterator it;
00314 for ( it = vertexContainer->Begin(); it != vertexContainer->End(); ++it )
00315 {
00316
00317 mitk::Point3D point3D;
00318 planarFigureGeometry2D->Map( it->Value(), point3D );
00319
00320
00321 mitk::Point3D indexPoint3D;
00322 imageGeometry->WorldToIndex( point3D, indexPoint3D );
00323
00324 ParametricPathType::OutputType index;
00325 index[0] = indexPoint3D[0];
00326 index[1] = indexPoint3D[1];
00327 index[2] = indexPoint3D[2];
00328
00329 MITK_INFO << point3D << " / " << index;
00330
00331
00332 m_ParametricPath->AddVertex( index );
00333 }
00334
00335 }
00336
00337
00338 void QmitkVtkLineProfileWidget::ComputePath()
00339 {
00340 switch ( m_PathMode )
00341 {
00342 case PATH_MODE_DIRECT:
00343 {
00344 m_DerivedPath = m_Path;
00345 break;
00346 }
00347
00348 case PATH_MODE_PLANARFIGURE:
00349 {
00350
00351 this->CreatePathFromPlanarFigure();
00352 m_DerivedPath = m_ParametricPath;
00353 break;
00354 }
00355 }
00356 }
00357
00358 void QmitkVtkLineProfileWidget::SetImage( mitk::Image* image )
00359 {
00360 m_Image = image;
00361 }
00362
00363 void QmitkVtkLineProfileWidget::SetPath( const PathType* path )
00364 {
00365 m_Path = path;
00366 }
00367
00368 void QmitkVtkLineProfileWidget::SetPlanarFigure( const mitk::PlanarFigure* planarFigure )
00369 {
00370 m_PlanarFigure = planarFigure;
00371 }
00372
00373 void QmitkVtkLineProfileWidget::SetPathMode( unsigned int pathMode )
00374 {
00375 m_PathMode = pathMode;
00376 }
00377
00378 unsigned int QmitkVtkLineProfileWidget::GetPathMode()
00379 {
00380 return m_PathMode;
00381 }