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

QmitkImageStatistics Class Reference
[Functionalities]

QmitkImageStatistics. More...

#include <QmitkImageStatisticsView.h>

Inheritance diagram for QmitkImageStatistics:
Inheritance graph
[legend]
Collaboration diagram for QmitkImageStatistics:
Collaboration graph
[legend]

List of all members.

Public Types

typedef
mitk::DataStorage::SetOfObjects 
ConstVector
typedef ConstVector::ConstPointer ConstVectorPointer
typedef ConstVector::ConstIterator ConstVectorIterator

Public Member Functions

 QmitkImageStatistics (QObject *parent=0, const char *name=0)
 default constructor
virtual ~QmitkImageStatistics ()
 default destructor
virtual void CreateQtPartControl (QWidget *parent)
 method for creating the widget containing the application controls, like sliders, buttons etc.
virtual void CreateConnections ()
 method for creating the connections of main and control widget
bool IsExclusiveFunctionality () const
virtual bool event (QEvent *event)
void OnSelectionChanged (std::vector< mitk::DataNode * > nodes)

Protected Types

typedef std::map< mitk::Image
*, mitk::ImageStatisticsCalculator::Pointer
ImageStatisticsMapType

Protected Slots

void ClipboardHistogramButtonClicked ()
void ClipboardStatisticsButtonClicked ()

Protected Member Functions

void StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget)
void FillStatisticsTableView (const mitk::ImageStatisticsCalculator::Statistics &s, const mitk::Image *image)
void InvalidateStatisticsTableView ()
void RequestStatisticsUpdate ()
 Issues a request to update statistics by sending an event to the Qt event processing queue.
void UpdateStatistics ()
 Recalculate statistics for currently selected image and mask and update the GUI.
void UpdateProgressBar ()
 Listener for progress events to update progress bar.
void RemoveOrphanImages ()
 Removes any cached images which are no longer referenced elsewhere.
void ComputeIntensityProfile (mitk::PlanarLine *line)
 Computes an Intensity Profile along line and updates the histogram widget with it.
void Visible ()

Protected Attributes

Ui::QmitkImageStatisticsViewControlsm_Controls
QmitkStepperAdapterm_TimeStepperAdapter
unsigned int m_CurrentTime
QString m_Clipboard
mitk::DataNodem_SelectedImageNode
mitk::Imagem_SelectedImage
mitk::DataNodem_SelectedMaskNode
mitk::Imagem_SelectedImageMask
mitk::PlanarFigurem_SelectedPlanarFigure
long m_ImageObserverTag
long m_ImageMaskObserverTag
long m_PlanarFigureObserverTag
ImageStatisticsMapType m_ImageStatisticsMap
mitk::ImageStatisticsCalculator::Pointer m_CurrentStatisticsCalculator
bool m_CurrentStatisticsValid
bool m_StatisticsUpdatePending

Detailed Description

QmitkImageStatistics.

See also:
QmitkFunctionality

Definition at line 43 of file QmitkImageStatisticsView.h.


Member Typedef Documentation

\ Convenient typedefs

Definition at line 52 of file QmitkImageStatisticsView.h.

typedef ConstVector::ConstIterator QmitkImageStatistics::ConstVectorIterator

Definition at line 54 of file QmitkImageStatisticsView.h.

typedef ConstVector::ConstPointer QmitkImageStatistics::ConstVectorPointer

Definition at line 53 of file QmitkImageStatisticsView.h.

Definition at line 124 of file QmitkImageStatisticsView.h.


Constructor & Destructor Documentation

QmitkImageStatistics::QmitkImageStatistics ( QObject *  parent = 0,
const char *  name = 0 
)
QmitkImageStatistics::~QmitkImageStatistics (  ) [virtual]

Member Function Documentation

void QmitkImageStatistics::ClipboardHistogramButtonClicked (  ) [protected, slot]

Definition at line 149 of file QmitkImageStatisticsView.cpp.

References m_CurrentStatisticsCalculator, and m_CurrentStatisticsValid.

Referenced by CreateConnections().

{
  if ( m_CurrentStatisticsValid && (m_CurrentStatisticsCalculator.IsNotNull()) )
  {
    typedef mitk::ImageStatisticsCalculator::HistogramType HistogramType;
    const HistogramType *histogram = m_CurrentStatisticsCalculator->GetHistogram();

    QString clipboard( "Measurement \t Frequency\n" );
    for ( HistogramType::ConstIterator it = histogram->Begin();
          it != histogram->End();
          ++it )
    {
      clipboard = clipboard.append( "%L1 \t %L2\n" )
        .arg( it.GetMeasurementVector()[0], 0, 'f', 2 )
        .arg( it.GetFrequency() );
    }

    QApplication::clipboard()->setText(
      clipboard, QClipboard::Clipboard );
  }
  else
  {
    QApplication::clipboard()->clear();
  }
}
void QmitkImageStatistics::ClipboardStatisticsButtonClicked (  ) [protected, slot]

