19#include "mitkIGTException.h"
20#include "mitkIGTHardwareException.h"
29 if (m_TrackingDevice.IsNotNull())
39 m_TrackingDevice =
nullptr;
45 if (m_IsFrozen) {
return;}
46 else if (m_TrackingDevice.IsNull()) {
return;}
48 if (m_TrackingDevice->GetToolCount() < 1)
51 if (this->GetNumberOfIndexedOutputs() != m_TrackingDevice->GetToolCount())
58 ss <<
"mitk::TrackingDeviceSource: not enough outputs available for all tools. "
59 << this->GetNumberOfOutputs() <<
" outputs available, but "
60 << m_TrackingDevice->GetToolCount() <<
" tools available in the tracking device.";
61 throw std::out_of_range(ss.str());
64 unsigned int toolCount = m_TrackingDevice->GetToolCount();
65 for (
unsigned int i = 0; i < toolCount; ++i)
74 nd->SetDataValid(
false);
77 nd->SetDataValid(
true);
84 nd->SetOrientation(o);
87 nd->SetIGTTimeStamp(t->GetIGTTimeStamp());
96 MITK_DEBUG <<
"Setting TrackingDevice to " << td;
97 if (this->m_TrackingDevice.GetPointer() != td)
99 this->m_TrackingDevice = td;
100 this->CreateOutputs();
101 std::stringstream name;
103 this->SetName(name.str());
109 if (this->GetNumberOfOutputs() > 0)
111 for (
int numOP = this->GetNumberOfOutputs() -1; numOP >= 0; numOP--)
112 this->RemoveOutput(numOP);
117 if (m_TrackingDevice.IsNull())
120 this->SetNumberOfIndexedOutputs(m_TrackingDevice->GetToolCount());
121 unsigned int numberOfOutputs = this->GetNumberOfIndexedOutputs();
122 MITK_DEBUG <<
"Number of tools at start of method CreateOutputs(): " << m_TrackingDevice->GetToolCount();
123 MITK_DEBUG <<
"Number of outputs at start of method CreateOutputs(): " << numberOfOutputs;
124 for (
unsigned int idx = 0; idx < m_TrackingDevice->GetToolCount(); ++idx)
126 if (this->GetOutput(idx) ==
nullptr)
128 DataObjectPointer newOutput = this->MakeOutput(idx);
129 static_cast<mitk::NavigationData*
>(newOutput.GetPointer())->SetName(m_TrackingDevice->GetTool(idx)->GetToolName());
130 this->SetNthOutput(idx, newOutput);
138 if (m_TrackingDevice.IsNull())
139 throw std::invalid_argument(
"mitk::TrackingDeviceSource: No tracking device set");
140 if (this->IsConnected())
145 if (!m_TrackingDevice->OpenConnection())
152 throw std::runtime_error(std::string(
"mitk::TrackingDeviceSource: Could not open connection to tracking device. Error: ") + e.GetDescription());
158 if (m_TrackingDevice.IsNull())
159 throw std::invalid_argument(
"mitk::TrackingDeviceSource: No tracking device set");
162 if (m_TrackingDevice->StartTracking() ==
false)
163 throw std::runtime_error(
"mitk::TrackingDeviceSource: Could not start tracking");
168 if (m_TrackingDevice.IsNull())
169 throw std::invalid_argument(
"mitk::TrackingDeviceSource: No tracking device set");
170 if (m_TrackingDevice->CloseConnection() ==
false)
171 throw std::runtime_error(
"mitk::TrackingDeviceSource: Could not close connection to tracking device");
176 if (m_TrackingDevice.IsNull())
177 throw std::invalid_argument(
"mitk::TrackingDeviceSource: No tracking device set");
178 if (m_TrackingDevice->StopTracking() ==
false)
179 throw std::runtime_error(
"mitk::TrackingDeviceSource: Could not stop tracking");
184 if(this->GetTrackingDevice()->GetToolCount() != this->GetNumberOfIndexedOutputs())
185 this->CreateOutputs();
188 Superclass::UpdateOutputInformation();
200 if (m_TrackingDevice.IsNull())
208 if (m_TrackingDevice.IsNull())
An object of this class represents an exception of the MITK-IGT module.
An object of this class represents an exception of the MITK-IGT module which are releated to the hard...
static IGTTimeStamp * GetInstance()
returns a pointer to the current instance of mitkTimeStamp
void SetPositionAccuracy(mitk::ScalarType error)
void SetOrientationAccuracy(mitk::ScalarType error)
mitk::Quaternion OrientationType
Type that holds the orientation part of the tracking data.
mitk::Point3D PositionType
Type that holds the position part of the tracking data.
~TrackingDeviceSource() override
void StartTracking()
starts tracking. This needs to be called before Update() or GetOutput()->Update()....
void StopTracking()
stops tracking.
void CreateOutputs()
Create the necessary outputs for the TrackingTool objects in m_TrackingDevice.
void UpdateOutputInformation() override
Used for pipeline update.
virtual bool IsTracking()
returns true if tracking is in progress
virtual void SetTrackingDevice(mitk::TrackingDevice *td)
sets the tracking device that will be used as a source for tracking data
void GenerateData() override
filter execute method
void Connect()
Establishes a connection to the tracking device. If there is already a connection the method does not...
void Disconnect()
Closes the connection to the tracking device.
virtual bool IsConnected()
returns true if a connection to the tracking device is established
Interface for all Tracking Devices.
TrackingDeviceData GetData() const
return device data