19 #include "mitkIGTConfig.h"
21 #include "mitkIGTHardwareException.h"
22 #include <itksys/SystemTools.hxx>
24 #include <itkMutexLockHolder.h>
40 if (
m_Device->IsMicronTrackerInstalled())
42 #ifdef MITK_MICRON_TRACKER_TEMP_DIR
46 #ifdef MITK_MICRON_TRACKER_CALIBRATION_DIR
62 return tempInterface->IsMicronTrackerInstalled();
74 if (t->LoadFile(fileName) ==
false)
78 t->SetToolName(toolName);
79 if (this->InternalAddTool(t) ==
false)
81 return t.GetPointer();
87 m_AllTools.push_back(tool);
94 std::vector<mitk::ClaronTool::Pointer> returnValue;
95 std::vector<claronToolHandle> allHandles = m_Device->GetAllActiveTools();
96 for (
auto iter = allHandles.begin(); iter != allHandles.end(); ++iter)
99 newTool->SetToolName(m_Device->GetName(*iter));
100 newTool->SetCalibrationName(m_Device->GetName(*iter));
101 newTool->SetToolHandle(*iter);
102 returnValue.push_back(newTool);
112 if (!m_Device->IsMicronTrackerInstalled())
117 itksys::SystemTools::RemoveADirectory(m_ToolfilesDir.c_str());
118 itksys::SystemTools::MakeDirectory(m_ToolfilesDir.c_str());
121 for (
unsigned int i=0; i<m_AllTools.size(); i++)
123 itksys::SystemTools::CopyAFile(m_AllTools[i]->GetFile().c_str(), m_ToolfilesDir.c_str());
125 this->SetState(Tracking);
126 this->m_StopTrackingMutex->Lock();
127 this->m_StopTracking =
false;
128 this->m_StopTrackingMutex->Unlock();
131 m_Device->StopTracking();
132 m_Device->Initialize(m_CalibrationDir,m_ToolfilesDir);
134 if (m_Device->StartTracking())
137 m_ThreadID = m_MultiThreader->SpawnThread(this->ThreadStartTracking,
this);
147 Superclass::StopTracking();
149 itksys::SystemTools::RemoveADirectory(m_ToolfilesDir.c_str());
156 return (
unsigned int)this->m_AllTools.size();
162 if ( toolNumber >= this->GetToolCount())
165 return this->m_AllTools[toolNumber];
173 itksys::SystemTools::MakeDirectory(m_ToolfilesDir.c_str());
175 m_Device->Initialize(m_CalibrationDir,m_ToolfilesDir);
176 returnValue = m_Device->StartTracking();
180 this->SetState(Ready);
185 if (m_Device.IsNull())
188 m_Device->Initialize(m_CalibrationDir, m_ToolfilesDir);
190 m_Device->StopTracking();
191 this->SetState(
Setup);
200 bool returnValue =
true;
201 if (this->GetState() ==
Setup)
204 returnValue = m_Device->StopTracking();
207 itksys::SystemTools::RemoveADirectory(m_ToolfilesDir.c_str());
209 this->SetState(
Setup);
222 return this->m_AllTools;
233 bool localStopTracking;
234 this->m_StopTrackingMutex->Lock();
235 localStopTracking = this->m_StopTracking;
236 this->m_StopTrackingMutex->Unlock();
238 while ((this->GetState() == Tracking) && (localStopTracking ==
false))
240 this->GetDevice()->GrabFrame();
242 std::vector<mitk::ClaronTool::Pointer> detectedTools = this->DetectTools();
243 std::vector<mitk::ClaronTool::Pointer> allTools = this->GetAllTools();
244 std::vector<mitk::ClaronTool::Pointer>::iterator itAllTools;
245 for(itAllTools = allTools.begin(); itAllTools != allTools.end(); itAllTools++)
249 std::vector<mitk::ClaronTool::Pointer>::iterator itDetectedTools;
250 bool foundTool =
false;
251 for(itDetectedTools = detectedTools.begin(); itDetectedTools != detectedTools.end(); itDetectedTools++)
254 std::string tempString(currentTool->GetCalibrationName());
255 if (tempString.compare(aktuDet->GetCalibrationName())==0)
257 currentTool->SetToolHandle(aktuDet->GetToolHandle());
263 currentTool->SetToolHandle(0);
266 if (currentTool->GetToolHandle() != 0)
268 currentTool->SetDataValid(
true);
270 std::vector<double> pos_vector = this->GetDevice()->GetTipPosition(currentTool->GetToolHandle());
273 pos[0] = pos_vector[0];
274 pos[1] = pos_vector[1];
275 pos[2] = pos_vector[2];
276 currentTool->SetPosition(pos);
278 std::vector<double> quat = this->GetDevice()->GetTipQuaternions(currentTool->GetToolHandle());
281 currentTool->SetOrientation(orientation);
290 currentTool->SetPosition(origin);
292 currentTool->SetDataValid(
false);
296 this->m_StopTrackingMutex->Lock();
297 localStopTracking = m_StopTracking;
298 this->m_StopTrackingMutex->Unlock();
303 this->StopTracking();
311 return this->m_Device->IsMicronTrackerInstalled();
318 struct itk::MultiThreader::ThreadInfoStruct * pInfo = (
struct itk::MultiThreader::ThreadInfoStruct*)pInfoStruct;
319 if (pInfo ==
nullptr)
321 return ITK_THREAD_RETURN_VALUE;
323 if (pInfo->UserData ==
nullptr)
325 return ITK_THREAD_RETURN_VALUE;
329 if (trackingDevice !=
nullptr)
332 return ITK_THREAD_RETURN_VALUE;
itk::MultiThreader::Pointer m_MultiThreader
An object of this class represents an exception of the MITK-IGT module which are releated to the hard...
itk::SmartPointer< Self > Pointer
std::string m_ToolfilesDir
The directory where the tool calibration files can be found.
std::vector< ClaronTool::Pointer > DetectTools()
Automatically detects tools in field of measurement of the tracking device. Tools can only be detecte...
virtual bool IsDeviceInstalled() override
ClaronInterface * GetDevice()
An object of this class represents the interface to the MicronTracker. The methods of this class are ...
DataCollection - Class to facilitate loading/accessing structured data.
std::vector< ClaronTool::Pointer > GetAllTools()
virtual bool StartTracking() override
Starts the tracking.
mitk::TrackingTool * AddTool(const char *toolName, const char *fileName)
Create a new Claron tool with toolName and fileName and add it to the list of tools.
An object of this class represents the MicronTracker device. You can add tools to this device...
virtual unsigned int GetToolCount() const override
virtual bool StopTracking() override
Stops the tracking.
virtual bool CloseConnection() override
Closes the connection and clears all resources.
virtual bool OpenConnection() override
Opens the connection to the device. This have to be done before the tracking is started.
Interface for all Tracking Devices.
static IGTTimeStamp * GetInstance()
returns a pointer to the current instance of mitkTimeStamp
vnl_quaternion< ScalarType > Quaternion
void Start(itk::Object::Pointer device)
starts the time-acquisition
bool InternalAddTool(ClaronTool::Pointer tool)
Adds a tool to the tracking device.
static ITK_THREAD_RETURN_TYPE ThreadStartTracking(void *data)
std::string m_CalibrationDir
The directory where the camera calibration files can be found.
TrackingDeviceData m_Data
current device Data
#define mitkThrowException(classname)
bool IsMicronTrackerInstalled()
void TrackTools()
This method tracks tools as long as the variable m_Mode is set to "Tracking". Tracking tools means gr...
ClaronInterface::Pointer m_Device
represents the interface to the tracking hardware
TrackingTool * GetTool(unsigned int toolNumber) const override
itk::MutexLockHolder< itk::FastMutexLock > MutexLockHolder
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.