Definition at line 176 of file QmitkImageStatisticsView.cpp.

References m_CurrentStatisticsCalculator, m_CurrentStatisticsValid, mitk::ImageStatisticsCalculator::Statistics::Max, mitk::ImageStatisticsCalculator::Statistics::Mean, mitk::ImageStatisticsCalculator::Statistics::Min, mitk::ImageStatisticsCalculator::Statistics::N, mitk::ImageStatisticsCalculator::Statistics::RMS, and mitk::ImageStatisticsCalculator::Statistics::Sigma.

Referenced by CreateConnections().

{
  if ( m_CurrentStatisticsValid && (m_CurrentStatisticsCalculator.IsNotNull()) )
  {
    const mitk::ImageStatisticsCalculator::Statistics &statistics =
      m_CurrentStatisticsCalculator->GetStatistics();

    // Copy statistics to clipboard ("%Ln" will use the default locale for
    // number formatting)
    QString clipboard( "Mean \t StdDev \t RMS \t Max \t Min \t N\n" );
    clipboard = clipboard.append( "%L1 \t %L2 \t %L3 \t %L4 \t %L5 \t %L6" )
      .arg( statistics.Mean, 0, 'f', 10 )
      .arg( statistics.Sigma, 0, 'f', 10 )
      .arg( statistics.RMS, 0, 'f', 10 )
      .arg( statistics.Max, 0, 'f', 10 )
      .arg( statistics.Min, 0, 'f', 10 )
      .arg( statistics.N );

    QApplication::clipboard()->setText(
      clipboard, QClipboard::Clipboard );
  }
  else
  {
    QApplication::clipboard()->clear();
  }
}
void QmitkImageStatistics::ComputeIntensityProfile ( mitk::PlanarLine line ) [protected]

Computes an Intensity Profile along line and updates the histogram widget with it.

Definition at line 730 of file QmitkImageStatisticsView.cpp.

References mitk::Image::GetPixelValueByWorldCoordinate(), mitk::PlanarFigure::GetWorldControlPoint(), m_Controls, Ui_QmitkImageStatisticsViewControls::m_HistogramWidget, m_SelectedImage, QmitkVtkHistogramWidget::SetHistogram(), QmitkVtkHistogramWidget::SetHistogramModeToDirectHistogram(), and QmitkVtkHistogramWidget::UpdateItemModelFromHistogram().

{
  double sampling = 300;
  QmitkVtkHistogramWidget::HistogramType::Pointer histogram = QmitkVtkHistogramWidget::HistogramType::New();
  itk::Size<1> siz;
  siz[0] = sampling;
  itk::FixedArray<double,1> lower, higher;
  lower.Fill(0);
    mitk::Point3D begin = line->GetWorldControlPoint(0);
  mitk::Point3D end = line->GetWorldControlPoint(1);
  itk::Vector<double,3> direction = (end - begin);
  higher.Fill(direction.GetNorm());
  histogram->Initialize(siz, lower, higher);
  for(int i = 0; i < sampling; i++)
  {
    mitk::Point3D location = begin + double(i)/sampling * direction;
    double d = m_SelectedImage->GetPixelValueByWorldCoordinate(begin + double(i)/sampling * direction);
    histogram->SetFrequency(i,d);
  }
  m_Controls->m_HistogramWidget->SetHistogramModeToDirectHistogram();
  m_Controls->m_HistogramWidget->SetHistogram( histogram );
  m_Controls->m_HistogramWidget->UpdateItemModelFromHistogram();

}
void QmitkImageStatistics::CreateConnections (  ) [virtual]

method for creating the connections of main and control widget

Definition at line 133 of file QmitkImageStatisticsView.cpp.

References ClipboardHistogramButtonClicked(), ClipboardStatisticsButtonClicked(), Ui_QmitkImageStatisticsViewControls::m_ButtonCopyHistogramToClipboard, Ui_QmitkImageStatisticsViewControls::m_ButtonCopyStatisticsToClipboard, and m_Controls.

Referenced by CreateQtPartControl().

