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

QmitkVtkLineProfileWidget Class Reference

Widget for displaying intensity profiles of images along a given path. More...

#include <QmitkVtkLineProfileWidget.h>

Collaboration diagram for QmitkVtkLineProfileWidget:
Collaboration graph
[legend]

List of all members.

Public Types

enum  { PATH_MODE_DIRECT = 0, PATH_MODE_PLANARFIGURE }
typedef itk::ParametricPath
< 3 >::Superclass 
PathType
typedef
itk::PolyLineParametricPath< 3 > 
ParametricPathType

Public Member Functions

 QmitkVtkLineProfileWidget (QWidget *)
virtual ~QmitkVtkLineProfileWidget ()
void SetImage (mitk::Image *image)
 Set image from which to calculate derive the intensity profile.
void SetPath (const PathType *path)
 Set path for calculating intensity profile directly.
void SetPlanarFigure (const mitk::PlanarFigure *planarFigure)
 Set planar figure for calculating intensity profile.
void SetPathMode (unsigned int pathMode)
 Set/Get mode which path to use.
unsigned int GetPathMode ()
 Set/Get mode which path to use.
void SetPathModeToDirectPath ()
 Set/Get mode which path to use.
void SetPathModeToPlanarFigure ()
 Set/Get mode which path to use.
void UpdateItemModelFromPath ()
void ClearItemModel ()
 Clear the intensity profile (nothing is displayed).

Protected Member Functions

void CreatePathFromPlanarFigure ()
void ComputePath ()

Protected Attributes

vtkQtChartWidgetm_ChartWidget
vtkQtLineChartm_LineChart
vtkQtBarChartm_BarChart
std::vector< vtkQtLineChart * > m_VectorLineCharts
QStandardItemModel * m_ItemModel
mitk::Image::Pointer m_Image
mitk::PlanarFigure::ConstPointer m_PlanarFigure
unsigned int m_PathMode
PathType::ConstPointer m_Path
ParametricPathType::Pointer m_ParametricPath
PathType::ConstPointer m_DerivedPath

Detailed Description

Widget for displaying intensity profiles of images along a given path.

Definition at line 45 of file QmitkVtkLineProfileWidget.h.


Member Typedef Documentation

typedef itk::PolyLineParametricPath< 3 > QmitkVtkLineProfileWidget::ParametricPathType

Definition at line 54 of file QmitkVtkLineProfileWidget.h.

typedef itk::ParametricPath< 3 >::Superclass QmitkVtkLineProfileWidget::PathType

Definition at line 53 of file QmitkVtkLineProfileWidget.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
PATH_MODE_DIRECT 
PATH_MODE_PLANARFIGURE 

Definition at line 56 of file QmitkVtkLineProfileWidget.h.


Constructor & Destructor Documentation

QmitkVtkLineProfileWidget::QmitkVtkLineProfileWidget ( QWidget *   )

Definition at line 56 of file QmitkVtkLineProfileWidget.cpp.

References vtkQtChartMouseSelection::addHandler(), vtkQtChartPenBrushGenerator::addPens(), vtkQtChartAxis::Bottom, vtkQtChartInteractorSetup::createDefault(), vtkQtChartAxisLayer::getAxis(), vtkQtChartArea::getAxisLayer(), vtkQtChartArea::getAxisLayerIndex(), vtkQtChartWidget::getChartArea(), vtkQtChartAxis::getOptions(), vtkQtChartArea::getStyleManager(), vtkQtChartArea::insertLayer(), vtkQtChartAxis::Left, m_ChartWidget, m_ItemModel, m_LineChart, m_ParametricPath, vtkQtChartStyleManager::setGenerator(), vtkQtChartAxisOptions::setGridVisible(), vtkQtChartSeriesSelectionHandler::setLayer(), vtkQtChartSeriesSelectionHandler::setModeNames(), vtkQtChartSeriesSelectionHandler::setMousePressModifiers(), vtkQtChartAxisOptions::setNotation(), vtkQtChartPenBrushGenerator::setPen(), vtkQtChartAxisOptions::setPrecision(), vtkQtChartMouseSelection::setSelectionMode(), vtkQtChartAxisOptions::Standard, and vtkQtChartColors::WildFlower.

