PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusUsImagingParameters.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"
9 
10 #include <iterator>
11 
12 //----------------------------------------------------------------------------
13 
15 
16 //----------------------------------------------------------------------------
17 
18 const char* vtkPlusUsImagingParameters::XML_ELEMENT_TAG = "UsImagingParameters";
19 const char* vtkPlusUsImagingParameters::US_PARAMETER_TAG = "UsParameter";
20 const char* vtkPlusUsImagingParameters::NAME_TAG = "name";
21 const char* vtkPlusUsImagingParameters::VALUE_TAG = "value";
22 const char* vtkPlusUsImagingParameters::KEY_CONTRAST = "Contrast";
23 const char* vtkPlusUsImagingParameters::KEY_DEPTH = "DepthMm";
24 const char* vtkPlusUsImagingParameters::KEY_FOCUS_DEPTH = "FocusDepthPercent";
25 const char* vtkPlusUsImagingParameters::KEY_DYNRANGE = "DynRangeDb";
26 const char* vtkPlusUsImagingParameters::KEY_FREQUENCY = "FrequencyMhz";
27 const char* vtkPlusUsImagingParameters::KEY_GAIN = "GainPercent";
28 const char* vtkPlusUsImagingParameters::KEY_TGC = "TimeGainCompensation";
29 const char* vtkPlusUsImagingParameters::KEY_INTENSITY = "Intensity";
30 const char* vtkPlusUsImagingParameters::KEY_POWER = "PowerDb";
31 const char* vtkPlusUsImagingParameters::KEY_SECTOR = "SectorPercent";
32 const char* vtkPlusUsImagingParameters::KEY_ZOOM = "ZoomFactor";
33 const char* vtkPlusUsImagingParameters::KEY_SOUNDVELOCITY = "SoundVelocity";
34 const char* vtkPlusUsImagingParameters::KEY_VOLTAGE = "Voltage";
35 const char* vtkPlusUsImagingParameters::KEY_IMAGESIZE = "ImageSize";
36 
37 //----------------------------------------------------------------------------
39  : vtkObject()
40 {
41  this->Parameters[KEY_FREQUENCY] = ParameterInfo("-1");
42  this->Parameters[KEY_DEPTH] = ParameterInfo("-1");
44  this->Parameters[KEY_SECTOR] = ParameterInfo("-1");
45  this->Parameters[KEY_GAIN] = ParameterInfo("-1");
46  this->Parameters[KEY_TGC] = ParameterInfo("-1 -1 -1");
47  this->Parameters[KEY_INTENSITY] = ParameterInfo("-1");
48  this->Parameters[KEY_CONTRAST] = ParameterInfo("-1");
49  this->Parameters[KEY_POWER] = ParameterInfo("-1");
50  this->Parameters[KEY_DYNRANGE] = ParameterInfo("-1");
51  this->Parameters[KEY_ZOOM] = ParameterInfo("-1");
53  this->Parameters[KEY_VOLTAGE] = ParameterInfo("-1");
54  this->Parameters[KEY_IMAGESIZE] = ParameterInfo("-1 -1 -1");
55 }
56 
57 //----------------------------------------------------------------------------
59 {
60  LOG_TRACE("vtkPlusUsImagingParameters::~vtkPlusUsImagingParameters()");
61 }
62 
63 //----------------------------------------------------------------------------
65 {
66  return this->SetValue<double>(KEY_FREQUENCY, aFrequencyMhz);
67 }
68 
69 //----------------------------------------------------------------------------
71 {
72  return this->GetValue<double>(KEY_FREQUENCY, aFrequencyMhz);
73 }
74 
75 //----------------------------------------------------------------------------
77 {
78  double aValue;
79  this->GetValue<double>(KEY_FREQUENCY, aValue);
80  return aValue;
81 }
82 
83 //----------------------------------------------------------------------------
85 {
86  return this->SetValue<double>(KEY_DEPTH, aDepthMm);
87 }
88 
89 //----------------------------------------------------------------------------
91 {
92  return this->GetValue<double>(KEY_DEPTH, aDepthMm);
93 }
94 
95 //----------------------------------------------------------------------------
97 {
98  double aValue;
99  this->GetValue<double>(KEY_DEPTH, aValue);
100  return aValue;
101 }
102 
103 //----------------------------------------------------------------------------
105 {
106  return this->SetValue<double>(KEY_FOCUS_DEPTH, aFocusDepthPercent);
107 }
108 
109 //----------------------------------------------------------------------------
111 {
112  return this->GetValue<double>(KEY_FOCUS_DEPTH, aFocusDepthPercent);
113 }
114 
115 //----------------------------------------------------------------------------
117 {
118  double aValue;
119  this->GetValue<double>(KEY_FOCUS_DEPTH, aValue);
120  return aValue;
121 }
122 
123 //----------------------------------------------------------------------------
125 {
126  return this->SetValue<double>(KEY_GAIN, aGainPercent);
127 }
128 
129 //----------------------------------------------------------------------------
131 {
132  return this->GetValue<double>(KEY_GAIN, aGainPercent);
133 }
134 
135 //----------------------------------------------------------------------------
137 {
138  double aValue;
139  this->GetValue<double>(KEY_GAIN, aValue);
140  return aValue;
141 }
142 
143 //----------------------------------------------------------------------------
145 {
146  std::stringstream result;
147  std::copy(tgc.begin(), tgc.end(), std::ostream_iterator<double>(result, " "));
148 
149  if (this->Parameters[KEY_TGC].Value != result.str())
150  {
151  // If the value changed, then mark it pending
152  this->Parameters[KEY_TGC].Pending = true;
153  }
154  this->Parameters[KEY_TGC].Value = result.str();
155  this->Parameters[KEY_TGC].Set = true;
156  return PLUS_SUCCESS;
157 }
158 
159 //----------------------------------------------------------------------------
161 {
162  std::vector<double> tgcVec(tgc, tgc + length);
163  return this->SetTimeGainCompensation(tgcVec);
164 }
165 
166 //----------------------------------------------------------------------------
168 {
169  ParameterMapConstIterator keyIt = this->Parameters.find(KEY_TGC);
170  if (keyIt != this->Parameters.end() && keyIt->second.Set == false)
171  {
172  return PLUS_FAIL;
173  }
174  else if (keyIt == this->Parameters.end())
175  {
176  return PLUS_FAIL;
177  }
178 
179  std::stringstream ss;
181  ss.str(it->second.Value);
182  std::vector<double> numbers((std::istream_iterator<double>(ss)), std::istream_iterator<double>());
183  tgc = numbers;
184  return PLUS_SUCCESS;
185 }
186 
187 //----------------------------------------------------------------------------
189 {
190  std::vector<double> vec;
191  this->GetTimeGainCompensation(vec);
192  return vec;
193 }
194 
195 //----------------------------------------------------------------------------
197 {
198  return this->SetValue<double>(KEY_INTENSITY, aIntensity);
199 }
200 
201 //----------------------------------------------------------------------------
203 {
204  return this->GetValue<double>(KEY_INTENSITY, aIntensity);
205 }
206 
207 //----------------------------------------------------------------------------
209 {
210  double aValue;
211  this->GetValue<double>(KEY_INTENSITY, aValue);
212  return aValue;
213 }
214 
215 //----------------------------------------------------------------------------
217 {
218  return this->SetValue<double>(KEY_CONTRAST, aContrast);
219 }
220 
221 //----------------------------------------------------------------------------
223 {
224  return this->GetValue<double>(KEY_CONTRAST, aContrast);
225 }
226 
227 //----------------------------------------------------------------------------
229 {
230  double aValue;
231  this->GetValue<double>(KEY_CONTRAST, aValue);
232  return aValue;
233 }
234 
235 //----------------------------------------------------------------------------
237 {
238  return this->SetValue<double>(KEY_POWER, aPower);
239 }
240 
241 //----------------------------------------------------------------------------
243 {
244  return this->GetValue<double>(KEY_POWER, aPower);
245 }
246 
247 //----------------------------------------------------------------------------
249 {
250  double aValue;
251  this->GetValue<double>(KEY_POWER, aValue);
252  return aValue;
253 }
254 
255 //----------------------------------------------------------------------------
257 {
258  return this->SetValue<double>(KEY_DYNRANGE, aDynRangeDb);
259 }
260 
261 //----------------------------------------------------------------------------
263 {
264  return this->GetValue<double>(KEY_DYNRANGE, aDynRangeDb);
265 }
266 
267 //----------------------------------------------------------------------------
269 {
270  double aValue;
271  this->GetValue<double>(KEY_DYNRANGE, aValue);
272  return aValue;
273 }
274 
275 //----------------------------------------------------------------------------
277 {
278  return this->SetValue<double>(KEY_ZOOM, aZoomFactor);
279 }
280 
281 //----------------------------------------------------------------------------
283 {
284  return this->GetValue<double>(KEY_ZOOM, aZoomFactor);
285 }
286 
287 //----------------------------------------------------------------------------
289 {
290  double aValue;
291  this->GetValue<double>(KEY_ZOOM, aValue);
292  return aValue;
293 }
294 
295 //----------------------------------------------------------------------------
297 {
298  return this->SetValue<double>(KEY_SECTOR, aSectorPercent);
299 }
300 
301 //----------------------------------------------------------------------------
303 {
304  return this->GetValue<double>(KEY_SECTOR, aSectorPercent);
305 }
306 
307 //----------------------------------------------------------------------------
309 {
310  double aValue;
311  this->GetValue<double>(KEY_SECTOR, aValue);
312  return aValue;
313 }
314 
315 //----------------------------------------------------------------------------
317 {
318  return this->SetValue<float>(KEY_SOUNDVELOCITY, aSoundVelocity);
319 }
320 
321 //----------------------------------------------------------------------------
323 {
324  return this->GetValue<float>(KEY_SOUNDVELOCITY, aSoundVelocity);
325 }
326 
327 //----------------------------------------------------------------------------
329 {
330  float aValue;
331  this->GetValue<float>(KEY_SOUNDVELOCITY, aValue);
332  return aValue;
333 }
334 
335 // Check
336 //----------------------------------------------------------------------------
338 {
339  return this->Parameters.begin();
340 }
341 
342 //----------------------------------------------------------------------------
344 {
345  return this->Parameters.end();
346 }
347 
348 //----------------------------------------------------------------------------
350 {
351  return this->SetValue<float>(KEY_VOLTAGE, aVoltage);
352 }
353 
354 //----------------------------------------------------------------------------
356 {
357  return this->GetValue<float>(KEY_VOLTAGE, aVoltage);
358 }
359 
360 //----------------------------------------------------------------------------
362 {
363  float aValue;
364  this->GetValue<float>(KEY_VOLTAGE, aValue);
365  return aValue;
366 }
367 
368 //----------------------------------------------------------------------------
370 {
371  std::stringstream result;
372  std::copy(imageSize.begin(), imageSize.end(), std::ostream_iterator<double>(result, " "));
373 
374  if (this->Parameters[KEY_IMAGESIZE].Value != result.str())
375  {
376  // If the value changed, then mark it pending
377  this->Parameters[KEY_IMAGESIZE].Pending = true;
378  }
379  this->Parameters[KEY_IMAGESIZE].Value = result.str();
380  this->Parameters[KEY_IMAGESIZE].Set = true;
381 
382  return PLUS_SUCCESS;
383 }
384 
385 //----------------------------------------------------------------------------
386 PlusStatus vtkPlusUsImagingParameters::SetImageSize(unsigned int x, unsigned int y, unsigned int z)
387 {
388  FrameSizeType imageSize = { x, y, z };
389  return this->SetImageSize(imageSize);
390 }
391 
392 //----------------------------------------------------------------------------
394 {
396  if (keyIt != this->Parameters.end() && keyIt->second.Set == false)
397  {
398  return PLUS_FAIL;
399  }
400  else if (keyIt == this->Parameters.end())
401  {
402  return PLUS_FAIL;
403  }
404 
405  std::stringstream ss;
407  ss.str(it->second.Value);
408  std::vector<unsigned int> numbers((std::istream_iterator<unsigned int>(ss)), std::istream_iterator<unsigned int>());
409 
410  imageSize[0] = numbers[0];
411  if (numbers.size() > 1)
412  {
413  imageSize[1] = numbers[1];
414  }
415  if (numbers.size() > 2)
416  {
417  imageSize[2] = numbers[2];
418  }
419  else
420  {
421  imageSize[2] = 1;
422  }
423  return PLUS_SUCCESS;
424 }
425 
426 //----------------------------------------------------------------------------
428 {
429  FrameSizeType imageSize;
430  this->GetImageSize(imageSize);
431  return imageSize;
432 }
433 
434 //----------------------------------------------------------------------------
435 void vtkPlusUsImagingParameters::PrintSelf(ostream& os, vtkIndent indent)
436 {
437  Superclass::PrintSelf(os, indent);
438 
439  for (ParameterMap::iterator it = this->Parameters.begin(); it != this->Parameters.end(); ++it)
440  {
441  if (it->second.Set == true)
442  {
443  os << indent << it->first << ": " << it->second.Value
444  << (it->second.Pending ? " (pending)" : "") << std::endl;
445  }
446  }
447 }
448 
449 //-----------------------------------------------------------------------------
451 {
452  vtkXMLDataElement* parameterList(NULL);
453  for (int i = 0; i < deviceConfig->GetNumberOfNestedElements(); ++i)
454  {
455  vtkXMLDataElement* element = deviceConfig->GetNestedElement(i);
456  if (STRCASECMP(element->GetName(), XML_ELEMENT_TAG) == 0)
457  {
458  parameterList = element;
459  break;
460  }
461  }
462 
463  if (parameterList == NULL)
464  {
465  LOG_ERROR("Unable to locate UsImagingParameters tag in device config. Unable to read imaging parameters. Device defaults will probably be used.");
466  return PLUS_FAIL;
467  }
468 
469  for (int i = 0; i < parameterList->GetNumberOfNestedElements(); ++i)
470  {
471  vtkXMLDataElement* element = parameterList->GetNestedElement(i);
472  std::string name = element->GetAttribute(NAME_TAG) ? element->GetAttribute(NAME_TAG) : "";
473  std::string value = element->GetAttribute(VALUE_TAG) ? element->GetAttribute(VALUE_TAG) : "";
474  if (name.empty())
475  {
476  continue;
477  }
478 
479  if (this->Parameters[name].Value != value)
480  {
481  // If the value changed, then mark it pending
482  this->Parameters[name].Pending = true;
483  }
484  this->Parameters[name].Value = value;
485  this->Parameters[name].Set = true;
486  }
487 
488  return PLUS_SUCCESS;
489 }
490 
491 //-----------------------------------------------------------------------------
493 {
494  /* Create a sub node, populate it with entries of the form
495  <device ...>
496  <UsImagingParameters>
497  <UsParameter name="DepthMm" value="55"/>
498  <UsParameter name="FrequencyMhz" value="12.5"/>
499  </UsImagingParameters>
500  ...
501  </device>
502  */
503 
504  XML_FIND_NESTED_ELEMENT_CREATE_IF_MISSING(parameterList, deviceConfig, XML_ELEMENT_TAG);
505 
506  // Clear the list before writing new elements
507  parameterList->RemoveAllNestedElements();
508 
509  for (ParameterMap::iterator it = this->Parameters.begin(); it != this->Parameters.end(); ++it)
510  {
511  if (it->second.Set == false)
512  {
513  // Don't write out parameters that are defaults
514  continue;
515  }
516 
517  vtkSmartPointer<vtkXMLDataElement> parameter = vtkSmartPointer<vtkXMLDataElement>::New();
518  parameter->SetName(US_PARAMETER_TAG);
519  parameter->SetAttribute(NAME_TAG, it->first.c_str());
520  parameter->SetAttribute(VALUE_TAG, it->second.Value.c_str());
521 
522  parameterList->AddNestedElement(parameter);
523  }
524 
525  return PLUS_SUCCESS;
526 }
527 
528 //-----------------------------------------------------------------------------
529 bool vtkPlusUsImagingParameters::IsSet(const std::string& paramName) const
530 {
531  ParameterMapConstIterator keyIt = this->Parameters.find(paramName);
532  if (keyIt != this->Parameters.end())
533  {
534  return keyIt->second.Set;
535  }
536 
537  LOG_ERROR("Invalid key request sent to vtkPlusUsImagingParameters::IsSet -- " << paramName);
538  return false;
539 }
540 
541 //-----------------------------------------------------------------------------
542 bool vtkPlusUsImagingParameters::IsPending(const std::string& paramName) const
543 {
544  ParameterMapConstIterator keyIt = this->Parameters.find(paramName);
545  if (keyIt != this->Parameters.end())
546  {
547  return keyIt->second.Pending;
548  }
549 
550  LOG_ERROR("Invalid key request sent to vtkPlusUsImagingParameters::IsPending -- " << paramName);
551  return false;
552 }
553 
554 //-----------------------------------------------------------------------------
555 PlusStatus vtkPlusUsImagingParameters::SetPending(const std::string& paramName, bool pending)
556 {
557  ParameterMapIterator keyIt = this->Parameters.find(paramName);
558  if (keyIt != this->Parameters.end())
559  {
560  if (keyIt->second.Set)
561  {
562  keyIt->second.Pending = pending;
563  return PLUS_SUCCESS;
564  }
565  else
566  {
567  LOG_ERROR("Pending status cannot be set for unset parameter -- " << paramName);
568  return PLUS_FAIL;
569  }
570  }
571 
572  LOG_ERROR("Invalid key request sent to vtkPlusUsImagingParameters::SetPending -- " << paramName);
573  return PLUS_FAIL;
574 }
575 
576 //-----------------------------------------------------------------------------
578 {
579  for (ParameterMapConstIterator it = otherParameters.Parameters.begin(); it != otherParameters.Parameters.end(); ++it)
580  {
581  if (this->Parameters[it->first].Value != it->second.Value)
582  {
583  // If the value changed, then mark it pending
584  this->Parameters[it->first].Pending = true;
585  }
586  this->Parameters[it->first].Value = it->second.Value;
587  this->Parameters[it->first].Set = it->second.Set;
588  }
589 
590  return PLUS_SUCCESS;
591 }
ParameterMap::const_iterator ParameterMapConstIterator
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *deviceConfig)
ParameterMap::iterator ParameterMapIterator
bool IsPending(const std::string &paramName) const
This class is used to store a configuration of the imaging parameters of an ultrasound video device....
igsioStatus PlusStatus
Definition: PlusCommon.h:40
PlusStatus SetContrast(double aContrast)
for i
PlusStatus SetPending(const std::string &paramName, bool pending)
ParameterMapConstIterator begin() const
#define PLUS_FAIL
Definition: PlusCommon.h:43
PlusStatus SetTimeGainCompensation(const std::vector< double > &tgc)
vtkStandardNewMacro(vtkPlusUsImagingParameters)
PlusStatus SetPowerDb(double aPower)
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
PlusStatus SetProbeVoltage(float aVoltage)
PlusStatus SetGainPercent(double aGainPercent)
PlusStatus SetImageSize(const FrameSizeType &imageSize)
PlusStatus SetDynRangeDb(double aDynRangeDb)
PlusStatus SetSectorPercent(double aSectorPercent)
int x
Definition: phidget22.h:4265
const char const char * value
Definition: phidget22.h:5111
std::vector< double > GetTimeGainCompensation() const
PlusStatus SetIntensity(double aIntensity)
PlusStatus SetFrequencyMhz(double aFrequencyMhz)
PlusStatus SetFocusDepthPercent(double aFocusDepthPercent)
Direction vectors of rods y
Definition: algo3.m:15
PlusStatus SetZoomFactor(double aZoomFactor)
bool IsSet(const std::string &paramName) const
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
PlusStatus SetDepthMm(double aDepthMm)
PlusStatus SetSoundVelocity(float aSoundVelocity)
virtual PlusStatus DeepCopy(const vtkPlusUsImagingParameters &otherParameters)
ParameterMapConstIterator end() const
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *deviceConfig)