PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusUpdateTransformCommand.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 "vtkPlusDataCollector.h"
11 #include "vtkIGSIOTransformRepository.h"
12 #include "vtkPlusVirtualCapture.h"
13 
15 
16 namespace
17 {
18  static const std::string UPDATE_TRANSFORM_CMD = "UpdateTransform";
19 }
20 
21 //----------------------------------------------------------------------------
23  : TransformValue(NULL)
24  , TransformPersistent(true)
25  , TransformError(-1.0)
26 {
27 }
28 
29 //----------------------------------------------------------------------------
31 {
32  this->SetTransformValue(static_cast<vtkMatrix4x4*>(NULL));
33 }
34 
35 //----------------------------------------------------------------------------
37 {
38  this->SetName(UPDATE_TRANSFORM_CMD);
39 }
40 
41 //----------------------------------------------------------------------------
42 void vtkPlusUpdateTransformCommand::GetCommandNames(std::list<std::string>& cmdNames)
43 {
44  cmdNames.clear();
45  cmdNames.push_back(UPDATE_TRANSFORM_CMD);
46 }
47 
48 //----------------------------------------------------------------------------
49 std::string vtkPlusUpdateTransformCommand::GetDescription(const std::string& commandName)
50 {
51  std::string desc;
52  if (commandName.empty() || igsioCommon::IsEqualInsensitive(commandName, UPDATE_TRANSFORM_CMD))
53  {
54  desc += UPDATE_TRANSFORM_CMD;
55  desc += ": Update the details of a transform in the remote transform repository.";
56  }
57  return desc;
58 }
59 
60 //----------------------------------------------------------------------------
61 void vtkPlusUpdateTransformCommand::PrintSelf(ostream& os, vtkIndent indent)
62 {
63  this->Superclass::PrintSelf(os, indent);
64 }
65 
66 //----------------------------------------------------------------------------
68 {
70  {
71  return PLUS_FAIL;
72  }
73  XML_READ_STRING_ATTRIBUTE_OPTIONAL(TransformName, aConfig);
74  XML_READ_VECTOR_ATTRIBUTE_REQUIRED(double, 16, TransformValue, aConfig);
75  XML_READ_BOOL_ATTRIBUTE_OPTIONAL(TransformPersistent, aConfig);
76  XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(double, TransformError, aConfig);
77  XML_READ_CSTRING_ATTRIBUTE_OPTIONAL(TransformDate, aConfig);
78  return PLUS_SUCCESS;
79 }
80 
81 //----------------------------------------------------------------------------
83 {
85  {
86  return PLUS_FAIL;
87  }
88 
89  aConfig->SetAttribute("TransformName", this->GetTransformName().c_str());
90 
91  if (this->GetTransformValue())
92  {
93  double vectorMatrix[16] = {0};
94  vtkMatrix4x4::DeepCopy(vectorMatrix, GetTransformValue());
95  aConfig->SetVectorAttribute("TransformValue", 16, vectorMatrix);
96  }
97 
98  XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(TransformDate, aConfig);
99 
100  if (this->GetTransformError() >= 0)
101  {
102  aConfig->SetDoubleAttribute("TransformError", this->GetTransformError());
103  }
104 
105  XML_WRITE_BOOL_ATTRIBUTE(TransformPersistent, aConfig);
106 
107  return PLUS_SUCCESS;
108 }
109 
110 //----------------------------------------------------------------------------
112 {
113  LOG_INFO("vtkPlusUpdateTransformCommand::Execute:");
114 
115  std::string baseMessageString = std::string("UpdateTransform (") + (!this->GetTransformName().empty() ? this->GetTransformName() : "undefined") + ")";
116  std::string warningString;
117 
118  if (this->GetTransformRepository() == NULL)
119  {
120  this->QueueCommandResponse(PLUS_FAIL, "Command failed. See error message.", baseMessageString + " failed: invalid transform repository");
121  return PLUS_FAIL;
122  }
123 
124  igsioTransformName aName;
125  aName.SetTransformName(this->GetTransformName());
126 
127  if (this->GetTransformRepository()->IsExistingTransform(aName) == PLUS_SUCCESS)
128  {
129  bool persistent = false;
130  this->GetTransformRepository()->GetTransformPersistent(aName, persistent);
131  if (!persistent && this->GetTransformPersistent())
132  {
133  warningString += " WARNING: replacing non-persistent transform with a persistent transform.";
134  }
135  }
136 
137  if (this->TransformValue)
138  {
139  this->GetTransformRepository()->SetTransform(aName, this->TransformValue);
140  }
141  else
142  {
143  warningString += " WARNING: transform is not specified.";
144  }
145 
146  this->GetTransformRepository()->SetTransformPersistent(aName, this->GetTransformPersistent());
147 
148  if (!this->GetTransformDate().empty())
149  {
150  this->GetTransformRepository()->SetTransformDate(aName, this->GetTransformDate());
151  }
152  if (this->GetTransformError() >= 0)
153  {
154  this->GetTransformRepository()->SetTransformError(aName, this->GetTransformError());
155  }
156 
157  this->QueueCommandResponse(PLUS_SUCCESS, baseMessageString + " completed successfully" + warningString);
158  return PLUS_SUCCESS;
159 }
160 
161 //-----------------------------------------------------------------------------
163 {
164  vtkSmartPointer<vtkMatrix4x4> matrix = vtkSmartPointer<vtkMatrix4x4>::New();
165  matrix->DeepCopy(matrixElements);
166  this->SetTransformValue(matrix);
167 }
virtual void GetCommandNames(std::list< std::string > &cmdNames)
virtual void PrintSelf(ostream &os, vtkIndent indent)
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
virtual bool GetTransformPersistent()
igsioStatus PlusStatus
Definition: PlusCommon.h:40
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
virtual vtkIGSIOTransformRepository * GetTransformRepository()
#define PLUS_FAIL
Definition: PlusCommon.h:43
virtual vtkMatrix4x4 * GetTransformValue()
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
virtual void SetTransformValue(vtkMatrix4x4 *)
virtual double GetTransformError()
void QueueCommandResponse(PlusStatus status, const std::string &message, const std::string &error="", const igtl::MessageBase::MetaDataMap *metaData=nullptr)
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
This command updates the value of a transformation in the transform repository.
vtkStandardNewMacro(vtkPlusUpdateTransformCommand)
virtual std::string GetDescription(const std::string &commandName)
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
virtual void PrintSelf(ostream &os, vtkIndent indent)