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

mitk::TrackingDeviceSource Class Reference

Connects a mitk::TrackingDevice to a MITK-IGT NavigationData-Filterpipeline. More...

#include <mitkTrackingDeviceSource.h>

Inheritance diagram for mitk::TrackingDeviceSource:
Inheritance graph
[legend]
Collaboration diagram for mitk::TrackingDeviceSource:
Collaboration graph
[legend]

List of all members.

Public Types

typedef TrackingDeviceSource Self
typedef NavigationDataSource Superclass
typedef itk::SmartPointer< SelfPointer
typedef itk::SmartPointer
< const Self
ConstPointer

Public Member Functions

virtual const char * GetClassName () const
virtual void SetTrackingDevice (mitk::TrackingDevice *td)
 sets the tracking device that will be used as a source for tracking data
virtual const
mitk::TrackingDevice
GetTrackingDevice ()
 returns the tracking device that is used by this filter
void Connect ()
 Establishes a connection to the tracking device.
void Disconnect ()
 Closes the connection to the tracking device.
void StartTracking ()
 starts tracking. This needs to be called before Update() or GetOutput()->Update().
void StopTracking ()
 stops tracking.
virtual bool IsConnected ()
 returns true if a connection to the tracking device is established
virtual bool IsTracking ()
 returns true if tracking is in progress
virtual void UpdateOutputInformation ()
 Used for pipeline update.

Static Public Member Functions

static Pointer New ()

Protected Member Functions

 TrackingDeviceSource ()
virtual ~TrackingDeviceSource ()
virtual void GenerateData ()
 filter execute method
void CreateOutputs ()
 Create the necessary outputs for the TrackingTool objects in m_TrackingDevice.

Protected Attributes

mitk::TrackingDevice::Pointer m_TrackingDevice
 the tracking device that is used as a source for this filter object

Detailed Description

Connects a mitk::TrackingDevice to a MITK-IGT NavigationData-Filterpipeline.

Documentation This class is the source of most navigation pipelines. It encapsulates a mitk::TrackingDevice and provides the position and orientation of the connected mitk::TrackingTool objects as NavigationData objects. Note, that the number of outputs of TrackingDeviceSource is equal to the number of tools connected to the TrackingDevice at the time SetTrackingDevice() is called. If tools are added to the TrackingDevice later, there will not be additional outputs in TrackingDeviceSource. You have to call SetTrackingDevice() again to add the new tools as additional outputs of the filter. Otherwise TrackingDeviceSource will raise an std::out_of_range exception when the filter pipeline is executed. the tool number corresponds with the output number, e.g. trackingDevice-GetTool(0) is the tool that will produce trackingDeviceSourceFilter->GetOutput(0).

Warning:
If a tool is removed from the tracking device, there will be a mismatch between the outputs and the tool number!

Definition at line 44 of file mitkTrackingDeviceSource.h.


Member Typedef Documentation

typedef itk::SmartPointer<const Self> mitk::TrackingDeviceSource::ConstPointer

Reimplemented from mitk::NavigationDataSource.

Definition at line 47 of file mitkTrackingDeviceSource.h.

typedef itk::SmartPointer<Self> mitk::TrackingDeviceSource::Pointer

Reimplemented from mitk::NavigationDataSource.

Definition at line 47 of file mitkTrackingDeviceSource.h.

Reimplemented from mitk::NavigationDataSource.

Definition at line 47 of file mitkTrackingDeviceSource.h.

Reimplemented from mitk::NavigationDataSource.

Definition at line 47 of file mitkTrackingDeviceSource.h.


Constructor & Destructor Documentation

mitk::TrackingDeviceSource::TrackingDeviceSource (  ) [protected]

Definition at line 26 of file mitkTrackingDeviceSource.cpp.

mitk::TrackingDeviceSource::~TrackingDeviceSource (  ) [protected, virtual]

Member Function Documentation

void mitk::TrackingDeviceSource::Connect (  )

Establishes a connection to the tracking device.

Warning:
. Will throw a std::invalid_argument exception if no tracking device was set with SetTrackingDevice(). Will throw a std::runtime_error if the tracking device returns an error.

Definition at line 132 of file mitkTrackingDeviceSource.cpp.

