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

QmitkToolPairNavigationView Class Reference
[Internal]

This view can be used to guide one tracking tool to another tracking tool. The plugin connects to a tracking system and shows the connected/added tools in two 3D widgets (standard 3D widget is interactable, the other (widget2) isn't). Furthermore it calculates the distance between the two tools and displays it in GUI. In widget 4 the tool connected on port b is shown from the point of view of the tool in port a. More...

#include <QmitkToolPairNavigationView.h>

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

List of all members.

Public Member Functions

 QmitkToolPairNavigationView ()
virtual ~QmitkToolPairNavigationView ()
virtual void CreateQtPartControl (QWidget *parent)
virtual void CreateConnections ()
 Creation of the connections of main and control widget.
virtual void Activated ()
 Called when the functionality is activated.
virtual void Deactivated ()
virtual void StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget)
virtual void StdMultiWidgetNotAvailable ()

Static Public Attributes

static const std::string VIEW_ID = "org.mitk.views.toolpairnavigation"

Protected Types

typedef std::map< std::string,
unsigned int > 
NameToIndexMap
typedef std::list< std::string > StringList

Protected Slots

void Disconnected ()
void ToolsAdded (QStringList tools)
void ToolsChanged ()
void SetNavigationUp ()
 starting navigation
void StopNavigation ()
 stopping navigation
void StartNavigation ()
void RenderScene ()

Protected Member Functions

void SetupIGTPipeline ()
 setup the IGT pipeline
void DestroyIGTPipeline ()
 stops the tracking and deletes all pipeline objects
mitk::DataNode::Pointer CreateConeAsInstrumentVisualization (const char *label="")
 create objects for visualization
mitk::DataNode::Pointer CreateSphereAsInstrumentVisualization (const char *label="")
void RemoveVisualizationObjects (mitk::DataStorage *ds)
 remove the visualized objects
void CreateBundleWidgets (QWidget *parent)
 setting up the bundle widgets

Protected Attributes

QmitkStdMultiWidgetm_MultiWidget
 MultiWidget for this view.
QmitkToolDistanceWidgetm_DistanceWidget
 GUI widget with tool distances matrix.
mitk::TrackingDeviceSource::Pointer m_Source
 source of the tracking system
mitk::NavigationDataObjectVisualizationFilter::Pointer m_Visualizer
 visualizer
mitk::CameraVisualization::Pointer m_CameraVisualizer
QmitkNDIConfigurationWidgetm_NDIConfigWidget
Ui::QmitkToolPairNavigationViewControls m_Controls
int m_LastMapperIDWidget3

Detailed Description

