An object of this class represents the MicronTracker device. You can add tools to this device, then open the connection and start tracking. The tracking device will then continuously update the tool coordinates. More...
#include <mitkClaronTrackingDevice.h>
Public Types | |
typedef ClaronTrackingDevice | Self |
typedef TrackingDevice | Superclass |
typedef itk::SmartPointer< Self > | Pointer |
typedef itk::SmartPointer < const Self > | ConstPointer |
Public Member Functions | |
virtual const char * | GetClassName () const |
virtual bool | StartTracking () |
Starts the tracking. | |
virtual bool | StopTracking () |
Stops the tracking. | |
virtual bool | OpenConnection () |
Opens the connection to the device. This have to be done before the tracking is startet. | |
virtual bool | CloseConnection () |
Closes the connection and clears all resources. | |
virtual unsigned int | GetToolCount () const |
TrackingTool * | GetTool (unsigned int toolNumber) const |
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. | |
bool | IsMicronTrackerInstalled () |
Static Public Member Functions | |
static Pointer | New () |
Protected Member Functions | |
ClaronTrackingDevice () | |
~ClaronTrackingDevice () | |
bool | InternalAddTool (ClaronTool::Pointer tool) |
Adds a tool to the tracking device. | |
void | TrackTools () |
This method tracks tools as long as the variable m_Mode is set to "Tracking". Tracking tools means grabbing frames from the camera an updating the tools. | |
std::vector< ClaronTool::Pointer > | DetectTools () |
Automatically detects tools in field of measurement of the tracking device. Tools can only be detected if their calibration file is availiable in the directory for calibration files. | |
std::vector< ClaronTool::Pointer > | GetAllTools () |
ClaronInterface * | GetDevice () |
Static Protected Member Functions | |
static ITK_THREAD_RETURN_TYPE | ThreadStartTracking (void *data) |
Protected Attributes | |
std::vector< ClaronTool::Pointer > | m_AllTools |
vector holding all tools | |
ClaronInterface::Pointer | m_Device |
represents the interface to the tracking hardware | |
itk::MultiThreader::Pointer | m_MultiThreader |
int | m_ThreadID |
std::string | m_CalibrationDir |
The directory where the camera calibration files can be found. | |
std::string | m_ToolfilesDir |
The directory where the tool calibration files can be found. |
An object of this class represents the MicronTracker device. You can add tools to this device, then open the connection and start tracking. The tracking device will then continuously update the tool coordinates.
Documentation:
Definition at line 43 of file mitkClaronTrackingDevice.h.
typedef itk::SmartPointer<const Self> mitk::ClaronTrackingDevice::ConstPointer |
Reimplemented from mitk::TrackingDevice.
Definition at line 47 of file mitkClaronTrackingDevice.h.
typedef itk::SmartPointer<Self> mitk::ClaronTrackingDevice::Pointer |
Reimplemented from mitk::TrackingDevice.
Definition at line 47 of file mitkClaronTrackingDevice.h.
Reimplemented from mitk::TrackingDevice.
Definition at line 47 of file mitkClaronTrackingDevice.h.
Reimplemented from mitk::TrackingDevice.
Definition at line 47 of file mitkClaronTrackingDevice.h.
mitk::ClaronTrackingDevice::ClaronTrackingDevice | ( | ) | [protected] |
Definition at line 29 of file mitkClaronTrackingDevice.cpp.
References mitk::ClaronMicron, m_CalibrationDir, m_Device, m_MultiThreader, m_ThreadID, m_ToolfilesDir, mitk::TrackingDevice::m_Type, and New().
: mitk::TrackingDevice() { //set the type of this tracking device this->m_Type = ClaronMicron; this->m_MultiThreader = itk::MultiThreader::New(); m_ThreadID = 0; m_Device = mitk::ClaronInterface::New(); //############################# standard directories (from cmake) ################################## if (m_Device->IsMicronTrackerInstalled()) { #ifdef MITK_MICRON_TRACKER_TEMP_DIR m_ToolfilesDir = std::string(MITK_MICRON_TRACKER_TEMP_DIR); #endif #ifdef MITK_MICRON_TRACKER_CALIBRATION_DIR m_CalibrationDir = std::string(MITK_MICRON_TRACKER_CALIBRATION_DIR); #endif } else { m_ToolfilesDir = "Error - No Microntracker installed"; m_CalibrationDir = "Error - No Microntracker installed"; } //################################################################################################## m_Device->Initialize(m_CalibrationDir, m_ToolfilesDir); }
mitk::ClaronTrackingDevice::~ClaronTrackingDevice | ( | ) | [protected] |
Definition at line 58 of file mitkClaronTrackingDevice.cpp.
{ }
mitk::TrackingTool * mitk::ClaronTrackingDevice::AddTool | ( | const char * | toolName, |
const char * | fileName | ||
) |
Create a new Claron tool with toolName and fileName and add it to the list of tools.
This method will create a new ClaronTool object, load the tool definition file fileName, set the tool name toolName and then add it to the list of tools. It returns a pointer of type mitk::TrackingTool to the tool that can be used to read tracking data from it. This is the only way to add tools to ClaronTrackingDevice.
Definition at line 63 of file mitkClaronTrackingDevice.cpp.
References mitk::ClaronTool::New(), and QuadProgPP::t().
{ mitk::ClaronTool::Pointer t = mitk::ClaronTool::New(); if (t->LoadFile(fileName) == false) return NULL; t->SetToolName(toolName); if (this->InternalAddTool(t) == false) return NULL; return t.GetPointer(); }
bool mitk::ClaronTrackingDevice::CloseConnection | ( | ) | [virtual] |
Closes the connection and clears all resources.
Implements mitk::TrackingDevice.
Definition at line 195 of file mitkClaronTrackingDevice.cpp.
std::vector< mitk::ClaronTool::Pointer > mitk::ClaronTrackingDevice::DetectTools | ( | ) | [protected] |
Automatically detects tools in field of measurement of the tracking device. Tools can only be detected if their calibration file is availiable in the directory for calibration files.
Definition at line 82 of file mitkClaronTrackingDevice.cpp.
References mitk::ClaronTool::New().
{ std::vector<mitk::ClaronTool::Pointer> returnValue; std::vector<claronToolHandle> allHandles = m_Device->GetAllActiveTools(); for (std::vector<claronToolHandle>::iterator iter = allHandles.begin(); iter != allHandles.end(); ++iter) { ClaronTool::Pointer newTool = ClaronTool::New(); newTool->SetToolName(m_Device->GetName(*iter)); newTool->SetCalibrationName(m_Device->GetName(*iter)); newTool->SetToolHandle(*iter); returnValue.push_back(newTool); } return returnValue; }
std::vector< mitk::ClaronTool::Pointer > mitk::ClaronTrackingDevice::GetAllTools | ( | ) | [protected] |
Definition at line 217 of file mitkClaronTrackingDevice.cpp.
{ return this->m_AllTools; }
virtual const char* mitk::ClaronTrackingDevice::GetClassName | ( | ) | const [virtual] |
Reimplemented from mitk::TrackingDevice.
mitk::ClaronInterface * mitk::ClaronTrackingDevice::GetDevice | ( | ) | [protected] |
Definition at line 211 of file mitkClaronTrackingDevice.cpp.
{ return m_Device; }
mitk::TrackingTool * mitk::ClaronTrackingDevice::GetTool | ( | unsigned int | toolNumber ) | const [virtual] |
toolNumber | The number of the tool which should be given back. |
Implements mitk::TrackingDevice.
Definition at line 156 of file mitkClaronTrackingDevice.cpp.
{ if ( toolNumber >= this->GetToolCount()) return NULL; else return this->m_AllTools[toolNumber]; }
unsigned int mitk::ClaronTrackingDevice::GetToolCount | ( | ) | const [virtual] |
Implements mitk::TrackingDevice.
Definition at line 150 of file mitkClaronTrackingDevice.cpp.
{ return (unsigned int)this->m_AllTools.size(); }
bool mitk::ClaronTrackingDevice::InternalAddTool | ( | ClaronTool::Pointer | tool ) | [protected] |
Adds a tool to the tracking device.
tool | The tool which will be added. |
Definition at line 75 of file mitkClaronTrackingDevice.cpp.
{ m_AllTools.push_back(tool); return true; }
bool mitk::ClaronTrackingDevice::IsMicronTrackerInstalled | ( | ) |
Definition at line 304 of file mitkClaronTrackingDevice.cpp.
{ return this->m_Device->IsMicronTrackerInstalled(); }
static Pointer mitk::ClaronTrackingDevice::New | ( | ) | [static] |
Referenced by ClaronTrackingDevice(), QmitkIGTExampleView::ConfigureTrackingDevice(), QmitkTrackingDeviceConfigurationWidget::ConstructTrackingDevice(), mitkClaronTrackingDeviceTestClass::TestAllMethodsOnSystemsWithoutMicronTracker(), mitkClaronTrackingDeviceTestClass::TestInstantiation(), mitkClaronTrackingDeviceTestClass::TestIsMicronTrackerInstalled(), and mitkClaronTrackingDeviceTestClass::TestToolConfiguration().
bool mitk::ClaronTrackingDevice::OpenConnection | ( | ) | [virtual] |
Opens the connection to the device. This have to be done before the tracking is startet.
Implements mitk::TrackingDevice.
Definition at line 165 of file mitkClaronTrackingDevice.cpp.
References mitk::ClaronInterface::New().
{ bool returnValue; //Create the temp directory itksys::SystemTools::MakeDirectory(m_ToolfilesDir.c_str()); m_Device->Initialize(m_CalibrationDir,m_ToolfilesDir); //m_Device = new ClaronInterface(m_CalibrationDir, m_ToolfilesDir); returnValue = m_Device->StartTracking(); if (returnValue) { this->SetState(Ready); } else { //reset everything if (m_Device.IsNull()) { m_Device = mitk::ClaronInterface::New(); m_Device->Initialize(m_CalibrationDir, m_ToolfilesDir); } m_Device->StopTracking(); this->SetState(Setup); m_ErrorMessage = "Error while trying to open connection to the MicronTracker."; } return returnValue; }
bool mitk::ClaronTrackingDevice::StartTracking | ( | ) | [virtual] |
Starts the tracking.
Implements mitk::TrackingDevice.
Definition at line 98 of file mitkClaronTrackingDevice.cpp.
References mitk::TimeStamp::GetInstance(), and mitk::TimeStamp::Start().
{ //By Alfred: next line because no temp directory is set if MicronTracker is not installed if (!m_Device->IsMicronTrackerInstalled()) return false; //################################################################################## //be sure that the temp-directory is empty at start: delete all files in the tool files directory itksys::SystemTools::RemoveADirectory(m_ToolfilesDir.c_str()); itksys::SystemTools::MakeDirectory(m_ToolfilesDir.c_str()); //copy all toolfiles into the temp directory for (unsigned int i=0; i<m_AllTools.size(); i++) { itksys::SystemTools::CopyAFile(m_AllTools[i]->GetFile().c_str(), m_ToolfilesDir.c_str()); } this->SetState(Tracking); // go to mode Tracking this->m_StopTrackingMutex->Lock(); // update the local copy of m_StopTracking this->m_StopTracking = false; this->m_StopTrackingMutex->Unlock(); //restart the Microntracker, so it will load the new tool files m_Device->StopTracking(); m_Device->Initialize(m_CalibrationDir,m_ToolfilesDir); m_TrackingFinishedMutex->Unlock(); // transfer the execution rights to tracking thread if (m_Device->StartTracking()) { mitk::TimeStamp::GetInstance()->Start(this); m_ThreadID = m_MultiThreader->SpawnThread(this->ThreadStartTracking, this); // start a new thread that executes the TrackTools() method return true; } else { m_ErrorMessage = "Error while trying to start the device!"; return false; } }
bool mitk::ClaronTrackingDevice::StopTracking | ( | ) | [virtual] |
Stops the tracking.
Reimplemented from mitk::TrackingDevice.
Definition at line 140 of file mitkClaronTrackingDevice.cpp.
{ Superclass::StopTracking(); //delete all files in the tool files directory itksys::SystemTools::RemoveADirectory(m_ToolfilesDir.c_str()); itksys::SystemTools::MakeDirectory(m_ToolfilesDir.c_str()); return true; }
ITK_THREAD_RETURN_TYPE mitk::ClaronTrackingDevice::ThreadStartTracking | ( | void * | data ) | [static, protected] |
Definition at line 310 of file mitkClaronTrackingDevice.cpp.
References TrackTools().
{ /* extract this pointer from Thread Info structure */ struct itk::MultiThreader::ThreadInfoStruct * pInfo = (struct itk::MultiThreader::ThreadInfoStruct*)pInfoStruct; if (pInfo == NULL) { return ITK_THREAD_RETURN_VALUE; } if (pInfo->UserData == NULL) { return ITK_THREAD_RETURN_VALUE; } ClaronTrackingDevice *trackingDevice = (ClaronTrackingDevice*)pInfo->UserData; if (trackingDevice != NULL) trackingDevice->TrackTools(); return ITK_THREAD_RETURN_VALUE; }
void mitk::ClaronTrackingDevice::TrackTools | ( | ) | [protected] |
This method tracks tools as long as the variable m_Mode is set to "Tracking". Tracking tools means grabbing frames from the camera an updating the tools.
Definition at line 223 of file mitkClaronTrackingDevice.cpp.
Referenced by ThreadStartTracking().
{ try { /* lock the TrackingFinishedMutex to signal that the execution rights are now transfered to the tracking thread */ MutexLockHolder trackingFinishedLockHolder(*m_TrackingFinishedMutex); // keep lock until end of scope bool localStopTracking; // Because m_StopTracking is used by two threads, access has to be guarded by a mutex. To minimize thread locking, a local copy is used here this->m_StopTrackingMutex->Lock(); // update the local copy of m_StopTracking localStopTracking = this->m_StopTracking; this->m_StopTrackingMutex->Unlock(); while ((this->GetState() == Tracking) && (localStopTracking == false)) { this->GetDevice()->GrabFrame(); std::vector<mitk::ClaronTool::Pointer> detectedTools = this->DetectTools(); std::vector<mitk::ClaronTool::Pointer> allTools = this->GetAllTools(); std::vector<mitk::ClaronTool::Pointer>::iterator itAllTools; for(itAllTools = allTools.begin(); itAllTools != allTools.end(); itAllTools++) { mitk::ClaronTool::Pointer currentTool = *itAllTools; //test if current tool was detected std::vector<mitk::ClaronTool::Pointer>::iterator itDetectedTools; bool foundTool = false; for(itDetectedTools = detectedTools.begin(); itDetectedTools != detectedTools.end(); itDetectedTools++) { mitk::ClaronTool::Pointer aktuDet = *itDetectedTools; std::string tempString(currentTool->GetCalibrationName()); if (tempString.compare(aktuDet->GetCalibrationName())==0) { currentTool->SetToolHandle(aktuDet->GetToolHandle()); foundTool = true; } } if (!foundTool) { currentTool->SetToolHandle(0); } if (currentTool->GetToolHandle() != 0) { currentTool->SetDataValid(true); //get tip position of tool: std::vector<double> pos_vector = this->GetDevice()->GetTipPosition(currentTool->GetToolHandle()); //write tip position into tool: mitk::Point3D pos; pos[0] = pos_vector[0]; pos[1] = pos_vector[1]; pos[2] = pos_vector[2]; currentTool->SetPosition(pos); //get tip quaternion of tool std::vector<double> quat = this->GetDevice()->GetTipQuaternions(currentTool->GetToolHandle()); //write tip quaternion into tool mitk::Quaternion orientation(quat[1], quat[2], quat[3], quat[0]); currentTool->SetOrientation(orientation); } else { mitk::Point3D origin; origin.Fill(0); currentTool->SetPosition(origin); currentTool->SetOrientation(mitk::Quaternion(0,0,0,0)); currentTool->SetDataValid(false); } } /* Update the local copy of m_StopTracking */ this->m_StopTrackingMutex->Lock(); localStopTracking = m_StopTracking; this->m_StopTrackingMutex->Unlock(); } } catch(...) { this->StopTracking(); this->SetErrorMessage("Error while trying to track tools. Thread stopped."); } }
std::vector<ClaronTool::Pointer> mitk::ClaronTrackingDevice::m_AllTools [protected] |
vector holding all tools
Definition at line 143 of file mitkClaronTrackingDevice.h.
std::string mitk::ClaronTrackingDevice::m_CalibrationDir [protected] |
The directory where the camera calibration files can be found.
Definition at line 149 of file mitkClaronTrackingDevice.h.
Referenced by ClaronTrackingDevice().
represents the interface to the tracking hardware
Definition at line 144 of file mitkClaronTrackingDevice.h.
Referenced by ClaronTrackingDevice().
itk::MultiThreader::Pointer mitk::ClaronTrackingDevice::m_MultiThreader [protected] |
Definition at line 145 of file mitkClaronTrackingDevice.h.
Referenced by ClaronTrackingDevice().
int mitk::ClaronTrackingDevice::m_ThreadID [protected] |
Definition at line 146 of file mitkClaronTrackingDevice.h.
Referenced by ClaronTrackingDevice().
std::string mitk::ClaronTrackingDevice::m_ToolfilesDir [protected] |
The directory where the tool calibration files can be found.
Definition at line 151 of file mitkClaronTrackingDevice.h.
Referenced by ClaronTrackingDevice().