{
  if ( m_Controls )
  {
    connect( (QObject*)(m_Controls->m_ButtonCopyHistogramToClipboard), SIGNAL(clicked()),(QObject*) this, SLOT(ClipboardHistogramButtonClicked()));
    connect( (QObject*)(m_Controls->m_ButtonCopyStatisticsToClipboard), SIGNAL(clicked()),(QObject*) this, SLOT(ClipboardStatisticsButtonClicked()));
  }
}
void QmitkImageStatistics::CreateQtPartControl ( QWidget *  parent ) [virtual]
bool QmitkImageStatistics::event ( QEvent *  event ) [virtual]

Definition at line 715 of file QmitkImageStatisticsView.cpp.

References m_StatisticsUpdatePending, QmitkRequestStatisticsUpdateEvent::StatisticsUpdateRequest, and UpdateStatistics().

{
  if ( event->type() == (QEvent::Type) QmitkRequestStatisticsUpdateEvent::StatisticsUpdateRequest )
  {
    // Update statistics

    m_StatisticsUpdatePending = false;

    this->UpdateStatistics();
    return true;
  }

  return false;
}
void QmitkImageStatistics::FillStatisticsTableView ( const mitk::ImageStatisticsCalculator::Statistics s,
const mitk::Image image 
) [protected]

Definition at line 204 of file QmitkImageStatisticsView.cpp.

References mitk::BaseData::GetGeometry(), mitk::Geometry3D::GetSpacing(), m_Controls, Ui_QmitkImageStatisticsViewControls::m_StatisticsTable, mitk::ImageStatisticsCalculator::Statistics::Max, mitk::ImageStatisticsCalculator::Statistics::Mean, mitk::ImageStatisticsCalculator::Statistics::Min, mitk::ImageStatisticsCalculator::Statistics::N, mitk::ImageStatisticsCalculator::Statistics::RMS, and mitk::ImageStatisticsCalculator::Statistics::Sigma.

Referenced by UpdateStatistics().

{
  m_Controls->m_StatisticsTable->setItem( 0, 0, new QTableWidgetItem(
    QString("%1").arg(s.Mean, 0, 'f', 2) ) );

  m_Controls->m_StatisticsTable->setItem( 0, 1, new QTableWidgetItem(
    QString("%1").arg(s.Sigma, 0, 'f', 2) ) );

  m_Controls->m_StatisticsTable->setItem( 0, 2, new QTableWidgetItem(
    QString("%1").arg(s.RMS, 0, 'f', 2) ) );

  m_Controls->m_StatisticsTable->setItem( 0, 3, new QTableWidgetItem(
    QString("%1").arg(s.Max, 0, 'f', 2) ) );

  m_Controls->m_StatisticsTable->setItem( 0, 4, new QTableWidgetItem(
    QString("%1").arg(s.Min, 0, 'f', 2) ) );

  m_Controls->m_StatisticsTable->setItem( 0, 5, new QTableWidgetItem(
    QString("%1").arg(s.N) ) );

  const mitk::Geometry3D *geometry = image->GetGeometry();
  if ( geometry != NULL )
  {
    const mitk::Vector3D &spacing = image->GetGeometry()->GetSpacing();
    double volume = spacing[0] * spacing[1] * spacing[2] * (double) s.N;
    m_Controls->m_StatisticsTable->setItem( 0, 6, new QTableWidgetItem(
      QString("%1").arg(volume, 0, 'f', 2) ) );
  }
  else
  {
    m_Controls->m_StatisticsTable->setItem( 0, 6, new QTableWidgetItem(
      "NA" ) );
  }
}
void QmitkImageStatistics::InvalidateStatisticsTableView (  ) [protected]

Definition at line 242 of file QmitkImageStatisticsView.cpp.

References m_Controls, and Ui_QmitkImageStatisticsViewControls::m_StatisticsTable.

Referenced by OnSelectionChanged(), and UpdateStatistics().

{
  for ( unsigned int i = 0; i < 7; ++i )
  {
    m_Controls->m_StatisticsTable->setItem( 0, i, new QTableWidgetItem( "NA" ) );
  }
}
bool QmitkImageStatistics::IsExclusiveFunctionality (  ) const [virtual]

Some functionalities need to add special interactors, removes the crosshair from the stdmultiwidget, etc. In this case the functionality has to tidy up when changing to another functionality which also wants to change the "default configuration". In the old Qt3-based version of MITK, two functionalities could never be opened at the same time so that the methods Activated() and Deactivated() were the right place for the functionalitites to add/remove their interactors, etc. This is still true for the new MITK Workbench, but as there can be several functionalities visible at the same time, the behaviour concerning when Activated() and Deactivated() are called has changed:

1. Activated() and Deactivated() are only called if IsExclusiveFunctionality() returns true

2. If only one standalone functionality is or becomes visible, Activated() will be called on that functionality

