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

QmitkIGTRecorderView Class Reference
[Functionalities]

QmitkIGTRecorderView. More...

#include <QmitkIGTRecorderView.h>

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

List of all members.

Public Member Functions

 QmitkIGTRecorderView (QObject *parent=0, const char *name=0)
 default constructor
virtual ~QmitkIGTRecorderView ()
 default destructor
virtual void CreateQtPartControl (QWidget *parent)
 method for creating the widget containing the application controls, like sliders, buttons etc.
virtual void StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget)
virtual void StdMultiWidgetNotAvailable ()
virtual void CreateConnections ()
 method for creating the connections of main and control widget

Protected Slots

void OnStartRecording ()
void OnStopRecording ()
void OnPauseRecording (bool pause)
void OnStartReplaying ()
void OnStopReplaying ()
void RecordFrame ()
void OnConnect ()
void OnDisconnect ()

Protected Member Functions

mitk::TrackingDevice::Pointer ConfigureTrackingDevice ()
 create the selected tracker object and configure it (using values from m_Controls)
void SetupIGTPipeline (mitk::TrackingDevice::Pointer tracker, QString fileName)
mitk::DataNode::Pointer CreateInstrumentVisualization (const char *label)

Protected Attributes

QmitkStdMultiWidgetm_MultiWidget
 default render widget
Ui::QmitkIGTRecorderControlsm_Controls
 GUI widget for this functionality.
mitk::TrackingDeviceSource::Pointer m_Source
 first filter in the pipeline
mitk::NavigationDataObjectVisualizationFilter::Pointer m_Visualizer
mitk::NavigationDataRecorder::Pointer m_Recorder
 records NDs to a XML file
mitk::NavigationDataToPointSetFilter::Pointer m_PointSetFilter
 has a NDs as input and a PointSet as output
mitk::NavigationDataToMessageFilter::Pointer m_MessageFilter
 calls OnErrorValueChanged when the error value of its input changes
QTimer * m_Timer
 timer for continuous tracking update
QTimer * m_RecordingTimer
 timer for continuous recording
QTimer * m_PlayingTimer
 timer for continuous playing
QStringList m_ToolList
 list to the tool description files
QmitkNDIConfigurationWidgetm_ConfigWidget

Detailed Description

QmitkIGTRecorderView.

Example functionality that shows the usage of the MITK-IGT component

See also:
QmitkFunctionality

Definition at line 47 of file QmitkIGTRecorderView.h.


Constructor & Destructor Documentation

QmitkIGTRecorderView::QmitkIGTRecorderView ( QObject *  parent = 0,
const char *  name = 0 
)

default constructor

Definition at line 60 of file QmitkIGTRecorderView.cpp.

References m_Controls, m_PlayingTimer, m_RecordingTimer, and m_Timer.

 : QmitkFunctionality()
{
  m_Timer = new QTimer(this);
  m_RecordingTimer = new QTimer(this);
  m_PlayingTimer = new QTimer(this);
  //m_XValues.clear();
  //m_YValues.clear();
  m_Controls = NULL;
}
QmitkIGTRecorderView::~QmitkIGTRecorderView (  ) [virtual]

default destructor

Definition at line 72 of file QmitkIGTRecorderView.cpp.

References m_PlayingTimer, m_Recorder, m_RecordingTimer, and OnStopRecording().

{
  this->OnStopRecording();  // cleanup IGT pipeline, if tracking is in progress
  m_RecordingTimer->stop();
  m_PlayingTimer->stop();
  m_Recorder = NULL;
  //m_Player = NULL;
  m_RecordingTimer = NULL;
  m_PlayingTimer = NULL;
}

Member Function Documentation

mitk::TrackingDevice::Pointer QmitkIGTRecorderView::ConfigureTrackingDevice (  ) [protected]

create the selected tracker object and configure it (using values from m_Controls)

void QmitkIGTRecorderView::CreateConnections (  ) [virtual]

method for creating the connections of main and control widget

Definition at line 118 of file QmitkIGTRecorderView.cpp.

References m_ConfigWidget, m_Controls, Ui_QmitkIGTRecorderControls::m_PauseRecording, m_RecordingTimer, Ui_QmitkIGTRecorderControls::m_StartRecording, Ui_QmitkIGTRecorderControls::m_StartReplay, Ui_QmitkIGTRecorderControls::m_StopRecording, Ui_QmitkIGTRecorderControls::m_StopReplay, OnConnect(), OnDisconnect(), OnPauseRecording(), OnStartRecording(), OnStartReplaying(), OnStopRecording(), OnStopReplaying(), and RecordFrame().

