superclass for specific NDI tracking Devices that use serial communication. More...
#include <mitkNDITrackingDevice.h>
Public Types | |
typedef std::vector < NDIPassiveTool::Pointer > | Tool6DContainerType |
List of 6D tools of the correct type for this tracking device. | |
typedef std::vector< int > | TrackingVolumeDimensionType |
List of the supported tracking volume dimensions. | |
typedef mitk::TrackingDeviceType | NDITrackingDeviceType |
This enumeration includes the two types of NDI tracking devices (Polaris, Aurora). | |
typedef std::vector < NDITrackingVolume > | NDITrackingVolumeContainerType |
vector of tracking volumes | |
typedef mitk::SerialCommunication::PortNumber | PortNumber |
Port number of the serial connection. | |
typedef mitk::SerialCommunication::BaudRate | BaudRate |
Baud rate of the serial connection. | |
typedef mitk::SerialCommunication::DataBits | DataBits |
Number of data bits used in the serial connection. | |
typedef mitk::SerialCommunication::Parity | Parity |
Parity mode used in the serial connection. | |
typedef mitk::SerialCommunication::StopBits | StopBits |
Number of stop bits used in the serial connection. | |
typedef mitk::SerialCommunication::HardwareHandshake | HardwareHandshake |
Hardware handshake mode of the serial connection. | |
typedef mitk::NDIPassiveTool::TrackingPriority | TrackingPriority |
Tracking priority used for tracking a tool. | |
typedef NDITrackingDevice | Self |
typedef TrackingDevice | Superclass |
typedef itk::SmartPointer< Self > | Pointer |
typedef itk::SmartPointer < const Self > | ConstPointer |
Public Member Functions | |
virtual const char * | GetClassName () const |
virtual void | SetType (TrackingDeviceType _arg) |
Set the type of the NDI Tracking Device because it can not jet handle this itself. | |
virtual bool | OpenConnection () |
initialize the connection to the tracking device | |
virtual bool | CloseConnection () |
Closes the connection. | |
bool | InitializeWiredTools () |
virtual mitk::TrackingDeviceType | TestConnection () |
TestConnection() tries to connect to a NDI tracking device on the current port/device and returns which device it has found. | |
bool | DiscoverWiredTools () |
retrieves all wired tools from the tracking device | |
virtual bool | StartTracking () |
Start the tracking. | |
virtual TrackingTool * | GetTool (unsigned int toolNumber) const |
return the tool with index toolNumber | |
virtual mitk::TrackingTool * | GetToolByName (std::string name) const |
Returns the tool with the given tool name. | |
virtual unsigned int | GetToolCount () const |
return current number of tools | |
mitk::TrackingTool * | AddTool (const char *toolName, const char *fileName, TrackingPriority p=NDIPassiveTool::Dynamic) |
Create a passive 6D tool with toolName and fileName and add it to the list of tools. | |
virtual bool | RemoveTool (TrackingTool *tool) |
Remove a passive 6D tool from the list of tracked tools. | |
virtual bool | UpdateTool (mitk::TrackingTool *tool) |
reloads the srom file and reinitializes the tool | |
virtual void | SetPortNumber (const PortNumber _arg) |
set port number for serial communication | |
virtual PortNumber | GetPortNumber () const |
virtual void | SetDeviceName (std::string _arg) |
returns the port number for serial communication | |
virtual const char * | GetDeviceName () const |
virtual void | SetBaudRate (const BaudRate _arg) |
returns the device name for serial communication | |
virtual BaudRate | GetBaudRate () const |
virtual void | SetDataBits (const DataBits _arg) |
returns the baud rate for serial communication | |
virtual DataBits | GetDataBits () const |
virtual void | SetParity (const Parity _arg) |
returns the data bits for serial communication | |
virtual Parity | GetParity () const |
virtual void | SetStopBits (const StopBits _arg) |
returns the parity mode | |
virtual StopBits | GetStopBits () const |
virtual void | SetHardwareHandshake (const HardwareHandshake _arg) |
returns the number of stop bits | |
virtual HardwareHandshake | GetHardwareHandshake () const |
virtual void | SetIlluminationActivationRate (const IlluminationActivationRate _arg) |
returns the hardware handshake setting | |
virtual IlluminationActivationRate | GetIlluminationActivationRate () const |
virtual void | SetDataTransferMode (const DataTransferMode _arg) |
returns the activation rate of IR illumator for polaris | |
virtual DataTransferMode | GetDataTransferMode () const |
virtual bool | Beep (unsigned char count) |
returns the data transfer mode | |
NDIErrorCode | GetErrorCode (const std::string *input) |
returns the error code for a string that contains an error code in hexadecimal format | |
virtual bool | SetOperationMode (OperationMode mode) |
set operation mode to 6D tool tracking, 3D marker tracking or 6D&3D hybrid tracking (see OperationMode) | |
virtual OperationMode | GetOperationMode () |
get current operation mode | |
virtual bool | GetMarkerPositions (MarkerPointContainerType *markerpositions) |
Get 3D marker positions (operation mode must be set to MarkerTracking3D or HybridTracking) | |
virtual int | GetMajorFirmwareRevisionNumber () |
Get major revision number from tracking device should not be called directly after starting to track. | |
virtual const char * | GetFirmwareRevisionNumber () |
Get revision number from tracking device as string should not be called directly after starting to track. | |
virtual bool | GetSupportedVolumes (unsigned int *numberOfVolumes, NDITrackingVolumeContainerType *volumes, TrackingVolumeDimensionType *volumesDimensions) |
Get number of supported tracking volumes, a vector containing the supported volumes and a vector containing the signed dimensions in mm. For each volume 10 boundaries are stored in the order of the supported volumes (see AURORA API GUIDE: SFLIST p.54). | |
virtual bool | SetVolume (NDITrackingVolume volume) |
Sets the desired tracking volume. Returns true if the volume type could be set. Usage: ndiTracker->SetVolume(mitk::Dome);. | |
virtual void | TrackTools () |
TrackTools() continuously polls serial interface for new 6d tool positions until StopTracking is called. | |
virtual void | TrackMarkerPositions () |
continuously polls serial interface for new 3D marker positions until StopTracking is called. | |
virtual void | TrackToolsAndMarkers () |
continuously polls serial interface for new 3D marker positions and 6D tool positions until StopTracking is called. | |
Static Public Member Functions | |
static Pointer | New () |
static ITK_THREAD_RETURN_TYPE | ThreadStartTracking (void *data) |
static start method for the tracking thread. | |
Protected Member Functions | |
virtual bool | InternalAddTool (NDIPassiveTool *tool) |
Add a passive 6D tool to the list of tracked tools. This method is used by AddTool. | |
virtual void | InvalidateAll () |
invalidate all tools | |
NDIPassiveTool * | GetInternalTool (std::string portHandle) |
returns the tool object that has been assigned the port handle or NULL if no tool can be found | |
NDIErrorCode | FreePortHandles () |
free all port handles that need to be freed | |
NDIErrorCode | Send (const std::string *message, bool addCRC=true) |
Send message to tracking device. | |
NDIErrorCode | Receive (std::string *answer, unsigned int numberOfBytes) |
receive numberOfBytes bytes from tracking device | |
NDIErrorCode | ReceiveByte (char *answer) |
lightweight receive function, that reads just one byte | |
NDIErrorCode | ReceiveLine (std::string *answer) |
receive characters until the first LF (The LF is included in the answer string) | |
void | ClearSendBuffer () |
empty send buffer of serial communication interface | |
void | ClearReceiveBuffer () |
empty receive buffer of serial communication interface | |
const std::string | CalcCRC (const std::string *input) |
returns the CRC16 for input as a std::string | |
NDITrackingDevice () | |
Constructor. | |
virtual | ~NDITrackingDevice () |
Destructor. | |
Protected Attributes | |
std::string | m_DeviceName |
Device Name. | |
PortNumber | m_PortNumber |
COM Port Number. | |
BaudRate | m_BaudRate |
COM Port Baud Rate. | |
DataBits | m_DataBits |
Number of Data Bits per token. | |
Parity | m_Parity |
Parity mode for communication. | |
StopBits | m_StopBits |
number of stop bits per token | |
HardwareHandshake | m_HardwareHandshake |
use hardware handshake for serial port connection | |
NDITrackingVolume | m_NDITrackingVolume |
which tracking volume is currently used (if device supports multiple volumes) ( | |
IlluminationActivationRate | m_IlluminationActivationRate |
update rate of IR illuminator for Polaris | |
DataTransferMode | m_DataTransferMode |
use TX (text) or BX (binary) ( | |
Tool6DContainerType | m_6DTools |
list of 6D tools | |
itk::FastMutexLock::Pointer | m_ToolsMutex |
mutex for coordinated access of tool container | |
mitk::SerialCommunication::Pointer | m_SerialCommunication |
serial communication interface | |
itk::FastMutexLock::Pointer | m_SerialCommunicationMutex |
mutex for coordinated access of serial communication interface | |
NDIProtocol::Pointer | m_DeviceProtocol |
create and parse NDI protocol strings | |
itk::MultiThreader::Pointer | m_MultiThreader |
creates tracking thread that continuously polls serial interface for new tracking data | |
int | m_ThreadID |
ID of tracking thread. | |
OperationMode | m_OperationMode |
tracking mode (6D tool tracking, 3D marker tracking,...) | |
itk::FastMutexLock::Pointer | m_MarkerPointsMutex |
mutex for marker point data container | |
MarkerPointContainerType | m_MarkerPoints |
container for markers (3D point tracking mode) | |
Friends | |
class | NDIProtocol |
superclass for specific NDI tracking Devices that use serial communication.
Documentation implements the TrackingDevice interface for NDI tracking devices (POLARIS, AURORA)
Definition at line 46 of file mitkNDITrackingDevice.h.
Baud rate of the serial connection.
Definition at line 56 of file mitkNDITrackingDevice.h.
typedef itk::SmartPointer<const Self> mitk::NDITrackingDevice::ConstPointer |
Reimplemented from mitk::TrackingDevice.
Definition at line 64 of file mitkNDITrackingDevice.h.
Number of data bits used in the serial connection.
Definition at line 57 of file mitkNDITrackingDevice.h.
Hardware handshake mode of the serial connection.
Definition at line 60 of file mitkNDITrackingDevice.h.
This enumeration includes the two types of NDI tracking devices (Polaris, Aurora).
Definition at line 53 of file mitkNDITrackingDevice.h.
typedef std::vector<NDITrackingVolume> mitk::NDITrackingDevice::NDITrackingVolumeContainerType |
vector of tracking volumes
Definition at line 54 of file mitkNDITrackingDevice.h.
Parity mode used in the serial connection.
Definition at line 58 of file mitkNDITrackingDevice.h.
typedef itk::SmartPointer<Self> mitk::NDITrackingDevice::Pointer |
Reimplemented from mitk::TrackingDevice.
Definition at line 64 of file mitkNDITrackingDevice.h.
Port number of the serial connection.
Definition at line 55 of file mitkNDITrackingDevice.h.
Reimplemented from mitk::TrackingDevice.
Definition at line 64 of file mitkNDITrackingDevice.h.
Number of stop bits used in the serial connection.
Definition at line 59 of file mitkNDITrackingDevice.h.
Reimplemented from mitk::TrackingDevice.
Definition at line 64 of file mitkNDITrackingDevice.h.
typedef std::vector<NDIPassiveTool::Pointer> mitk::NDITrackingDevice::Tool6DContainerType |
List of 6D tools of the correct type for this tracking device.
Definition at line 51 of file mitkNDITrackingDevice.h.
Tracking priority used for tracking a tool.
Definition at line 61 of file mitkNDITrackingDevice.h.
typedef std::vector<int> mitk::NDITrackingDevice::TrackingVolumeDimensionType |
List of the supported tracking volume dimensions.
Definition at line 52 of file mitkNDITrackingDevice.h.
mitk::NDITrackingDevice::NDITrackingDevice | ( | ) | [protected] |
Constructor.
Definition at line 32 of file mitkNDITrackingDevice.cpp.
References m_6DTools, m_DeviceProtocol, m_MarkerPoints, m_MarkerPointsMutex, m_MultiThreader, m_SerialCommunicationMutex, m_ToolsMutex, mitk::TrackingDevice::m_Type, New(), and mitk::TrackingSystemNotSpecified.
: TrackingDevice(),m_DeviceName(""), m_PortNumber(mitk::SerialCommunication::COM5), m_BaudRate(mitk::SerialCommunication::BaudRate9600), m_DataBits(mitk::SerialCommunication::DataBits8), m_Parity(mitk::SerialCommunication::None), m_StopBits(mitk::SerialCommunication::StopBits1), m_HardwareHandshake(mitk::SerialCommunication::HardwareHandshakeOff), m_NDITrackingVolume(Standard), m_IlluminationActivationRate(Hz20), m_DataTransferMode(TX), m_6DTools(), m_ToolsMutex(NULL), m_SerialCommunication(NULL), m_SerialCommunicationMutex(NULL), m_DeviceProtocol(NULL), m_MultiThreader(NULL), m_ThreadID(0), m_OperationMode(ToolTracking6D), m_MarkerPointsMutex(NULL), m_MarkerPoints() { this->m_Type = TrackingSystemNotSpecified; //NDIPolaris; // = 0; //set the type = 0 (=Polaris, default) m_6DTools.clear(); m_SerialCommunicationMutex = itk::FastMutexLock::New(); m_DeviceProtocol = NDIProtocol::New(); m_DeviceProtocol->SetTrackingDevice(this); m_DeviceProtocol->UseCRCOn(); m_MultiThreader = itk::MultiThreader::New(); m_ToolsMutex = itk::FastMutexLock::New(); m_MarkerPointsMutex = itk::FastMutexLock::New(); m_MarkerPoints.reserve(50); // a maximum of 50 marker positions can be reported by the tracking device }
mitk::NDITrackingDevice::~NDITrackingDevice | ( | ) | [protected, virtual] |
Destructor.
Definition at line 87 of file mitkNDITrackingDevice.cpp.
{ /* stop tracking and disconnect from tracking device */ if (GetState() == Tracking) { this->StopTracking(); } if (GetState() == Ready) { this->CloseConnection(); } /* cleanup tracking thread */ if ((m_ThreadID != 0) && (m_MultiThreader.IsNotNull())) { m_MultiThreader->TerminateThread(m_ThreadID); } m_MultiThreader = NULL; /* free serial communication interface */ if (m_SerialCommunication.IsNotNull()) { m_SerialCommunication->ClearReceiveBuffer(); m_SerialCommunication->ClearSendBuffer(); m_SerialCommunication->CloseConnection(); m_SerialCommunication = NULL; } }
mitk::TrackingTool * mitk::NDITrackingDevice::AddTool | ( | const char * | toolName, |
const char * | fileName, | ||
TrackingPriority | p = NDIPassiveTool::Dynamic |
||
) |
Create a passive 6D tool with toolName and fileName and add it to the list of tools.
This method will create a new NDIPassiveTool object, load the SROM file fileName, set the tool name toolName and the tracking priority p 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 NDITrackingDevice.
Definition at line 944 of file mitkNDITrackingDevice.cpp.
References mitk::NDIPassiveTool::New(), and QuadProgPP::t().
{ mitk::NDIPassiveTool::Pointer t = mitk::NDIPassiveTool::New(); if (t->LoadSROMFile(fileName) == false) return NULL; t->SetToolName(toolName); t->SetTrackingPriority(p); if (this->InternalAddTool(t) == false) return NULL; return t.GetPointer(); }
bool mitk::NDITrackingDevice::Beep | ( | unsigned char | count ) | [virtual] |
returns the data transfer mode
Beep the tracking device 1 to 9 times
Definition at line 932 of file mitkNDITrackingDevice.cpp.
References mitk::NDIOKAY.
{ if (this->GetState() != Setup) { return (m_DeviceProtocol->BEEP(count) == NDIOKAY); } else { return false; } }
const std::string mitk::NDITrackingDevice::CalcCRC | ( | const std::string * | input ) | [protected] |
returns the CRC16 for input as a std::string
Definition at line 327 of file mitkNDITrackingDevice.cpp.
{ if (input == NULL) return ""; /* the crc16 calculation code is taken from the NDI API guide example code section */ static int oddparity[16] = {0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0}; unsigned int data; // copy of the input string's current character unsigned int crcValue = 0; // the crc value is stored here unsigned int* puCRC16 = &crcValue; // the algorithm uses a pointer to crcValue, so it's easier to provide that than to change the algorithm for (unsigned int i = 0; i < input->length(); i++) { data = (*input)[i]; data = (data ^ (*(puCRC16) & 0xff)) & 0xff; *puCRC16 >>= 8; if (oddparity[data & 0x0f] ^ oddparity[data >> 4]) { *(puCRC16) ^= 0xc001; } data <<= 6; *puCRC16 ^= data; data <<= 1; *puCRC16 ^= data; } // crcValue contains now the CRC16 value. Convert it to a string and return it char returnvalue[13]; sprintf(returnvalue,"%04X", crcValue); // 4 hexadecimal digit with uppercase format return std::string(returnvalue); }
void mitk::NDITrackingDevice::ClearReceiveBuffer | ( | ) | [protected] |
empty receive buffer of serial communication interface
Definition at line 320 of file mitkNDITrackingDevice.cpp.
{ MutexLockHolder lock(*m_SerialCommunicationMutex); // lock and unlock the mutex m_SerialCommunication->ClearReceiveBuffer(); }
void mitk::NDITrackingDevice::ClearSendBuffer | ( | ) | [protected] |
empty send buffer of serial communication interface
Definition at line 313 of file mitkNDITrackingDevice.cpp.
{ MutexLockHolder lock(*m_SerialCommunicationMutex); // lock and unlock the mutex m_SerialCommunication->ClearSendBuffer(); }
bool mitk::NDITrackingDevice::CloseConnection | ( | ) | [virtual] |
Closes the connection.
CloseConnection() resets the tracking device, invalidates all tools and then closes the serial port.
Implements mitk::TrackingDevice.
Definition at line 692 of file mitkNDITrackingDevice.cpp.
{ if (this->GetState() != Setup) { //init before closing to force the field generator from aurora to switch itself off m_DeviceProtocol->INIT(); /* close the serial connection */ m_SerialCommunication->CloseConnection(); /* invalidate all tools */ this->InvalidateAll(); /* return to setup mode */ this->SetState(Setup); this->SetErrorMessage(""); m_SerialCommunication = NULL; } return true; }
bool mitk::NDITrackingDevice::DiscoverWiredTools | ( | ) |
retrieves all wired tools from the tracking device
This method queries the tracking device for all wired tools, initializes them and creates TrackingTool representation objects for them
* we need to remember the ports which are occupied to be able to readout the serial numbers of the connected tools later*/
Definition at line 1103 of file mitkNDITrackingDevice.cpp.
References mitk::NDIPassiveTool::Dynamic, mitk::NDIINITIALIZATIONFAILED, mitk::NDIOKAY, mitk::NDIPassiveTool::New(), and mitk::OCCUPIED.
{ /* First, check for disconnected tools and remove them */ this->FreePortHandles(); /* check for new tools, add and initialize them */ NDIErrorCode returnvalue; std::string portHandle; returnvalue = m_DeviceProtocol->PHSR(OCCUPIED, &portHandle); if (returnvalue != NDIOKAY) { this->SetErrorMessage("Could not obtain a list of port handles that are connected"); return false; // ToDo: Is this a fatal error? } /* if there are port handles that need to be initialized, initialize them. Furthermore instantiate tools for each handle that has no tool yet. */ std::string ph; //std::vector<int> occupiedPorts; for (unsigned int i = 0; i < portHandle.size(); i += 2) { ph = portHandle.substr(i, 2); if (this->GetInternalTool(ph) != NULL) // if we already have a tool with this handle continue; // then skip the initialization //instantiate an object for each tool that is connected mitk::NDIPassiveTool::Pointer newTool = mitk::NDIPassiveTool::New(); newTool->SetPortHandle(ph.c_str()); newTool->SetTrackingPriority(mitk::NDIPassiveTool::Dynamic); //set a name for identification newTool->SetToolName((std::string("Port ") + ph).c_str()); returnvalue = m_DeviceProtocol->PINIT(&ph); if (returnvalue != NDIINITIALIZATIONFAILED) //if the initialization failed (AURORA) it can not be enabled. A srom file will have to be specified manually first. Still return true to be able to continue { if (returnvalue != NDIOKAY) { this->SetErrorMessage((std::string("Could not initialize port '") + ph + std::string("' for tool '")+ newTool->GetToolName() + std::string("'")).c_str()); return false; } /* enable the port handle */ returnvalue = m_DeviceProtocol->PENA(&ph, newTool->GetTrackingPriority()); // Enable tool if (returnvalue != NDIOKAY) { this->SetErrorMessage((std::string("Could not enable port '") + ph + std::string("' for tool '")+ newTool->GetToolName() + std::string("'")).c_str()); return false; } } //we have to temporarily unlock m_ModeMutex here to avoid a deadlock with another lock inside InternalAddTool() if (this->InternalAddTool(newTool) == false) this->SetErrorMessage("Error while adding new tool"); //else occupiedPorts.push_back(i); } //after initialization readout serial numbers of tools //for (unsigned int i = 0; i < this->GetToolCount(); i += 2) // { // ph = portHandle.substr(occupiedPorts.at(i), 2); // std::string portInfo; // NDIErrorCode returnvaluePort = m_DeviceProtocol->PHINF(ph, &portInfo); // if ((returnvaluePort==NDIOKAY) && (portInfo.size()>31)) dynamic_cast<mitk::NDIPassiveTool*>(this->GetTool(i))->SetSerialNumber(portInfo.substr(23,8)); // } return true; }
mitk::NDIErrorCode mitk::NDITrackingDevice::FreePortHandles | ( | ) | [protected] |
free all port handles that need to be freed
This method retrieves a list of all port handles that need to be freed (e.g. tool got disconnected) and frees the handles at the tracking device and it removes the tools from the internal tool list
Definition at line 1179 of file mitkNDITrackingDevice.cpp.
References mitk::FREED, mitk::NDIERROR, mitk::NDIOKAY, and QuadProgPP::t().
{ /* first search for port handles that need to be freed: e.g. because of a reset of the tracking system */ NDIErrorCode returnvalue = NDIOKAY; std::string portHandle; returnvalue = m_DeviceProtocol->PHSR(FREED, &portHandle); if (returnvalue != NDIOKAY) { this->SetErrorMessage("Could not obtain a list of port handles that need to be freed"); return returnvalue; // ToDo: Is this a fatal error? } /* if there are port handles that need to be freed, free them */ if (portHandle.empty() == true) return returnvalue; std::string ph; for (unsigned int i = 0; i < portHandle.size(); i += 2) { ph = portHandle.substr(i, 2); mitk::NDIPassiveTool* t = this->GetInternalTool(ph); if (t != NULL) // if we have a tool for the port handle that needs to be freed { if (this->RemoveTool(t) == false) // remove it (this will free the port too) returnvalue = NDIERROR; } else // we don't have a tool, the port handle exists only in the tracking device { returnvalue = m_DeviceProtocol->PHF(&ph); // free it there // What to do if port handle could not be freed? This seems to be a non critical error if (returnvalue != NDIOKAY) { this->SetErrorMessage("Could not free all port handles"); // return false; // could not free all Handles } } } return returnvalue; }
virtual BaudRate mitk::NDITrackingDevice::GetBaudRate | ( | ) | const [virtual] |
virtual const char* mitk::NDITrackingDevice::GetClassName | ( | ) | const [virtual] |
Reimplemented from mitk::TrackingDevice.
virtual DataBits mitk::NDITrackingDevice::GetDataBits | ( | ) | const [virtual] |
virtual DataTransferMode mitk::NDITrackingDevice::GetDataTransferMode | ( | ) | const [virtual] |
virtual const char* mitk::NDITrackingDevice::GetDeviceName | ( | ) | const [virtual] |
NDIErrorCode mitk::NDITrackingDevice::GetErrorCode | ( | const std::string * | input ) |
returns the error code for a string that contains an error code in hexadecimal format
const char * mitk::NDITrackingDevice::GetFirmwareRevisionNumber | ( | ) | [virtual] |
Get revision number from tracking device as string should not be called directly after starting to track.
Definition at line 1235 of file mitkNDITrackingDevice.cpp.
References mitk::NDIOKAY.
{ static std::string revision; if (m_DeviceProtocol->APIREV(&revision) != mitk::NDIOKAY || revision.empty() || (revision.size() != 9) ) { this->SetErrorMessage("Could not receive firmware revision number!"); revision = ""; return revision.c_str(); } return revision.c_str(); }
virtual HardwareHandshake mitk::NDITrackingDevice::GetHardwareHandshake | ( | ) | const [virtual] |
virtual IlluminationActivationRate mitk::NDITrackingDevice::GetIlluminationActivationRate | ( | ) | const [virtual] |
mitk::NDIPassiveTool * mitk::NDITrackingDevice::GetInternalTool | ( | std::string | portHandle ) | [protected] |
returns the tool object that has been assigned the port handle or NULL if no tool can be found
Definition at line 914 of file mitkNDITrackingDevice.cpp.
{ MutexLockHolder toolsMutexLockHolder(*m_ToolsMutex); // lock and unlock the mutex Tool6DContainerType::iterator end = m_6DTools.end(); for (Tool6DContainerType::iterator iterator = m_6DTools.begin(); iterator != end; ++iterator) if (portHandle.compare((*iterator)->GetPortHandle()) == 0) return *iterator; return NULL; }
int mitk::NDITrackingDevice::GetMajorFirmwareRevisionNumber | ( | ) | [virtual] |
Get major revision number from tracking device should not be called directly after starting to track.
Definition at line 1221 of file mitkNDITrackingDevice.cpp.
References mitk::NDIOKAY.
{ std::string revision; if (m_DeviceProtocol->APIREV(&revision) != mitk::NDIOKAY || revision.empty() || (revision.size() != 9) ) { this->SetErrorMessage("Could not receive firmware revision number!"); return 0; } const std::string majrevno = revision.substr(2,3); //cut out "004" from "D.004.001" return std::atoi(majrevno.c_str()); }
bool mitk::NDITrackingDevice::GetMarkerPositions | ( | MarkerPointContainerType * | markerpositions ) | [virtual] |
Get 3D marker positions (operation mode must be set to MarkerTracking3D or HybridTracking)
Definition at line 1094 of file mitkNDITrackingDevice.cpp.
{ m_MarkerPointsMutex->Lock(); *markerpositions = m_MarkerPoints; // copy the internal vector to the one provided m_MarkerPointsMutex->Unlock(); return (markerpositions->size() != 0) ; }
mitk::OperationMode mitk::NDITrackingDevice::GetOperationMode | ( | ) | [virtual] |
get current operation mode
Definition at line 1088 of file mitkNDITrackingDevice.cpp.
Referenced by ThreadStartTracking().
{ return m_OperationMode; }
virtual Parity mitk::NDITrackingDevice::GetParity | ( | ) | const [virtual] |
virtual PortNumber mitk::NDITrackingDevice::GetPortNumber | ( | ) | const [virtual] |
virtual StopBits mitk::NDITrackingDevice::GetStopBits | ( | ) | const [virtual] |
bool mitk::NDITrackingDevice::GetSupportedVolumes | ( | unsigned int * | numberOfVolumes, |
NDITrackingVolumeContainerType * | volumes, | ||
TrackingVolumeDimensionType * | volumesDimensions | ||
) | [virtual] |
Get number of supported tracking volumes, a vector containing the supported volumes and a vector containing the signed dimensions in mm. For each volume 10 boundaries are stored in the order of the supported volumes (see AURORA API GUIDE: SFLIST p.54).
Definition at line 1247 of file mitkNDITrackingDevice.cpp.
References mitk::Cube, mitk::Dome, int(), mitk::NDIOKAY, mitk::Pyramid, mitk::SpectraPyramid, mitk::Standard, and mitk::VicraVolume.
{ if (numberOfVolumes == NULL || volumes == NULL || volumesDimensions == NULL) return false; static std::string info; if (m_DeviceProtocol->SFLIST(&info) != mitk::NDIOKAY || info.empty()) { this->SetErrorMessage("Could not receive tracking volume information of tracking system!"); return false; } /*info contains the following: <HEX:number of volumes> (+n times:) <HEX:shape type> <shape parameters D1-D10> <HEX:reserved / number of wavelength supported> <metal resistant / supported wavelength> */ (*numberOfVolumes) = (unsigned int) std::atoi(info.substr(0,1).c_str()); for (unsigned int i=0; i<(*numberOfVolumes); i++) { //e.g. for cube: "9-025000+025000-025000+025000-055000-005000+000000+000000+000000+00000011" //for dome: "A+005000+048000+005000+066000+000000+000000+000000+000000+000000+00000011" std::string::size_type offset, end; offset = (i*73)+1; end = 73+(i*73); std::string currentVolume = info.substr(offset, end);//i=0: from 1 to 73 characters; i=1: from 75 to 148 char; // if i>0 then we have a return statement <LF> infront if (i>0) currentVolume = currentVolume.substr(1, currentVolume.size()); std::string standard = "0"; std::string pyramid = "4"; std::string spectraPyramid = "5"; std::string vicraVolume = "7"; std::string cube = "9"; std::string dome = "A"; if (currentVolume.compare(0,1,standard)==0) volumes->push_back(mitk::Standard); if (currentVolume.compare(0,1,pyramid)==0) volumes->push_back(mitk::Pyramid); if (currentVolume.compare(0,1,spectraPyramid)==0) volumes->push_back(mitk::SpectraPyramid); if (currentVolume.compare(0,1,vicraVolume)==0) volumes->push_back(mitk::VicraVolume); else if (currentVolume.compare(0,1,cube)==0) volumes->push_back(mitk::Cube);//alias cube else if (currentVolume.compare(0,1,dome)==0) volumes->push_back(mitk::Dome); //fill volumesDimensions for (unsigned int index = 0; index < 10; index++) { std::string::size_type offD, endD; offD = 1+(index*7); //7 digits per dimension and the first is the type of volume endD = offD+7; int dimension = std::atoi(currentVolume.substr(offD, endD).c_str()); dimension /= 100; //given in mm. 7 digits are xxxx.xx according to NDI //strange, the last two digits (11) also for the metal flag get read also... volumesDimensions->push_back(dimension); } } return true; }
mitk::TrackingTool * mitk::NDITrackingDevice::GetTool | ( | unsigned int | toolNumber ) | const [virtual] |
return the tool with index toolNumber
Implements mitk::TrackingDevice.
Definition at line 894 of file mitkNDITrackingDevice.cpp.
{ MutexLockHolder toolsMutexLockHolder(*m_ToolsMutex); // lock and unlock the mutex if (toolNumber < m_6DTools.size()) return m_6DTools.at(toolNumber); return NULL; }
mitk::TrackingTool * mitk::NDITrackingDevice::GetToolByName | ( | std::string | name ) | const [virtual] |
Returns the tool with the given tool name.
Note: subclasses can and should implement optimized versions of this method
Reimplemented from mitk::TrackingDevice.
Definition at line 903 of file mitkNDITrackingDevice.cpp.
{ MutexLockHolder toolsMutexLockHolder(*m_ToolsMutex); // lock and unlock the mutex Tool6DContainerType::const_iterator end = m_6DTools.end(); for (Tool6DContainerType::const_iterator iterator = m_6DTools.begin(); iterator != end; ++iterator) if (name.compare((*iterator)->GetToolName()) == 0) return *iterator; return NULL; }
unsigned int mitk::NDITrackingDevice::GetToolCount | ( | ) | const [virtual] |
return current number of tools
Implements mitk::TrackingDevice.
Definition at line 925 of file mitkNDITrackingDevice.cpp.
{ MutexLockHolder toolsMutexLockHolder(*m_ToolsMutex); // lock and unlock the mutex return m_6DTools.size(); }
bool mitk::NDITrackingDevice::InitializeWiredTools | ( | ) |
Definition at line 569 of file mitkNDITrackingDevice.cpp.
References mitk::NDIPassiveTool::GetSROMData(), mitk::NDIPassiveTool::GetSROMDataLength(), mitk::TrackingTool::GetToolName(), mitk::NDIPassiveTool::GetTrackingPriority(), mitk::InternalTrackingTool::IsEnabled(), mitk::NDIOKAY, and mitk::OCCUPIED.
{ NDIErrorCode returnvalue; std::string portHandle; returnvalue = m_DeviceProtocol->PHSR(OCCUPIED, &portHandle); if (returnvalue != NDIOKAY) { this->SetErrorMessage("Could not obtain a list of port handles that are connected"); return false; // ToDo: Is this a fatal error? } /* if there are port handles that need to be initialized, initialize them. Furthermore instantiate tools for each handle that has no tool yet. */ std::string ph; for (unsigned int i = 0; i < portHandle.size(); i += 2) { ph = portHandle.substr(i, 2); mitk::NDIPassiveTool* pt = this->GetInternalTool(ph); if ( pt == NULL) // if we don't have a tool, something is wrong. Tools should be discovered first by calling DiscoverWiredTools() continue; if (pt->GetSROMData() == NULL) continue; returnvalue = m_DeviceProtocol->PVWR(&ph, pt->GetSROMData(), pt->GetSROMDataLength()); if (returnvalue != NDIOKAY) { this->SetErrorMessage((std::string("Could not write SROM file for tool '") + pt->GetToolName() + std::string("' to tracking device")).c_str()); return false; } returnvalue = m_DeviceProtocol->PINIT(&ph); if (returnvalue != NDIOKAY) { this->SetErrorMessage((std::string("Could not initialize tool '") + pt->GetToolName()).c_str()); return false; } if (pt->IsEnabled() == true) { returnvalue = m_DeviceProtocol->PENA(&ph, pt->GetTrackingPriority()); // Enable tool if (returnvalue != NDIOKAY) { this->SetErrorMessage((std::string("Could not enable port '") + portHandle + std::string("' for tool '")+ pt->GetToolName() + std::string("'")).c_str()); return false; } } } return true; }
bool mitk::NDITrackingDevice::InternalAddTool | ( | mitk::NDIPassiveTool * | tool ) | [protected, virtual] |
Add a passive 6D tool to the list of tracked tools. This method is used by AddTool.
Definition at line 957 of file mitkNDITrackingDevice.cpp.
References mitk::NDIOKAY, and mitk::NDIPassiveTool::SetPortHandle().
{ if (tool == NULL) return false; NDIPassiveTool::Pointer p = tool; /* if the connection to the tracking device is already established, add the new tool to the device now */ if (this->GetState() == Ready) { /* get a port handle for the tool */ std::string newPortHandle; NDIErrorCode returnvalue; returnvalue = m_DeviceProtocol->PHRQ(&newPortHandle); if (returnvalue == NDIOKAY) { p->SetPortHandle(newPortHandle.c_str()); /* now write the SROM file of the tool to the tracking system using PVWR */ returnvalue = m_DeviceProtocol->PVWR(&newPortHandle, p->GetSROMData(), p->GetSROMDataLength()); if (returnvalue != NDIOKAY) { this->SetErrorMessage((std::string("Could not write SROM file for tool '") + p->GetToolName() + std::string("' to tracking device")).c_str()); return false; } /* initialize the port handle */ returnvalue = m_DeviceProtocol->PINIT(&newPortHandle); if (returnvalue != NDIOKAY) { this->SetErrorMessage((std::string("Could not initialize port '") + newPortHandle + std::string("' for tool '")+ p->GetToolName() + std::string("'")).c_str()); return false; } /* enable the port handle */ if (p->IsEnabled() == true) { returnvalue = m_DeviceProtocol->PENA(&newPortHandle, p->GetTrackingPriority()); // Enable tool if (returnvalue != NDIOKAY) { this->SetErrorMessage((std::string("Could not enable port '") + newPortHandle + std::string("' for tool '")+ p->GetToolName() + std::string("'")).c_str()); return false; } } } /* now that the tool is added to the device, add it to list too */ m_ToolsMutex->Lock(); this->m_6DTools.push_back(p); m_ToolsMutex->Unlock(); this->Modified(); return true; } else if (this->GetState() == Setup) { /* In Setup mode, we only add it to the list, so that OpenConnection() can add it later */ m_ToolsMutex->Lock(); this->m_6DTools.push_back(p); m_ToolsMutex->Unlock(); this->Modified(); return true; } else // in Tracking mode, no tools can be added return false; }
void mitk::NDITrackingDevice::InvalidateAll | ( | ) | [protected, virtual] |
invalidate all tools
Definition at line 1069 of file mitkNDITrackingDevice.cpp.
{ MutexLockHolder toolsMutexLockHolder(*m_ToolsMutex); // lock and unlock the mutex Tool6DContainerType::iterator end = m_6DTools.end(); for (Tool6DContainerType::iterator iterator = m_6DTools.begin(); iterator != end; ++iterator) (*iterator)->SetDataValid(false); }
static Pointer mitk::NDITrackingDevice::New | ( | ) | [static] |
bool mitk::NDITrackingDevice::OpenConnection | ( | ) | [virtual] |
initialize the connection to the tracking device
OpenConnection() establishes the connection to the tracking device by:
now add tools to the tracking system
POLARIS: initialize the tools that were added manually
Implements mitk::TrackingDevice.
Definition at line 358 of file mitkNDITrackingDevice.cpp.
References mitk::SerialCommunication::BaudRate9600, mitk::SerialCommunication::DataBits8, mitk::NDIOKAY, mitk::NDIPolaris, mitk::SerialCommunication::New(), mitk::SerialCommunication::None, mitk::SerialCommunication::StopBits1, and mitk::TrackingSystemNotSpecified.
{ //this->m_ModeMutex->Lock(); if (this->GetState() != Setup) { this->SetErrorMessage("Can only try to open the connection if in setup mode"); return false; } // m_SerialCommunication = mitk::SerialCommunication::New(); /* init local com port to standard com settings for a NDI tracking device: 9600 baud, 8 data bits, no parity, 1 stop bit, no hardware handshake */ if (m_DeviceName.empty()) m_SerialCommunication->SetPortNumber(m_PortNumber); else m_SerialCommunication->SetDeviceName(m_DeviceName); m_SerialCommunication->SetBaudRate(mitk::SerialCommunication::BaudRate9600); m_SerialCommunication->SetDataBits(mitk::SerialCommunication::DataBits8); m_SerialCommunication->SetParity(mitk::SerialCommunication::None); m_SerialCommunication->SetStopBits(mitk::SerialCommunication::StopBits1); m_SerialCommunication->SetSendTimeout(5000); m_SerialCommunication->SetReceiveTimeout(5000); if (m_SerialCommunication->OpenConnection() == 0) // 0 == ERROR_VALUE { this->SetErrorMessage("Can not open serial port"); m_SerialCommunication->CloseConnection(); m_SerialCommunication = NULL; return false; } /* Reset Tracking device by sending a serial break for 500ms */ m_SerialCommunication->SendBreak(400); /* Read answer from tracking device (RESETBE6F) */ static const std::string reset("RESETBE6F\r"); std::string answer = ""; this->Receive(&answer, reset.length()); // read answer (should be RESETBE6F) this->ClearReceiveBuffer(); // flush the receive buffer of all remaining data (carriage return, strings other than reset if (reset.compare(answer) != 0) // check for RESETBE6F { this->SetErrorMessage("Hardware Reset of tracking device did not work"); if (m_SerialCommunication.IsNotNull()) { m_SerialCommunication->CloseConnection(); m_SerialCommunication = NULL; } return false; } /* Now the tracking device is reset, start initialization */ NDIErrorCode returnvalue; /* set device com settings to new values and wait for the device to change them */ returnvalue = m_DeviceProtocol->COMM(m_BaudRate, m_DataBits, m_Parity, m_StopBits, m_HardwareHandshake); if (returnvalue != NDIOKAY) { this->SetErrorMessage("Could not set comm settings in trackingdevice"); return false; } //after changing COMM wait at least 100ms according to NDI Api documentation page 31 itksys::SystemTools::Delay(500); /* now change local com settings accordingly */ m_SerialCommunication->CloseConnection(); m_SerialCommunication->SetBaudRate(m_BaudRate); m_SerialCommunication->SetDataBits(m_DataBits); m_SerialCommunication->SetParity(m_Parity); m_SerialCommunication->SetStopBits(m_StopBits); m_SerialCommunication->SetHardwareHandshake(m_HardwareHandshake); m_SerialCommunication->SetSendTimeout(5000); m_SerialCommunication->SetReceiveTimeout(5000); m_SerialCommunication->OpenConnection(); /* initialize the tracking device */ returnvalue = m_DeviceProtocol->INIT(); if (returnvalue != NDIOKAY) { this->SetErrorMessage("Could not initialize the tracking device"); return false; } if (this->GetType() == mitk::TrackingSystemNotSpecified) // if the type of tracking device is not specified, try to query the connected device { mitk::TrackingDeviceType deviceType; returnvalue = m_DeviceProtocol->VER(deviceType); if ((returnvalue != NDIOKAY) || (deviceType == mitk::TrackingSystemNotSpecified)) { this->SetErrorMessage("Could not determine tracking device type. Please set manually and try again."); return false; } this->SetType(deviceType); } /**** Optional Polaris specific code, Work in progress // start diagnostic mode returnvalue = m_DeviceProtocol->DSTART(); if (returnvalue != NDIOKAY) { this->SetErrorMessage("Could not start diagnostic mode"); return false; } else // we are in diagnostic mode { // initialize extensive IR checking returnvalue = m_DeviceProtocol->IRINIT(); if (returnvalue != NDIOKAY) { this->SetErrorMessage("Could not initialize intense infrared light checking"); return false; } bool intenseIR = false; returnvalue = m_DeviceProtocol->IRCHK(&intenseIR); if (returnvalue != NDIOKAY) { this->SetErrorMessage("Could not execute intense infrared light checking"); return false; } if (intenseIR == true) // do something - warn the user, raise exception, write to protocol or similar std::cout << "Warning: Intense infrared light detected. Accurate tracking will probably not be possible.\n"; // stop diagnictic mode returnvalue = m_DeviceProtocol->DSTOP(); if (returnvalue != NDIOKAY) { this->SetErrorMessage("Could not stop diagnostic mode"); return false; } } *** end of optional polaris code ***/ /* First, check if the tracking device has port handles that need to be freed and free them */ returnvalue = FreePortHandles(); // non-critical, therefore no error handling { MutexLockHolder toolsMutexLockHolder(*m_ToolsMutex); // lock and unlock the mutex std::string portHandle; Tool6DContainerType::iterator endIt = m_6DTools.end(); for(Tool6DContainerType::iterator it = m_6DTools.begin(); it != endIt; ++it) { /* get a port handle for the tool */ returnvalue = m_DeviceProtocol->PHRQ(&portHandle); if (returnvalue == NDIOKAY) { (*it)->SetPortHandle(portHandle.c_str()); /* now write the SROM file of the tool to the tracking system using PVWR */ if (this->m_Type == NDIPolaris) { returnvalue = m_DeviceProtocol->PVWR(&portHandle, (*it)->GetSROMData(), (*it)->GetSROMDataLength()); if (returnvalue != NDIOKAY) { this->SetErrorMessage((std::string("Could not write SROM file for tool '") + (*it)->GetToolName() + std::string("' to tracking device")).c_str()); return false; } returnvalue = m_DeviceProtocol->PINIT(&portHandle); if (returnvalue != NDIOKAY) { this->SetErrorMessage((std::string("Could not initialize tool '") + (*it)->GetToolName()).c_str()); return false; } if ((*it)->IsEnabled() == true) { returnvalue = m_DeviceProtocol->PENA(&portHandle, (*it)->GetTrackingPriority()); // Enable tool if (returnvalue != NDIOKAY) { this->SetErrorMessage((std::string("Could not enable port '") + portHandle + std::string("' for tool '")+ (*it)->GetToolName() + std::string("'")).c_str()); return false; } } } } } } // end of toolsmutexlockholder scope /* check for wired tools and add them too */ if (this->DiscoverWiredTools() == false) // query the tracking device for wired tools and add them to our tool list return false; // \TODO: could we continue anyways? /*POLARIS: set the illuminator activation rate */ if (this->m_Type == NDIPolaris) { returnvalue = m_DeviceProtocol->IRATE(this->m_IlluminationActivationRate); if (returnvalue != NDIOKAY) { this->SetErrorMessage("Could not set the illuminator activation rate"); return false; } } /* finish - now all tools should be added, initialized and enabled, so that tracking can be started */ this->SetState(Ready); this->SetErrorMessage(""); return true; }
mitk::NDIErrorCode mitk::NDITrackingDevice::Receive | ( | std::string * | answer, |
unsigned int | numberOfBytes | ||
) | [protected] |
receive numberOfBytes bytes from tracking device
Definition at line 259 of file mitkNDITrackingDevice.cpp.
References mitk::NDIOKAY, and mitk::SERIALRECEIVEERROR.
{ if (answer == NULL) return SERIALRECEIVEERROR; MutexLockHolder lock(*m_SerialCommunicationMutex); // lock and unlock the mutex long returnvalue = m_SerialCommunication->Receive(*answer, numberOfBytes); // never read more bytes than the device has send, the function will block until enough bytes are send... if (returnvalue == 0) return SERIALRECEIVEERROR; else return NDIOKAY; }
mitk::NDIErrorCode mitk::NDITrackingDevice::ReceiveByte | ( | char * | answer ) | [protected] |
lightweight receive function, that reads just one byte
Definition at line 274 of file mitkNDITrackingDevice.cpp.
References mitk::NDIOKAY, and mitk::SERIALRECEIVEERROR.
{ if (answer == NULL) return SERIALRECEIVEERROR; std::string m; MutexLockHolder lock(*m_SerialCommunicationMutex); // lock and unlock the mutex long returnvalue = m_SerialCommunication->Receive(m, 1); if ((returnvalue == 0) ||(m.size() != 1)) return SERIALRECEIVEERROR; *answer = m.at(0); return NDIOKAY; }
mitk::NDIErrorCode mitk::NDITrackingDevice::ReceiveLine | ( | std::string * | answer ) | [protected] |
receive characters until the first LF (The LF is included in the answer string)
Definition at line 293 of file mitkNDITrackingDevice.cpp.
References LF, mitk::NDIOKAY, and mitk::SERIALRECEIVEERROR.
{ if (answer == NULL) return SERIALRECEIVEERROR; std::string m; MutexLockHolder lock(*m_SerialCommunicationMutex); // lock and unlock the mutex do { long returnvalue = m_SerialCommunication->Receive(m, 1); if ((returnvalue == 0) ||(m.size() != 1)) return SERIALRECEIVEERROR; *answer += m; } while (m.at(0) != LF); return NDIOKAY; }
bool mitk::NDITrackingDevice::RemoveTool | ( | mitk::TrackingTool * | tool ) | [virtual] |
Remove a passive 6D tool from the list of tracked tools.
Definition at line 1020 of file mitkNDITrackingDevice.cpp.
References mitk::NDIPassiveTool::GetPortHandle(), and mitk::NDIOKAY.
{ mitk::NDIPassiveTool* ndiTool = dynamic_cast<mitk::NDIPassiveTool*>(tool); if (ndiTool == NULL) return false; std::string portHandle = ndiTool->GetPortHandle(); /* a valid portHandle has length 2. If a valid handle exists, the tool is already added to the tracking device, so we have to remove it there if the connection to the tracking device has already been established. */ if ((portHandle.length() == 2) && (this->GetState() == Ready)) // do not remove a tool in tracking mode { NDIErrorCode returnvalue; returnvalue = m_DeviceProtocol->PHF(&portHandle); if (returnvalue != NDIOKAY) return false; /* Now that the tool is removed from the tracking device, remove it from our tool list too */ MutexLockHolder toolsMutexLockHolder(*m_ToolsMutex); // lock and unlock the mutex (scope is inside the if-block Tool6DContainerType::iterator end = m_6DTools.end(); for (Tool6DContainerType::iterator iterator = m_6DTools.begin(); iterator != end; ++iterator) { if (iterator->GetPointer() == ndiTool) { m_6DTools.erase(iterator); this->Modified(); return true; } } return false; } else if (this->GetState() == Setup) // in Setup Mode, we are not connected to the tracking device, so we can just remove the tool from the tool list { MutexLockHolder toolsMutexLockHolder(*m_ToolsMutex); // lock and unlock the mutex Tool6DContainerType::iterator end = m_6DTools.end(); for (Tool6DContainerType::iterator iterator = m_6DTools.begin(); iterator != end; ++iterator) { if ((*iterator).GetPointer() == ndiTool) { m_6DTools.erase(iterator); this->Modified(); return true; } } return false; } return false; }
mitk::NDIErrorCode mitk::NDITrackingDevice::Send | ( | const std::string * | message, |
bool | addCRC = true |
||
) | [protected] |
Send message to tracking device.
Definition at line 232 of file mitkNDITrackingDevice.cpp.
References CR, mitk::NDIOKAY, and mitk::SERIALSENDERROR.
{ if (input == NULL) return SERIALSENDERROR; std::string message; if (addCRC == true) message = *input + CalcCRC(input) + std::string(1, CR); else message = *input + std::string(1, CR); //unsigned int messageLength = message.length() + 1; // +1 for CR // Clear send buffer this->ClearSendBuffer(); // Send the date to the device MutexLockHolder lock(*m_SerialCommunicationMutex); // lock and unlock the mutex long returnvalue = m_SerialCommunication->Send(message); if (returnvalue == 0) return SERIALSENDERROR; else return NDIOKAY; }
void mitk::NDITrackingDevice::SetBaudRate | ( | const BaudRate | _arg ) | [virtual] |
returns the device name for serial communication
set baud rate for serial communication
Definition at line 141 of file mitkNDITrackingDevice.cpp.
{ if (this->GetState() != Setup) return; itkDebugMacro("setting BaudRate to " << _arg); if (this->m_BaudRate != _arg) { this->m_BaudRate = _arg; this->Modified(); } }
void mitk::NDITrackingDevice::SetDataBits | ( | const DataBits | _arg ) | [virtual] |
returns the baud rate for serial communication
set number of data bits
Definition at line 154 of file mitkNDITrackingDevice.cpp.
{ if (this->GetState() != Setup) return; itkDebugMacro("setting DataBits to " << _arg); if (this->m_DataBits != _arg) { this->m_DataBits = _arg; this->Modified(); } }
void mitk::NDITrackingDevice::SetDataTransferMode | ( | const DataTransferMode | _arg ) | [virtual] |
returns the activation rate of IR illumator for polaris
set data transfer mode to text (TX) or binary (BX).
Definition at line 221 of file mitkNDITrackingDevice.cpp.
{ itkDebugMacro("setting DataTransferMode to " << _arg); if (this->m_DataTransferMode != _arg) { this->m_DataTransferMode = _arg; this->Modified(); } }
void mitk::NDITrackingDevice::SetDeviceName | ( | std::string | _arg ) | [virtual] |
returns the port number for serial communication
set device name (e.g. COM1, /dev/ttyUSB0). If this is set, PortNumber will be ignored
Definition at line 128 of file mitkNDITrackingDevice.cpp.
{ if (this->GetState() != Setup) return; itkDebugMacro("setting eviceName to " << _arg); if (this->m_DeviceName != _arg) { this->m_DeviceName = _arg; this->Modified(); } }
void mitk::NDITrackingDevice::SetHardwareHandshake | ( | const HardwareHandshake | _arg ) | [virtual] |
returns the number of stop bits
set use hardware handshake for serial communication
Definition at line 193 of file mitkNDITrackingDevice.cpp.
{ if (this->GetState() != Setup) return; itkDebugMacro("setting HardwareHandshake to " << _arg); if (this->m_HardwareHandshake != _arg) { this->m_HardwareHandshake = _arg; this->Modified(); } }
void mitk::NDITrackingDevice::SetIlluminationActivationRate | ( | const IlluminationActivationRate | _arg ) | [virtual] |
returns the hardware handshake setting
set activation rate of IR illumator for polaris
Definition at line 206 of file mitkNDITrackingDevice.cpp.
{ if (this->GetState() == Tracking) return; itkDebugMacro("setting IlluminationActivationRate to " << _arg); if (this->m_IlluminationActivationRate != _arg) { this->m_IlluminationActivationRate = _arg; this->Modified(); if (this->GetState() == Ready) // if the connection to the tracking system is established, send the new rate to the tracking device too m_DeviceProtocol->IRATE(this->m_IlluminationActivationRate); } }
bool mitk::NDITrackingDevice::SetOperationMode | ( | OperationMode | mode ) | [virtual] |
set operation mode to 6D tool tracking, 3D marker tracking or 6D&3D hybrid tracking (see OperationMode)
Definition at line 1078 of file mitkNDITrackingDevice.cpp.
{ if (GetState() == Tracking) return false; m_OperationMode = mode; return true; }
void mitk::NDITrackingDevice::SetParity | ( | const Parity | _arg ) | [virtual] |
void mitk::NDITrackingDevice::SetPortNumber | ( | const PortNumber | _arg ) | [virtual] |
set port number for serial communication
Definition at line 115 of file mitkNDITrackingDevice.cpp.
{ if (this->GetState() != Setup) return; itkDebugMacro("setting PortNumber to " << _arg); if (this->m_PortNumber != _arg) { this->m_PortNumber = _arg; this->Modified(); } }
void mitk::NDITrackingDevice::SetStopBits | ( | const StopBits | _arg ) | [virtual] |
returns the parity mode
set number of stop bits
Definition at line 180 of file mitkNDITrackingDevice.cpp.
{ if (this->GetState() != Setup) return; itkDebugMacro("setting StopBits to " << _arg); if (this->m_StopBits != _arg) { this->m_StopBits = _arg; this->Modified(); } }
virtual void mitk::NDITrackingDevice::SetType | ( | TrackingDeviceType | _arg ) | [virtual] |
Set the type of the NDI Tracking Device because it can not jet handle this itself.
Reimplemented from mitk::TrackingDevice.
bool mitk::NDITrackingDevice::SetVolume | ( | NDITrackingVolume | volume ) | [virtual] |
Sets the desired tracking volume. Returns true if the volume type could be set. Usage: ndiTracker->SetVolume(mitk::Dome);.
Definition at line 1311 of file mitkNDITrackingDevice.cpp.
References mitk::NDIOKAY.
{ if (m_DeviceProtocol->VSEL(volume) != mitk::NDIOKAY) { this->SetErrorMessage("Could not set volume!"); return false; } return true; }
bool mitk::NDITrackingDevice::StartTracking | ( | ) | [virtual] |
Start the tracking.
A new thread is created, which continuously reads the position and orientation information of each tool and stores them inside the tools. Depending on the current operation mode (see SetOperationMode()), either the 6D tools (ToolTracking6D), 5D tools (ToolTracking5D), 3D marker positions (MarkerTracking3D) or both 6D tools and 3D markers (HybridTracking) are updated. Call StopTracking() to stop the tracking thread.
Implements mitk::TrackingDevice.
Definition at line 742 of file mitkNDITrackingDevice.cpp.
References mitk::TimeStamp::GetInstance(), and mitk::TimeStamp::Start().
{ if (this->GetState() != Ready) return false; 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(); m_TrackingFinishedMutex->Unlock(); // transfer the execution rights to tracking thread m_ThreadID = m_MultiThreader->SpawnThread(this->ThreadStartTracking, this); // start a new thread that executes the TrackTools() method mitk::TimeStamp::GetInstance()->Start(this); return true; }
mitk::TrackingDeviceType mitk::NDITrackingDevice::TestConnection | ( | ) | [virtual] |
TestConnection() tries to connect to a NDI tracking device on the current port/device and returns which device it has found.
TestConnection() tries to connect to a NDI tracking device on the current port/device.
Definition at line 621 of file mitkNDITrackingDevice.cpp.
References mitk::SerialCommunication::BaudRate9600, mitk::SerialCommunication::DataBits8, mitk::NDIOKAY, mitk::SerialCommunication::New(), mitk::SerialCommunication::None, mitk::SerialCommunication::StopBits1, and mitk::TrackingSystemNotSpecified.
{ if (this->GetState() != Setup) { return mitk::TrackingSystemNotSpecified; } m_SerialCommunication = mitk::SerialCommunication::New(); //m_DeviceProtocol = mitk::NDIProtocol::New(); //m_DeviceProtocol->SetTrackingDevice(this); //m_DeviceProtocol->UseCRCOn(); /* init local com port to standard com settings for a NDI tracking device: 9600 baud, 8 data bits, no parity, 1 stop bit, no hardware handshake */ if (m_DeviceName.empty()) m_SerialCommunication->SetPortNumber(m_PortNumber); else m_SerialCommunication->SetDeviceName(m_DeviceName); m_SerialCommunication->SetBaudRate(mitk::SerialCommunication::BaudRate9600); m_SerialCommunication->SetDataBits(mitk::SerialCommunication::DataBits8); m_SerialCommunication->SetParity(mitk::SerialCommunication::None); m_SerialCommunication->SetStopBits(mitk::SerialCommunication::StopBits1); m_SerialCommunication->SetSendTimeout(5000); m_SerialCommunication->SetReceiveTimeout(5000); if (m_SerialCommunication->OpenConnection() == 0) // error { m_SerialCommunication = NULL; return mitk::TrackingSystemNotSpecified; } /* Reset Tracking device by sending a serial break for 500ms */ m_SerialCommunication->SendBreak(400); /* Read answer from tracking device (RESETBE6F) */ static const std::string reset("RESETBE6F\r"); std::string answer = ""; this->Receive(&answer, reset.length()); // read answer (should be RESETBE6F) this->ClearReceiveBuffer(); // flush the receive buffer of all remaining data (carriage return, strings other than reset if (reset.compare(answer) != 0) // check for RESETBE6F { this->SetErrorMessage("Hardware Reset of tracking device did not work"); m_SerialCommunication->CloseConnection(); m_SerialCommunication = NULL; return mitk::TrackingSystemNotSpecified; } /* Now the tracking device is reset, start initialization */ NDIErrorCode returnvalue; /* initialize the tracking device */ //returnvalue = m_DeviceProtocol->INIT(); //if (returnvalue != NDIOKAY) //{ // this->SetErrorMessage("Could not initialize the tracking device"); // return mitk::TrackingSystemNotSpecified; //} mitk::TrackingDeviceType deviceType; returnvalue = m_DeviceProtocol->VER(deviceType); if ((returnvalue != NDIOKAY) || (deviceType == mitk::TrackingSystemNotSpecified)) { m_SerialCommunication = NULL; return mitk::TrackingSystemNotSpecified; } m_SerialCommunication = NULL; return deviceType; }
ITK_THREAD_RETURN_TYPE mitk::NDITrackingDevice::ThreadStartTracking | ( | void * | data ) | [static] |
static start method for the tracking thread.
Definition at line 711 of file mitkNDITrackingDevice.cpp.
References GetOperationMode(), mitk::HybridTracking, m_ThreadID, mitk::MarkerTracking3D, mitk::ToolTracking5D, mitk::ToolTracking6D, TrackMarkerPositions(), TrackTools(), and TrackToolsAndMarkers().
{ /* 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; } NDITrackingDevice *trackingDevice = (NDITrackingDevice*)pInfo->UserData; if (trackingDevice != NULL) { if (trackingDevice->GetOperationMode() == ToolTracking6D) trackingDevice->TrackTools(); // call TrackTools() from the original object else if (trackingDevice->GetOperationMode() == MarkerTracking3D) trackingDevice->TrackMarkerPositions(); // call TrackMarkerPositions() from the original object else if (trackingDevice->GetOperationMode() == ToolTracking5D) trackingDevice->TrackMarkerPositions(); // call TrackMarkerPositions() from the original object else if (trackingDevice->GetOperationMode() == HybridTracking) { trackingDevice->TrackToolsAndMarkers(); } } trackingDevice->m_ThreadID = 0; // erase thread id, now that this thread will end. return ITK_THREAD_RETURN_VALUE; }
void mitk::NDITrackingDevice::TrackMarkerPositions | ( | ) | [virtual] |
continuously polls serial interface for new 3D marker positions until StopTracking is called.
Continuously tracks the 3D position of all markers until StopTracking() is called. This function is executed by the tracking thread (through StartTracking() and ThreadStartTracking()). It should not be called directly.
Definition at line 808 of file mitkNDITrackingDevice.cpp.
References mitk::NDICRCDOESNOTMATCH, mitk::NDICRCERROR, mitk::NDIOKAY, and mitk::ToolTracking6D.
Referenced by ThreadStartTracking().
{ if (m_OperationMode == ToolTracking6D) return; if (this->GetState() != Tracking) return; NDIErrorCode returnvalue; returnvalue = m_DeviceProtocol->DSTART(); // Start Diagnostic Mode if (returnvalue != NDIOKAY) return; 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)) { m_MarkerPointsMutex->Lock(); // lock points data structure returnvalue = this->m_DeviceProtocol->POS3D(&m_MarkerPoints); // update points data structure with new position data from tracking device m_MarkerPointsMutex->Unlock(); if (!((returnvalue == NDIOKAY) || (returnvalue == NDICRCERROR) || (returnvalue == NDICRCDOESNOTMATCH))) // right now, do not stop on crc errors { std::cout << "Error in POS3D: could not read data. Possibly no markers present." << std::endl; } /* Update the local copy of m_StopTracking */ this->m_StopTrackingMutex->Lock(); localStopTracking = m_StopTracking; this->m_StopTrackingMutex->Unlock(); } /* StopTracking was called, thus the mode should be changed back to Ready now that the tracking loop has ended. */ returnvalue = m_DeviceProtocol->DSTOP(); if (returnvalue != NDIOKAY) return; // how can this thread tell the application, that an error has occured? this->SetState(Ready); return; // returning from this function (and ThreadStartTracking()) this will end the thread }
void mitk::NDITrackingDevice::TrackTools | ( | ) | [virtual] |
TrackTools() continuously polls serial interface for new 6d tool positions until StopTracking is called.
Continuously tracks the 6D position of all tools until StopTracking() is called. This function is executed by the tracking thread (through StartTracking() and ThreadStartTracking()). It should not be called directly.
Definition at line 760 of file mitkNDITrackingDevice.cpp.
References mitk::NDICRCDOESNOTMATCH, mitk::NDICRCERROR, mitk::NDIOKAY, and mitk::TX.
Referenced by ThreadStartTracking().
{ if (this->GetState() != Tracking) return; NDIErrorCode returnvalue; returnvalue = m_DeviceProtocol->TSTART(); if (returnvalue != NDIOKAY) return; /* 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)) { if (this->m_DataTransferMode == TX) { returnvalue = this->m_DeviceProtocol->TX(); if (!((returnvalue == NDIOKAY) || (returnvalue == NDICRCERROR) || (returnvalue == NDICRCDOESNOTMATCH))) // right now, do not stop on crc errors break; } else { returnvalue = this->m_DeviceProtocol->BX(); if (returnvalue != NDIOKAY) break; } /* Update the local copy of m_StopTracking */ this->m_StopTrackingMutex->Lock(); localStopTracking = m_StopTracking; this->m_StopTrackingMutex->Unlock(); } /* StopTracking was called, thus the mode should be changed back to Ready now that the tracking loop has ended. */ returnvalue = m_DeviceProtocol->TSTOP(); if (returnvalue != NDIOKAY) { /* insert error handling/notification here */ ; // how can this thread tell the application, that an error has occurred? } return; // returning from this function (and ThreadStartTracking()) this will end the thread and transfer control back to main thread by releasing trackingFinishedLockHolder }
void mitk::NDITrackingDevice::TrackToolsAndMarkers | ( | ) | [virtual] |
continuously polls serial interface for new 3D marker positions and 6D tool positions until StopTracking is called.
Continuously tracks the 3D position of all markers and the 6D position of all tools until StopTracking() is called. This function is executed by the tracking thread (through StartTracking() and ThreadStartTracking()). It should not be called directly.
Definition at line 852 of file mitkNDITrackingDevice.cpp.
References mitk::HybridTracking, mitk::NDICRCDOESNOTMATCH, mitk::NDICRCERROR, and mitk::NDIOKAY.
Referenced by ThreadStartTracking().
{ if (m_OperationMode != HybridTracking) return; NDIErrorCode returnvalue; returnvalue = m_DeviceProtocol->TSTART(); // Start Diagnostic Mode if (returnvalue != NDIOKAY) return; 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)) { m_MarkerPointsMutex->Lock(); // lock points data structure returnvalue = this->m_DeviceProtocol->TX(true, &m_MarkerPoints); // update points data structure with new position data from tracking device m_MarkerPointsMutex->Unlock(); if (!((returnvalue == NDIOKAY) || (returnvalue == NDICRCERROR) || (returnvalue == NDICRCDOESNOTMATCH))) // right now, do not stop on crc errors { std::cout << "Error in TX: could not read data. Possibly no markers present." << std::endl; } /* Update the local copy of m_StopTracking */ this->m_StopTrackingMutex->Lock(); localStopTracking = m_StopTracking; this->m_StopTrackingMutex->Unlock(); } /* StopTracking was called, thus the mode should be changed back to Ready now that the tracking loop has ended. */ returnvalue = m_DeviceProtocol->TSTOP(); if (returnvalue != NDIOKAY) return; // how can this thread tell the application, that an error has occurred? this->SetState(Ready); return; // returning from this function (and ThreadStartTracking()) this will end the thread }
bool mitk::NDITrackingDevice::UpdateTool | ( | mitk::TrackingTool * | tool ) | [virtual] |
reloads the srom file and reinitializes the tool
Definition at line 53 of file mitkNDITrackingDevice.cpp.
References mitk::NDIPassiveTool::GetPortHandle(), mitk::NDIPassiveTool::GetSROMData(), mitk::NDIPassiveTool::GetSROMDataLength(), mitk::NDIPassiveTool::GetTrackingPriority(), and mitk::NDIOKAY.
{ if (this->GetState() != Setup) { mitk::NDIPassiveTool* ndiTool = dynamic_cast<mitk::NDIPassiveTool*>(tool); if (ndiTool == NULL) return false; std::string portHandle = ndiTool->GetPortHandle(); //return false if the SROM Data has not been set if (ndiTool->GetSROMData() == NULL) return false; NDIErrorCode returnvalue; returnvalue = m_DeviceProtocol->PVWR(&portHandle, ndiTool->GetSROMData(), ndiTool->GetSROMDataLength()); if (returnvalue != NDIOKAY) return false; returnvalue = m_DeviceProtocol->PINIT(&portHandle); if (returnvalue != NDIOKAY) return false; returnvalue = m_DeviceProtocol->PENA(&portHandle, ndiTool->GetTrackingPriority()); // Enable tool if (returnvalue != NDIOKAY) return false; return true; } else { return false; } }
friend class NDIProtocol [friend] |
Definition at line 48 of file mitkNDITrackingDevice.h.
list of 6D tools
Definition at line 292 of file mitkNDITrackingDevice.h.
Referenced by NDITrackingDevice().
BaudRate mitk::NDITrackingDevice::m_BaudRate [protected] |
COM Port Baud Rate.
Definition at line 284 of file mitkNDITrackingDevice.h.
DataBits mitk::NDITrackingDevice::m_DataBits [protected] |
Number of Data Bits per token.
Definition at line 285 of file mitkNDITrackingDevice.h.
use TX (text) or BX (binary) (
Definition at line 291 of file mitkNDITrackingDevice.h.
std::string mitk::NDITrackingDevice::m_DeviceName [protected] |
Device Name.
Definition at line 282 of file mitkNDITrackingDevice.h.
create and parse NDI protocol strings
Definition at line 297 of file mitkNDITrackingDevice.h.
Referenced by NDITrackingDevice().
use hardware handshake for serial port connection
Definition at line 288 of file mitkNDITrackingDevice.h.
update rate of IR illuminator for Polaris
Definition at line 290 of file mitkNDITrackingDevice.h.
container for markers (3D point tracking mode)
Definition at line 303 of file mitkNDITrackingDevice.h.
Referenced by NDITrackingDevice().
itk::FastMutexLock::Pointer mitk::NDITrackingDevice::m_MarkerPointsMutex [protected] |
mutex for marker point data container
Definition at line 302 of file mitkNDITrackingDevice.h.
Referenced by NDITrackingDevice().
itk::MultiThreader::Pointer mitk::NDITrackingDevice::m_MultiThreader [protected] |
creates tracking thread that continuously polls serial interface for new tracking data
Definition at line 299 of file mitkNDITrackingDevice.h.
Referenced by NDITrackingDevice().
which tracking volume is currently used (if device supports multiple volumes) (
Definition at line 289 of file mitkNDITrackingDevice.h.
tracking mode (6D tool tracking, 3D marker tracking,...)
Definition at line 301 of file mitkNDITrackingDevice.h.
Parity mitk::NDITrackingDevice::m_Parity [protected] |
Parity mode for communication.
Definition at line 286 of file mitkNDITrackingDevice.h.
PortNumber mitk::NDITrackingDevice::m_PortNumber [protected] |
COM Port Number.
Definition at line 283 of file mitkNDITrackingDevice.h.
serial communication interface
Definition at line 295 of file mitkNDITrackingDevice.h.
itk::FastMutexLock::Pointer mitk::NDITrackingDevice::m_SerialCommunicationMutex [protected] |
mutex for coordinated access of serial communication interface
Definition at line 296 of file mitkNDITrackingDevice.h.
Referenced by NDITrackingDevice().
StopBits mitk::NDITrackingDevice::m_StopBits [protected] |
number of stop bits per token
Definition at line 287 of file mitkNDITrackingDevice.h.
int mitk::NDITrackingDevice::m_ThreadID [protected] |
ID of tracking thread.
Definition at line 300 of file mitkNDITrackingDevice.h.
Referenced by ThreadStartTracking().
itk::FastMutexLock::Pointer mitk::NDITrackingDevice::m_ToolsMutex [protected] |
mutex for coordinated access of tool container
Definition at line 294 of file mitkNDITrackingDevice.h.
Referenced by NDITrackingDevice().