3. If two or more standalone functionalities are visible, Activated() will be called on the functionality that receives focus, Deactivated() will be called on the one that looses focus, gets hidden or closed

As a consequence of 1. if you overwrite IsExclusiveFunctionality() and let it return false, you signalize the MITK Workbench that this functionality does nothing to the "default configuration" and can easily be visible while other functionalities are also visible.

By default the method returns true.

Returns:
true if this functionality is meant to work as a standalone view, false otherwise

Reimplemented from QmitkFunctionality.

Definition at line 755 of file QmitkImageStatisticsView.cpp.

{
  return false;
}
void QmitkImageStatistics::OnSelectionChanged ( std::vector< mitk::DataNode * >   ) [virtual]

Called when the selection in the workbench changed

Reimplemented from QmitkFunctionality.

Definition at line 251 of file QmitkImageStatisticsView.cpp.

References QmitkVtkLineProfileWidget::ClearItemModel(), QmitkVtkHistogramWidget::ClearItemModel(), mitk::DataNode::GetData(), QmitkFunctionality::GetDefaultDataStorage(), mitk::DataNode::GetPropertyValue(), InvalidateStatisticsTableView(), QmitkFunctionality::IsVisible(), m_Controls, m_CurrentStatisticsValid, Ui_QmitkImageStatisticsViewControls::m_ErrorMessageLabel, Ui_QmitkImageStatisticsViewControls::m_HistogramWidget, m_ImageMaskObserverTag, m_ImageObserverTag, Ui_QmitkImageStatisticsViewControls::m_LineProfileWidget, m_PlanarFigureObserverTag, m_SelectedImage, m_SelectedImageMask, m_SelectedImageNode, Ui_QmitkImageStatisticsViewControls::m_SelectedMaskLabel, m_SelectedMaskNode, m_SelectedPlanarFigure, RemoveOrphanImages(), and RequestStatisticsUpdate().

Referenced by Visible().