: m_PathMode( PATH_MODE_DIRECT )
{
  m_ChartWidget = new vtkQtChartWidget( this );

  QBoxLayout *layout = new QVBoxLayout( this );
  layout->addWidget( m_ChartWidget );
  layout->setSpacing( 10 );

  vtkQtChartArea *area = m_ChartWidget->getChartArea();

  // Set up the line chart.
  m_LineChart = new vtkQtLineChart();
  area->insertLayer( area->getAxisLayerIndex(), m_LineChart );
  //m_BarChart->getOptions()->setBarGroupFraction(10);

  // Set up the default interactor.
  vtkQtChartMouseSelection *selector =
    vtkQtChartInteractorSetup::createDefault( area );
  vtkQtChartSeriesSelectionHandler *handler =
    new vtkQtChartSeriesSelectionHandler( selector );
  handler->setModeNames( "Bar Chart - Series", "Bar Chart - Bars" );
  handler->setMousePressModifiers( Qt::ControlModifier, Qt::ControlModifier );
  handler->setLayer( m_LineChart );
  selector->addHandler( handler );
  selector->setSelectionMode("Bar Chart - Bars");

  // Hide the x-axis grid.
  vtkQtChartAxisLayer *axisLayer = area->getAxisLayer();
  vtkQtChartAxis *xAxis = axisLayer->getAxis(vtkQtChartAxis::Bottom);
  xAxis->getOptions()->setGridVisible(false);
  xAxis->getOptions()->setPrecision( 1 );
  xAxis->getOptions()->setNotation( vtkQtChartAxisOptions::Standard );
  
  vtkQtChartAxis *yAxis = axisLayer->getAxis(vtkQtChartAxis::Left);
  yAxis->getOptions()->setPrecision( 0 );
  yAxis->getOptions()->setNotation( vtkQtChartAxisOptions::Standard );

  // Set up the model for the bar chart.
  m_ItemModel = new QStandardItemModel( m_LineChart );
  m_ItemModel->setItemPrototype( new QStandardItem() );
  m_ItemModel->setHorizontalHeaderItem( 0, new QStandardItem("Intensity profile") );

#if ((VTK_MAJOR_VERSION<=5) && (VTK_MINOR_VERSION<=4) )
  vtkQtChartStyleManager *styleManager = area->getStyleManager();
  vtkQtChartPenBrushGenerator *pen = new vtkQtChartPenBrushGenerator();
  pen->setPen(0,QPen(Qt::SolidLine));
  pen->addPens(vtkQtChartColors::WildFlower);
  styleManager->setGenerator(pen);
#endif

#if ((VTK_MAJOR_VERSION>=5) && (VTK_MINOR_VERSION>=6) )
  
  vtkQtChartBasicStyleManager *styleManager =
      qobject_cast<vtkQtChartBasicStyleManager *>(area->getStyleManager());

  vtkQtChartPenGenerator *pen = new vtkQtChartPenGenerator();
  pen->setPen(0,QPen(Qt::SolidLine));
  pen->addPens(vtkQtChartColors::WildFlower);
  styleManager->setGenerator("Pen",pen);

#endif
  
  

  // Initialize parametric path object
  m_ParametricPath = ParametricPathType::New();
}
QmitkVtkLineProfileWidget::~QmitkVtkLineProfileWidget (  ) [virtual]

Definition at line 127 of file QmitkVtkLineProfileWidget.cpp.

{
}

Member Function Documentation

void QmitkVtkLineProfileWidget::ClearItemModel (  )

Clear the intensity profile (nothing is displayed).

Definition at line 271 of file QmitkVtkLineProfileWidget.cpp.

References m_ItemModel.

Referenced by QmitkImageStatistics::OnSelectionChanged(), and QmitkImageStatistics::UpdateStatistics().

{
  m_ItemModel->clear();
}
void QmitkVtkLineProfileWidget::ComputePath (  ) [protected]