This view can be used to guide one tracking tool to another tracking tool. The plugin connects to a tracking system and shows the connected/added tools in two 3D widgets (standard 3D widget is interactable, the other (widget2) isn't). Furthermore it calculates the distance between the two tools and displays it in GUI. In widget 4 the tool connected on port b is shown from the point of view of the tool in port a.

See also:
QmitkFunctionality

Definition at line 46 of file QmitkToolPairNavigationView.h.


Member Typedef Documentation

typedef std::map<std::string, unsigned int> QmitkToolPairNavigationView::NameToIndexMap [protected]

Definition at line 97 of file QmitkToolPairNavigationView.h.

typedef std::list<std::string> QmitkToolPairNavigationView::StringList [protected]

Definition at line 98 of file QmitkToolPairNavigationView.h.


Constructor & Destructor Documentation

QmitkToolPairNavigationView::QmitkToolPairNavigationView (  )

Definition at line 43 of file QmitkToolPairNavigationView.cpp.

QmitkToolPairNavigationView::~QmitkToolPairNavigationView (  ) [virtual]

Member Function Documentation

void QmitkToolPairNavigationView::Activated (  ) [virtual]

Called when the functionality is activated.

Reimplemented from QmitkFunctionality.

Definition at line 116 of file QmitkToolPairNavigationView.cpp.

References mitk::BaseRenderer::GetInstance(), m_LastMapperIDWidget3, m_MultiWidget, QmitkStdMultiWidget::mitkWidget2, and QmitkStdMultiWidget::mitkWidget3.

{
  QmitkFunctionality::Activated();

  //switch to 3D rendering mode in Widget3
  m_LastMapperIDWidget3 = mitk::BaseRenderer::GetInstance(m_MultiWidget->mitkWidget3->GetRenderWindow())->GetMapperID();
  mitk::BaseRenderer::GetInstance(m_MultiWidget->mitkWidget3->GetRenderWindow())->SetMapperID(2);
  mitk::BaseRenderer::GetInstance(m_MultiWidget->mitkWidget2->GetRenderWindow())->SetMapperID(2);
}
void QmitkToolPairNavigationView::CreateBundleWidgets ( QWidget *  parent ) [protected]

setting up the bundle widgets

Definition at line 69 of file QmitkToolPairNavigationView.cpp.

References m_Controls, m_DistanceWidget, m_NDIConfigWidget, and Ui_QmitkToolPairNavigationViewControls::m_ToolBox.

Referenced by CreateQtPartControl().

{
  //get default data storage
  //mitk::DataStorage* ds = this->GetDefaultDataStorage();

  //instanciate widget
  m_NDIConfigWidget = new QmitkNDIConfigurationWidget(parent);
  m_DistanceWidget = new QmitkToolDistanceWidget(parent);


  // removes all placeholder tabs from the toolbox that where created in the qt designer before
  int tabnr = this->m_Controls.m_ToolBox->count();
  for(int i=0; i < tabnr ;i++)
  {
    this->m_Controls.m_ToolBox->removeItem(0);
  }

  // inserts this bundle's widgets into the toolbox
  this->m_Controls.m_ToolBox->insertItem(0,m_NDIConfigWidget,QString("Configuration"));
  this->m_Controls.m_ToolBox->insertItem(1,m_DistanceWidget,QString("Distances"));



}
mitk::DataNode::Pointer QmitkToolPairNavigationView::CreateConeAsInstrumentVisualization ( const char *  label = "" ) [protected]

create objects for visualization

Definition at line 302 of file QmitkToolPairNavigationView.cpp.

References mitk::BaseRenderer::GetInstance(), m_MultiWidget, QmitkStdMultiWidget::mitkWidget3, mitk::BoolProperty::New(), mitk::IntProperty::New(), mitk::StringProperty::New(), mitk::DataNode::New(), and mitk::Cone::New().

Referenced by SetupIGTPipeline().

{
  //new data
  mitk::Cone::Pointer activeToolData = mitk::Cone::New();
  vtkConeSource* vtkData = vtkConeSource::New();
  vtkData->SetRadius(3.0);
  vtkData->SetHeight(6.0);
  vtkData->SetDirection(0.0, 0.0, 1.0); //(0.0, 0.0, -1.0) for 5DoF
  vtkData->SetCenter(0.0, 0.0, 0.0);
  vtkData->SetResolution(20);
  vtkData->CappingOn();
  vtkData->Update();
  activeToolData->SetVtkPolyData(vtkData->GetOutput());
  vtkData->Delete();

  //new node
  mitk::DataNode::Pointer coneNode = mitk::DataNode::New();
  coneNode->SetData(activeToolData);
  coneNode->GetPropertyList()->SetProperty("name", mitk::StringProperty::New ( label ) );
  coneNode->GetPropertyList()->SetProperty("layer", mitk::IntProperty::New(0));
  coneNode->GetPropertyList()->SetProperty("visible",mitk::BoolProperty::New(true));
  //don't display in widget 3 (3D camera view)
  coneNode->SetVisibility(false, mitk::BaseRenderer::GetInstance(m_MultiWidget->mitkWidget3->GetRenderWindow()));
  coneNode->SetColor(1.0,0.0,0.0);//red
  coneNode->SetOpacity(0.7);
  coneNode->Modified();

  return coneNode;
}
void QmitkToolPairNavigationView::CreateConnections (  ) [virtual]

Creation of the connections of main and control widget.

Definition at line 104 of file QmitkToolPairNavigationView.cpp.

References Disconnected(), m_Controls, m_NDIConfigWidget, Ui_QmitkToolPairNavigationViewControls::m_RenderingTimerWidget, and SetNavigationUp().

Referenced by CreateQtPartControl().

{
  connect( m_NDIConfigWidget, SIGNAL(Connected()), this, SLOT(SetNavigationUp()));
  connect( m_NDIConfigWidget, SIGNAL(Connected()), this->m_Controls.m_RenderingTimerWidget, SLOT(EnableWidget()));
  connect( m_NDIConfigWidget, SIGNAL(Disconnected()), this, SLOT(Disconnected()));
  connect( m_NDIConfigWidget, SIGNAL(Disconnected()), this->m_Controls.m_RenderingTimerWidget, SLOT(DisableWidget()));


  //to be implemented for tool name changig e.g.
  //  connect(m_NDIConfigWidget, SIGNAL(ToolsChanged()), this, SLOT(ToolsChanged()));
}
void QmitkToolPairNavigationView::CreateQtPartControl ( QWidget *  parent ) [virtual]
mitk::DataNode::Pointer QmitkToolPairNavigationView::CreateSphereAsInstrumentVisualization ( const char *  label = "" ) [protected]

Definition at line 332 of file QmitkToolPairNavigationView.cpp.

References mitk::BoolProperty::New(), mitk::IntProperty::New(), mitk::StringProperty::New(), mitk::DataNode::New(), and mitk::Ellipsoid::New().

Referenced by SetupIGTPipeline().

{
  //new data
  mitk::Ellipsoid::Pointer activeToolData = mitk::Ellipsoid::New();
  vtkSphereSource *vtkData = vtkSphereSource::New();
  vtkData->SetRadius(1.0f);
  vtkData->SetCenter(0.0, 0.0, 0.0);
  vtkData->Update();
  activeToolData->SetVtkPolyData(vtkData->GetOutput());
  vtkData->Delete();

  //new node
  mitk::DataNode::Pointer sphereNode = mitk::DataNode::New();
  sphereNode->SetData(activeToolData);
  sphereNode->GetPropertyList()->SetProperty("name", mitk::StringProperty::New ( label ) );
  sphereNode->GetPropertyList()->SetProperty("layer", mitk::IntProperty::New(0));
  sphereNode->GetPropertyList()->SetProperty("visible",mitk::BoolProperty::New(true));
  sphereNode->SetColor(0.0,1.0,0.0);//green
  sphereNode->SetOpacity(1.0);
  sphereNode->Modified();

  return sphereNode;
}
void QmitkToolPairNavigationView::Deactivated (  ) [virtual]
void QmitkToolPairNavigationView::DestroyIGTPipeline (  ) [protected]

stops the tracking and deletes all pipeline objects

Definition at line 287 of file QmitkToolPairNavigationView.cpp.

References m_CameraVisualizer, m_Source, and m_Visualizer.

Referenced by Disconnected(), and SetNavigationUp().

{
  if (m_Source.IsNotNull())
  {
    m_Source->StopTracking();
    m_Source->Disconnect();
    m_Source = NULL;
  }

  m_Visualizer = NULL;
  m_CameraVisualizer = NULL;
}
void QmitkToolPairNavigationView::Disconnected (  ) [protected, slot]
void QmitkToolPairNavigationView::RemoveVisualizationObjects ( mitk::DataStorage ds ) [protected]

remove the visualized objects

Definition at line 396 of file QmitkToolPairNavigationView.cpp.

References mitk::DataStorage::GetSubset(), mitk::BoolProperty::New(), mitk::NodePredicateProperty::New(), and mitk::DataStorage::Remove().

Referenced by Disconnected().

{
  if (ds != NULL)
    ds->Remove(ds->GetSubset(mitk::NodePredicateProperty::New("ToolPairNavigation", mitk::BoolProperty::New(true)))); // remove all objects that have the ToolPairNavigation tag
}
void QmitkToolPairNavigationView::RenderScene (  ) [protected, slot]

Definition at line 357 of file QmitkToolPairNavigationView.cpp.

References QmitkFunctionality::GetActiveStdMultiWidget(), mitk::RenderingManager::GetInstance(), m_CameraVisualizer, m_DistanceWidget, m_Source, m_Visualizer, mitk::RenderingManager::REQUEST_UPDATE_3DWINDOWS, and QmitkToolDistanceWidget::ShowDistanceValues().

Referenced by SetNavigationUp().

{
  try
  {
    if (m_Visualizer.IsNull() || m_CameraVisualizer.IsNull() || this->GetActiveStdMultiWidget() == NULL)
      return;
    try
    {
      m_Visualizer->Update();
      m_CameraVisualizer->Update();

      //every tenth update
      static int counter = 0;
      if (counter > 9)
      {
        this->m_DistanceWidget->ShowDistanceValues(m_Source->GetOutputs());
        counter = 0;
      }
      else
        counter++;
    }
    catch(std::exception& e)
    {
      std::cout << "Exception during QmitkToolPairNavigationView::RenderScene():" << e.what() << "\n";
    }

    //update all Widgets
    mitk::RenderingManager::GetInstance()->RequestUpdateAll(mitk::RenderingManager::REQUEST_UPDATE_3DWINDOWS);
  }
  catch (std::exception& e)
  {
    std::cout << "RenderAll exception: " << e.what() << "\n";
  }
  catch (...)
  {
    std::cout << "RenderAll unknown exception\n";
  }
}
void QmitkToolPairNavigationView::SetNavigationUp (  ) [protected, slot]

starting navigation

Definition at line 158 of file QmitkToolPairNavigationView.cpp.

References DestroyIGTPipeline(), QmitkFunctionality::GetDefaultDataStorage(), QmitkUpdateTimerWidget::GetUpdateTimer(), m_Controls, m_DistanceWidget, Ui_QmitkToolPairNavigationViewControls::m_RenderingTimerWidget, m_Source, RenderScene(), QmitkUpdateTimerWidget::SetPurposeLabelText(), QmitkUpdateTimerWidget::SetTimerInterval(), SetupIGTPipeline(), StartNavigation(), StopNavigation(), and QmitkUpdateTimerWidget::StopTimer().

Referenced by CreateConnections().

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

  mitk::DataStorage* ds = this->GetDefaultDataStorage();
  if (ds == NULL)
  {
    QMessageBox::warning(NULL, "ToolPairNavigation: Error", "can not access DataStorage. Navigation not possible");
    return;
  }

  //1. build up the filter pipeline
  try
  {
    this->SetupIGTPipeline();
  }
  catch(std::exception& e)
  {
    QMessageBox::warning(NULL, "ToolPairNavigation: Error", QString("Error while building the IGT-Pipeline: %1").arg(e.what()));
    this->DestroyIGTPipeline();
    return;
  }
  catch (...)
  {
    QMessageBox::warning(NULL, "ToolPairNavigation: Error", QString("Error while building the IGT-Pipeline."));
    this->DestroyIGTPipeline();
    return;
  }

  //2. start IGT pipeline to display tracking devices (20 Hz update rate -> 50 msec timeout)
  try
  {
    // setup for the bundle's update timer widget
    m_Controls.m_RenderingTimerWidget->SetPurposeLabelText(QString("Navigation"));
    m_Controls.m_RenderingTimerWidget->SetTimerInterval( 50 );

    connect( m_Controls.m_RenderingTimerWidget->GetUpdateTimer() , SIGNAL(timeout()) , this, SLOT (RenderScene()) );
    connect( m_Controls.m_RenderingTimerWidget, SIGNAL(Started()), this, SLOT(StartNavigation()));
    connect( m_Controls.m_RenderingTimerWidget, SIGNAL(Stopped()) , this, SLOT (StopNavigation()));
    connect( m_Controls.m_RenderingTimerWidget, SIGNAL(Stopped()) , m_DistanceWidget, SLOT (SetDistanceLabelValuesInvalid()));

  }
  catch(std::exception& e)
  {
    QMessageBox::warning(NULL, "ToolPairNavigation: Error", QString("Error while starting the IGT-Pipeline: %1").arg(e.what()));
    this->m_Controls.m_RenderingTimerWidget->StopTimer();
    this->DestroyIGTPipeline();
    return;
  }
}
void QmitkToolPairNavigationView::SetupIGTPipeline (  ) [protected]

