PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusUsDevice.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 "vtkPlusUsDevice.h"
10 #include "vtkPlusDataSource.h"
11 
12 #ifdef PLUS_USE_tesseract
14 #endif
15 
16 //----------------------------------------------------------------------------
17 
19 
20 //----------------------------------------------------------------------------
22  : vtkPlusDevice()
23  , ImagingParameters(vtkPlusUsImagingParameters::New())
24  , ImageToTransducerTransformName("")
25 {
26  this->CurrentTransducerOriginPixels[0] = 0;
27  this->CurrentTransducerOriginPixels[1] = 0;
28  this->CurrentTransducerOriginPixels[2] = 0;
29 
30  this->CurrentPixelSpacingMm[0] = 1;
31  this->CurrentPixelSpacingMm[1] = 1;
32  this->CurrentPixelSpacingMm[2] = 1;
33 }
34 
35 //----------------------------------------------------------------------------
37 {
38  ImagingParameters->Delete();
39 }
40 
41 //----------------------------------------------------------------------------
42 void vtkPlusUsDevice::PrintSelf(ostream& os, vtkIndent indent)
43 {
44  this->Superclass::PrintSelf(os, indent);
45  os << indent << "Imaging parameters: " << std::endl;
46  this->ImagingParameters->PrintSelf(os, indent);
47  os << indent << "ImageToTransducerTransformName: " << this->ImageToTransducerTransformName << std::endl;
48 }
49 
50 //----------------------------------------------------------------------------
51 PlusStatus vtkPlusUsDevice::ReadConfiguration(vtkXMLDataElement* rootConfigElement)
52 {
53  vtkXMLDataElement* deviceConfig = this->FindThisDeviceElement(rootConfigElement);
54  if (deviceConfig == NULL)
55  {
56  LOG_ERROR("Unable to continue configuration of " << this->GetClassName() << ". Could not find corresponding element.");
57  return PLUS_FAIL;
58  }
59 
60  XML_READ_STRING_ATTRIBUTE_OPTIONAL(ImageToTransducerTransformName, deviceConfig);
62  {
63  LOG_ERROR("Transform name is not properly formatted. It should be of the format <From>ToTransducer.");
64  this->SetImageToTransducerTransformName(NULL);
65  }
66 
67  XML_FIND_NESTED_ELEMENT_OPTIONAL(imagingParams, deviceConfig, vtkPlusUsImagingParameters::XML_ELEMENT_TAG);
68  if (imagingParams != NULL)
69  {
70  this->ImagingParameters->ReadConfiguration(deviceConfig);
71 
73  {
74  LOG_ERROR("Failed to change imaging parameters in the device");
75  return PLUS_FAIL;
76  }
77  }
78 
79  return Superclass::ReadConfiguration(rootConfigElement);
80 }
81 
82 //----------------------------------------------------------------------------
83 PlusStatus vtkPlusUsDevice::WriteConfiguration(vtkXMLDataElement* deviceConfig)
84 {
85  XML_FIND_NESTED_ELEMENT_CREATE_IF_MISSING(imagingParams, deviceConfig, vtkPlusUsImagingParameters::XML_ELEMENT_TAG);
86 
87  XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(ImageToTransducerTransformName, deviceConfig);
88 
89  return this->ImagingParameters->WriteConfiguration(deviceConfig);
90 }
91 
92 //----------------------------------------------------------------------------
94 {
95  if (this->ImagingParameters->DeepCopy(newImagingParameters) == PLUS_FAIL)
96  {
97  LOG_ERROR("Unable to deep copy new imaging parameters");
98  return PLUS_FAIL;
99  }
100 
102  {
103  LOG_ERROR("Failed to change imaging parameters in the device");
104  return PLUS_FAIL;
105  }
106 
107  return PLUS_SUCCESS;
108 }
109 
110 //----------------------------------------------------------------------------
111 PlusStatus vtkPlusUsDevice::AddVideoItemToVideoSource(vtkPlusDataSource& videoSource, const igsioVideoFrame& frame, long frameNumber, double unfilteredTimestamp /*= UNDEFINED_TIMESTAMP*/, double filteredTimestamp /*= UNDEFINED_TIMESTAMP*/, const igsioFieldMapType* customFields /*= NULL*/)
112 {
113  igsioFieldMapType localCustomFields;
114  if (!this->ImageToTransducerTransform.GetTransformName().empty())
115  {
116  if (customFields != NULL)
117  {
118  localCustomFields = *customFields;
119  }
120  this->CalculateImageToTransducer(localCustomFields);
121  }
122 
123  return videoSource.AddItem(&frame, frameNumber, unfilteredTimestamp, filteredTimestamp, &localCustomFields);
124 }
125 
126 //----------------------------------------------------------------------------
127 PlusStatus vtkPlusUsDevice::AddVideoItemToVideoSource(vtkPlusDataSource& videoSource, void* imageDataPtr, US_IMAGE_ORIENTATION usImageOrientation, const FrameSizeType& frameSizeInPx, igsioCommon::VTKScalarPixelType pixelType, unsigned int numberOfScalarComponents, US_IMAGE_TYPE imageType, int numberOfBytesToSkip, long frameNumber, double unfilteredTimestamp /*= UNDEFINED_TIMESTAMP*/, double filteredTimestamp /*= UNDEFINED_TIMESTAMP*/, const igsioFieldMapType* customFields /*= NULL*/)
128 {
129  igsioFieldMapType localCustomFields;
130  if (!this->ImageToTransducerTransform.GetTransformName().empty())
131  {
132  if (customFields != NULL)
133  {
134  localCustomFields = *customFields;
135  }
136  this->CalculateImageToTransducer(localCustomFields);
137  }
138 
139  return videoSource.AddItem(imageDataPtr, usImageOrientation, frameSizeInPx, pixelType, numberOfScalarComponents, imageType, numberOfBytesToSkip, frameNumber, unfilteredTimestamp, filteredTimestamp, customFields);
140 }
141 
142 //----------------------------------------------------------------------------
143 PlusStatus vtkPlusUsDevice::AddVideoItemToVideoSources(const std::vector<vtkPlusDataSource*>& videoSources, const igsioVideoFrame& frame, long frameNumber, double unfilteredTimestamp/*=UNDEFINED_TIMESTAMP*/, double filteredTimestamp/*=UNDEFINED_TIMESTAMP*/, const igsioFieldMapType* customFields /*= NULL*/)
144 {
145  igsioFieldMapType localCustomFields;
146  if (!this->ImageToTransducerTransform.GetTransformName().empty() && customFields != NULL)
147  {
148  localCustomFields = *customFields;
149  this->CalculateImageToTransducer(localCustomFields);
150  }
151 
152  return Superclass::AddVideoItemToVideoSources(videoSources, frame, frameNumber, unfilteredTimestamp, filteredTimestamp, &localCustomFields);
153 }
154 
155 //----------------------------------------------------------------------------
156 PlusStatus vtkPlusUsDevice::AddVideoItemToVideoSources(const std::vector<vtkPlusDataSource*>& videoSources, void* imageDataPtr, US_IMAGE_ORIENTATION usImageOrientation, const FrameSizeType& frameSizeInPx, igsioCommon::VTKScalarPixelType pixelType, unsigned int numberOfScalarComponents, US_IMAGE_TYPE imageType, int numberOfBytesToSkip, long frameNumber, double unfilteredTimestamp /*= UNDEFINED_TIMESTAMP*/, double filteredTimestamp /*= UNDEFINED_TIMESTAMP*/, const igsioFieldMapType* customFields /*= NULL*/)
157 {
158  igsioFieldMapType localCustomFields;
159  if (customFields != NULL)
160  {
161  localCustomFields = *customFields;
162  if (this->ImageToTransducerTransform.IsValid())
163  {
164  this->CalculateImageToTransducer(localCustomFields);
165  }
166  }
167 
168  return Superclass::AddVideoItemToVideoSources(videoSources, imageDataPtr, usImageOrientation, frameSizeInPx, pixelType, numberOfScalarComponents, imageType, numberOfBytesToSkip, frameNumber, unfilteredTimestamp, filteredTimestamp, &localCustomFields);
169 }
170 
171 //----------------------------------------------------------------------------
172 PlusStatus vtkPlusUsDevice::SetParameter(const std::string& key, const std::string& value)
173 {
174  // Catch any vtkPlusUsImagingParameters known params before sending to base class
175  if (this->IsKnownKey(key))
176  {
177  return this->ImagingParameters->SetValue(key, value);
178  }
179 
181 }
182 
183 //----------------------------------------------------------------------------
184 std::string vtkPlusUsDevice::GetParameter(const std::string& key) const
185 {
186  if (this->IsKnownKey(key))
187  {
188  std::string value;
189  if (this->ImagingParameters->GetValue<std::string>(key, value) != PLUS_SUCCESS)
190  {
191  return "";
192  }
193  return value;
194  }
195 
197 }
198 
199 //----------------------------------------------------------------------------
200 PlusStatus vtkPlusUsDevice::GetParameter(const std::string& key, std::string& outValue) const
201 {
202  if (this->IsKnownKey(key))
203  {
204  return this->ImagingParameters->GetValue<std::string>(key, outValue);
205  }
206 
207  return Superclass::GetParameter(key, outValue);
208 }
209 
210 //----------------------------------------------------------------------------
211 bool vtkPlusUsDevice::IsKnownKey(const std::string& queryKey) const
212 {
213  if (igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_FREQUENCY) ||
214  igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_DEPTH) ||
215  igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_DYNRANGE) ||
216  igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_GAIN) ||
217  igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_TGC) ||
218  igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_INTENSITY) ||
219  igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_CONTRAST) ||
220  igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_SECTOR) ||
221  igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_ZOOM) ||
222  igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_SOUNDVELOCITY) ||
223  igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_VOLTAGE) ||
224  igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_IMAGESIZE))
225  {
226  return true;
227  }
228 
229  return false;
230 }
231 
232 //----------------------------------------------------------------------------
233 IGTLIO_PROBE_TYPE vtkPlusUsDevice::GetProbeType()
234 {
235  return UNKNOWN;
236 }
237 
238 //----------------------------------------------------------------------------
239 std::vector<double> vtkPlusUsDevice::CalculateOrigin()
240 {
241  return std::vector<double>();
242 }
243 
244 //----------------------------------------------------------------------------
245 std::vector<double> vtkPlusUsDevice::CalculateAngles()
246 {
247  return std::vector<double>();
248 }
249 
250 //----------------------------------------------------------------------------
252 {
253  return std::vector<double>();
254 }
255 
256 //----------------------------------------------------------------------------
257 std::vector<double> vtkPlusUsDevice::CalculateDepths()
258 {
259  return std::vector<double>();
260 }
261 
262 //----------------------------------------------------------------------------
264 {
265  return 0;
266 }
267 
268 //----------------------------------------------------------------------------
270 {
271  return PLUS_FAIL;
272 }
273 
274 //----------------------------------------------------------------------------
275 void vtkPlusUsDevice::CalculateImageToTransducer(igsioFieldMapType& customFields)
276 {
277  std::ostringstream imageToTransducerName;
278  imageToTransducerName << ImageToTransducerTransform.GetTransformName() << "Transform";
279 
280  std::ostringstream imageToTransducerTransformStr;
281  imageToTransducerTransformStr << this->CurrentPixelSpacingMm[0] << " 0 0 " << -1.0 * this->CurrentTransducerOriginPixels[0]*this->CurrentPixelSpacingMm[0];
282  imageToTransducerTransformStr << " 0 " << this->CurrentPixelSpacingMm[1] << " 0 " << -1.0 * this->CurrentTransducerOriginPixels[1]*this->CurrentPixelSpacingMm[1];
283  imageToTransducerTransformStr << " 0 0 " << this->CurrentPixelSpacingMm[2] << " " << -1.0 * this->CurrentTransducerOriginPixels[2]*this->CurrentPixelSpacingMm[2];
284  imageToTransducerTransformStr << " 0 0 0 1";
285  customFields[imageToTransducerName.str()].first = FRAMEFIELD_NONE;
286  customFields[imageToTransducerName.str()].second = imageToTransducerTransformStr.str();
287  imageToTransducerName << "Status";
288  customFields[imageToTransducerName.str()].first = FRAMEFIELD_NONE;
289  customFields[imageToTransducerName.str()].second = "OK";
290 }
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
const char * key
Definition: phidget22.h:5111
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *deviceConfig)
int CurrentTransducerOriginPixels[3]
Values used in calculation of image to transducer matrix.
Abstract interface for tracker and video devices.
Definition: vtkPlusDevice.h:60
This class is used to store a configuration of the imaging parameters of an ultrasound video device....
bool IsKnownKey(const std::string &queryKey) const
virtual PlusStatus SetParameter(const std::string &key, const std::string &value)
igsioStatus PlusStatus
Definition: PlusCommon.h:40
virtual PlusStatus AddItem(vtkImageData *frame, US_IMAGE_ORIENTATION usImageOrientation, US_IMAGE_TYPE imageType, long frameNumber, double unfilteredTimestamp=UNDEFINED_TIMESTAMP, double filteredTimestamp=UNDEFINED_TIMESTAMP, const igsioFieldMapType *customFields=NULL)
PlusStatus GetValue(const std::string &paramName, T &outputValue) const
virtual std::string GetParameter(const std::string &key) const
vtkPlusUsImagingParameters * ImagingParameters
Store the current imaging parameters.
virtual PlusStatus AddVideoItemToVideoSources(const std::vector< vtkPlusDataSource * > &videoSources, const igsioVideoFrame &frame, long frameNumber, double unfilteredTimestamp=UNDEFINED_TIMESTAMP, double filteredTimestamp=UNDEFINED_TIMESTAMP, const igsioFieldMapType *customFields=NULL) override
double CurrentPixelSpacingMm[3]
Values used in calculation of image to transducer matrix.
std::string ImageToTransducerTransformName
virtual PlusStatus SetNewImagingParameters(const vtkPlusUsImagingParameters &newImagingParameters)
#define PLUS_FAIL
Definition: PlusCommon.h:43
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *)
virtual PlusStatus AddVideoItemToVideoSource(vtkPlusDataSource &videoSource, const igsioVideoFrame &frame, long frameNumber, double unfilteredTimestamp=UNDEFINED_TIMESTAMP, double filteredTimestamp=UNDEFINED_TIMESTAMP, const igsioFieldMapType *customFields=NULL)
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *)
virtual std::vector< double > CalculateAngles()
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
virtual std::vector< double > CalculateOrigin()
vtkXMLDataElement * FindThisDeviceElement(vtkXMLDataElement *rootXMLElement)
virtual std::vector< double > CalculateBoundingBox()
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *)
virtual const char * GetClassName()
vtkStandardNewMacro(vtkPlusUsDevice)
const char const char * value
Definition: phidget22.h:5111
virtual std::string GetParameter(const std::string &key) const
int VTKScalarPixelType
Definition: PlusCommon.h:55
igsioTransformName ImageToTransducerTransform
PlusStatus SetValue(const std::string &paramName, T aValue)
void CalculateImageToTransducer(igsioFieldMapType &customFields)
virtual PlusStatus InternalApplyImagingParameterChange()
virtual std::vector< double > CalculateDepths()
virtual PlusStatus AddVideoItemToVideoSources(const std::vector< vtkPlusDataSource * > &videoSources, const igsioVideoFrame &frame, long frameNumber, double unfilteredTimestamp=UNDEFINED_TIMESTAMP, double filteredTimestamp=UNDEFINED_TIMESTAMP, const igsioFieldMapType *customFields=NULL)
virtual double CalculateLinearWidth()
virtual ~vtkPlusUsDevice()
Abstract interface for ultrasound video devices.
virtual PlusStatus SetParameter(const std::string &key, const std::string &value)
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
virtual IGTLIO_PROBE_TYPE GetProbeType()
virtual PlusStatus DeepCopy(const vtkPlusUsImagingParameters &otherParameters)
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *deviceConfig)
Interface to a 3D positioning tool, video source, or generalized data stream.