Referenced by CreateQtPartControl().

{
  if ( m_Controls )
  {
    connect((QObject*)(m_Controls->m_StartRecording), SIGNAL(clicked()), (QObject*) this, SLOT(OnStartRecording()));
    connect((QObject*)(m_Controls->m_PauseRecording), SIGNAL(toggled (bool)), (QObject*) this, SLOT(OnPauseRecording(bool)));
    connect((QObject*)(m_Controls->m_StopRecording), SIGNAL(clicked()), (QObject*) this, SLOT(OnStopRecording()));
    connect((QObject*)(m_Controls->m_StartReplay), SIGNAL(clicked()), (QObject*) this, SLOT(OnStartReplaying()));
    connect((QObject*)(m_Controls->m_StopReplay), SIGNAL(clicked()), (QObject*) this, SLOT(OnStopReplaying()));
    connect((QObject*)(m_RecordingTimer), SIGNAL(timeout()), (QObject*) this, SLOT(RecordFrame()));
    connect((QObject*)(m_ConfigWidget), SIGNAL(Connected()), this, SLOT(OnConnect()));
    connect((QObject*)(m_ConfigWidget), SIGNAL(Disconnected()), this, SLOT(OnDisconnect()));
  }
}
mitk::DataNode::Pointer QmitkIGTRecorderView::CreateInstrumentVisualization ( const char *  label ) [protected]

Definition at line 310 of file QmitkIGTRecorderView.cpp.

References mitk::DataNode::New(), and mitk::Surface::New().

Referenced by SetupIGTPipeline().

{
  vtkAxes* axes = vtkAxes::New();
  axes->SymmetricOn();
  axes->SetScaleFactor(10.0); 
  vtkTubeFilter* tuber = vtkTubeFilter::New();
  tuber->SetRadius(0.02);
  tuber->SetNumberOfSides(6);
  tuber->SetInputConnection(axes->GetOutputPort());
  vtkTextSource* tss = vtkTextSource::New();
  tss->SetText(label);
  tss->BackingOff();
  vtkConeSource* cone = vtkConeSource::New();
  cone->SetDirection(0.0, 0.0, -1.0); // direction: along z-axis, facing towards -z direction
  cone->SetCenter(0.0, 0.0, 100.0);
  cone->SetHeight(200.0);              // center at 100, height 200 should set the tip of the cone to the origin
  cone->SetRadius(10.0);
  vtkAppendPolyData* ap = vtkAppendPolyData::New();
  //ap->AddInput(tss->GetOutput());
  ap->AddInput(tuber->GetOutput());
  //ap->AddInput(cone->GetOutput());
  ap->GetOutput()->Update();
  mitk::Surface::Pointer dummy = mitk::Surface::New();
  dummy->SetVtkPolyData(ap->GetOutput());
  ap->Delete(); 
  cone->Delete();
  tss->Delete();
  tuber->Delete();
  axes->Delete();

  mitk::DataNode::Pointer node = mitk::DataNode::New();
  node->SetData(dummy);
  node->SetName(label);
  node->SetColor(0.2, 0.9, 0.2);
  //node->SetBoolProperty("helperObject", true);
  return node;
}
void QmitkIGTRecorderView::CreateQtPartControl ( QWidget *  parent ) [virtual]

method for creating the widget containing the application controls, like sliders, buttons etc.

Implements berry::QtViewPart.

Definition at line 83 of file QmitkIGTRecorderView.cpp.

References CreateConnections(), QmitkFunctionality::GetDefaultDataStorage(), m_ConfigWidget, m_Controls, Ui_QmitkIGTRecorderControls::m_DeviceConfigGroup, mitk::GroupTagProperty::New(), mitk::NodePredicateDataType::New(), mitk::NodePredicateProperty::New(), mitk::NodePredicateNot::New(), mitk::NodePredicateAnd::New(), QmitkNDIConfigurationWidget::SetDataStorage(), QmitkNDIConfigurationWidget::SetPredicate(), QmitkNDIConfigurationWidget::SetTagProperty(), QmitkNDIConfigurationWidget::SetTagPropertyName(), QmitkNDIConfigurationWidget::SetToolTypes(), and Ui_QmitkIGTRecorderControls::setupUi().

void QmitkIGTRecorderView::OnConnect (  ) [protected, slot]

Definition at line 349 of file QmitkIGTRecorderView.cpp.