Definition at line 338 of file QmitkVtkLineProfileWidget.cpp.

References CreatePathFromPlanarFigure(), m_DerivedPath, m_ParametricPath, m_Path, m_PathMode, PATH_MODE_DIRECT, and PATH_MODE_PLANARFIGURE.

Referenced by UpdateItemModelFromPath().

{
  switch ( m_PathMode )
  {
  case PATH_MODE_DIRECT:
    {
      m_DerivedPath = m_Path;
      break;
    }

  case PATH_MODE_PLANARFIGURE:
    {
      // Calculate path from PlanarFigure using geometry of specified Image
      this->CreatePathFromPlanarFigure();
      m_DerivedPath = m_ParametricPath;
      break;
    }
  }
}
void QmitkVtkLineProfileWidget::CreatePathFromPlanarFigure (  ) [protected]

Definition at line 277 of file QmitkVtkLineProfileWidget.cpp.

References m_Image, m_ParametricPath, m_PlanarFigure, mitk::Geometry2D::Map(), MITK_INFO, and mitk::Geometry3D::WorldToIndex().

Referenced by ComputePath().

{
  m_ParametricPath->Initialize();

  if ( m_PlanarFigure.IsNull() )
  {
    throw std::invalid_argument("QmitkVtkLineProfileWidget: PlanarFigure not set!" );
  }

  if ( m_Image.IsNull() )
  {
    throw std::invalid_argument("QmitkVtkLineProfileWidget: Image not set -- needed to calculate path from PlanarFigure!" );
  }

  // Get 2D geometry frame of PlanarFigure
  mitk::Geometry2D *planarFigureGeometry2D = 
    dynamic_cast< mitk::Geometry2D * >( m_PlanarFigure->GetGeometry( 0 ) );
  if ( planarFigureGeometry2D == NULL )
  {
    throw std::invalid_argument("QmitkVtkLineProfileWidget: PlanarFigure has no valid geometry!" );
  }

  // Get 3D geometry from Image (needed for conversion of point to index)
  mitk::Geometry3D *imageGeometry = m_Image->GetGeometry( 0 );
  if ( imageGeometry == NULL )
  {
    throw std::invalid_argument("QmitkVtkLineProfileWidget: Image has no valid geometry!" );
  }

  // Get first poly-line of PlanarFigure (other possible poly-lines in PlanarFigure
  // are not supported)
  typedef mitk::PlanarFigure::VertexContainerType VertexContainerType;
  const VertexContainerType *vertexContainer = m_PlanarFigure->GetPolyLine( 0 );

  MITK_INFO << "WorldToIndex:";

  VertexContainerType::ConstIterator it;
  for ( it = vertexContainer->Begin(); it != vertexContainer->End(); ++it )
  {
    // Map PlanarFigure 2D point to 3D point
    mitk::Point3D point3D;
    planarFigureGeometry2D->Map( it->Value(), point3D );

    // Convert world to index coordinates
    mitk::Point3D indexPoint3D;
    imageGeometry->WorldToIndex( point3D, indexPoint3D );

    ParametricPathType::OutputType index;
    index[0] = indexPoint3D[0];
    index[1] = indexPoint3D[1];
    index[2] = indexPoint3D[2];

    MITK_INFO << point3D << " / " << index;

    // Add index to parametric path
    m_ParametricPath->AddVertex( index );
  }

}
unsigned int QmitkVtkLineProfileWidget::GetPathMode (  )

Set/Get mode which path to use.

Definition at line 378 of file QmitkVtkLineProfileWidget.cpp.

References m_PathMode.

{
  return m_PathMode;
}
void QmitkVtkLineProfileWidget::SetImage ( mitk::Image image )

Set image from which to calculate derive the intensity profile.

Definition at line 358 of file QmitkVtkLineProfileWidget.cpp.

References m_Image.

Referenced by QmitkImageStatistics::UpdateStatistics().

{
  m_Image = image;
}
void QmitkVtkLineProfileWidget::SetPath ( const PathType path )