setup the IGT pipeline

Definition at line 237 of file QmitkToolPairNavigationView.cpp.

References mitk::DataStorage::Add(), CreateConeAsInstrumentVisualization(), CreateSphereAsInstrumentVisualization(), QmitkFunctionality::GetDefaultDataStorage(), mitk::BaseRenderer::GetInstance(), mitk::DataStorage::GetNamedNode(), QmitkNDIConfigurationWidget::GetTracker(), m_CameraVisualizer, m_MultiWidget, m_NDIConfigWidget, m_Source, m_Visualizer, QmitkStdMultiWidget::mitkWidget3, mitk::CameraVisualization::New(), mitk::NavigationDataObjectVisualizationFilter::New(), and mitk::TrackingDeviceSource::New().

Referenced by SetNavigationUp().

{
  mitk::DataStorage* ds = this->GetDefaultDataStorage(); // check if dataStorage is available
  if (ds == NULL)
    throw std::invalid_argument("DataStorage not available");

  mitk::TrackingDevice::Pointer tracker = m_NDIConfigWidget->GetTracker(); // get current tracker from the configuration widget
  if (tracker.IsNull()) // check if tracker is valid
    throw std::invalid_argument("tracking device is NULL.");

  m_Source = mitk::TrackingDeviceSource::New(); // create a new source for the IGT filter pipeline
  m_Source->SetTrackingDevice(tracker); // set the found tracker to the source

  m_Visualizer = mitk::NavigationDataObjectVisualizationFilter::New(); // filter to display NDs
  m_CameraVisualizer = mitk::CameraVisualization::New();
  //set widget 3
  m_CameraVisualizer->SetRenderer(mitk::BaseRenderer::GetInstance(m_MultiWidget->mitkWidget3->GetRenderWindow()));

  //set viewing direction
  mitk::Vector3D viewVector;
  mitk::FillVector3D( viewVector, 0.0, 0.0, 1.0 );
  m_CameraVisualizer->SetDirectionOfProjectionInToolCoordinates(viewVector);

  /* prepare visualization objects and filter */
  for (unsigned int i = 0; i < m_Source->GetNumberOfOutputs(); ++i) //for each connected tool
  {
    m_Visualizer->SetInput(i, m_Source->GetOutput(i)); // set input for visualization filter

    const char* toolName = tracker->GetTool(i)->GetToolName();
    mitk::DataNode::Pointer toolrepresentationNode = ds->GetNamedNode(toolName);
    if (toolrepresentationNode.IsNull())
    {
      //the first tool represents the tool to guide
      //it will be represented as cone wheras the target tools will be represented by a sphere
      if (i<1) //tool to guide
      {
        toolrepresentationNode = this->CreateConeAsInstrumentVisualization(toolName);
        m_CameraVisualizer->SetInput(m_Source->GetOutput(i));
      }
      else
        toolrepresentationNode = this->CreateSphereAsInstrumentVisualization(toolName);
      ds->Add(toolrepresentationNode);
    }

    m_Visualizer->SetRepresentationObject(i, toolrepresentationNode->GetData());  // set instrument nodes as baseData for visualisation filter
  }


}
void QmitkToolPairNavigationView::StartNavigation (  ) [protected, slot]

