-
Notifications
You must be signed in to change notification settings - Fork 102
/
vtkPlusUsDevice.cxx
288 lines (244 loc) · 12.3 KB
/
vtkPlusUsDevice.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*=Plus=header=begin======================================================
Program: Plus
Copyright (c) Laboratory for Percutaneous Surgery. All rights reserved.
See License.txt for details.
=========================================================Plus=header=end*/
#include "PlusConfigure.h"
#include "vtkPlusUsDevice.h"
#include "vtkPlusUsImagingParameters.h"
#include "vtkPlusDataSource.h"
#ifdef PLUS_USE_tesseract
#include "vtkPlusVirtualTextRecognizer.h"
#endif
//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkPlusUsDevice);
//----------------------------------------------------------------------------
vtkPlusUsDevice::vtkPlusUsDevice()
: vtkPlusDevice()
, ImagingParameters(vtkPlusUsImagingParameters::New())
, ImageToTransducerTransformName("")
{
this->CurrentTransducerOriginPixels[0] = 0;
this->CurrentTransducerOriginPixels[1] = 0;
this->CurrentTransducerOriginPixels[2] = 0;
this->CurrentPixelSpacingMm[0] = 1;
this->CurrentPixelSpacingMm[1] = 1;
this->CurrentPixelSpacingMm[2] = 1;
}
//----------------------------------------------------------------------------
vtkPlusUsDevice::~vtkPlusUsDevice()
{
ImagingParameters->Delete();
}
//----------------------------------------------------------------------------
void vtkPlusUsDevice::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Imaging parameters: " << std::endl;
this->ImagingParameters->PrintSelf(os, indent);
os << indent << "ImageToTransducerTransformName: " << this->ImageToTransducerTransformName << std::endl;
}
//----------------------------------------------------------------------------
PlusStatus vtkPlusUsDevice::ReadConfiguration(vtkXMLDataElement* rootConfigElement)
{
vtkXMLDataElement* deviceConfig = this->FindThisDeviceElement(rootConfigElement);
if (deviceConfig == NULL)
{
LOG_ERROR("Unable to continue configuration of " << this->GetClassName() << ". Could not find corresponding element.");
return PLUS_FAIL;
}
XML_READ_STRING_ATTRIBUTE_OPTIONAL(ImageToTransducerTransformName, deviceConfig);
if (!this->ImageToTransducerTransformName.empty() && this->ImageToTransducerTransform.SetTransformName(this->ImageToTransducerTransformName) != PLUS_SUCCESS)
{
LOG_ERROR("Transform name is not properly formatted. It should be of the format <From>ToTransducer.");
this->SetImageToTransducerTransformName(NULL);
}
XML_FIND_NESTED_ELEMENT_OPTIONAL(imagingParams, deviceConfig, vtkPlusUsImagingParameters::XML_ELEMENT_TAG);
if (imagingParams != NULL)
{
this->ImagingParameters->ReadConfiguration(deviceConfig);
if (this->InternalApplyImagingParameterChange() == PLUS_FAIL)
{
LOG_ERROR("Failed to change imaging parameters in the device");
return PLUS_FAIL;
}
}
return Superclass::ReadConfiguration(rootConfigElement);
}
//----------------------------------------------------------------------------
PlusStatus vtkPlusUsDevice::WriteConfiguration(vtkXMLDataElement* deviceConfig)
{
XML_FIND_NESTED_ELEMENT_CREATE_IF_MISSING(imagingParams, deviceConfig, vtkPlusUsImagingParameters::XML_ELEMENT_TAG);
XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(ImageToTransducerTransformName, deviceConfig);
return this->ImagingParameters->WriteConfiguration(deviceConfig);
}
//----------------------------------------------------------------------------
PlusStatus vtkPlusUsDevice::SetNewImagingParameters(const vtkPlusUsImagingParameters& newImagingParameters)
{
if (this->ImagingParameters->DeepCopy(newImagingParameters) == PLUS_FAIL)
{
LOG_ERROR("Unable to deep copy new imaging parameters");
return PLUS_FAIL;
}
if (this->InternalApplyImagingParameterChange() == PLUS_FAIL)
{
LOG_ERROR("Failed to change imaging parameters in the device");
return PLUS_FAIL;
}
return PLUS_SUCCESS;
}
//----------------------------------------------------------------------------
PlusStatus vtkPlusUsDevice::AddVideoItemToVideoSource(vtkPlusDataSource& videoSource, const igsioVideoFrame& frame, long frameNumber, double unfilteredTimestamp /*= UNDEFINED_TIMESTAMP*/, double filteredTimestamp /*= UNDEFINED_TIMESTAMP*/, const igsioTrackedFrame::FieldMapType* customFields /*= NULL*/)
{
igsioTrackedFrame::FieldMapType localCustomFields;
if (!this->ImageToTransducerTransform.GetTransformName().empty())
{
if (customFields != NULL)
{
localCustomFields = *customFields;
}
this->CalculateImageToTransducer(localCustomFields);
}
return videoSource.AddItem(&frame, frameNumber, unfilteredTimestamp, filteredTimestamp, &localCustomFields);
}
//----------------------------------------------------------------------------
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 igsioTrackedFrame::FieldMapType* customFields /*= NULL*/)
{
igsioTrackedFrame::FieldMapType localCustomFields;
if (!this->ImageToTransducerTransform.GetTransformName().empty())
{
if (customFields != NULL)
{
localCustomFields = *customFields;
}
this->CalculateImageToTransducer(localCustomFields);
}
return videoSource.AddItem(imageDataPtr, usImageOrientation, frameSizeInPx, pixelType, numberOfScalarComponents, imageType, numberOfBytesToSkip, frameNumber, unfilteredTimestamp, filteredTimestamp, customFields);
}
//----------------------------------------------------------------------------
PlusStatus vtkPlusUsDevice::AddVideoItemToVideoSources(const std::vector<vtkPlusDataSource*>& videoSources, const igsioVideoFrame& frame, long frameNumber, double unfilteredTimestamp/*=UNDEFINED_TIMESTAMP*/, double filteredTimestamp/*=UNDEFINED_TIMESTAMP*/, const igsioTrackedFrame::FieldMapType* customFields /*= NULL*/)
{
igsioTrackedFrame::FieldMapType localCustomFields;
if (!this->ImageToTransducerTransform.GetTransformName().empty() && customFields != NULL)
{
localCustomFields = *customFields;
this->CalculateImageToTransducer(localCustomFields);
}
return Superclass::AddVideoItemToVideoSources(videoSources, frame, frameNumber, unfilteredTimestamp, filteredTimestamp, &localCustomFields);
}
//----------------------------------------------------------------------------
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 igsioTrackedFrame::FieldMapType* customFields /*= NULL*/)
{
igsioTrackedFrame::FieldMapType localCustomFields;
if (customFields != NULL)
{
localCustomFields = *customFields;
if (this->ImageToTransducerTransform.IsValid())
{
this->CalculateImageToTransducer(localCustomFields);
}
}
return Superclass::AddVideoItemToVideoSources(videoSources, imageDataPtr, usImageOrientation, frameSizeInPx, pixelType, numberOfScalarComponents, imageType, numberOfBytesToSkip, frameNumber, unfilteredTimestamp, filteredTimestamp, &localCustomFields);
}
//----------------------------------------------------------------------------
PlusStatus vtkPlusUsDevice::SetParameter(const std::string& key, const std::string& value)
{
// Catch any vtkPlusUsImagingParameters known params before sending to base class
if (this->IsKnownKey(key))
{
return this->ImagingParameters->SetValue(key, value);
}
return Superclass::SetParameter(key, value);
}
//----------------------------------------------------------------------------
std::string vtkPlusUsDevice::GetParameter(const std::string& key) const
{
if (this->IsKnownKey(key))
{
std::string value;
if (this->ImagingParameters->GetValue<std::string>(key, value) != PLUS_SUCCESS)
{
return "";
}
return value;
}
return Superclass::GetParameter(key);
}
//----------------------------------------------------------------------------
PlusStatus vtkPlusUsDevice::GetParameter(const std::string& key, std::string& outValue) const
{
if (this->IsKnownKey(key))
{
return this->ImagingParameters->GetValue<std::string>(key, outValue);
}
return Superclass::GetParameter(key, outValue);
}
//----------------------------------------------------------------------------
bool vtkPlusUsDevice::IsKnownKey(const std::string& queryKey) const
{
if (igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_FREQUENCY) ||
igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_DEPTH) ||
igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_DYNRANGE) ||
igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_GAIN) ||
igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_TGC) ||
igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_INTENSITY) ||
igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_CONTRAST) ||
igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_SECTOR) ||
igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_ZOOM) ||
igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_SOUNDVELOCITY) ||
igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_VOLTAGE) ||
igsioCommon::IsEqualInsensitive(queryKey, vtkPlusUsImagingParameters::KEY_IMAGESIZE))
{
return true;
}
return false;
}
//----------------------------------------------------------------------------
IGTLIO_PROBE_TYPE vtkPlusUsDevice::GetProbeType()
{
return UNKNOWN;
}
//----------------------------------------------------------------------------
std::vector<double> vtkPlusUsDevice::CalculateOrigin()
{
return std::vector<double>();
}
//----------------------------------------------------------------------------
std::vector<double> vtkPlusUsDevice::CalculateAngles()
{
return std::vector<double>();
}
//----------------------------------------------------------------------------
std::vector<double> vtkPlusUsDevice::CalculateBoundingBox()
{
return std::vector<double>();
}
//----------------------------------------------------------------------------
std::vector<double> vtkPlusUsDevice::CalculateDepths()
{
return std::vector<double>();
}
//----------------------------------------------------------------------------
double vtkPlusUsDevice::CalculateLinearWidth()
{
return 0;
}
//----------------------------------------------------------------------------
PlusStatus vtkPlusUsDevice::InternalApplyImagingParameterChange()
{
return PLUS_FAIL;
}
//----------------------------------------------------------------------------
void vtkPlusUsDevice::CalculateImageToTransducer(igsioTrackedFrame::FieldMapType& customFields)
{
std::ostringstream imageToTransducerName;
imageToTransducerName << ImageToTransducerTransform.GetTransformName() << "Transform";
std::ostringstream imageToTransducerTransformStr;
imageToTransducerTransformStr << this->CurrentPixelSpacingMm[0] << " 0 0 " << -1.0 * this->CurrentTransducerOriginPixels[0]*this->CurrentPixelSpacingMm[0];
imageToTransducerTransformStr << " 0 " << this->CurrentPixelSpacingMm[1] << " 0 " << -1.0 * this->CurrentTransducerOriginPixels[1]*this->CurrentPixelSpacingMm[1];
imageToTransducerTransformStr << " 0 0 " << this->CurrentPixelSpacingMm[2] << " " << -1.0 * this->CurrentTransducerOriginPixels[2]*this->CurrentPixelSpacingMm[2];
imageToTransducerTransformStr << " 0 0 0 1";
customFields[imageToTransducerName.str()] = imageToTransducerTransformStr.str();
imageToTransducerName << "Status";
customFields[imageToTransducerName.str()] = "OK";
}