Set path for calculating intensity profile directly.

Definition at line 363 of file QmitkVtkLineProfileWidget.cpp.

References m_Path.

{
  m_Path = path;
}
void QmitkVtkLineProfileWidget::SetPathMode ( unsigned int  pathMode )

Set/Get mode which path to use.

Definition at line 373 of file QmitkVtkLineProfileWidget.cpp.

References m_PathMode.

{
  m_PathMode = pathMode;
}
void QmitkVtkLineProfileWidget::SetPathModeToDirectPath (  )

Set/Get mode which path to use.

Definition at line 132 of file QmitkVtkLineProfileWidget.cpp.

References m_PathMode, and PATH_MODE_DIRECT.

void QmitkVtkLineProfileWidget::SetPathModeToPlanarFigure (  )

Set/Get mode which path to use.

Definition at line 141 of file QmitkVtkLineProfileWidget.cpp.

References m_PathMode, and PATH_MODE_PLANARFIGURE.

Referenced by QmitkImageStatistics::CreateQtPartControl().

void QmitkVtkLineProfileWidget::SetPlanarFigure ( const mitk::PlanarFigure planarFigure )

Set planar figure for calculating intensity profile.

Definition at line 368 of file QmitkVtkLineProfileWidget.cpp.

References m_PlanarFigure.

Referenced by QmitkImageStatistics::UpdateStatistics().

{
  m_PlanarFigure = planarFigure;
}
void QmitkVtkLineProfileWidget::UpdateItemModelFromPath (  )

Fill the graphical widget with intensity profile from currently specified image/path .

Definition at line 150 of file QmitkVtkLineProfileWidget.cpp.

References ComputePath(), QuadProgPP::distance(), vtkQtChartArea::getAxisLayerIndex(), vtkQtChartWidget::getChartArea(), mitk::Geometry3D::IndexToWorld(), vtkQtChartArea::insertLayer(), int(), m_ChartWidget, m_DerivedPath, m_Image, m_ItemModel, m_LineChart, m_VectorLineCharts, MITK_INFO, vtkQtChartArea::removeLayer(), vtkQtLineChart::setModel(), QuadProgPP::t(), and mitk::Geometry3D::WorldToIndex().

Referenced by QmitkImageStatistics::UpdateStatistics().