Definition at line 211 of file QmitkToolPairNavigationView.cpp.

References QmitkToolDistanceWidget::CreateToolDistanceMatrix(), m_DistanceWidget, and m_Source.

Referenced by SetNavigationUp().

{
  if(m_Source.IsNotNull() && !m_Source->IsTracking())
  {
    m_Source->StartTracking();
    // creates the matrix with distances from the tracking source's outputs
    m_DistanceWidget->CreateToolDistanceMatrix(m_Source->GetOutputs());
  }
}
void QmitkToolPairNavigationView::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 94 of file QmitkToolPairNavigationView.cpp.

References m_MultiWidget.

{
  m_MultiWidget = &stdMultiWidget;
}
void QmitkToolPairNavigationView::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 99 of file QmitkToolPairNavigationView.cpp.

References m_MultiWidget.

{
  m_MultiWidget = NULL;
}
void QmitkToolPairNavigationView::StopNavigation (  ) [protected, slot]

stopping navigation

Definition at line 228 of file QmitkToolPairNavigationView.cpp.

References m_Source.

Referenced by SetNavigationUp().

{
  if(m_Source.IsNotNull() && m_Source->IsTracking())
  {
    m_Source->StopTracking();
  }
}
void QmitkToolPairNavigationView::ToolsAdded ( QStringList  tools ) [protected, slot]

Definition at line 152 of file QmitkToolPairNavigationView.cpp.

{

}
void QmitkToolPairNavigationView::ToolsChanged (  ) [protected, slot]

Definition at line 223 of file QmitkToolPairNavigationView.cpp.

{

}

Member Data Documentation

GUI widget with tool distances matrix.

Definition at line 132 of file QmitkToolPairNavigationView.h.

Referenced by CreateBundleWidgets(), Disconnected(), RenderScene(), SetNavigationUp(), StartNavigation(), and ~QmitkToolPairNavigationView().

Definition at line 157 of file QmitkToolPairNavigationView.h.

Referenced by Activated(), and Deactivated().

visualizer

visualization filter

Definition at line 142 of file QmitkToolPairNavigationView.h.

Referenced by DestroyIGTPipeline(), RenderScene(), SetupIGTPipeline(), and ~QmitkToolPairNavigationView().

const std::string QmitkToolPairNavigationView::VIEW_ID = "org.mitk.views.toolpairnavigation" [static]

Definition at line 55 of file QmitkToolPairNavigationView.h.


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