References m_Controls, Ui_QmitkIGTRecorderControls::m_PauseRecording, Ui_QmitkIGTRecorderControls::m_StartRecording, and Ui_QmitkIGTRecorderControls::m_StopRecording.

Referenced by CreateConnections().

{
  m_Controls->m_StartRecording->setEnabled(true);
  m_Controls->m_StopRecording->setEnabled(true);
  m_Controls->m_PauseRecording->setEnabled(true);
  //m_Controls->m_StartReplay->setEnabled(true);
  //m_Controls->m_StopReplay->setEnabled(true);

}
void QmitkIGTRecorderView::OnDisconnect (  ) [protected, slot]
void QmitkIGTRecorderView::OnPauseRecording ( bool  pause ) [protected, slot]

Definition at line 196 of file QmitkIGTRecorderView.cpp.

References m_RecordingTimer.

Referenced by CreateConnections().

{
  if (pause == true)
    m_RecordingTimer->stop();
  else
    m_RecordingTimer->start(50);
}
void QmitkIGTRecorderView::OnStartRecording (  ) [protected, slot]

Definition at line 134 of file QmitkIGTRecorderView.cpp.

References QmitkFunctionality::GetActiveStdMultiWidget(), QmitkFunctionality::GetDefaultDataStorage(), mitk::StatusBar::GetInstance(), mitk::RenderingManager::GetInstance(), QmitkNDIConfigurationWidget::GetTracker(), m_ConfigWidget, m_RecordingTimer, m_Source, mitk::DataNode::New(), mitk::TrackingVolume::New(), SetupIGTPipeline(), and QmitkStdMultiWidget::SetWidgetPlanesVisibility().

Referenced by CreateConnections().

{
  if (m_Source.IsNotNull())
    if (m_Source->IsTracking())
      return;

  if ((m_ConfigWidget == NULL))
    return; 
  mitk::TrackingDevice::Pointer tracker = m_ConfigWidget->GetTracker();

  QString fileName = QFileDialog::getSaveFileName(NULL, tr("Save tracking data to"),"D:/home/jochen/Versuche/2010.01.25 EM Messungen in der Speiseröhre" /*QDir::homePath()*/, tr("MITK Navigation Data XML logfile(*.xml)"));
  if (fileName.isEmpty())
    return;
// recorder!

  if (this->GetDefaultDataStorage()->GetNamedNode("Tracking Volume") == NULL) // add tracking volume node
  {
    mitk::TrackingVolume::Pointer tv = mitk::TrackingVolume::New();
    tv->SetTrackingDeviceType(tracker->GetType());
    mitk::DataNode::Pointer n = mitk::DataNode::New();
    n->SetData(tv);
    n->SetName("Tracking Volume");
    n->SetOpacity(0.1);
    n->SetColor(0.4, 0.4, 1.0);
    this->GetDefaultDataStorage()->Add(n);
    this->GetActiveStdMultiWidget()->SetWidgetPlanesVisibility(false);
    mitk::RenderingManager::GetInstance()->InitializeViews(this->GetDefaultDataStorage()->ComputeBoundingGeometry3D(this->GetDefaultDataStorage()->GetAll()));  // reset render window geometry to include all objects
  }
  try
  {
    this->SetupIGTPipeline(tracker, fileName);
    //m_Source->Connect();
    m_Source->StartTracking();
    m_RecordingTimer->start(50);
  }
  catch (std::exception& e)
  {
    mitk::StatusBar::GetInstance()->DisplayText(QString("Error during navigation pipeline setup: %1").arg(e.what()).toLatin1(), 4000);
    m_RecordingTimer->stop();
  }
}
void QmitkIGTRecorderView::OnStartReplaying (  ) [protected, slot]

Definition at line 231 of file QmitkIGTRecorderView.cpp.

Referenced by CreateConnections().

{

}
void QmitkIGTRecorderView::OnStopRecording (  ) [protected, slot]

Definition at line 177 of file QmitkIGTRecorderView.cpp.

References m_MessageFilter, m_PointSetFilter, m_Recorder, m_RecordingTimer, m_Source, and m_Visualizer.

Referenced by CreateConnections(), OnDisconnect(), and ~QmitkIGTRecorderView().

{
  if (m_RecordingTimer != NULL)
    m_RecordingTimer->stop();
  if (m_Recorder.IsNotNull())
    m_Recorder->StopRecording();
  if (m_Source.IsNotNull())
  {
    m_Source->StopTracking();
    //m_Source->Disconnect();
  }  
  m_MessageFilter = NULL;
  m_PointSetFilter = NULL;
  m_Recorder = NULL;
  m_Visualizer = NULL;
  //m_Source = NULL;
}
void QmitkIGTRecorderView::OnStopReplaying (  ) [protected, slot]