{
  if (m_TrackingDevice.IsNull())
    throw std::invalid_argument("mitk::TrackingDeviceSource: No tracking device set");
  if (this->IsConnected())
    return;
  if (m_TrackingDevice->OpenConnection() == false)
    throw std::runtime_error(std::string("mitk::TrackingDeviceSource: Could not open connection to tracking device. Error: ") + m_TrackingDevice->GetErrorMessage());
  
  /* NDI Aurora needs a connection to discover tools that are connected to it. 
     Therefore we need to create outputs for these tools now */
  //if (m_TrackingDevice->GetType() == mitk::NDIAurora)
    //this->CreateOutputs();
}
void mitk::TrackingDeviceSource::CreateOutputs (  ) [protected]

Create the necessary outputs for the TrackingTool objects in m_TrackingDevice.

Definition at line 105 of file mitkTrackingDeviceSource.cpp.

                                            {
  //if outputs are set then delete them
  if (this->GetNumberOfOutputs() > 0)
  {
    for (unsigned int numOP = this->GetNumberOfOutputs(); numOP>0; numOP--)
      this->RemoveOutput(this->GetOutput(numOP));
    this->Modified();
  }
  
  //fill the outputs if a valid tracking device is set
  if (m_TrackingDevice.IsNull())
    return;

  this->SetNumberOfOutputs(m_TrackingDevice->GetToolCount());  // create outputs for all tools
  unsigned int numberOfOutputs = this->GetNumberOfOutputs();
  for (unsigned int idx = 0; idx < numberOfOutputs; ++idx)
  {
    if (this->GetOutput(idx) == NULL)
    {
      DataObjectPointer newOutput = this->MakeOutput(idx);
      static_cast<mitk::NavigationData*>(newOutput.GetPointer())->SetName(m_TrackingDevice->GetTool(idx)->GetToolName()); // set NavigationData name to ToolName
      this->SetNthOutput(idx, newOutput);
      this->Modified();
    }    
  }
}
void mitk::TrackingDeviceSource::Disconnect (  )

Closes the connection to the tracking device.

Warning:
. Will throw a std::invalid_argument exception if no tracking device was set with SetTrackingDevice(). Will throw a std::runtime_error if the tracking device returns an error.

Definition at line 157 of file mitkTrackingDeviceSource.cpp.

{
  if (m_TrackingDevice.IsNull())
    throw std::invalid_argument("mitk::TrackingDeviceSource: No tracking device set");
  if (m_TrackingDevice->CloseConnection() == false)
    throw std::runtime_error("mitk::TrackingDeviceSource: Could not close connection to tracking device");
}
void mitk::TrackingDeviceSource::GenerateData (  ) [protected, virtual]

filter execute method

queries the tracking device for new position and orientation data for all tools and updates its output NavigationData objects with it.

Warning:
Will raise a std::out_of_range exception, if tools were added to the tracking device after it was set as input for this filter

Definition at line 46 of file mitkTrackingDeviceSource.cpp.

References mitk::TimeStamp::GetInstance(), mitk::TrackingTool::GetOrientation(), mitk::TrackingTool::GetPosition(), mitk::TrackingTool::GetTrackingError(), mitk::TrackingTool::IsDataValid(), mitk::TrackingTool::IsEnabled(), mitk::NavigationData::SetDataValid(), mitk::NavigationData::SetOrientation(), mitk::NavigationData::SetOrientationAccuracy(), mitk::NavigationData::SetPosition(), mitk::NavigationData::SetPositionAccuracy(), mitk::NavigationData::SetTimeStamp(), and QuadProgPP::t().

