Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxIGTLinkConversion.h"
34 
35 #include <vtkImageData.h>
36 
37 #include "igtl_status.h"
38 
39 #include "cxLog.h"
40 #include "cxProbeDefinition.h"
41 #include "cxTypeConversions.h"
45 
46 namespace cx
47 {
48 //--------------------------------Standard opentiglink messages---------------------------------------
49 
50 igtl::StringMessage::Pointer IGTLinkConversion::encode(QString msg)
51 {
52  igtl::StringMessage::Pointer retval;
53  retval = igtl::StringMessage::New();
54  retval->SetDeviceName("CustusX");
55  retval->SetString(msg.toStdString().c_str());
56  return retval;
57 }
58 
59 QString IGTLinkConversion::decode(igtl::StringMessage::Pointer msg)
60 {
61  QString devicename(msg->GetDeviceName());
62  QString message(msg->GetString());
63  QString retval = devicename + ": " + message;
64  return retval;
65 }
66 
67 QString IGTLinkConversion::decode(igtl::StatusMessage::Pointer msg)
68 {
69  QString code = this->convertIGTLinkStatusCodes(msg->GetCode());
70  QString retval = code;
71  return retval;
72 }
73 
74 ImagePtr IGTLinkConversion::decode(igtl::ImageMessage::Pointer message)
75 {
76  return IGTLinkConversionSonixCXLegacy().decode(message);
77 // return IGTLinkConversionImage().decode(message);
78 }
79 
80 Transform3D IGTLinkConversion::decode(igtl::TransformMessage::Pointer msg)
81 {
82  igtl::Matrix4x4 matrix;
83  msg->GetMatrix(matrix);
84  Transform3D retval = Transform3D::fromFloatArray(matrix);
85  return retval;
86 }
87 
88 //--------------------------------CustusX messages---------------------------------------
89 
91 {
92  IGTLinkUSStatusMessage::Pointer retval = IGTLinkUSStatusMessage::New();
93 
94  retval->SetOrigin(input->getOrigin_p().data());
95  // 1 = sector, 2 = linear
96  retval->SetProbeType(input->getType());
97 
98  retval->SetDepthStart(input->getDepthStart());// Start of sector in mm from origin
99  retval->SetDepthEnd(input->getDepthEnd()); // End of sector in mm from origin
100  retval->SetWidth(input->getWidth());// Width of sector in mm for LINEAR, Width of sector in radians for SECTOR.
101  retval->SetDeviceName(cstring_cast(input->getUid()));
102 
103  return retval;
104 }
105 
106 //'copied' from OpenIGTLinkRTSource::updateSonixStatus()
107 ProbeDefinitionPtr IGTLinkConversion::decode(IGTLinkUSStatusMessage::Pointer probeMessage, igtl::ImageMessage::Pointer imageMessage, ProbeDefinitionPtr base)
108 {
109  ProbeDefinitionPtr retval;
110  if (base)
111  retval = base;
112  else
113  retval = ProbeDefinitionPtr(new ProbeDefinition());
114 
115  if (probeMessage)
116  {
117  // Update the parts of the probe data that is read from the probe message.
118  retval->setType(ProbeDefinition::TYPE(probeMessage->GetProbeType()));
119  retval->setSector(
120  probeMessage->GetDepthStart(),
121  probeMessage->GetDepthEnd(),
122  probeMessage->GetWidth(),
123  0);
124  retval->setOrigin_p(Vector3D(probeMessage->GetOrigin()));
125  retval->setUid(probeMessage->GetDeviceName());
126  }
127 
128  if (imageMessage)
129  {
130  // Update the parts of the probe data that must be read from the image.
131 
132  // Retrive the image data
133  float spacing[3]; // spacing (mm/pixel)
134  int size[3]; // image dimension
135  imageMessage->GetDimensions(size);
136  imageMessage->GetSpacing(spacing);
137 
138  retval->setSpacing(Vector3D(spacing[0], spacing[1], spacing[2]));
139  retval->setSize(QSize(size[0], size[1]));
140  retval->setClipRect_p(DoubleBoundingBox3D(0, retval->getSize().width(), 0, retval->getSize().height(), 0, 0));
141  }
142 
143  return retval;
144 // return this->decode(retval);
145 }
146 
147 //ImagePtr IGTLinkConversion::decode(ImagePtr msg)
148 //{
149 // return IGTLinkConversionSonixCXLegacy().decode(msg);
150 //}
151 
152 //ProbeDefinitionPtr IGTLinkConversion::decode(ProbeDefinitionPtr msg)
153 //{
154 // return IGTLinkConversionSonixCXLegacy().decode(msg);
155 //}
156 
157 QString IGTLinkConversion::convertIGTLinkStatusCodes(const int code)
158 {
159  QString retval;
160  switch(code)
161  {
162  case IGTL_STATUS_INVALID:
163  retval = "Status invalid";
164  break;
165  case IGTL_STATUS_OK:
166  retval = "Ok / Freeze mode on";
167  break;
168  case IGTL_STATUS_UNKNOWN_ERROR:
169  retval = "Unknown error";
170  break;
171  case IGTL_STATUS_PANICK_MODE:
172  retval = "Panick mode";
173  break;
174  case IGTL_STATUS_NOT_FOUND:
175  retval = "Not found";
176  break;
177  case IGTL_STATUS_ACCESS_DENIED:
178  retval = "Access denied";
179  break;
180  case IGTL_STATUS_BUSY:
181  retval = "Busy";
182  break;
183  case IGTL_STATUS_TIME_OUT:
184  retval = "Time out / Connection lost";
185  break;
186  case IGTL_STATUS_OVERFLOW:
187  retval = "Overflow / Can't be reached";
188  break;
189  case IGTL_STATUS_CHECKSUM_ERROR:
190  retval = "Checksum error";
191  break;
192  case IGTL_STATUS_CONFIG_ERROR:
193  retval = "Configuration error";
194  break;
195  case IGTL_STATUS_RESOURCE_ERROR:
196  retval = "Not enough resource (memory, storage etc)";
197  break;
198  case IGTL_STATUS_ILLEGAL_INSTRUCTION:
199  retval = "Illegal/Unknown instruction";
200  break;
201  case IGTL_STATUS_NOT_READY:
202  retval = "Device not ready (starting up)";
203  break;
204  case IGTL_STATUS_MANUAL_MODE:
205  retval = "Manual mode (device does not accept commands";
206  break;
207  case IGTL_STATUS_DISABLED:
208  retval = "Device disabled";
209  break;
210  case IGTL_STATUS_NOT_PRESENT:
211  retval = "Device not present";
212  break;
213  case IGTL_STATUS_UNKNOWN_VERSION:
214  retval = "Device version not known";
215  break;
216  case IGTL_STATUS_HARDWARE_FAILURE:
217  retval = "Hardware failure";
218  break;
219  case IGTL_STATUS_SHUT_DOWN:
220  retval = "Exiting / shut down in progress";
221  break;
222  default:
223  retval = "Could not determine what OpenIGTLink status code means.";
224  }
225  return retval;
226 }
227 
228 } // namespace cx
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
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:63
Definition of characteristics for an Ultrasound Probe Sector.
boost::shared_ptr< class ProbeDefinition > ProbeDefinitionPtr