Definition at line 237 of file QmitkIGTRecorderView.cpp.

Referenced by CreateConnections().

{

}
void QmitkIGTRecorderView::RecordFrame (  ) [protected, slot]

Definition at line 205 of file QmitkIGTRecorderView.cpp.

References QmitkFunctionality::GetActiveStdMultiWidget(), mitk::StatusBar::GetInstance(), mitk::RenderingManager::GetInstance(), m_Controls, m_PointSetFilter, m_Recorder, Ui_QmitkIGTRecorderControls::m_UpdateRecorder, Ui_QmitkIGTRecorderControls::m_UpdateTrajectory, and m_Visualizer.

Referenced by CreateConnections().

{
 
  try
  {
    bool updated = false;
    if ((m_Controls->m_UpdateTrajectory->checkState() == Qt::Checked) && (m_PointSetFilter.IsNotNull()))
      m_PointSetFilter->Update(); // update pipeline
    else
      updated |= false;
    if ((m_Controls->m_UpdateRecorder->checkState() == Qt::Checked) && (m_Recorder.IsNotNull()))
      m_Recorder->Update(); // record data to file
    else
      updated |= false;
    if ((updated == false) && (m_Recorder.IsNotNull()))
      m_Visualizer->Update();

    mitk::RenderingManager::GetInstance()->RequestUpdate(this->GetActiveStdMultiWidget()->GetRenderWindow4()->GetRenderWindow()); // render 3D scene
  }
  catch (...)
  {
    mitk::StatusBar::GetInstance()->DisplayText("Error during navigation pipeline update", 1000);
  }
}
void QmitkIGTRecorderView::SetupIGTPipeline ( mitk::TrackingDevice::Pointer  tracker,
QString  fileName 
) [protected]

Definition at line 243 of file QmitkIGTRecorderView.cpp.

References mitk::DataStorage::Add(), CreateInstrumentVisualization(), QmitkFunctionality::GetDefaultDataStorage(), QmitkNDIConfigurationWidget::GetToolsByToolType(), m_ConfigWidget, m_MessageFilter, m_PointSetFilter, m_Recorder, m_Source, m_Visualizer, mitk::NavigationDataToPointSetFilter::Mode3D, mitk::FloatProperty::New(), mitk::ColorProperty::New(), mitk::DataNode::New(), mitk::NavigationDataRecorder::New(), mitk::NavigationDataToPointSetFilter::New(), mitk::NavigationDataToMessageFilter::New(), mitk::NavigationDataObjectVisualizationFilter::New(), and mitk::TrackingDeviceSource::New().

Referenced by OnStartRecording().

