PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusGetTransformCommand.cxx
Go to the documentation of this file.
1 /*=Plus=header=begin======================================================
2 Program: Plus
3 Copyright (c) Laboratory for Percutaneous Surgery. All rights reserved.
4 See License.txt for details.
5 =========================================================Plus=header=end*/
6 
7 #include "PlusConfigure.h"
8 #include "igtl_header.h"
10 #include "vtkPlusDataCollector.h"
12 #include "vtkIGSIOTransformRepository.h"
13 
15 
16 namespace
17 {
18  static const std::string GET_TRANSFORM_CMD = "GetTransform";
19 }
20 
21 //----------------------------------------------------------------------------
23 {
24 }
25 
26 //----------------------------------------------------------------------------
28 {
29 }
30 
31 //----------------------------------------------------------------------------
33 {
34  this->SetName(GET_TRANSFORM_CMD);
35 }
36 
37 //----------------------------------------------------------------------------
38 void vtkPlusGetTransformCommand::GetCommandNames(std::list<std::string>& cmdNames)
39 {
40  cmdNames.clear();
41  cmdNames.push_back(GET_TRANSFORM_CMD);
42 }
43 
44 //----------------------------------------------------------------------------
45 std::string vtkPlusGetTransformCommand::GetDescription(const std::string& commandName)
46 {
47  std::string desc;
48  if (commandName.empty() || igsioCommon::IsEqualInsensitive(commandName, GET_TRANSFORM_CMD))
49  {
50  desc += GET_TRANSFORM_CMD;
51  desc += ": Retrieve the details of a transform in the remote transform repository.";
52  }
53  return desc;
54 }
55 
56 //----------------------------------------------------------------------------
57 void vtkPlusGetTransformCommand::PrintSelf(ostream& os, vtkIndent indent)
58 {
59  this->Superclass::PrintSelf(os, indent);
60 }
61 
62 //----------------------------------------------------------------------------
64 {
66  {
67  return PLUS_FAIL;
68  }
69  XML_READ_STRING_ATTRIBUTE_REQUIRED(TransformName, aConfig);
70  return PLUS_SUCCESS;
71 }
72 
73 //----------------------------------------------------------------------------
75 {
77  {
78  return PLUS_FAIL;
79  }
80 
81  XML_WRITE_STRING_ATTRIBUTE(TransformName, aConfig);
82 
83  return PLUS_SUCCESS;
84 }
85 
86 //----------------------------------------------------------------------------
88 {
89  LOG_INFO("vtkPlusGetTransformCommand::Execute:");
90 
91  std::string baseMessageString = std::string("GetTransform (") + (!this->GetTransformName().empty() ? this->GetTransformName() : "undefined") + ")";
92  std::string warningString;
93 
94  if (this->GetTransformRepository() == NULL)
95  {
96  this->QueueCommandResponse(PLUS_FAIL, "Command failed. See error message.", baseMessageString + " Failed: invalid transform repository.");
97  return PLUS_FAIL;
98  }
99 
100  igsioTransformName aName;
101  aName.SetTransformName(this->GetTransformName());
102 
103  if (this->GetTransformRepository()->IsExistingTransform(aName) != PLUS_SUCCESS)
104  {
105  this->QueueCommandResponse(PLUS_FAIL, "Command failed. See error message.", baseMessageString + " Failed. Transform not found.");
106  return PLUS_SUCCESS;
107  }
108 
109  bool persistent;
110  this->GetTransformRepository()->GetTransformPersistent(aName, persistent);
111  vtkSmartPointer<vtkMatrix4x4> value = vtkSmartPointer<vtkMatrix4x4>::New();
112  this->GetTransformRepository()->GetTransform(aName, value);
113  std::string date;
114  this->GetTransformRepository()->GetTransformDate(aName, date);
115  double error;
116  this->GetTransformRepository()->GetTransformError(aName, error);
117  std::ostringstream errorStringStream;
118  errorStringStream << error;
119 
120  std::ostringstream valueStringStream;
121  if (!this->RespondWithCommandMessage)
122  {
123  valueStringStream << "<name=\"" << aName.GetTransformName() << "\" value=\"";
124  }
125  for (int i = 0; i < 4; ++i)
126  {
127  for (int j = 0; j < 4; ++j)
128  {
129  valueStringStream << value->GetElement(i, j);
130  if (i * j < 9)
131  {
132  valueStringStream << " ";
133  }
134  }
135  }
136  if (!this->RespondWithCommandMessage)
137  {
138  valueStringStream << "\" persistent=\"" << (persistent ? "true" : "false") << "\" date=\"" << date << "\" error=\"" << error << "\"/>";
139  this->QueueCommandResponse(PLUS_SUCCESS, baseMessageString + valueStringStream.str());
140  }
141  else
142  {
143  igtl::MessageBase::MetaDataMap parameters;
144  parameters[aName.GetTransformName()] = std::pair<IANA_ENCODING_TYPE, std::string>(IANA_TYPE_US_ASCII, valueStringStream.str());
145  parameters["persistent"] = std::pair<IANA_ENCODING_TYPE, std::string>(IANA_TYPE_US_ASCII, persistent ? "true" : "false");
146  parameters["date"] = std::pair<IANA_ENCODING_TYPE, std::string>(IANA_TYPE_US_ASCII, date);
147  parameters["error"] = std::pair<IANA_ENCODING_TYPE, std::string>(IANA_TYPE_US_ASCII, errorStringStream.str());
148  this->QueueCommandResponse(PLUS_SUCCESS, baseMessageString + " Command successful.", "", &parameters);
149  }
150  return PLUS_SUCCESS;
151 }
virtual void PrintSelf(ostream &os, vtkIndent indent)
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
This command retrieves the value of a transformation in the transform repository.
igsioStatus PlusStatus
Definition: PlusCommon.h:40
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
virtual void GetCommandNames(std::list< std::string > &cmdNames)
virtual vtkIGSIOTransformRepository * GetTransformRepository()
for i
virtual std::string GetDescription(const std::string &commandName)
#define PLUS_FAIL
Definition: PlusCommon.h:43
vtkStandardNewMacro(vtkPlusGetTransformCommand)
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
bool RespondWithCommandMessage
virtual void PrintSelf(ostream &os, vtkIndent indent)
void QueueCommandResponse(PlusStatus status, const std::string &message, const std::string &error="", const igtl::MessageBase::MetaDataMap *metaData=nullptr)
const char const char * value
Definition: phidget22.h:5111
PhidgetGPS_Date * date
Definition: phidget22.h:3617
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)