{
  if (m_TrackingDevice.IsNull())
    return;

  if (m_TrackingDevice->GetToolCount() < 1)
    return;

  if (this->GetNumberOfOutputs() != m_TrackingDevice->GetToolCount()) // mismatch between tools and outputs. What should we do? Were tools added to the tracking device after SetTrackingDevice() was called?
  {
    //check this: TODO:
    //this->CreateOutputs();

    std::stringstream ss;
    ss << "mitk::TrackingDeviceSource: not enough outputs available for all tools. " 
      << this->GetNumberOfOutputs() << " outputs available, but "
      << m_TrackingDevice->GetToolCount() << " tools available in the tracking device.";
    throw std::out_of_range(ss.str());
  }
  /* update outputs with tracking data from tools */
  unsigned int toolCount = m_TrackingDevice->GetToolCount();
  for (unsigned int i = 0; i < toolCount; ++i)
  {
    mitk::NavigationData* nd = this->GetOutput(i);
    assert(nd);
    mitk::TrackingTool* t = m_TrackingDevice->GetTool(i);
    assert(t);

    if ((t->IsEnabled() == false) || (t->IsDataValid() == false))
    {
      nd->SetDataValid(false);
      continue;
    }
    nd->SetDataValid(true);
    mitk::NavigationData::PositionType p;
    t->GetPosition(p);
    nd->SetPosition(p);

    mitk::NavigationData::OrientationType o;
    t->GetOrientation(o);
    nd->SetOrientation(o);
    nd->SetOrientationAccuracy(t->GetTrackingError());
    nd->SetPositionAccuracy(t->GetTrackingError());
    nd->SetTimeStamp( mitk::TimeStamp::GetInstance()->GetElapsed() );
  }
}
virtual const char* mitk::TrackingDeviceSource::GetClassName (  ) const [virtual]

Reimplemented from mitk::NavigationDataSource.

virtual const mitk::TrackingDevice* mitk::TrackingDeviceSource::GetTrackingDevice (  ) [virtual]

returns the tracking device that is used by this filter

bool mitk::TrackingDeviceSource::IsConnected (  ) [virtual]

returns true if a connection to the tracking device is established

Definition at line 190 of file mitkTrackingDeviceSource.cpp.

References mitk::TrackingDevice::Ready, and mitk::TrackingDevice::Tracking.

{
  if (m_TrackingDevice.IsNull())
    return false;
  
  return (m_TrackingDevice->GetState() == mitk::TrackingDevice::Ready) || (m_TrackingDevice->GetState() == mitk::TrackingDevice::Tracking);
}
bool mitk::TrackingDeviceSource::IsTracking (  ) [virtual]

returns true if tracking is in progress

Definition at line 199 of file mitkTrackingDeviceSource.cpp.

References mitk::TrackingDevice::Tracking.

{
  if (m_TrackingDevice.IsNull())
    return false;

  return m_TrackingDevice->GetState() == mitk::TrackingDevice::Tracking;
}
static Pointer mitk::TrackingDeviceSource::New (  ) [static]
void mitk::TrackingDeviceSource::SetTrackingDevice ( mitk::TrackingDevice td ) [virtual]

sets the tracking device that will be used as a source for tracking data

Definition at line 95 of file mitkTrackingDeviceSource.cpp.

{
  itkDebugMacro("setting TrackingDevice to " << td );
  if (this->m_TrackingDevice.GetPointer() != td)
  {
    this->m_TrackingDevice = td;
    this->CreateOutputs();
  }
}
void mitk::TrackingDeviceSource::StartTracking (  )

starts tracking. This needs to be called before Update() or GetOutput()->Update().

Warning:
. Will throw a std::invalid_argument exception if no tracking device was set with SetTrackingDevice(). Will throw a std::runtime_error if the tracking device returns an error.

Definition at line 148 of file mitkTrackingDeviceSource.cpp.

{
  if (m_TrackingDevice.IsNull())
    throw std::invalid_argument("mitk::TrackingDeviceSource: No tracking device set");
  if (m_TrackingDevice->StartTracking() == false)
    throw std::runtime_error("mitk::TrackingDeviceSource: Could not start tracking");
}
void mitk::TrackingDeviceSource::StopTracking (  )

stops tracking.

Warning:
. Will throw a std::invalid_argument exception if no tracking device was set with SetTrackingDevice(). Will throw a std::runtime_error if the tracking device returns an error.

Definition at line 166 of file mitkTrackingDeviceSource.cpp.

{
  if (m_TrackingDevice.IsNull())
    throw std::invalid_argument("mitk::TrackingDeviceSource: No tracking device set");
  if (m_TrackingDevice->StopTracking() == false)
    throw std::runtime_error("mitk::TrackingDeviceSource: Could not stop tracking");
}
void mitk::TrackingDeviceSource::UpdateOutputInformation (  ) [virtual]

Used for pipeline update.

Definition at line 175 of file mitkTrackingDeviceSource.cpp.

{
  this->Modified();  // make sure that we need to be updated
  Superclass::UpdateOutputInformation();
}

Member Data Documentation

the tracking device that is used as a source for this filter object

Definition at line 129 of file mitkTrackingDeviceSource.h.


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