23 #include "mitkIGTException.h"
32 if (m_TrackingDevice.IsNotNull())
42 m_TrackingDevice = NULL;
48 if (m_IsFrozen) {
return;}
49 else if (m_TrackingDevice.IsNull()) {
return;}
51 if (m_TrackingDevice->GetToolCount() < 1)
54 if (this->GetNumberOfIndexedOutputs() != m_TrackingDevice->GetToolCount())
61 ss <<
"mitk::TrackingDeviceSource: not enough outputs available for all tools. "
62 << this->GetNumberOfOutputs() <<
" outputs available, but "
63 << m_TrackingDevice->GetToolCount() <<
" tools available in the tracking device.";
64 throw std::out_of_range(ss.str());
67 unsigned int toolCount = m_TrackingDevice->GetToolCount();
68 for (
unsigned int i = 0; i < toolCount; ++i)
99 MITK_DEBUG <<
"Setting TrackingDevice to " << td;
100 if (this->m_TrackingDevice.GetPointer() != td)
102 this->m_TrackingDevice = td;
103 this->CreateOutputs();
104 std::stringstream name;
105 name << td->GetData().Model <<
" Tracking Source";
106 this->SetName(name.str());
112 if (this->GetNumberOfOutputs() > 0)
114 for (
int numOP = this->GetNumberOfOutputs() -1; numOP >= 0; numOP--)
115 this->RemoveOutput(numOP);
120 if (m_TrackingDevice.IsNull())
123 this->SetNumberOfIndexedOutputs(m_TrackingDevice->GetToolCount());
124 unsigned int numberOfOutputs = this->GetNumberOfIndexedOutputs();
125 MITK_DEBUG <<
"Number of tools at start of method CreateOutputs(): " << m_TrackingDevice->GetToolCount();
126 MITK_DEBUG <<
"Number of outputs at start of method CreateOutputs(): " << numberOfOutputs;
127 for (
unsigned int idx = 0; idx < m_TrackingDevice->GetToolCount(); ++idx)
129 if (this->GetOutput(idx) == NULL)
131 DataObjectPointer newOutput = this->MakeOutput(idx);
132 static_cast<mitk::NavigationData*
>(newOutput.GetPointer())->SetName(m_TrackingDevice->GetTool(idx)->GetToolName());
133 this->SetNthOutput(idx, newOutput);
141 if (m_TrackingDevice.IsNull())
142 throw std::invalid_argument(
"mitk::TrackingDeviceSource: No tracking device set");
143 if (this->IsConnected())
145 try {m_TrackingDevice->OpenConnection();}
148 throw std::runtime_error(std::string(
"mitk::TrackingDeviceSource: Could not open connection to tracking device. Error: ") + e.GetDescription());
159 if (m_TrackingDevice.IsNull())
160 throw std::invalid_argument(
"mitk::TrackingDeviceSource: No tracking device set");
163 if (m_TrackingDevice->StartTracking() ==
false)
164 throw std::runtime_error(
"mitk::TrackingDeviceSource: Could not start tracking");
169 if (m_TrackingDevice.IsNull())
170 throw std::invalid_argument(
"mitk::TrackingDeviceSource: No tracking device set");
171 if (m_TrackingDevice->CloseConnection() ==
false)
172 throw std::runtime_error(
"mitk::TrackingDeviceSource: Could not close connection to tracking device");
177 if (m_TrackingDevice.IsNull())
178 throw std::invalid_argument(
"mitk::TrackingDeviceSource: No tracking device set");
179 if (m_TrackingDevice->StopTracking() ==
false)
180 throw std::runtime_error(
"mitk::TrackingDeviceSource: Could not stop tracking");
185 if(this->GetTrackingDevice()->GetToolCount() != this->GetNumberOfIndexedOutputs())
186 this->CreateOutputs();
189 Superclass::UpdateOutputInformation();
201 if (m_TrackingDevice.IsNull())
209 if (m_TrackingDevice.IsNull())
virtual void GenerateData() override
filter execute method
void SetOrientationAccuracy(mitk::ScalarType error)
virtual void SetTrackingDevice(mitk::TrackingDevice *td)
sets the tracking device that will be used as a source for tracking data
double GetElapsed()
returns the time elapsed since calling Start() for the first time in milliseconds ...
An object of this class represents an exception of the MITK-IGT module.
virtual ~TrackingDeviceSource()
void CreateOutputs()
Create the necessary outputs for the TrackingTool objects in m_TrackingDevice.
DataCollection - Class to facilitate loading/accessing structured data.
virtual void SetDataValid(bool _arg)
sets the dataValid flag of the NavigationData object indicating if the object contains valid data ...
virtual void SetIGTTimeStamp(TimeStampType _arg)
sets the IGT timestamp of the NavigationData object
mitk::Quaternion OrientationType
Type that holds the orientation part of the tracking data.
void StartTracking()
starts tracking. This needs to be called before Update() or GetOutput()->Update(). If the device is already tracking the method does nothing.
virtual void SetOrientation(OrientationType _arg)
sets the orientation of the NavigationData object
void StopTracking()
stops tracking.
Interface for all Tracking Devices.
virtual TimeStampType GetIGTTimeStamp() const
gets the IGT timestamp of the NavigationData object
static IGTTimeStamp * GetInstance()
returns a pointer to the current instance of mitkTimeStamp
virtual bool IsConnected()
returns true if a connection to the tracking device is established
virtual bool IsTracking()
returns true if tracking is in progress
void Disconnect()
Closes the connection to the tracking device.
virtual void SetPosition(PositionType _arg)
sets the position of the NavigationData object
void Connect()
Establishes a connection to the tracking device. If there is already a connection the method does not...
virtual void UpdateOutputInformation() override
Used for pipeline update.
void SetPositionAccuracy(mitk::ScalarType error)