{
  // Clear any unreferenced images
  this->RemoveOrphanImages();

  if ( !this->IsVisible() )
  {
    return;
  }

  // Check if selection makeup consists only of valid nodes:
  // One image, segmentation or planarFigure
  // One image and one of the other two
  bool tooManyNodes( true );
  bool invalidNodes( true );

  if ( nodes.size() < 3 )
  {
    tooManyNodes = false;
  }

  if( !tooManyNodes )
  {
    unsigned int numberImages = 0;
    unsigned int numberSegmentations = 0;
    unsigned int numberPlanarFigures = 0;

    for ( unsigned int index = 0; index < nodes.size(); index++ )
    {
      m_SelectedImageMask = dynamic_cast< mitk::Image * >( nodes[ index ]->GetData() );
      m_SelectedPlanarFigure = dynamic_cast< mitk::PlanarFigure * >( nodes[ index ]->GetData() );

      if ( m_SelectedImageMask != NULL )
      {
        bool isMask( false );
        nodes[ index ]->GetPropertyValue("binary", isMask);
        if ( !isMask )
        {
          numberImages++;
        }
        else
        {
          numberSegmentations++;
          if ( numberImages != 0 ) // image should be last element
          {
            std::swap( nodes[ index ], nodes[ index - 1 ] );
          }
        }
      }
      else if ( m_SelectedPlanarFigure != NULL )
      {
        numberPlanarFigures++;
        if ( numberImages != 0 ) // image should be last element
        {
          std::swap( nodes[ index ], nodes[ index - 1 ] );
        }
      }
    }

    if ( ( numberPlanarFigures + numberSegmentations + numberImages ) == nodes.size() && //No invalid nodes
      ( numberPlanarFigures + numberSegmentations ) < 2 && numberImages < 2 
      // maximum of one image and/or one of either planar figure or segmentation
      )
    {
      invalidNodes = false;
    }
  }

  if ( nodes.empty() || tooManyNodes || invalidNodes )
  {
    // Nothing to do: invalidate image, clear statistics, histogram, and GUI
    m_SelectedImage = NULL;
    this->InvalidateStatisticsTableView() ;
    m_Controls->m_HistogramWidget->ClearItemModel();
    m_Controls->m_LineProfileWidget->ClearItemModel();

    m_CurrentStatisticsValid = false;
    m_Controls->m_ErrorMessageLabel->hide();
    m_Controls->m_SelectedMaskLabel->setText( "None" );
    return;
  }

  // Get selected element

  mitk::DataNode *selectedNode = nodes.front();
  mitk::Image *selectedImage = dynamic_cast< mitk::Image * >( selectedNode->GetData() );

  // Find the next parent/grand-parent node containing an image, if any
  mitk::DataStorage::SetOfObjects::ConstPointer parentObjects;
  mitk::DataNode *parentNode = NULL;
  mitk::Image *parentImage = NULL;

  // Possibly previous change listeners
  if ( (m_SelectedPlanarFigure != NULL) && (m_PlanarFigureObserverTag >= 0) )
  {
    m_SelectedPlanarFigure->RemoveObserver( m_PlanarFigureObserverTag );
    m_PlanarFigureObserverTag = -1;
  }
  if ( (m_SelectedImage != NULL) && (m_ImageObserverTag >= 0) )
  {
    m_SelectedImage->RemoveObserver( m_ImageObserverTag );
    m_ImageObserverTag = -1;
  }
  if ( (m_SelectedImageMask != NULL) && (m_ImageMaskObserverTag >= 0) )
  {
    m_SelectedImageMask->RemoveObserver( m_ImageMaskObserverTag );
    m_ImageMaskObserverTag = -1;
  }

  // Deselect all images and masks by default
  m_SelectedImageNode = NULL;
  m_SelectedImage = NULL;
  m_SelectedMaskNode = NULL;
  m_SelectedImageMask = NULL;
  m_SelectedPlanarFigure = NULL;

  {
    unsigned int parentObjectIndex = 0;
    parentObjects = this->GetDefaultDataStorage()->GetSources( selectedNode );
    while( parentObjectIndex < parentObjects->Size() )
    {
      // Use first parent object (if multiple parents are present)
      parentNode = parentObjects->ElementAt( parentObjectIndex );
      parentImage = dynamic_cast< mitk::Image * >( parentNode->GetData() );
      if( parentImage != NULL )
      {
        break;
      }
      parentObjectIndex++;
    }
  }

  if ( nodes.size() == 2 )
  {
    parentNode = nodes.back();
    parentImage = dynamic_cast< mitk::Image * >( parentNode->GetData() );
  }

  if ( parentImage != NULL )
  {
    m_SelectedImageNode = parentNode;
    m_SelectedImage = parentImage;

    // Check if a valid mask has been selected (Image or PlanarFigure)
    m_SelectedImageMask = dynamic_cast< mitk::Image * >( selectedNode->GetData() );
    m_SelectedPlanarFigure = dynamic_cast< mitk::PlanarFigure * >( selectedNode->GetData() );

    // Check whether ImageMask is a binary segmentation

    if ( (m_SelectedImageMask != NULL) )
    {
      bool isMask( false );
      selectedNode->GetPropertyValue("binary", isMask);
      if ( !isMask )
      {
        m_SelectedImageNode = selectedNode;
        m_SelectedImage = selectedImage;
        m_SelectedImageMask = NULL;
      }
      else
      {
        m_SelectedMaskNode = selectedNode;
      }
    }
    else if ( (m_SelectedPlanarFigure != NULL) )
    {
      m_SelectedMaskNode = selectedNode;
    }
  }
  else if ( selectedImage != NULL )
  {
    m_SelectedImageNode = selectedNode;
    m_SelectedImage = selectedImage;
  }


  typedef itk::SimpleMemberCommand< QmitkImageStatistics > ITKCommandType;
  ITKCommandType::Pointer changeListener;
  changeListener = ITKCommandType::New();
  changeListener->SetCallbackFunction( this, &QmitkImageStatistics::RequestStatisticsUpdate );

  // Add change listeners to selected objects
  if ( m_SelectedImage != NULL )
  {
    m_ImageObserverTag = m_SelectedImage->AddObserver(
      itk::ModifiedEvent(), changeListener );
  }

  if ( m_SelectedImageMask != NULL )
  {
    m_ImageMaskObserverTag = m_SelectedImageMask->AddObserver(
      itk::ModifiedEvent(), changeListener );
  }

  if ( m_SelectedPlanarFigure != NULL )
  {
    m_PlanarFigureObserverTag = m_SelectedPlanarFigure->AddObserver(
      mitk::EndInteractionPlanarFigureEvent(), changeListener );
  }


  // Clear statistics / histogram GUI if nothing is selected
  if ( m_SelectedImage == NULL )
  {
    // Clear statistics, histogram, and GUI
    this->InvalidateStatisticsTableView();
    m_Controls->m_HistogramWidget->ClearItemModel();
    m_Controls->m_LineProfileWidget->ClearItemModel();
    m_CurrentStatisticsValid = false;
    m_Controls->m_ErrorMessageLabel->hide();
    m_Controls->m_SelectedMaskLabel->setText( "None" );
  }
  else
  {
    // Else, request statistics and GUI update
    this->RequestStatisticsUpdate();
  }
}
void QmitkImageStatistics::RemoveOrphanImages (  ) [protected]

