Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
cxIGTLinkConversion.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxIGTLinkConversion.h"
13 
14 #include <vtkImageData.h>
15 
16 #include "igtl_status.h"
17 
18 #include "cxLog.h"
19 #include "cxProbeDefinition.h"
20 #include "cxTypeConversions.h"
24 
25 namespace cx
26 {
27 //--------------------------------Standard opentiglink messages---------------------------------------
28 
29 igtl::StringMessage::Pointer IGTLinkConversion::encode(QString msg)
30 {
31  igtl::StringMessage::Pointer retval;
32  retval = igtl::StringMessage::New();
33  retval->SetDeviceName("CustusX");
34  retval->SetString(msg.toStdString().c_str());
35  return retval;
36 }
37 
38 QString IGTLinkConversion::decode(igtl::StringMessage::Pointer msg)
39 {
40  QString devicename(msg->GetDeviceName());
41  QString message(msg->GetString());
42  QString retval = devicename + ": " + message;
43  return retval;
44 }
45 
46 QString IGTLinkConversion::decode(igtl::StatusMessage::Pointer msg)
47 {
48  QString code = this->convertIGTLinkStatusCodes(msg->GetCode());
49  QString retval = code;
50  return retval;
51 }
52 
53 ImagePtr IGTLinkConversion::decode(igtl::ImageMessage::Pointer message)
54 {
55  return IGTLinkConversionSonixCXLegacy().decode(message);
56 // return IGTLinkConversionImage().decode(message);
57 }
58 
59 Transform3D IGTLinkConversion::decode(igtl::TransformMessage::Pointer msg)
60 {
61  igtl::Matrix4x4 matrix;
62  msg->GetMatrix(matrix);
63  Transform3D retval = Transform3D::fromFloatArray(matrix);
64  return retval;
65 }
66 
67 //--------------------------------CustusX messages---------------------------------------
68 
70 {
71  IGTLinkUSStatusMessage::Pointer retval = IGTLinkUSStatusMessage::New();
72 
73  retval->SetOrigin(input->getOrigin_p().data());
74  // 1 = sector, 2 = linear
75  retval->SetProbeType(input->getType());
76 
77  retval->SetDepthStart(input->getDepthStart());// Start of sector in mm from origin
78  retval->SetDepthEnd(input->getDepthEnd()); // End of sector in mm from origin
79  retval->SetWidth(input->getWidth());// Width of sector in mm for LINEAR, Width of sector in radians for SECTOR.
80  retval->SetDeviceName(cstring_cast(input->getUid()));
81 
82  return retval;
83 }
84 
85 //'copied' from OpenIGTLinkRTSource::updateSonixStatus()
86 ProbeDefinitionPtr IGTLinkConversion::decode(IGTLinkUSStatusMessage::Pointer probeMessage, igtl::ImageMessage::Pointer imageMessage, ProbeDefinitionPtr base)
87 {
88  ProbeDefinitionPtr retval;
89  if (base)
90  retval = base;
91  else
92  retval = ProbeDefinitionPtr(new ProbeDefinition());
93 
94  if (probeMessage)
95  {
96  // Update the parts of the probe data that is read from the probe message.
97  retval->setType(ProbeDefinition::TYPE(probeMessage->GetProbeType()));
98  retval->setSector(
99  probeMessage->GetDepthStart(),
100  probeMessage->GetDepthEnd(),
101  probeMessage->GetWidth(),
102  0);
103  retval->setOrigin_p(Vector3D(probeMessage->GetOrigin()));
104  retval->setUid(probeMessage->GetDeviceName());
105  }
106 
107  if (imageMessage)
108  {
109  // Update the parts of the probe data that must be read from the image.
110 
111  // Retrive the image data
112  float spacing[3]; // spacing (mm/pixel)
113  int size[3]; // image dimension
114  imageMessage->GetDimensions(size);
115  imageMessage->GetSpacing(spacing);
116 
117  retval->setSpacing(Vector3D(spacing[0], spacing[1], spacing[2]));
118  retval->setSize(QSize(size[0], size[1]));
119  retval->setClipRect_p(DoubleBoundingBox3D(0, retval->getSize().width(), 0, retval->getSize().height(), 0, 0));
120  }
121 
122  return retval;
123 // return this->decode(retval);
124 }
125 
126 //ImagePtr IGTLinkConversion::decode(ImagePtr msg)
127 //{
128 // return IGTLinkConversionSonixCXLegacy().decode(msg);
129 //}
130 
131 //ProbeDefinitionPtr IGTLinkConversion::decode(ProbeDefinitionPtr msg)
132 //{
133 // return IGTLinkConversionSonixCXLegacy().decode(msg);
134 //}
135 
136 QString IGTLinkConversion::convertIGTLinkStatusCodes(const int code)
137 {
138  QString retval;
139  switch(code)
140  {
141  case IGTL_STATUS_INVALID:
142  retval = "Status invalid";
143  break;
144  case IGTL_STATUS_OK:
145  retval = "Ok / Freeze mode on";
146  break;
147  case IGTL_STATUS_UNKNOWN_ERROR:
148  retval = "Unknown error";
149  break;
150  case IGTL_STATUS_PANICK_MODE:
151  retval = "Panick mode";
152  break;
153  case IGTL_STATUS_NOT_FOUND:
154  retval = "Not found";
155  break;
156  case IGTL_STATUS_ACCESS_DENIED:
157  retval = "Access denied";
158  break;
159  case IGTL_STATUS_BUSY:
160  retval = "Busy";
161  break;
162  case IGTL_STATUS_TIME_OUT:
163  retval = "Time out / Connection lost";
164  break;
165  case IGTL_STATUS_OVERFLOW:
166  retval = "Overflow / Can't be reached";
167  break;
168  case IGTL_STATUS_CHECKSUM_ERROR:
169  retval = "Checksum error";
170  break;
171  case IGTL_STATUS_CONFIG_ERROR:
172  retval = "Configuration error";
173  break;
174  case IGTL_STATUS_RESOURCE_ERROR:
175  retval = "Not enough resource (memory, storage etc)";
176  break;
177  case IGTL_STATUS_ILLEGAL_INSTRUCTION:
178  retval = "Illegal/Unknown instruction";
179  break;
180  case IGTL_STATUS_NOT_READY:
181  retval = "Device not ready (starting up)";
182  break;
183  case IGTL_STATUS_MANUAL_MODE:
184  retval = "Manual mode (device does not accept commands";
185  break;
186  case IGTL_STATUS_DISABLED:
187  retval = "Device disabled";
188  break;
189  case IGTL_STATUS_NOT_PRESENT:
190  retval = "Device not present";
191  break;
192  case IGTL_STATUS_UNKNOWN_VERSION:
193  retval = "Device version not known";
194  break;
195  case IGTL_STATUS_HARDWARE_FAILURE:
196  retval = "Hardware failure";
197  break;
198  case IGTL_STATUS_SHUT_DOWN:
199  retval = "Exiting / shut down in progress";
200  break;
201  default:
202  retval = "Could not determine what OpenIGTLink status code means.";
203  }
204  return retval;
205 }
206 
207 } // namespace cx
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
cstring_cast_Placeholder cstring_cast(const T &val)
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,xmax,ymin,ymax,zmin,zmax}, in order to simplify communication with vtk.
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
Definition of characteristics for an Ultrasound Probe Sector.
boost::shared_ptr< class ProbeDefinition > ProbeDefinitionPtr
Namespace for all CustusX production code.