7 #include "PlusConfigure.h" 8 #include "PlusConfigure.h" 9 #include "vtkMatrix4x4.h" 10 #include "vtkObjectFactory.h" 12 #include "vtkTransform.h" 13 #include "vtkXMLDataElement.h" 14 #include "vtksys/SystemTools.hxx" 32 this->AscensionRecordBuffer = NULL;
34 this->TransmitterAttached =
false;
35 this->NumberOfSensors = 0;
36 this->FilterAcWideNotch = 0;
37 this->FilterAcNarrowNotch = 0;
38 this->FilterDcAdaptive = 0.0;
39 this->FilterLargeChange = 0;
40 this->FilterAlpha =
false;
41 this->Hemisphere =
FRONT;
58 if (this->AscensionRecordBuffer != NULL)
60 delete this->AscensionRecordBuffer;
61 this->AscensionRecordBuffer = NULL;
74 LOG_TRACE(
"vtkAscension3DGTracker::Connect");
78 LOG_ERROR(
"Connection probe failed");
88 LOG_ERROR(
"Connection initialization failed");
96 LOG_ERROR(
"Connection set to metric units failed");
104 for (
int sensorID = 0; sensorID < systemConfig.
numberSensors; ++ sensorID)
121 alphaStruct.
vm[0] = 2;
122 alphaStruct.
vm[1] = alphaStruct.
vm[2] = alphaStruct.
vm[3]
123 = alphaStruct.
vm[4] = alphaStruct.
vm[5] = alphaStruct.
vm[6] = 4;
124 alphaStruct.
alphaOn = this->FilterAlpha;
129 this->SensorSaturated.push_back((status &
SATURATED) ?
true :
false);
130 this->SensorAttached.push_back((status &
NOT_ATTACHED) ?
false :
true);
134 std::ostringstream portName;
135 portName << sensorID;
140 if (this->SensorAttached[ sensorID ])
143 this->SensorAttached[ sensorID ] =
false;
150 LOG_ERROR(
"Invalid tool");
154 if (!this->SensorAttached[ sensorID ])
166 if (!slopeStr.empty() || !offsetStr.empty() || !sensitivityStr.empty() || !alphaStr.empty())
178 if (!slopeStr.empty() && igsioCommon::StringToDouble(slopeStr.c_str(), qualityStruct.
error_slope) !=
PLUS_SUCCESS)
182 if (!offsetStr.empty() && igsioCommon::StringToDouble(offsetStr.c_str(), qualityStruct.
error_offset) !=
PLUS_SUCCESS)
201 if (this->AscensionRecordBuffer == NULL)
209 if (IsQualityPortName(it->second->GetPortName()))
214 std::stringstream convert(it->second->GetPortName());
216 if (!(convert >>
port))
222 if (!this->SensorAttached[
port ])
233 LOG_TRACE(
"vtkAscension3DGTracker::Disconnect");
240 LOG_TRACE(
"vtkAscension3DGTracker::Probe");
248 LOG_TRACE(
"vtkAscension3DGTracker::InternalStartRecording");
259 short selectID = TRANSMITTER_OFF;
276 LOG_ERROR(
"Select transmitter failed");
286 LOG_TRACE(
"vtkAscension3DGTracker::InternalStopRecording");
288 short selectID = vtkPlusAscension3DGTrackerBase::TRANSMITTER_OFF;
292 LOG_ERROR(
"Select transmitter failed");
299 LOG_ERROR(
"Unable to close BIRD system");
309 LOG_TRACE(
"vtkAscension3DGTracker::InternalUpdate");
313 LOG_ERROR(
"called Update() when not tracking");
321 LOG_ERROR(
"Cannot get system configuration");
327 LOG_ERROR(
"Changing sensors while tracking is not supported. Reconnect necessary.");
333 AscensionRecordType* record = static_cast<AscensionRecordType*>(this->AscensionRecordBuffer);
336 LOG_ERROR(
"Ascension record buffer is invalid, reconnect necessary.");
340 #ifdef ATC_READ_ALL_SENSOR_AT_ONCE 344 LOG_ERROR(
"Cannot get synchronous record");
351 for (
int sensorIndex = 0; sensorIndex < sysConfig.
numberSensors; sensorIndex++)
353 if (this->SensorAttached[sensorIndex])
358 LOG_ERROR(
"Cannot get synchronous record for sensor " << sensorIndex);
367 bool saturated(
false),
attached(
false), inMotionBox(
false);
368 bool transmitterRunning(
false), transmitterAttached(
false), globalError(
false);
370 ToolStatus toolStatus = TOOL_OK;
371 const double unfilteredTimestamp = vtkIGSIOAccurateTimer::GetSystemTime();
372 int numberOfErrors(0);
374 std::vector<unsigned short> qualityValues(sysConfig.
numberSensors, 0);
375 for (
unsigned short sensorIndex = 0; sensorIndex < sysConfig.
numberSensors; ++ sensorIndex)
377 if (!this->SensorAttached[sensorIndex])
386 toolStatus = TOOL_OK;
390 toolStatus = TOOL_INVALID;
393 LOG_WARNING(
"Attempting to produce data but no transmitter is attached");
397 LOG_WARNING(
"Attempting to produce data but the transmitter is not running");
401 LOG_WARNING(
"Signal is saturated for sensor index " << sensorIndex);
406 toolStatus = TOOL_MISSING;
411 toolStatus = TOOL_OUT_OF_VIEW;
415 vtkSmartPointer< vtkMatrix4x4 > mToolToTracker = vtkSmartPointer< vtkMatrix4x4 >::New();
416 mToolToTracker->Identity();
417 for (
int row = 0; row < 3; ++ row)
419 for (
int col = 0; col < 3; ++ col)
421 mToolToTracker->SetElement(row, col, record[ sensorIndex ].s[ row ][ col ]);
424 qualityValues[sensorIndex] = record[sensorIndex].
quality;
426 mToolToTracker->Invert();
428 mToolToTracker->SetElement(0, 3, record[ sensorIndex ].
x);
429 mToolToTracker->SetElement(1, 3, record[ sensorIndex ].
y);
430 mToolToTracker->SetElement(2, 3, record[ sensorIndex ].z);
432 std::ostringstream toolPortName;
433 toolPortName << sensorIndex;
438 LOG_ERROR(
"Unable to find tool on port: " << toolPortName.str());
444 unsigned long frameNumber = tool->GetFrameNumber() + 1 ;
448 vtkPlusAscension3DGTrackerBase::QualityToolTimeStampedUpdate(
QUALITY_PORT_NAME_1, 0, qualityValues, unfilteredTimestamp);
449 vtkPlusAscension3DGTrackerBase::QualityToolTimeStampedUpdate(
QUALITY_PORT_NAME_2, 3, qualityValues, unfilteredTimestamp);
450 vtkPlusAscension3DGTrackerBase::QualityToolTimeStampedUpdate(
QUALITY_PORT_NAME_3, 6, qualityValues, unfilteredTimestamp);
456 PlusStatus vtkPlusAscension3DGTrackerBase::CheckReturnStatus(
int status)
473 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(
int, FilterAcWideNotch, deviceConfig);
474 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(
int, FilterAcNarrowNotch, deviceConfig);
475 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(
double, FilterDcAdaptive, deviceConfig);
476 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(
int, FilterLargeChange, deviceConfig);
477 XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(
int, FilterAlpha, deviceConfig);
480 XML_FIND_NESTED_ELEMENT_REQUIRED(dataSourcesElement, deviceConfig,
"DataSources");
482 for (
int toolIndex = 0; toolIndex < dataSourcesElement->GetNumberOfNestedElements(); toolIndex++)
484 vtkXMLDataElement* toolDataElement = dataSourcesElement->GetNestedElement(toolIndex);
485 if (STRCASECMP(toolDataElement->GetName(),
"DataSource") != 0)
491 if (toolDataElement->GetAttribute(
"Type") != NULL && STRCASECMP(toolDataElement->GetAttribute(
"Type"),
"Tool") != 0)
497 const char* portName = toolDataElement->GetAttribute(
"PortName");
498 if (portName == NULL)
500 LOG_ERROR(
"Cannot set sensor-specific parameters: tool portname is undefined");
506 LOG_ERROR(
"Cannot set sensor-specific parameters: tool " << portName <<
" was not found");
511 LOG_ERROR(
"Cannot set sensor-specific parameters: tool " << portName <<
" was not found");
516 if (paramValue != NULL)
522 if (paramValue != NULL)
528 if (paramValue != NULL)
534 if (paramValue != NULL)
553 trackerConfig->SetIntAttribute(
"FilterAlpha", (this->
GetFilterAlpha() ? 1 : 0));
560 bool vtkPlusAscension3DGTrackerBase::IsQualityPortName(
const char* name)
567 return this->IsQualityPortName(std::string(name));
571 bool vtkPlusAscension3DGTrackerBase::IsQualityPortName(
const std::string& name)
581 PlusStatus vtkPlusAscension3DGTrackerBase::QualityToolTimeStampedUpdate(
const char* qualityToolPortName,
unsigned int sensorStartIndex,
const std::vector<unsigned short>& qualityValues,
double unfilteredTimestamp)
589 if (qualityTool == NULL)
591 LOG_ERROR(
"Quality tool port name " << qualityToolPortName <<
" is invalid");
594 vtkSmartPointer< vtkMatrix4x4 > qualityStorageMatrix = vtkSmartPointer< vtkMatrix4x4 >::New();
595 qualityStorageMatrix->SetElement(0, 3, -1);
596 qualityStorageMatrix->SetElement(1, 3, -1);
597 qualityStorageMatrix->SetElement(2, 3, -1);
598 for (
unsigned short valueIndex = 0; valueIndex < 3; ++valueIndex)
600 unsigned int sensorIndex = valueIndex + sensorStartIndex;
601 double qualityValue = -1;
602 if (sensorIndex < qualityValues.size())
604 qualityValue = qualityValues[sensorIndex];
606 qualityStorageMatrix->SetElement(valueIndex, 3, qualityValue);
610 unsigned long frameNumber = qualityTool->GetFrameNumber() + 1 ;
619 case FRONT:
return "FRONT";
620 case BACK:
return "BACK";
621 case TOP:
return "TOP";
622 case BOTTOM:
return "BOTTOM";
623 case LEFT:
return "LEFT";
624 case RIGHT:
return "RIGHT";
626 LOG_ERROR(
"Unknown hemisphere type: " << type);
636 LOG_ERROR(
"Invalid hemisphere type string");
639 for (
int i = 0;
i < 6;
i++)
646 LOG_ERROR(
"Unknown hemisphere type string: "<<typeStr);
DataSourceContainer::const_iterator DataSourceContainerConstIterator
ATC3DGm_API int GetErrorText(int errorCode, char *pBuffer, int bufferSize, enum MESSAGE_TYPE type)
std::string GetCustomProperty(const std::string &propertyName)
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
USHORT numberTransmitters
virtual bool GetFilterAlpha()
vtkStandardNewMacro(vtkPlusAscension3DGTrackerBase)
ATC3DGm_API int SetSensorParameter(USHORT sensorID, enum SENSOR_PARAMETER_TYPE parameterType, void *pBuffer, int bufferSize)
virtual int GetHemisphere()
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_WRITING(deviceConfig, rootConfigElement)
ATC3DGm_API int GetBIRDSystemConfiguration(SYSTEM_CONFIGURATION *systemConfiguration)
std::string GetSourceId() const
static const char QUALITY_PORT_NAME_3[]
std::string GetDeviceSetConfigurationFileName()
#define NO_TRANSMITTER_RUNNING
static const char QUALITY_PORT_NAME_2[]
virtual PlusStatus ToolTimeStampedUpdate(const std::string &aToolSourceId, vtkMatrix4x4 *matrix, ToolStatus status, unsigned long frameNumber, double unfilteredtimestamp, const igsioFieldMapType *customFields=NULL)
bool RequirePortNameInDeviceSetConfiguration
virtual int GetFilterLargeChange()
ATC3DGm_API int InitializeBIRDSystem(void)
ATC3DGm_API int SetSystemParameter(enum SYSTEM_PARAMETER_TYPE parameterType, void *pBuffer, int bufferSize)
ATC3DGm_API int GetTransmitterConfiguration(USHORT transmitterID, TRANSMITTER_CONFIGURATION *transmitterConfiguration)
DOUBLE_POSITION_ANGLES_MATRIX_QUATERNION_TIME_Q_BUTTON_RECORD AscensionRecordType
static vtkPlusConfig * GetInstance()
vtkPlusAscension3DGTrackerBase()
PlusStatus InternalConnect()
#define NO_TRANSMITTER_ATTACHED
virtual PlusStatus Disconnect()
~vtkPlusAscension3DGTrackerBase()
virtual int GetFilterAcNarrowNotch()
static const char QUALITY_PORT_NAME_1[]
void SetCustomProperty(const std::string &propertyName, const std::string &propertyValue)
virtual int GetFilterAcWideNotch()
ATC3DGm_API DEVICE_STATUS GetSensorStatus(USHORT sensorID)
PlusStatus GetToolByPortName(const char *aPortName, vtkPlusDataSource *&aSource)
void PrintSelf(ostream &os, vtkIndent indent)
static const char PROP_QUALITY_FILTER_ALPHA[]
virtual double GetFilterDcAdaptive()
virtual PlusStatus StopRecording()
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_READING(deviceConfig, rootConfigElement)
PlusStatus InternalUpdate()
static int GetHemisphereTypeFromString(const char *typeStr)
PlusStatus InternalStopRecording()
ATC3DGm_API int GetAsynchronousRecord(USHORT sensorID, void *pRecord, int recordSize)
bool StartThreadForInternalUpdates
DataSourceContainerConstIterator GetToolIteratorBegin() const
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *config)
virtual PlusStatus InternalDisconnect()
static const char PROP_QUALITY_ERROR_OFFSET[]
Direction vectors of rods y
Interface for the Ascension 3DG magnetic tracker.
static std::string GetHemisphereTypeAsString(int type)
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *config)
DataSourceContainerConstIterator GetToolIteratorEnd() const
PlusStatus InternalStartRecording()
static const char PROP_QUALITY_ERROR_SLOPE[]
ATC3DGm_API int GetBoardConfiguration(USHORT boardID, BOARD_CONFIGURATION *boardConfiguration)
static const char PROP_QUALITY_ERROR_SENSITIVITY[]
ATC3DGm_API int CloseBIRDSystem(void)
virtual int GetNumberOfSensors()
Interface to a 3D positioning tool, video source, or generalized data stream.