Removes any cached images which are no longer referenced elsewhere.

Definition at line 686 of file QmitkImageStatisticsView.cpp.

References QmitkFunctionality::GetDefaultDataStorage(), m_CurrentStatisticsCalculator, m_ImageStatisticsMap, m_SelectedImage, m_SelectedImageNode, and mitk::NodePredicateData::New().

Referenced by OnSelectionChanged(), and UpdateStatistics().

{
  ImageStatisticsMapType::iterator it = m_ImageStatisticsMap.begin();

  while ( it != m_ImageStatisticsMap.end() )
  {
    mitk::Image *image = it->first;
    mitk::ImageStatisticsCalculator *calculator = it->second;
    ++it;

    mitk::NodePredicateData::Pointer hasImage = mitk::NodePredicateData::New( image );
    if ( this->GetDefaultDataStorage()->GetNode( hasImage ) == NULL )
    {
      if ( m_SelectedImage == image )
      {
        m_SelectedImage = NULL;
        m_SelectedImageNode = NULL;
      }
      if ( m_CurrentStatisticsCalculator == calculator )
      {
        m_CurrentStatisticsCalculator = NULL;
      }
      m_ImageStatisticsMap.erase( image );
      it = m_ImageStatisticsMap.begin();
    }
  }
}
void QmitkImageStatistics::RequestStatisticsUpdate (  ) [protected]

Issues a request to update statistics by sending an event to the Qt event processing queue.

Statistics update should only be executed after program execution returns to the Qt main loop. This mechanism also prevents multiple execution of updates where only one is required.

Definition at line 676 of file QmitkImageStatisticsView.cpp.

References m_StatisticsUpdatePending.

Referenced by OnSelectionChanged().

{
  if ( !m_StatisticsUpdatePending )
  {
    QApplication::postEvent( this, new QmitkRequestStatisticsUpdateEvent );
    m_StatisticsUpdatePending = true;
  }
}
void QmitkImageStatistics::StdMultiWidgetAvailable ( QmitkStdMultiWidget stdMultiWidget ) [protected, virtual]

Called when a StdMultiWidget is available. Should not be used anymore, see GetActiveStdMultiWidget()

See also:
GetActiveStdMultiWidget()

Reimplemented from QmitkFunctionality.

Definition at line 143 of file QmitkImageStatisticsView.cpp.

void QmitkImageStatistics::UpdateProgressBar (  ) [protected]

Listener for progress events to update progress bar.

Definition at line 670 of file QmitkImageStatisticsView.cpp.

References mitk::ProgressBar::GetInstance().

Referenced by UpdateStatistics().

{
  mitk::ProgressBar::GetInstance()->Progress();
}
void QmitkImageStatistics::UpdateStatistics (  ) [protected]

Recalculate statistics for currently selected image and mask and update the GUI.

Definition at line 471 of file QmitkImageStatisticsView.cpp.

References QmitkVtkLineProfileWidget::ClearItemModel(), QmitkVtkHistogramWidget::ClearItemModel(), FillStatisticsTableView(), QmitkFunctionality::GetActiveStdMultiWidget(), mitk::PlanarFigure::GetGeometry2D(), mitk::ProgressBar::GetInstance(), mitk::DataNode::GetName(), mitk::PixelType::GetNumberOfComponents(), mitk::Image::GetPixelType(), mitk::Stepper::GetPos(), mitk::BaseController::GetTime(), QmitkStdMultiWidget::GetTimeNavigationController(), InvalidateStatisticsTableView(), m_Controls, m_CurrentStatisticsCalculator, m_CurrentStatisticsValid, Ui_QmitkImageStatisticsViewControls::m_ErrorMessageLabel, Ui_QmitkImageStatisticsViewControls::m_HistogramWidget, m_ImageStatisticsMap, Ui_QmitkImageStatisticsViewControls::m_LineProfileWidget, m_SelectedImage, m_SelectedImageMask, Ui_QmitkImageStatisticsViewControls::m_SelectedMaskLabel, m_SelectedMaskNode, m_SelectedPlanarFigure, Ui_QmitkImageStatisticsViewControls::m_StatisticsWidgetStack, MITK_ERROR, MITK_INFO, mitk::ImageStatisticsCalculator::New(), RemoveOrphanImages(), QmitkVtkHistogramWidget::SetHistogram(), QmitkVtkHistogramWidget::SetHistogramModeToDirectHistogram(), QmitkVtkLineProfileWidget::SetImage(), QmitkVtkLineProfileWidget::SetPlanarFigure(), QmitkVtkHistogramWidget::UpdateItemModelFromHistogram(), QmitkVtkLineProfileWidget::UpdateItemModelFromPath(), UpdateProgressBar(), QmitkFunctionality::WaitCursorOff(), and QmitkFunctionality::WaitCursorOn().

