PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusDataSource.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 // Local includes
8 #include "PlusConfigure.h"
9 #include "vtkPlusBuffer.h"
10 #include "vtkPlusDataSource.h"
11 
12 // VTK includes
13 #include <vtkMatrix4x4.h>
14 #include <vtkTransform.h>
15 
16 //----------------------------------------------------------------------------
17 
19 
20 //----------------------------------------------------------------------------
21 
25 
26 //----------------------------------------------------------------------------
28  : Device(NULL)
29  , PortName("")
30  , InputImageOrientation(US_IMG_ORIENT_XX) // a.k.a. PortUsImageOrientation, PortImageOrientation
31  , Type(DATA_SOURCE_TYPE_NONE)
32  , FrameNumber(0)
33  , Id("")
34  , ReferenceCoordinateFrameName("")
35  , Buffer(vtkPlusBuffer::New())
36 {
37  this->ClipRectangleOrigin[0] = igsioCommon::NO_CLIP;
38  this->ClipRectangleOrigin[1] = igsioCommon::NO_CLIP;
39  this->ClipRectangleOrigin[2] = igsioCommon::NO_CLIP;
40 
41  this->ClipRectangleSize[0] = igsioCommon::NO_CLIP;
42  this->ClipRectangleSize[1] = igsioCommon::NO_CLIP;
43  this->ClipRectangleSize[2] = igsioCommon::NO_CLIP;
44 
45  this->InputFrameSize[0] = 0;
46  this->InputFrameSize[1] = 0;
47  this->InputFrameSize[2] = 1;
48 }
49 
50 //----------------------------------------------------------------------------
52 {
53  if (this->Buffer != NULL)
54  {
55  this->Buffer->Delete();
56  this->Buffer = NULL;
57  }
58 }
59 
60 //----------------------------------------------------------------------------
61 void vtkPlusDataSource::PrintSelf(ostream& os, vtkIndent indent)
62 {
63  vtkObject::PrintSelf(os, indent);
64 
65  if (this->Device)
66  {
67  os << indent << "Tracker: " << this->Device << std::endl;
68  }
69  os << indent << "Id: " << this->GetId() << std::endl;
70  if (this->Type != DATA_SOURCE_TYPE_NONE)
71  {
72  switch (this->Type)
73  {
75  os << indent << "Type: Tool" << std::endl;
76  break;
78  os << indent << "Type: Video" << std::endl;
79  break;
81  os << indent << "Type: Fields" << std::endl;
82  break;
84  break;
85  }
86  }
87  os << indent << "ReferenceCoordinateFrameName: " << this->GetReferenceCoordinateFrameName() << std::endl;
88 
89  if (!this->PortName.empty())
90  {
91  os << indent << "PortName: " << this->GetPortName() << std::endl;
92  }
93 
94  if (this->Buffer)
95  {
96  os << indent << "Buffer: " << this->Buffer << std::endl;
97  this->Buffer->PrintSelf(os, indent.GetNextIndent());
98  }
99 }
100 
101 //----------------------------------------------------------------------------
102 PlusStatus vtkPlusDataSource::SetId(const char* aSourceId)
103 {
104  if (aSourceId == NULL && !this->Id.empty())
105  {
106  return PLUS_FAIL;
107  }
108 
109  return this->SetId(std::string(aSourceId));
110 }
111 
112 //----------------------------------------------------------------------------
113 PlusStatus vtkPlusDataSource::SetId(const std::string& aSourceId)
114 {
115  if (this->Id == aSourceId)
116  {
117  return PLUS_SUCCESS;
118  }
119 
120  if (!this->Id.empty())
121  {
122  // Here we would normally delete SourceId and set it to NULL, but we just return with an error instead because modification of the value is not allowed
123  LOG_ERROR("SourceId change is not allowed for source '" << this->Id << "'");
124  return PLUS_FAIL;
125  }
126 
127  this->Id = aSourceId;
128 
129  return PLUS_SUCCESS;
130 }
131 
132 //----------------------------------------------------------------------------
133 PlusStatus vtkPlusDataSource::SetSourceId(const std::string& aSourceId)
134 {
135  return this->SetId(aSourceId);
136 }
137 
138 //----------------------------------------------------------------------------
140 {
141  return this->GetId();
142 }
143 
144 //----------------------------------------------------------------------------
145 PlusStatus vtkPlusDataSource::SetReferenceCoordinateFrameName(const std::string& referenceCoordinateName)
146 {
147  if (this->ReferenceCoordinateFrameName == referenceCoordinateName)
148  {
149  return PLUS_SUCCESS;
150  }
151 
152  if (!this->ReferenceCoordinateFrameName.empty())
153  {
154  // Here we would normally delete ReferenceCoordinateFrame and set it to NULL, but we just return with an error instead because modification of the value is not allowed
155  LOG_ERROR("Reference frame name change is not allowed for tool '" << this->ReferenceCoordinateFrameName << "'");
156  return PLUS_FAIL;
157  }
158 
159  this->ReferenceCoordinateFrameName = referenceCoordinateName;
160 
161  return PLUS_SUCCESS;
162 }
163 
164 //----------------------------------------------------------------------------
166 {
167  if (referenceName == NULL && !this->ReferenceCoordinateFrameName.empty())
168  {
169  return PLUS_FAIL;
170  }
171 
172  return this->SetReferenceCoordinateFrameName(std::string(referenceName));
173 }
174 
175 //----------------------------------------------------------------------------
177 {
178  if (portName == NULL)
179  {
180  LOG_ERROR("NULL portName sent to SetPortName.");
181  return PLUS_FAIL;
182  }
183 
184  return this->SetPortName(std::string(portName));
185 }
186 
187 //----------------------------------------------------------------------------
188 PlusStatus vtkPlusDataSource::SetPortName(const std::string& portName)
189 {
190  if (this->PortName == portName)
191  {
192  // no change (current and requested name are the same)
193  return PLUS_SUCCESS;
194  }
195 
196  if (!this->PortName.empty())
197  {
198  LOG_ERROR("Port name change is not allowed on source port'" << this->PortName << "'");
199  return PLUS_FAIL;
200  }
201 
202  if (!portName.empty())
203  {
204  this->PortName = portName;
205  }
206 
207  return PLUS_SUCCESS;
208 }
209 
210 //----------------------------------------------------------------------------
212 {
213  LOG_TRACE("vtkPlusDataSource::DeepCopy");
214 
215  this->SetId(aSource.GetId());
216  this->SetType(aSource.GetType());
217  this->SetReferenceCoordinateFrameName(aSource.GetReferenceCoordinateFrameName());
218 
219  this->Buffer->DeepCopy(aSource.Buffer);
220 
221  this->SetFrameNumber(aSource.GetFrameNumber());
222 
223  this->CustomProperties = aSource.CustomProperties;
224 }
225 
226 //----------------------------------------------------------------------------
227 std::array<int, 3> vtkPlusDataSource::GetClipRectangleSize() const
228 {
229  return this->ClipRectangleSize;
230 }
231 
232 //----------------------------------------------------------------------------
234 {
235  return this->ClipRectangleOrigin;
236 }
237 
238 //----------------------------------------------------------------------------
239 void vtkPlusDataSource::SetClipRectangleSize(const std::array<int, 3> _arg)
240 {
241  this->ClipRectangleSize = _arg;
242 }
243 
244 //----------------------------------------------------------------------------
245 void vtkPlusDataSource::SetClipRectangleOrigin(const std::array<int, 3> _arg)
246 {
247  this->ClipRectangleOrigin = _arg;
248 }
249 
250 //-----------------------------------------------------------------------------
251 PlusStatus vtkPlusDataSource::ReadConfiguration(vtkXMLDataElement* sourceElement, bool requirePortNameInSourceConfiguration, bool requireImageOrientationInSourceConfiguration, const std::string& aDescriptiveNameForBuffer)
252 {
253  LOG_TRACE("vtkPlusDataSource::ReadConfiguration");
254 
255  if (sourceElement == NULL)
256  {
257  LOG_ERROR("Unable to configure data source! (XML data element is NULL)");
258  return PLUS_FAIL;
259  }
260 
261  std::string sourceId = sourceElement->GetAttribute("Id") != NULL ? sourceElement->GetAttribute("Id") : "";
262  if (sourceId.empty())
263  {
264  LOG_ERROR("Unable to find attribute \"Id\"! Id attribute is mandatory in source definition.");
265  return PLUS_FAIL;
266  }
267 
268  const char* portName = sourceElement->GetAttribute("PortName");
269  if (portName != NULL)
270  {
271  this->SetPortName(portName);
272  }
273 
274  const char* type = sourceElement->GetAttribute("Type");
275  if (type != NULL && STRCASECMP(type, DATA_SOURCE_TYPE_TOOL_TAG.c_str()) == 0)
276  {
277  igsioTransformName idName(sourceId, this->GetReferenceCoordinateFrameName());
278  this->SetId(idName.GetTransformName());
280 
281  if (requirePortNameInSourceConfiguration && portName == NULL)
282  {
283  LOG_ERROR("Unable to find PortName! This attribute is mandatory in tool definition.");
284  return PLUS_FAIL;
285  }
286  }
287  else if (type != NULL && STRCASECMP(type, DATA_SOURCE_TYPE_FIELDDATA_TAG.c_str()) == 0)
288  {
289  this->SetId(sourceId);
291  }
292  else if (type != NULL && STRCASECMP(type, DATA_SOURCE_TYPE_VIDEO_TAG.c_str()) == 0)
293  {
294  this->SetId(sourceId);
296 
297  const char* usImageOrientation = sourceElement->GetAttribute("PortUsImageOrientation");
298  if (usImageOrientation != NULL)
299  {
300  LOG_INFO("Selected US image orientation: " << usImageOrientation);
301  this->SetInputImageOrientation(igsioCommon::GetUsImageOrientationFromString(usImageOrientation));
302  if (this->GetInputImageOrientation() == US_IMG_ORIENT_XX)
303  {
304  LOG_ERROR("Video image orientation is undefined - please set PortUsImageOrientation in the source configuration");
305  }
306  }
307  else if (requireImageOrientationInSourceConfiguration)
308  {
309  LOG_ERROR("Video image orientation is not defined in the source \'" << this->GetId() << "\' element - please set PortUsImageOrientation in the source configuration");
310  }
311 
312  const char* imageType = sourceElement->GetAttribute("ImageType");
313  if (imageType != NULL && this->GetBuffer() != NULL)
314  {
315  if (STRCASECMP(imageType, "BRIGHTNESS") == 0)
316  {
317  this->GetBuffer()->SetImageType(US_IMG_BRIGHTNESS);
318  }
319  else if (STRCASECMP(imageType, "RGB_COLOR") == 0)
320  {
321  this->GetBuffer()->SetImageType(US_IMG_RGB_COLOR);
322  }
323  else if (STRCASECMP(imageType, "RF_I_LINE_Q_LINE") == 0)
324  {
325  this->GetBuffer()->SetImageType(US_IMG_RF_I_LINE_Q_LINE);
326  }
327  else if (STRCASECMP(imageType, "RF_IQ_LINE") == 0)
328  {
329  this->GetBuffer()->SetImageType(US_IMG_RF_IQ_LINE);
330  }
331  else if (STRCASECMP(imageType, "RF_REAL") == 0)
332  {
333  this->GetBuffer()->SetImageType(US_IMG_RF_REAL);
334  }
335  }
336 
337  // Clipping parameters:
338  // Users may forget that images are 3D and provide clipping coordinates and size in 2D only.
339  // Detect this and set correct values in the third component.
340  int tmpValue[3] = {0}; // 3 so that we can see if only 2 components could be successfully read
341  int clipRectangleOriginComponents = sourceElement->GetVectorAttribute("ClipRectangleOrigin", 3, tmpValue);
342  if (clipRectangleOriginComponents == 2)
343  {
344  // Only 2D data is provided
345  XML_READ_STD_ARRAY_ATTRIBUTE_EXACT_OPTIONAL(int, 2, ClipRectangleOrigin, sourceElement);
346  if (this->ClipRectangleOrigin[0] == igsioCommon::NO_CLIP || this->ClipRectangleOrigin[1] == igsioCommon::NO_CLIP)
347  {
348  this->ClipRectangleOrigin[2] = igsioCommon::NO_CLIP;
349  }
350  else
351  {
352  this->ClipRectangleOrigin[2] = 0;
353  }
354  }
355  else
356  {
357  XML_READ_STD_ARRAY_ATTRIBUTE_OPTIONAL(int, 3, ClipRectangleOrigin, sourceElement);
358  }
359  int clipRectangleSizeComponents = sourceElement->GetVectorAttribute("ClipRectangleSize", 3, tmpValue);
360  if (clipRectangleSizeComponents == 2)
361  {
362  // Only 2D data is provided
363  XML_READ_STD_ARRAY_ATTRIBUTE_EXACT_OPTIONAL(int, 2, ClipRectangleSize, sourceElement);
364  if (this->ClipRectangleSize[0] == igsioCommon::NO_CLIP || this->ClipRectangleSize[1] == igsioCommon::NO_CLIP)
365  {
366  this->ClipRectangleSize[2] = igsioCommon::NO_CLIP;
367  }
368  else
369  {
370  this->ClipRectangleSize[2] = 1;
371  }
372  }
373  else
374  {
375  XML_READ_STD_ARRAY_ATTRIBUTE_OPTIONAL(int, 3, ClipRectangleSize, sourceElement);
376  }
377  }
378  else
379  {
380  LOG_ERROR("Missing type element. It is required to define the source type.");
381  return PLUS_FAIL;
382  }
383 
384  int bufferSize = 0;
385  if (sourceElement->GetScalarAttribute("BufferSize", bufferSize))
386  {
387  this->GetBuffer()->SetBufferSize(bufferSize);
388  }
389  else
390  {
391  LOG_DEBUG("Buffer size is not defined in source element \"" << this->GetId() << "\". Using default buffer size: " << this->GetBuffer()->GetBufferSize());
392  }
393 
394  int averagedItemsForFiltering = 0;
395  if (sourceElement->GetScalarAttribute("AveragedItemsForFiltering", averagedItemsForFiltering))
396  {
397  this->GetBuffer()->SetAveragedItemsForFiltering(averagedItemsForFiltering);
398  }
399  else
400  {
401  LOG_DEBUG("AveragedItemsForFiltering is not defined in source element \"" << this->GetId() << "\". Using default value: " << this->GetBuffer()->GetAveragedItemsForFiltering());
402  }
403 
404  std::string descName;
405  if (!aDescriptiveNameForBuffer.empty())
406  {
407  descName += aDescriptiveNameForBuffer;
408  descName += "-";
409  descName += this->GetId();
410  }
411  else
412  {
413  descName += this->GetId();
414  }
415  this->GetBuffer()->SetDescriptiveName(descName.c_str());
416 
417  // Read custom properties
418  for (int i = 0; i < sourceElement->GetNumberOfNestedElements(); ++i)
419  {
420  if (STRCASECMP(sourceElement->GetNestedElement(i)->GetName(), "CustomProperties") == 0)
421  {
422  vtkXMLDataElement* customPropertiesElement = sourceElement->GetNestedElement(i);
423 
424  for (int j = 0; j < customPropertiesElement->GetNumberOfNestedElements(); ++j)
425  {
426  vtkXMLDataElement* customPropertyElement = customPropertiesElement->GetNestedElement(j);
427  this->CustomProperties[customPropertyElement->GetName()] = customPropertyElement->GetCharacterData();
428  }
429  break;
430  }
431  }
432 
433  return PLUS_SUCCESS;
434 }
435 
436 //-----------------------------------------------------------------------------
437 PlusStatus vtkPlusDataSource::WriteConfiguration(vtkXMLDataElement* aSourceElement)
438 {
439  LOG_TRACE("vtkPlusDataSource::WriteConfiguration");
440 
441  if (aSourceElement == NULL)
442  {
443  LOG_ERROR("Unable to configure data source! (XML data element is NULL)");
444  return PLUS_FAIL;
445  }
446 
447  if (this->GetType() == DATA_SOURCE_TYPE_TOOL)
448  {
449  igsioTransformName sourceId(this->GetId());
450  aSourceElement->SetAttribute("Id", sourceId.From().c_str());
451  }
452  else
453  {
454  XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(Id, aSourceElement);
455  }
456 
457  XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(PortName, aSourceElement);
458  aSourceElement->SetIntAttribute("BufferSize", this->GetBuffer()->GetBufferSize());
459 
460  if (aSourceElement->GetAttribute("AveragedItemsForFiltering") != NULL)
461  {
462  aSourceElement->SetIntAttribute("AveragedItemsForFiltering", this->GetBuffer()->GetAveragedItemsForFiltering());
463  }
464 
465  // Write custom properties
466  if (this->CustomProperties.size() > 0)
467  {
468  vtkSmartPointer<vtkXMLDataElement> customPropertiesElement = vtkSmartPointer<vtkXMLDataElement>::New();
469  customPropertiesElement->SetName("CustomProperties");
470 
471  for (CustomPropertyMapIterator it = this->CustomProperties.begin(); it != this->CustomProperties.end(); ++it)
472  {
473  vtkSmartPointer<vtkXMLDataElement> customPropertyElement = vtkSmartPointer<vtkXMLDataElement>::New();
474  customPropertyElement->SetName(it->first.c_str());
475  customPropertyElement->SetCharacterData(it->second.c_str(), it->second.length());
476  customPropertiesElement->AddNestedElement(customPropertyElement);
477  }
478 
479  aSourceElement->AddNestedElement(customPropertiesElement);
480  }
481 
482  if (igsioCommon::IsClippingRequested(this->ClipRectangleOrigin, this->ClipRectangleSize))
483  {
484  {
485  int tmpValue[3] = { this->ClipRectangleOrigin[0], this->ClipRectangleOrigin[1], this->ClipRectangleOrigin[2] };
486  aSourceElement->SetVectorAttribute("ClipRectangleOrigin", 3, tmpValue);
487  }
488  {
489  int tmpValue[3] = { this->ClipRectangleSize[0], this->ClipRectangleSize[1], this->ClipRectangleSize[2] };
490  aSourceElement->SetVectorAttribute("ClipRectangleSize", 3, tmpValue);
491  }
492  }
493 
494  return PLUS_SUCCESS;
495 }
496 
497 //-----------------------------------------------------------------------------
499 {
500  LOG_TRACE("vtkPlusDataSource::WriteConfiguration");
501 
502  if (aSourceElement == NULL)
503  {
504  LOG_ERROR("Unable to configure source! (XML data element is NULL)");
505  return PLUS_FAIL;
506  }
507 
508  if (this->GetType() == DATA_SOURCE_TYPE_TOOL)
509  {
510  igsioTransformName sourceId(this->GetId());
511  aSourceElement->SetAttribute("Id", sourceId.From().c_str());
512  }
513  else
514  {
515  XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(Id, aSourceElement);
516  }
517  XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(PortName, aSourceElement);
518 
519  return PLUS_SUCCESS;
520 }
521 
522 //-----------------------------------------------------------------------------
524 {
525  std::ostringstream ss;
526  ss << this->Id << "To" << this->ReferenceCoordinateFrameName;
527  return ss.str();
528 }
529 
530 //-----------------------------------------------------------------------------
531 std::string vtkPlusDataSource::GetCustomProperty(const std::string& propertyName)
532 {
533  std::map< std::string, std::string > :: iterator prop = this->CustomProperties.find(propertyName);
534  std::string propValue;
535  if (prop != this->CustomProperties.end())
536  {
537  propValue = prop->second;
538  }
539  return propValue;
540 }
541 
542 //-----------------------------------------------------------------------------
543 void vtkPlusDataSource::SetCustomProperty(const std::string& propertyName, const std::string& propertyValue)
544 {
545  this->CustomProperties[propertyName] = propertyValue;
546 }
547 
548 //-----------------------------------------------------------------------------
549 PlusStatus vtkPlusDataSource::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*/)
550 {
551  return this->GetBuffer()->AddItem(frame, usImageOrientation, imageType, frameNumber, this->ClipRectangleOrigin, this->ClipRectangleSize, unfilteredTimestamp, filteredTimestamp, customFields);
552 }
553 
554 //-----------------------------------------------------------------------------
555 PlusStatus vtkPlusDataSource::AddItem(const igsioVideoFrame* frame, long frameNumber, double unfilteredTimestamp/*=UNDEFINED_TIMESTAMP*/, double filteredTimestamp/*=UNDEFINED_TIMESTAMP*/, const igsioFieldMapType* customFields /*= NULL*/)
556 {
557  return this->GetBuffer()->AddItem(frame, frameNumber, this->ClipRectangleOrigin, this->ClipRectangleSize, unfilteredTimestamp, filteredTimestamp, customFields);
558 }
559 
560 //----------------------------------------------------------------------------
561 PlusStatus vtkPlusDataSource::AddItem(const igsioFieldMapType& customFields, long frameNumber, double unfilteredTimestamp/*=UNDEFINED_TIMESTAMP*/,
562  double filteredTimestamp/*=UNDEFINED_TIMESTAMP*/)
563 {
564  return this->GetBuffer()->AddItem(customFields, frameNumber, unfilteredTimestamp, filteredTimestamp);
565 }
566 
567 //----------------------------------------------------------------------------
568 PlusStatus vtkPlusDataSource::AddItem(void* imageDataPtr, US_IMAGE_ORIENTATION usImageOrientation, const FrameSizeType& frameSizeInPx, igsioCommon::VTKScalarPixelType pixelType,
569  unsigned int numberOfScalarComponents, US_IMAGE_TYPE imageType, int numberOfBytesToSkip, long frameNumber, double unfilteredTimestamp /*= UNDEFINED_TIMESTAMP*/,
570  double filteredTimestamp /*= UNDEFINED_TIMESTAMP*/, const igsioFieldMapType* customFields /*= NULL*/)
571 {
572  return this->GetBuffer()->AddItem(imageDataPtr, usImageOrientation, frameSizeInPx, pixelType, numberOfScalarComponents, imageType, numberOfBytesToSkip, frameNumber,
573  this->ClipRectangleOrigin, this->ClipRectangleSize, unfilteredTimestamp, filteredTimestamp, customFields);
574 }
575 
576 //----------------------------------------------------------------------------
577 PlusStatus vtkPlusDataSource::AddItem(void* imageDataPtr, const FrameSizeType& frameSize, unsigned int frameSizeInBytes, US_IMAGE_TYPE imageType, long frameNumber, double unfilteredTimestamp /*= UNDEFINED_TIMESTAMP*/, double filteredTimestamp /*= UNDEFINED_TIMESTAMP*/, const igsioFieldMapType* customFields /*= NULL*/)
578 {
579  return this->GetBuffer()->AddItem(imageDataPtr, frameSize, frameSizeInBytes, imageType, frameNumber, unfilteredTimestamp, filteredTimestamp, customFields);
580 }
581 
582 //-----------------------------------------------------------------------------
584 {
585  return this->GetBuffer()->GetImageType();
586 }
587 
588 //-----------------------------------------------------------------------------
590 {
591  return this->GetBuffer()->SetImageType(imageType);
592 }
593 
594 //-----------------------------------------------------------------------------
595 PlusStatus vtkPlusDataSource::SetInputFrameSize(unsigned int x, unsigned int y, unsigned int z)
596 {
597  this->InputFrameSize[0] = x;
598  this->InputFrameSize[1] = y;
599  this->InputFrameSize[2] = z;
600 
601  FrameSizeType outputFrameSizeInPx = {x, y, z};
602 
603  if (x > static_cast<unsigned int>(std::numeric_limits<int>::max()) ||
604  y > static_cast<unsigned int>(std::numeric_limits<int>::max()) ||
605  z > static_cast<unsigned int>(std::numeric_limits<int>::max()))
606  {
607  LOG_ERROR("Unable to determine clipping details in vtkPlusDataSource::SetInputFrameSize. Cannot continue.");
608  return PLUS_FAIL;
609  }
610 
611  int extents[6] = {0, static_cast<int>(x) - 1, 0, static_cast<int>(y) - 1, 0, static_cast<int>(z) - 1};
612  if (igsioCommon::IsClippingRequested(this->ClipRectangleOrigin, this->ClipRectangleSize))
613  {
614  if (igsioCommon::IsClippingWithinExtents(this->ClipRectangleOrigin, this->ClipRectangleSize, extents))
615  {
616  outputFrameSizeInPx[0] = static_cast<unsigned int>(this->ClipRectangleSize[0]);
617  outputFrameSizeInPx[1] = static_cast<unsigned int>(this->ClipRectangleSize[1]);
618  outputFrameSizeInPx[2] = static_cast<unsigned int>(this->ClipRectangleSize[2]);
619  }
620  else
621  {
622  LOG_WARNING("Clipping information cannot fit within the original image extents [" << extents[0] << "," << extents[1] << ","
623  << extents[2] << "," << extents[3] << "," << extents[4] << "," << extents[5] << "]. No clipping will be performed."
624  << " Origin=[" << this->ClipRectangleOrigin[0] << "," << this->ClipRectangleOrigin[1] << "," << this->ClipRectangleOrigin[2] << "]."
625  << " Size=[" << this->ClipRectangleSize[0] << "," << this->ClipRectangleSize[1] << "," << this->ClipRectangleSize[2] << "].");
626  this->ClipRectangleOrigin[0] = igsioCommon::NO_CLIP;
627  this->ClipRectangleOrigin[1] = igsioCommon::NO_CLIP;
628  this->ClipRectangleOrigin[2] = igsioCommon::NO_CLIP;
629  this->ClipRectangleSize[0] = igsioCommon::NO_CLIP;
630  this->ClipRectangleSize[1] = igsioCommon::NO_CLIP;
631  this->ClipRectangleSize[2] = igsioCommon::NO_CLIP;
632  }
633  }
634 
635  igsioVideoFrame::FlipInfoType flipInfo;
636  if (igsioVideoFrame::GetFlipAxes(this->InputImageOrientation, this->GetBuffer()->GetImageType(), this->GetBuffer()->GetImageOrientation(), flipInfo) != PLUS_SUCCESS)
637  {
638  LOG_ERROR("Failed to convert image data to the requested orientation, from " << igsioCommon::GetStringFromUsImageOrientation(this->InputImageOrientation) <<
639  " to " << igsioCommon::GetStringFromUsImageOrientation(this->GetBuffer()->GetImageOrientation()) <<
640  " for a buffer of type " << igsioCommon::GetStringFromUsImageType(this->GetBuffer()->GetImageType()));
641  return PLUS_FAIL;
642  }
643 
644  if (flipInfo.tranpose == igsioVideoFrame::TRANSPOSE_IJKtoKIJ)
645  {
646  unsigned int temp = outputFrameSizeInPx[0];
647  outputFrameSizeInPx[0] = outputFrameSizeInPx[2];
648  outputFrameSizeInPx[2] = outputFrameSizeInPx[1];
649  outputFrameSizeInPx[1] = temp;
650  }
651 
652  return this->GetBuffer()->SetFrameSize(outputFrameSizeInPx[0], outputFrameSizeInPx[1], outputFrameSizeInPx[2]);
653 }
654 
655 //----------------------------------------------------------------------------
656 PlusStatus vtkPlusDataSource::SetInputFrameSize(const FrameSizeType& frameSize)
657 {
658  return this->SetInputFrameSize(frameSize[0], frameSize[1], frameSize[2]);
659 }
660 
661 //----------------------------------------------------------------------------
663 {
664  return this->InputFrameSize;
665 }
666 
667 //-----------------------------------------------------------------------------
669 {
670  return this->GetBuffer()->GetFrameSize();
671 }
672 
673 //-----------------------------------------------------------------------------
674 PlusStatus vtkPlusDataSource::GetOutputFrameSize(unsigned int& _arg1, unsigned int& _arg2, unsigned int& _arg3) const
675 {
676  return this->GetBuffer()->GetFrameSize(_arg1, _arg2, _arg3);
677 }
678 
679 //-----------------------------------------------------------------------------
681 {
682  return this->Buffer;
683 }
684 
685 //-----------------------------------------------------------------------------
686 PlusStatus vtkPlusDataSource::SetInputImageOrientation(US_IMAGE_ORIENTATION imageOrientation)
687 {
688  this->InputImageOrientation = imageOrientation;
689  // Orientation of the images in the buffer is standardized (MF(A) for B-mode images, FM for RF-mode images).
690  // We set up the this standard image orientation based on the orientation of the input data.
691  if (imageOrientation <= US_IMG_ORIENT_XX || imageOrientation >= US_IMG_ORIENT_LAST)
692  {
693  LOG_ERROR("vtkPlusDataSource::SetInputImageOrientation failed: invalid image orientation received");
694  return PLUS_FAIL;
695  }
696  if (imageOrientation <= US_IMG_ORIENT_FU)
697  {
698  // B-mode or non-ultrasound
699  return SetOutputImageOrientation(US_IMG_ORIENT_MF);
700  }
701  else
702  {
703  // RF-mode
704  return SetOutputImageOrientation(US_IMG_ORIENT_FM);
705  }
706 }
707 
708 //-----------------------------------------------------------------------------
709 PlusStatus vtkPlusDataSource::SetOutputImageOrientation(US_IMAGE_ORIENTATION imageOrientation)
710 {
711  if (imageOrientation != US_IMG_ORIENT_MF && imageOrientation != US_IMG_ORIENT_FM)
712  {
713  LOG_ERROR("vtkPlusDataSource::SetOutputImageOrientation failed: only standard MF and FM orientations are allowed, got "
714  << igsioCommon::GetStringFromUsImageOrientation(imageOrientation));
715  return PLUS_FAIL;
716  }
717  return this->GetBuffer()->SetImageOrientation(imageOrientation);
718 }
719 
720 //-----------------------------------------------------------------------------
722 {
723  return this->GetBuffer()->GetImageOrientation();
724 }
725 
726 //-----------------------------------------------------------------------------
728 {
729  return this->InputImageOrientation;
730 }
731 
732 //-----------------------------------------------------------------------------
733 PlusStatus vtkPlusDataSource::SetNumberOfScalarComponents(unsigned int numberOfScalarComponents)
734 {
735  return this->GetBuffer()->SetNumberOfScalarComponents(numberOfScalarComponents);
736 }
737 
738 //-----------------------------------------------------------------------------
740 {
741  return this->GetBuffer()->GetNumberOfScalarComponents();
742 }
743 
744 //-----------------------------------------------------------------------------
746 {
747  return this->GetBuffer()->GetPixelType();
748 }
749 
750 //-----------------------------------------------------------------------------
752 {
753  return this->GetBuffer()->SetPixelType(pixelType);
754 }
755 
756 //-----------------------------------------------------------------------------
757 void vtkPlusDataSource::SetStartTime(double startTime)
758 {
759  return this->GetBuffer()->SetStartTime(startTime);
760 }
761 
762 //-----------------------------------------------------------------------------
764 {
765  return this->GetBuffer()->GetStartTime();
766 }
767 
768 //-----------------------------------------------------------------------------
770 {
771  return this->GetBuffer()->GetNumberOfItems();
772 }
773 
774 //-----------------------------------------------------------------------------
776 {
777  return this->GetBuffer()->GetOldestItemUidInBuffer();
778 }
779 
780 //-----------------------------------------------------------------------------
782 {
783  return this->GetBuffer()->GetLatestItemUidInBuffer();
784 }
785 
786 //-----------------------------------------------------------------------------
788 {
789  return this->GetBuffer()->GetItemUidFromTime(time, uid);
790 }
791 
792 //-----------------------------------------------------------------------------
794 {
795  return this->GetBuffer()->GetLatestItemHasValidVideoData();
796 }
797 
798 //-----------------------------------------------------------------------------
800 {
802 }
803 
804 //----------------------------------------------------------------------------
806 {
807  return this->GetBuffer()->GetLatestItemHasValidFieldData();
808 }
809 
810 //-----------------------------------------------------------------------------
812 {
813  return this->GetBuffer()->GetStreamBufferItem(uid, bufferItem);
814 }
815 
816 //-----------------------------------------------------------------------------
818 {
819  return this->GetBuffer()->GetLatestStreamBufferItem(bufferItem);
820 }
821 
822 //-----------------------------------------------------------------------------
824 {
825  return this->GetBuffer()->GetOldestStreamBufferItem(bufferItem);
826 }
827 
828 //-----------------------------------------------------------------------------
830 {
831  return this->GetBuffer()->GetStreamBufferItemFromTime(time, bufferItem, interpolation);
832 }
833 
834 //----------------------------------------------------------------------------
836 {
837  return this->GetBuffer()->ModifyBufferItemFrameField(uid, key, value);
838 }
839 
840 //-----------------------------------------------------------------------------
842 {
843  return this->GetBuffer()->Clear();
844 }
845 
846 //-----------------------------------------------------------------------------
848 {
849  return this->GetBuffer()->SetBufferSize(n);
850 }
851 
852 //-----------------------------------------------------------------------------
854 {
855  return this->GetBuffer()->GetBufferSize();
856 }
857 
858 //-----------------------------------------------------------------------------
860 {
861  return this->GetBuffer()->GetLatestTimeStamp(latestTimestamp);
862 }
863 
864 //-----------------------------------------------------------------------------
866 {
867  return this->GetBuffer()->GetOldestTimeStamp(oldestTimestamp);
868 }
869 
870 //-----------------------------------------------------------------------------
872 {
873  return this->GetBuffer()->GetTimeStamp(uid, timestamp);
874 }
875 
876 //-----------------------------------------------------------------------------
878 {
879  return this->GetBuffer()->SetLocalTimeOffsetSec(offsetSec);
880 }
881 
882 //-----------------------------------------------------------------------------
884 {
885  return this->GetBuffer()->GetLocalTimeOffsetSec();
886 }
887 
888 //-----------------------------------------------------------------------------
890 {
891  return this->GetBuffer()->GetTimeStampReportTable(timeStampReportTable);
892 }
893 
894 //-----------------------------------------------------------------------------
896 {
897  return this->GetBuffer()->SetTimeStampReporting(enable);
898 }
899 
900 //-----------------------------------------------------------------------------
902 {
903  return this->GetBuffer()->GetTimeStampReporting();
904 }
905 
906 //-----------------------------------------------------------------------------
907 PlusStatus vtkPlusDataSource::WriteToSequenceFile(const char* filename, bool useCompression /*= false */)
908 {
909  return this->GetBuffer()->WriteToSequenceFile(filename, useCompression);
910 }
911 
912 //-----------------------------------------------------------------------------
914 {
915  bufferToFill.DeepCopy(this->GetBuffer());
916 
917  return PLUS_SUCCESS;
918 }
919 
920 //-----------------------------------------------------------------------------
921 PlusStatus vtkPlusDataSource::AddTimeStampedItem(vtkMatrix4x4* matrix, ToolStatus status, unsigned long frameNumber, double unfilteredTimestamp, double filteredTimestamp/*=UNDEFINED_TIMESTAMP*/, const igsioFieldMapType* customFields /*= NULL*/)
922 {
923  return this->GetBuffer()->AddTimeStampedItem(matrix, status, frameNumber, unfilteredTimestamp, filteredTimestamp, customFields);
924 }
925 
926 //-----------------------------------------------------------------------------
928 {
929  return this->GetBuffer()->GetNumberOfBytesPerPixel();
930 }
931 
932 //-----------------------------------------------------------------------------
934 {
935  return this->GetBuffer()->GetIndex(uid, index);
936 }
937 
938 //-----------------------------------------------------------------------------
939 double vtkPlusDataSource::GetFrameRate(bool ideal /*= false*/, double* framePeriodStdevSecPtr/*=NULL*/)
940 {
941  return this->GetBuffer()->GetFrameRate(ideal, framePeriodStdevSecPtr);
942 }
virtual BufferItemUidType GetLatestItemUidInBuffer()
vtkPlusBuffer * Buffer
void SetTimeStampReporting(bool enable)
std::string GetCustomProperty(const std::string &propertyName)
vtkPlusDevice * Device
virtual PlusStatus SetBufferSize(int n)
const char * key
Definition: phidget22.h:5111
PlusStatus SetImageType(US_IMAGE_TYPE imageType)
virtual void SetLocalTimeOffsetSec(double offsetSec)
DataSourceType Type
virtual ItemStatus GetOldestStreamBufferItem(StreamBufferItem *bufferItem)
virtual PlusStatus SetOutputImageOrientation(US_IMAGE_ORIENTATION imageOrientation)
virtual PlusStatus WriteToSequenceFile(const char *filename, bool useCompression=false)
DataItemTemporalInterpolationType
Definition: vtkPlusBuffer.h:45
US_IMAGE_TYPE GetImageType()
std::string GetTransformName() const
std::string ReferenceCoordinateFrameName
virtual double GetLocalTimeOffsetSec()
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *toolElement)
PlusStatus SetId(const char *aSourceId)
double * timestamp
Definition: phidget22.h:3432
virtual ItemStatus GetStreamBufferItem(BufferItemUidType uid, StreamBufferItem *bufferItem)
virtual US_IMAGE_ORIENTATION GetImageOrientation()
std::string GetSourceId() const
virtual FrameSizeType GetFrameSize() const
virtual void SetStartTime(double startTime)
igsioStatus PlusStatus
Definition: PlusCommon.h:40
PlusStatus SetSourceId(const std::string &aSourceId)
PlusStatus SetReferenceCoordinateFrameName(const char *referenceName)
PlusStatus SetInputFrameSize(unsigned int x, unsigned int y, unsigned int z)
virtual double GetLocalTimeOffsetSec()
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 SetImageOrientation(US_IMAGE_ORIENTATION imageOrientation)
virtual PlusStatus ModifyBufferItemFrameField(BufferItemUidType uid, const std::string &key, const std::string &value)
PlusStatus AddTimeStampedItem(vtkMatrix4x4 *matrix, ToolStatus status, unsigned long frameNumber, double unfilteredTimestamp, double filteredTimestamp=UNDEFINED_TIMESTAMP, const igsioFieldMapType *customFields=NULL)
virtual unsigned int GetNumberOfScalarComponents()
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
PlusStatus SetImageType(US_IMAGE_TYPE imageType)
for i
virtual bool GetLatestItemHasValidVideoData()
virtual ItemStatus GetItemUidFromTime(double time, BufferItemUidType &uid)
void SetTimeStampReporting(bool enable)
#define PLUS_FAIL
Definition: PlusCommon.h:43
virtual PlusStatus SetInputImageOrientation(US_IMAGE_ORIENTATION imageOrientation)
virtual igsioCommon::VTKScalarPixelType GetPixelType()
static std::string DATA_SOURCE_TYPE_FIELDDATA_TAG
PlusStatus SetPixelType(igsioCommon::VTKScalarPixelType pixelType)
std::array< int, 3 > GetClipRectangleOrigin() const
virtual PlusStatus SetBufferSize(int n)
virtual bool GetLatestItemHasValidFieldData()
static std::string DATA_SOURCE_TYPE_VIDEO_TAG
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
virtual void DeepCopy(vtkPlusBuffer *buffer)
virtual PlusStatus AddItem(vtkImageData *frame, US_IMAGE_ORIENTATION usImageOrientation, US_IMAGE_TYPE imageType, long frameNumber, const std::array< int, 3 > &clipRectangleOrigin, const std::array< int, 3 > &clipRectangleSize, double unfilteredTimestamp=UNDEFINED_TIMESTAMP, double filteredTimestamp=UNDEFINED_TIMESTAMP, const igsioFieldMapType *customFields=NULL)
virtual ItemStatus GetTimeStamp(BufferItemUidType uid, double &timestamp)
virtual BufferItemUidType GetLatestItemUidInBuffer()
virtual double GetStartTime()
virtual ItemStatus GetOldestTimeStamp(double &oldestTimestamp)
virtual igsioCommon::VTKScalarPixelType GetPixelType()
void SetCustomProperty(const std::string &propertyName, const std::string &propertyValue)
virtual vtkPlusBuffer * GetBuffer() const
virtual void SetDescriptiveName(const char *)
virtual int GetNumberOfItems()
virtual BufferItemUidType GetOldestItemUidInBuffer()
virtual PlusStatus GetTimeStampReportTable(vtkTable *timeStampReportTable)
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
PhidgetGPS_Time * time
Definition: phidget22.h:3623
FrameSizeType InputFrameSize
virtual unsigned int GetNumberOfScalarComponents()
CustomPropertyMap CustomProperties
vtkStandardNewMacro(vtkPlusDataSource)
std::array< int, 3 > ClipRectangleSize
virtual void SetFrameNumber(unsigned long)
virtual void SetLocalTimeOffsetSec(double offsetSec)
void DeepCopy(const vtkPlusDataSource &source)
virtual PlusStatus DeepCopyBufferTo(vtkPlusBuffer &bufferToFill)
void SetClipRectangleOrigin(const std::array< int, 3 > _arg)
virtual double GetFrameRate(bool ideal=false, double *framePeriodStdevSecPtr=NULL)
US_IMAGE_ORIENTATION InputImageOrientation
virtual ItemStatus GetStreamBufferItemFromTime(double time, StreamBufferItem *bufferItem, DataItemTemporalInterpolationType interpolation)
virtual ItemStatus GetOldestStreamBufferItem(StreamBufferItem *bufferItem)
PlusStatus SetFrameSize(unsigned int x, unsigned int y, unsigned int z, bool allocateFrames=true)
PlusStatus SetPixelType(igsioCommon::VTKScalarPixelType pixelType)
virtual PlusStatus GetTimeStampReportTable(vtkTable *timeStampReportTable)
virtual US_IMAGE_TYPE GetImageType()
virtual bool GetLatestItemHasValidTransformData()
virtual double GetFrameRate(bool ideal=false, double *framePeriodStdevSecPtr=NULL)
virtual int GetBufferSize()
virtual int GetBufferSize()
int x
Definition: phidget22.h:4265
virtual ItemStatus GetLatestTimeStamp(double &latestTimestamp)
virtual ItemStatus GetTimeStamp(BufferItemUidType uid, double &timestamp)
const char const char * value
Definition: phidget22.h:5111
virtual US_IMAGE_ORIENTATION GetInputImageOrientation()
static std::string DATA_SOURCE_TYPE_TOOL_TAG
virtual ItemStatus GetIndex(const BufferItemUidType uid, unsigned long &index)
virtual ItemStatus GetLatestStreamBufferItem(StreamBufferItem *bufferItem)
int VTKScalarPixelType
Definition: PlusCommon.h:55
virtual FrameSizeType GetOutputFrameSize() const
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *toolElement, bool requirePortNameInSourceConfiguration=false, bool requireImageOrientationInChannelConfiguration=false, const std::string &aDescriptiveNameForBuffer=std::string(""))
virtual ItemStatus GetStreamBufferItemFromTime(double time, StreamBufferItem *bufferItem, vtkPlusBuffer::DataItemTemporalInterpolationType interpolation)
virtual ItemStatus GetIndex(const BufferItemUidType uid, unsigned long &index)
void SetClipRectangleSize(const std::array< int, 3 > _arg)
virtual ItemStatus GetStreamBufferItem(BufferItemUidType uid, StreamBufferItem *bufferItem)
virtual PlusStatus ModifyBufferItemFrameField(BufferItemUidType uid, const std::string &key, const std::string &value)
PlusStatus SetPortName(const std::string &portName)
PlusStatus SetNumberOfScalarComponents(unsigned int numberOfScalarComponents)
virtual US_IMAGE_ORIENTATION GetOutputImageOrientation()
Direction vectors of rods y
Definition: algo3.m:15
virtual ItemStatus GetLatestTimeStamp(double &latestTimestamp)
std::array< int, 3 > ClipRectangleOrigin
virtual void SetAveragedItemsForFiltering(int averagedItemsForFiltering)
virtual void Clear()
virtual ItemStatus GetItemUidFromTime(double time, BufferItemUidType &uid)
virtual BufferItemUidType GetOldestItemUidInBuffer()
bool GetTimeStampReporting()
std::array< int, 3 > GetClipRectangleSize() const
virtual void SetType(DataSourceType)
unsigned long long BufferItemUidType
virtual ItemStatus GetOldestTimeStamp(double &oldestTimestamp)
FrameSizeType GetInputFrameSize() const
virtual double GetStartTime()
PlusStatus SetNumberOfScalarComponents(unsigned int numberOfScalarComponents)
int GetNumberOfBytesPerPixel()
virtual PlusStatus WriteCompactConfiguration(vtkXMLDataElement *toolElement)
virtual void SetStartTime(double startTime)
virtual bool GetLatestItemHasValidVideoData()
virtual PlusStatus WriteToSequenceFile(const char *filename, bool useCompression=false)
PlusStatus AddTimeStampedItem(vtkMatrix4x4 *matrix, ToolStatus status, unsigned long frameNumber, double unfilteredTimestamp, double filteredTimestamp=UNDEFINED_TIMESTAMP, const igsioFieldMapType *customFields=NULL)
virtual int GetNumberOfItems()
virtual ItemStatus GetLatestStreamBufferItem(StreamBufferItem *bufferItem)
virtual bool GetLatestItemHasValidFieldData()
virtual bool GetLatestItemHasValidTransformData()
Interface to a 3D positioning tool, video source, or generalized data stream.