{
  this->ComputePath();

  if ( m_DerivedPath.IsNull() )
  {
    throw std::invalid_argument("QmitkVtkLineProfileWidget: no path set");
  }

  // TODO: indices according to mm

  m_ItemModel->clear();

  MITK_INFO << "Intensity profile (t)";
  MITK_INFO << "Start: " << m_DerivedPath->StartOfInput();
  MITK_INFO << "End:   " << m_DerivedPath->EndOfInput();

  // Get geometry from image
  mitk::Geometry3D *imageGeometry = m_Image->GetGeometry();

  // Fill item model with line profile data
  double distance = 0.0;
  mitk::Point3D currentWorldPoint;

  double t;
  unsigned int i = 0;
  int t_tmp = 0;
  QStandardItemModel *tmp_ItemModel = new QStandardItemModel();
  vtkQtChartTableSeriesModel *table;
  vtkQtChartArea* area = m_ChartWidget->getChartArea();
  for(unsigned int j = 0; j < m_VectorLineCharts.size(); j++)
  {
      area->removeLayer(m_VectorLineCharts[j]);
      m_VectorLineCharts[j]->getModel()->deleteLater();
      m_VectorLineCharts[j]->deleteLater();
  }
  m_VectorLineCharts.clear();

  int k = 0;
  for ( i = 0, t = m_DerivedPath->StartOfInput(); ;++i )
  {
    const PathType::OutputType &continuousIndex = m_DerivedPath->Evaluate( t );
    
    mitk::Point3D worldPoint;
    imageGeometry->IndexToWorld( continuousIndex, worldPoint );

    if ( i == 0 )
    {
      currentWorldPoint = worldPoint;
    }

    distance += currentWorldPoint.EuclideanDistanceTo( worldPoint );

    mitk::Index3D indexPoint;
    imageGeometry->WorldToIndex( worldPoint, indexPoint );
    double intensity = m_Image->GetPixelValueByIndex( indexPoint );

    MITK_INFO << t << "/" << distance << ": " << indexPoint << " (" << intensity << ")";

    m_ItemModel->setVerticalHeaderItem( i, new QStandardItem() );
    m_ItemModel->verticalHeaderItem( i )->setData(
      QVariant( distance ), Qt::DisplayRole );

    m_ItemModel->setItem( i, 0, new QStandardItem() );
    m_ItemModel->item( i, 0 )->setData( intensity, Qt::DisplayRole );

    tmp_ItemModel->setVerticalHeaderItem( k, new QStandardItem() );
    tmp_ItemModel->verticalHeaderItem( k )->setData(
      QVariant( distance ), Qt::DisplayRole );

    tmp_ItemModel->setItem( k, 0, new QStandardItem() );
    tmp_ItemModel->item( k, 0 )->setData( intensity, Qt::DisplayRole );

    if ((int)t > t_tmp){
        t_tmp = (int)t;

        vtkQtLineChart *tmp_LineChart = new vtkQtLineChart();
        table = new vtkQtChartTableSeriesModel( tmp_ItemModel, tmp_LineChart );
        tmp_LineChart->setModel( table );

        m_VectorLineCharts.push_back(tmp_LineChart);
        
        tmp_ItemModel = new QStandardItemModel();
        
        k = 0;
        
        tmp_ItemModel->setVerticalHeaderItem( k, new QStandardItem() );
        tmp_ItemModel->verticalHeaderItem( k )->setData(
            QVariant( distance ), Qt::DisplayRole );

        tmp_ItemModel->setItem( k, 0, new QStandardItem() );
        tmp_ItemModel->item( k, 0 )->setData( intensity, Qt::DisplayRole );
    }
    k++;

    // Go to next index; when iteration offset reaches zero, iteration is finished
    PathType::OffsetType offset = m_DerivedPath->IncrementInput( t );
    if ( !(offset[0] || offset[1] || offset[2]) )
    {
      break;
    }

    currentWorldPoint = worldPoint;
  }
  for(unsigned int j = 0; j < m_VectorLineCharts.size() ; j++)
  {
/*    int styleIndex = styleManager->getStyleIndex(m_LineChart, m_LineChart->getSeriesOptions(0));
  
    vtkQtChartStylePen *stylePen = qobject_cast<vtkQtChartStylePen *>(
      styleManager->getGenerator("Pen"));
    stylePen->getStylePen(styleIndex).setStyle(Qt::SolidLine);*/
    area->insertLayer(area->getAxisLayerIndex() + j +1, m_VectorLineCharts[j]);
  }

  table =
    new vtkQtChartTableSeriesModel( m_ItemModel, m_LineChart );
  //m_LineChart->setModel( table );
}

Member Data Documentation

Definition at line 103 of file QmitkVtkLineProfileWidget.h.

PathType::ConstPointer QmitkVtkLineProfileWidget::m_DerivedPath [protected]

Definition at line 123 of file QmitkVtkLineProfileWidget.h.

Referenced by ComputePath(), and UpdateItemModelFromPath().

QStandardItemModel* QmitkVtkLineProfileWidget::m_ItemModel [protected]
ParametricPathType::Pointer QmitkVtkLineProfileWidget::m_ParametricPath [protected]
PathType::ConstPointer QmitkVtkLineProfileWidget::m_Path [protected]

Definition at line 116 of file QmitkVtkLineProfileWidget.h.

Referenced by ComputePath(), and SetPath().

unsigned int QmitkVtkLineProfileWidget::m_PathMode [protected]

Definition at line 110 of file QmitkVtkLineProfileWidget.h.

Referenced by CreatePathFromPlanarFigure(), and SetPlanarFigure().

Definition at line 104 of file QmitkVtkLineProfileWidget.h.

Referenced by UpdateItemModelFromPath().


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