7 #include "PlusConfigure.h" 12 #include "vtkObjectFactory.h" 16 #include <vtkVariant.h> 17 #include <vtkSmartPointer.h> 26 static const std::string ATRACSYS_CMD_NAME =
"AtracsysCommand";
45 SetName(ATRACSYS_CMD_NAME);
58 cmdNames.push_back(ATRACSYS_CMD_NAME);
65 if (commandName.empty() || igsioCommon::IsEqualInsensitive(commandName, ATRACSYS_CMD_NAME))
67 desc += ATRACSYS_CMD_NAME;
68 desc +=
": Send command to Atracsys device.";
82 this->SetAtracsysDeviceId(aConfig->GetAttribute(
"DeviceId"));
85 for (
int elemIndex = 0; elemIndex < aConfig->GetNumberOfNestedElements(); ++elemIndex)
87 vtkXMLDataElement* currentElem = aConfig->GetNestedElement(elemIndex);
90 const char* parameterName = currentElem->GetAttribute(
"Name");
91 const char* parameterValue = currentElem->GetAttribute(
"Value");
93 if (!parameterName || !parameterValue)
95 LOG_ERROR(
"Unable to find required Name or Value attribute in " << (currentElem->GetName() ? currentElem->GetName() :
"(undefined)") <<
" element in Atracsys SetFlag command");
103 const char* rValue = currentElem->GetAttribute(
"Red");
104 const char* gValue = currentElem->GetAttribute(
"Green");
105 const char* bValue = currentElem->GetAttribute(
"Blue");
106 const char* freqValue = currentElem->GetAttribute(
"Frequency");
108 if (!rValue || !gValue || !bValue || !freqValue)
115 this->
LedR = vtkVariant(rValue).ToInt(&valid);
121 this->
LedG = vtkVariant(gValue).ToInt(&valid);
127 this->
LedB = vtkVariant(bValue).ToInt(&valid);
133 this->
LedFreq = vtkVariant(freqValue).ToInt(&valid);
144 const char* toolId = currentElem->GetAttribute(
"ToolId");
145 const char*
enabled = currentElem->GetAttribute(
"Enabled");
158 const char* toolId = currentElem->GetAttribute(
"ToolId");
159 const char* geometry = currentElem->GetAttribute(
"Geometry");
161 if (!toolId || !geometry)
168 this->
Markers[toolId] = geometry;
173 LOG_ERROR(
"Invalid command name (" << currentElem->GetName() <<
") provided to AtracsysCommand.")
191 std::map<std::string, std::string>::iterator commandIt;
197 vtkSmartPointer<vtkXMLDataElement> ledElem = vtkSmartPointer<vtkXMLDataElement>::New();
203 aConfig->AddNestedElement(ledElem);
208 vtkSmartPointer<vtkXMLDataElement> enableToolElem = vtkSmartPointer<vtkXMLDataElement>::New();
210 enableToolElem->SetAttribute(
"ToolId", commandIt->second.c_str());
211 std::map<std::string, std::string>::iterator enabledToolValue = this->
EnableDisableTools.find(commandIt->second);
212 enableToolElem->SetAttribute(
"Enabled", enabledToolValue->second.c_str());
213 aConfig->AddNestedElement(enableToolElem);
218 vtkSmartPointer<vtkXMLDataElement> addToolElem = vtkSmartPointer<vtkXMLDataElement>::New();
220 addToolElem->SetAttribute(
"ToolId", commandIt->second.c_str());
221 std::map<std::string, std::string>::iterator marker = this->
Markers.find(commandIt->second);
222 addToolElem->SetAttribute(
"Geometry", marker->second.c_str());
223 aConfig->AddNestedElement(addToolElem);
228 vtkSmartPointer<vtkXMLDataElement> flagElem = vtkSmartPointer<vtkXMLDataElement>::New();
230 flagElem->SetAttribute(
"Name", commandIt->first.c_str());
231 flagElem->SetAttribute(
"Value", commandIt->second.c_str());
232 aConfig->AddNestedElement(flagElem);
241 if (igsioCommon::IsEqualInsensitive(strVal,
"TRUE"))
246 else if (igsioCommon::IsEqualInsensitive(strVal,
"FALSE"))
257 LOG_DEBUG(
"vtkPlusAtracsysCommand::Execute: " << (!this->
Name.empty() ? this->
Name :
"(undefined)")
260 if (this->
Name.empty())
265 else if (!igsioCommon::IsEqualInsensitive(this->
Name, ATRACSYS_CMD_NAME))
272 if (atracsysDevice == NULL)
279 std::string atracsysDeviceId = (atracsysDevice->
GetDeviceId().empty() ?
"(unknown)" : atracsysDevice->
GetDeviceId());
280 std::string resultString =
"<CommandReply>";
281 std::string error =
"";
282 std::map <std::string, std::pair<IANA_ENCODING_TYPE, std::string> > metaData;
285 std::map<std::string, std::string>::iterator commandIt;
288 std::string commandName = commandIt->first;
289 std::string
value = commandIt->second;
290 resultString +=
"<Parameter Name=\"" + commandName +
"\"";
323 conversion = this->
StringToBool(strEnabled, boolEnabled);
329 std::string geometry = this->
Markers.find(value)->second;
334 LOG_WARNING(
"Unrecognized AtracsysCommand recieved with name: " << commandName
335 <<
". Please see the documentation for a list of available commands.");
344 resultString +=
" Success=\"true\"/>";
345 metaData[commandName] = std::make_pair(IANA_TYPE_US_ASCII,
"SUCCESS");
347 resultString +=
"</CommandReply>";
349 vtkSmartPointer<vtkPlusCommandRTSCommandResponse> commandResponse = vtkSmartPointer<vtkPlusCommandRTSCommandResponse>::New();
350 commandResponse->UseDefaultFormatOff();
351 commandResponse->SetClientId(this->
ClientId);
352 commandResponse->SetOriginalId(this->
Id);
353 commandResponse->SetDeviceName(this->
DeviceName);
354 commandResponse->SetCommandName(this->GetName());
355 commandResponse->SetStatus(status);
357 commandResponse->SetErrorString(error);
358 commandResponse->SetResultString(resultString);
359 commandResponse->SetParameters(metaData);
369 if (dataCollector == NULL)
371 LOG_ERROR(
"Data collector is invalid");
380 LOG_ERROR(
"No Atracsys device has been found by the name " << this->
AtracsysDeviceId);
385 if (atracsysDevice == NULL)
388 LOG_ERROR(
"The specified device " << this->
AtracsysDeviceId <<
" is not an Atracsys device");
391 return atracsysDevice;
399 if (atracsysDevice != NULL)
402 this->SetAtracsysDeviceId(atracsysDevice->
GetDeviceId());
403 return atracsysDevice;
406 LOG_ERROR(
"No Atracsys device has been found");
static const char * ATRACSYS_COMMAND_SET_FLAG
PlusStatus AddToolGeometry(std::string toolId, std::string geomString)
static vtkPlusAtracsysTracker * SafeDownCast(vtkObject *o)
vtkPlusAtracsysTracker * GetAtracsysDevice()
virtual void PrintSelf(ostream &os, vtkIndent indent)
Abstract interface for tracker and video devices.
std::vector< vtkPlusDevice * >::const_iterator DeviceCollectionConstIterator
PlusStatus SetLedEnabled(bool enabled)
std::string AtracsysDeviceId
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
std::map< std::string, std::string > Markers
virtual PlusStatus Execute()
PlusStatus GetDevice(vtkPlusDevice *&aDevice, const std::string &aDeviceId) const
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
static const char * ATRACSYS_COMMAND_VIDEO_ENABLED
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
virtual std::string GetDeviceId() const
PlusStatus StringToBool(std::string strVal, bool &boolVal)
std::string to_string(ClariusAvailability avail)
PlusStatus SetLaserEnabled(bool enabled)
static const char * ATRACSYS_COMMAND_ENABLE_TOOL
PlusStatus SetUserLEDState(int red, int green, int blue, int frequency, bool enabled=true)
DeviceCollectionConstIterator GetDeviceConstIteratorBegin() const
static const char * ATRACSYS_COMMAND_LED_ENABLED
DeviceCollectionConstIterator GetDeviceConstIteratorEnd() const
Manages devices that record image or positional data.
static const char * ATRACSYS_COMMAND_LASER_ENABLED
vtkStandardNewMacro(vtkPlusAtracsysCommand)
bool RespondWithCommandMessage
void SetNameToSetUsParameter()
void QueueCommandResponse(PlusStatus status, const std::string &message, const std::string &error="", const igtl::MessageBase::MetaDataMap *metaData=nullptr)
virtual vtkPlusDataCollector * GetDataCollector()
virtual void PrintSelf(ostream &os, vtkIndent indent)
const char const char * value
std::map< std::string, std::string > CommandList
static const char * ATRACSYS_COMMAND_SET_LED_RGBF
std::map< std::string, std::string > EnableDisableTools
virtual void GetCommandNames(std::list< std::string > &cmdNames)
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
static const char * ATRACSYS_COMMAND_ADD_TOOL
PlusCommandResponseList CommandResponseQueue
virtual std::string GetDescription(const std::string &commandName)
This command allows OpenIGTLink commands to configure specific functionalities in the Atracsys device...
PlusStatus SetToolEnabled(std::string toolId, bool enabled)
virtual ~vtkPlusAtracsysCommand()
PlusStatus SetVideoEnabled(bool enabled)
Interface to the Atracsys trackers This class talks with a Atracsys Tracker over the sTk Passive Trac...