Referenced by event().

{
  // Remove any cached images that are no longer referenced elsewhere
  this->RemoveOrphanImages();

  QmitkStdMultiWidget *multiWidget = this->GetActiveStdMultiWidget();
  if ( multiWidget == NULL )
  {
    return;
  }

  unsigned int timeStep = multiWidget->GetTimeNavigationController()->GetTime()->GetPos();

  if ( m_SelectedImage != NULL )
  {
    // Check if a the selected image is a multi-channel image. If yes, statistics
    // cannot be calculated currently.
    if ( m_SelectedImage->GetPixelType().GetNumberOfComponents() > 1 )
    {
      std::stringstream message;
      message << "<font color='red'>Multi-component images not supported.</font>";
      m_Controls->m_ErrorMessageLabel->setText( message.str().c_str() );
      m_Controls->m_ErrorMessageLabel->show();

      this->InvalidateStatisticsTableView();
      m_Controls->m_StatisticsWidgetStack->setCurrentIndex( 0 );
      m_Controls->m_HistogramWidget->ClearItemModel();
      m_CurrentStatisticsValid = false;
      return;
    }

    // Retrieve ImageStatisticsCalculator from has map (or create a new one
    // for this image if non-existant)
    ImageStatisticsMapType::iterator it =
      m_ImageStatisticsMap.find( m_SelectedImage );

    if ( it != m_ImageStatisticsMap.end() )
    {
      m_CurrentStatisticsCalculator = it->second;
      MITK_INFO << "Retrieving StatisticsCalculator";
    }
    else
    {
      m_CurrentStatisticsCalculator = mitk::ImageStatisticsCalculator::New();
      m_CurrentStatisticsCalculator->SetImage( m_SelectedImage );
      m_ImageStatisticsMap[m_SelectedImage] = m_CurrentStatisticsCalculator;
      MITK_INFO << "Creating StatisticsCalculator";
    }

    std::string maskName;
    std::string maskType;
    unsigned int maskDimension;

    if ( m_SelectedImageMask != NULL )
    {
      m_CurrentStatisticsCalculator->SetImageMask( m_SelectedImageMask );
      m_CurrentStatisticsCalculator->SetMaskingModeToImage();

      maskName = m_SelectedMaskNode->GetName();
      maskType = m_SelectedImageMask->GetNameOfClass();
      maskDimension = 3;
    }
    else if ( m_SelectedPlanarFigure != NULL )
    {
      m_CurrentStatisticsCalculator->SetPlanarFigure( m_SelectedPlanarFigure );
      m_CurrentStatisticsCalculator->SetMaskingModeToPlanarFigure();

      maskName = m_SelectedMaskNode->GetName();
      maskType = m_SelectedPlanarFigure->GetNameOfClass();
      maskDimension = 2;
    }
    else
    {
      m_CurrentStatisticsCalculator->SetMaskingModeToNone();

      maskName = "None";
      maskType = "";
      maskDimension = 0;
    }

    std::stringstream maskLabel;
    maskLabel << maskName;
    if ( maskDimension > 0 )
    {
      maskLabel << "  [" << maskDimension << "D " << maskType << "]";
    }

    m_Controls->m_SelectedMaskLabel->setText( maskLabel.str().c_str() );

    bool statisticsChanged = false;
    bool statisticsCalculationSuccessful = false;

    // Initialize progress bar
    mitk::ProgressBar::GetInstance()->AddStepsToDo( 100 );

    // Install listener for progress events and initialize progress bar
    typedef itk::SimpleMemberCommand< QmitkImageStatistics > ITKCommandType;
    ITKCommandType::Pointer progressListener;
    progressListener = ITKCommandType::New();
    progressListener->SetCallbackFunction( this, &QmitkImageStatistics::UpdateProgressBar );
    unsigned long progressObserverTag = m_CurrentStatisticsCalculator
      ->AddObserver( itk::ProgressEvent(), progressListener );

    // show wait cursor
    this->WaitCursorOn();

    try
    {
      // Compute statistics
      statisticsChanged =
        m_CurrentStatisticsCalculator->ComputeStatistics( timeStep );

      statisticsCalculationSuccessful = true;
    }
    catch ( const std::runtime_error &e )
    {
      // In case of exception, print error message on GUI
      std::stringstream message;
      message << "<font color='red'>" << e.what() << "</font>";
      m_Controls->m_ErrorMessageLabel->setText( message.str().c_str() );
      m_Controls->m_ErrorMessageLabel->show();
    }
    catch ( const std::exception &e )
    {
      MITK_ERROR << "Caught exception: " << e.what();

      // In case of exception, print error message on GUI
      std::stringstream message;
      message << "<font color='red'>Error in calculating histogram</font>";
      m_Controls->m_ErrorMessageLabel->setText( message.str().c_str() );
      m_Controls->m_ErrorMessageLabel->show();
    }

    m_CurrentStatisticsCalculator->RemoveObserver( progressObserverTag );

    // Make sure that progress bar closes
    mitk::ProgressBar::GetInstance()->Progress( 100 );

    // remove wait cursor
    this->WaitCursorOff();

    if ( statisticsCalculationSuccessful )
    {
      if ( statisticsChanged )
      {
        // Do not show any error messages
        m_Controls->m_ErrorMessageLabel->hide();

        m_CurrentStatisticsValid = true;
      }

      m_Controls->m_StatisticsWidgetStack->setCurrentIndex( 0 );
      m_Controls->m_HistogramWidget->SetHistogramModeToDirectHistogram();
      m_Controls->m_HistogramWidget->SetHistogram(
        m_CurrentStatisticsCalculator->GetHistogram( timeStep ) );
      m_Controls->m_HistogramWidget->UpdateItemModelFromHistogram();

      MITK_INFO << "UpdateItemModelFromHistogram()";

      this->FillStatisticsTableView(
        m_CurrentStatisticsCalculator->GetStatistics( timeStep ),
        m_SelectedImage );
    }
    else
    {
      m_Controls->m_SelectedMaskLabel->setText( "None" );

      // Clear statistics and histogram
      this->InvalidateStatisticsTableView();
      m_Controls->m_HistogramWidget->ClearItemModel();
      m_CurrentStatisticsValid = false;


      // If a (non-closed) PlanarFigure is selected, display a line profile widget
      if ( m_SelectedPlanarFigure != NULL )
      {
        // check whether PlanarFigure is initialized
        const mitk::Geometry2D *planarFigureGeometry2D = m_SelectedPlanarFigure->GetGeometry2D();
        if ( planarFigureGeometry2D == NULL )
        {
          // Clear statistics, histogram, and GUI
          this->InvalidateStatisticsTableView();
          m_Controls->m_HistogramWidget->ClearItemModel();
          m_Controls->m_LineProfileWidget->ClearItemModel();
          m_CurrentStatisticsValid = false;
          m_Controls->m_ErrorMessageLabel->hide();
          m_Controls->m_SelectedMaskLabel->setText( "None" );
          return;
        }
        // TODO: enable line profile widget
        m_Controls->m_StatisticsWidgetStack->setCurrentIndex( 1 );       
        m_Controls->m_LineProfileWidget->SetImage( m_SelectedImage );
        m_Controls->m_LineProfileWidget->SetPlanarFigure( m_SelectedPlanarFigure );
        m_Controls->m_LineProfileWidget->UpdateItemModelFromPath();
      }
    }
  }
}
void QmitkImageStatistics::Visible (  ) [protected, virtual]