{
  mitk::DataStorage* ds = this->GetDefaultDataStorage();
  if (ds == NULL)
    throw std::invalid_argument("DataStorage not available");
  if (tracker.IsNull())
    throw std::invalid_argument("invalid tracking device provided.");

  
  if (m_ConfigWidget->GetToolsByToolType("Instrument").isEmpty())
    throw std::invalid_argument("insufficient tool assignments for instrument");

  /* build pipeline filters */
  if (m_Source.IsNull())
  {
    m_Source = mitk::TrackingDeviceSource::New();
    m_Source->SetTrackingDevice(tracker);
  }
  m_Visualizer = mitk::NavigationDataObjectVisualizationFilter::New();
  m_MessageFilter = mitk::NavigationDataToMessageFilter::New();
  m_PointSetFilter = mitk::NavigationDataToPointSetFilter::New();
  m_PointSetFilter->SetOperationMode(mitk::NavigationDataToPointSetFilter::Mode3D);
  m_Recorder = mitk::NavigationDataRecorder::New();
  m_Recorder->SetFileName(fileName.toLatin1());

  /* connect inputs and outputs of filters */
  for (unsigned int i = 0; i < m_Source->GetNumberOfOutputs(); ++i)   // source --> visualizer --> messager --> pointset
  {
    /* visualization filter */
    m_Visualizer->SetInput(i, m_Source->GetOutput(i));
    /* message filter */
    m_MessageFilter->SetInput(i, m_Visualizer->GetOutput(i));  
    /* landmark transform filter */
    m_PointSetFilter->SetInput(i, m_MessageFilter->GetOutput(i));
    m_Recorder->AddNavigationData(m_MessageFilter->GetOutput(i));
  }
  m_Recorder->StartRecording();
  /* set filter parameters */
  /* instrument visualization */
  const QList<unsigned int> instruments = m_ConfigWidget->GetToolsByToolType("Instrument");
  foreach (const unsigned int& index, instruments)
  {
    mitk::DataNode::Pointer node = this->CreateInstrumentVisualization(m_Source->GetOutput(index)->GetName());
    ds->Add(node);      
    m_Visualizer->SetRepresentationObject(index, node->GetData());
  }
  for (unsigned int i = 0; i < m_PointSetFilter->GetNumberOfOutputs(); i++)
  {

    mitk::PointSet* p = m_PointSetFilter->GetOutput(i);
    assert(p);

    mitk::DataNode::Pointer pointSetNode = mitk::DataNode::New();
    pointSetNode->SetData(p);
    pointSetNode->SetName(QString("Trajectory of Tool #%1 (%2)").arg(i).arg(QTime::currentTime().toString()).toLatin1());
    mitk::Color color;
    color.Set(0.2, 0.3 * i ,0.9 - 0.2 * i);
    pointSetNode->SetColor(color); //change color of points
    pointSetNode->SetProperty("contourcolor", mitk::ColorProperty::New(color)); // change color of trajectory line
    pointSetNode->SetProperty("pointsize", mitk::FloatProperty::New(1.0)); // enlarge visualization of points
    pointSetNode->SetProperty("contoursize", mitk::FloatProperty::New(0.5)); // enlarge visualization of trajectory line
    pointSetNode->SetBoolProperty("show contour", true);
    pointSetNode->SetBoolProperty("updateDataOnRender", false); // do not call Update() on the pointset during render (this would cause a execution of the pipeline that is still connected to the pointset)
    this->GetDefaultDataStorage()->Add(pointSetNode); //add it to the DataStorage
  }
}
void QmitkIGTRecorderView::StdMultiWidgetAvailable ( QmitkStdMultiWidget stdMultiWidget ) [virtual]

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

See also:
GetActiveStdMultiWidget()

Reimplemented from QmitkFunctionality.

Definition at line 106 of file QmitkIGTRecorderView.cpp.

References m_MultiWidget.

{
  m_MultiWidget = &stdMultiWidget;
}
void QmitkIGTRecorderView::StdMultiWidgetNotAvailable (  ) [virtual]

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

See also:
GetActiveStdMultiWidget()

Reimplemented from QmitkFunctionality.

Definition at line 112 of file QmitkIGTRecorderView.cpp.

References m_MultiWidget.

{
  m_MultiWidget = NULL;
}

Member Data Documentation

GUI widget for this functionality.

Definition at line 93 of file QmitkIGTRecorderView.h.

Referenced by CreateConnections(), CreateQtPartControl(), OnConnect(), OnDisconnect(), QmitkIGTRecorderView(), and RecordFrame().

calls OnErrorValueChanged when the error value of its input changes

Definition at line 99 of file QmitkIGTRecorderView.h.

Referenced by OnStopRecording(), and SetupIGTPipeline().

default render widget

Definition at line 92 of file QmitkIGTRecorderView.h.

Referenced by StdMultiWidgetAvailable(), and StdMultiWidgetNotAvailable().

timer for continuous playing

Definition at line 105 of file QmitkIGTRecorderView.h.

Referenced by QmitkIGTRecorderView(), and ~QmitkIGTRecorderView().

has a NDs as input and a PointSet as output

Definition at line 98 of file QmitkIGTRecorderView.h.

Referenced by OnStopRecording(), RecordFrame(), and SetupIGTPipeline().

records NDs to a XML file

Definition at line 97 of file QmitkIGTRecorderView.h.

Referenced by OnStopRecording(), RecordFrame(), SetupIGTPipeline(), and ~QmitkIGTRecorderView().

first filter in the pipeline

Definition at line 95 of file QmitkIGTRecorderView.h.

Referenced by OnStartRecording(), OnStopRecording(), and SetupIGTPipeline().

QTimer* QmitkIGTRecorderView::m_Timer [protected]

timer for continuous tracking update

Definition at line 103 of file QmitkIGTRecorderView.h.

Referenced by QmitkIGTRecorderView().

QStringList QmitkIGTRecorderView::m_ToolList [protected]

list to the tool description files

Definition at line 106 of file QmitkIGTRecorderView.h.

Definition at line 96 of file QmitkIGTRecorderView.h.

Referenced by OnStopRecording(), RecordFrame(), and SetupIGTPipeline().


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