Called when this functionality becomes visible ( no matter what IsExclusiveFunctionality() returns )

Reimplemented from QmitkFunctionality.

Definition at line 760 of file QmitkImageStatisticsView.cpp.

References QmitkFunctionality::GetDataManagerSelection(), and OnSelectionChanged().


Member Data Documentation

QString QmitkImageStatistics::m_Clipboard [protected]

Definition at line 134 of file QmitkImageStatisticsView.h.

unsigned int QmitkImageStatistics::m_CurrentTime [protected]

Definition at line 132 of file QmitkImageStatisticsView.h.

Definition at line 145 of file QmitkImageStatisticsView.h.

Referenced by OnSelectionChanged(), and ~QmitkImageStatistics().

Definition at line 144 of file QmitkImageStatisticsView.h.

Referenced by OnSelectionChanged(), and ~QmitkImageStatistics().

Definition at line 151 of file QmitkImageStatisticsView.h.

Referenced by RemoveOrphanImages(), and UpdateStatistics().

Definition at line 146 of file QmitkImageStatisticsView.h.

Referenced by OnSelectionChanged(), and ~QmitkImageStatistics().

Definition at line 137 of file QmitkImageStatisticsView.h.

Referenced by OnSelectionChanged(), and RemoveOrphanImages().

Definition at line 140 of file QmitkImageStatisticsView.h.

Referenced by OnSelectionChanged(), and UpdateStatistics().

Definition at line 157 of file QmitkImageStatisticsView.h.

Referenced by event(), and RequestStatisticsUpdate().

Definition at line 131 of file QmitkImageStatisticsView.h.


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