8 #include "PlusConfigure.h" 13 #include <vtkMatrix4x4.h> 14 #include <vtkTransform.h> 30 , InputImageOrientation(US_IMG_ORIENT_XX)
34 , ReferenceCoordinateFrameName(
"")
63 vtkObject::PrintSelf(os, indent);
67 os << indent <<
"Tracker: " << this->
Device << std::endl;
69 os << indent <<
"Id: " << this->GetId() << std::endl;
75 os << indent <<
"Type: Tool" << std::endl;
78 os << indent <<
"Type: Video" << std::endl;
81 os << indent <<
"Type: Fields" << std::endl;
87 os << indent <<
"ReferenceCoordinateFrameName: " << this->GetReferenceCoordinateFrameName() << std::endl;
91 os << indent <<
"PortName: " << this->GetPortName() << std::endl;
96 os << indent <<
"Buffer: " << this->
Buffer << std::endl;
104 if (aSourceId == NULL && !this->
Id.empty())
109 return this->
SetId(std::string(aSourceId));
115 if (this->
Id == aSourceId)
120 if (!this->
Id.empty())
123 LOG_ERROR(
"SourceId change is not allowed for source '" << this->
Id <<
"'");
127 this->
Id = aSourceId;
135 return this->
SetId(aSourceId);
141 return this->GetId();
178 if (portName == NULL)
180 LOG_ERROR(
"NULL portName sent to SetPortName.");
198 LOG_ERROR(
"Port name change is not allowed on source port'" << this->
PortName <<
"'");
202 if (!portName.empty())
213 LOG_TRACE(
"vtkPlusDataSource::DeepCopy");
215 this->
SetId(aSource.GetId());
216 this->
SetType(aSource.GetType());
253 LOG_TRACE(
"vtkPlusDataSource::ReadConfiguration");
255 if (sourceElement == NULL)
257 LOG_ERROR(
"Unable to configure data source! (XML data element is NULL)");
261 std::string sourceId = sourceElement->GetAttribute(
"Id") != NULL ? sourceElement->GetAttribute(
"Id") :
"";
262 if (sourceId.empty())
264 LOG_ERROR(
"Unable to find attribute \"Id\"! Id attribute is mandatory in source definition.");
268 const char* portName = sourceElement->GetAttribute(
"PortName");
269 if (portName != NULL)
274 const char* type = sourceElement->GetAttribute(
"Type");
277 igsioTransformName idName(sourceId, this->GetReferenceCoordinateFrameName());
278 this->
SetId(idName.GetTransformName());
281 if (requirePortNameInSourceConfiguration && portName == NULL)
283 LOG_ERROR(
"Unable to find PortName! This attribute is mandatory in tool definition.");
289 this->
SetId(sourceId);
294 this->
SetId(sourceId);
297 const char* usImageOrientation = sourceElement->GetAttribute(
"PortUsImageOrientation");
298 if (usImageOrientation != NULL)
300 LOG_INFO(
"Selected US image orientation: " << usImageOrientation);
304 LOG_ERROR(
"Video image orientation is undefined - please set PortUsImageOrientation in the source configuration");
307 else if (requireImageOrientationInSourceConfiguration)
309 LOG_ERROR(
"Video image orientation is not defined in the source \'" << this->GetId() <<
"\' element - please set PortUsImageOrientation in the source configuration");
312 const char* imageType = sourceElement->GetAttribute(
"ImageType");
313 if (imageType != NULL && this->
GetBuffer() != NULL)
315 if (STRCASECMP(imageType,
"BRIGHTNESS") == 0)
319 else if (STRCASECMP(imageType,
"RGB_COLOR") == 0)
323 else if (STRCASECMP(imageType,
"RF_I_LINE_Q_LINE") == 0)
327 else if (STRCASECMP(imageType,
"RF_IQ_LINE") == 0)
331 else if (STRCASECMP(imageType,
"RF_REAL") == 0)
340 int tmpValue[3] = {0};
341 int clipRectangleOriginComponents = sourceElement->GetVectorAttribute(
"ClipRectangleOrigin", 3, tmpValue);
342 if (clipRectangleOriginComponents == 2)
359 int clipRectangleSizeComponents = sourceElement->GetVectorAttribute(
"ClipRectangleSize", 3, tmpValue);
360 if (clipRectangleSizeComponents == 2)
363 XML_READ_STD_ARRAY_ATTRIBUTE_EXACT_OPTIONAL(
int, 2,
ClipRectangleSize, sourceElement);
380 LOG_ERROR(
"Missing type element. It is required to define the source type.");
385 if (sourceElement->GetScalarAttribute(
"BufferSize", bufferSize))
391 LOG_DEBUG(
"Buffer size is not defined in source element \"" << this->GetId() <<
"\". Using default buffer size: " << this->
GetBuffer()->
GetBufferSize());
394 int averagedItemsForFiltering = 0;
395 if (sourceElement->GetScalarAttribute(
"AveragedItemsForFiltering", averagedItemsForFiltering))
401 LOG_DEBUG(
"AveragedItemsForFiltering is not defined in source element \"" << this->GetId() <<
"\". Using default value: " << this->
GetBuffer()->GetAveragedItemsForFiltering());
404 std::string descName;
405 if (!aDescriptiveNameForBuffer.empty())
407 descName += aDescriptiveNameForBuffer;
409 descName += this->GetId();
413 descName += this->GetId();
418 for (
int i = 0;
i < sourceElement->GetNumberOfNestedElements(); ++
i)
420 if (STRCASECMP(sourceElement->GetNestedElement(
i)->GetName(),
"CustomProperties") == 0)
422 vtkXMLDataElement* customPropertiesElement = sourceElement->GetNestedElement(
i);
424 for (
int j = 0; j < customPropertiesElement->GetNumberOfNestedElements(); ++j)
426 vtkXMLDataElement* customPropertyElement = customPropertiesElement->GetNestedElement(j);
427 this->
CustomProperties[customPropertyElement->GetName()] = customPropertyElement->GetCharacterData();
439 LOG_TRACE(
"vtkPlusDataSource::WriteConfiguration");
441 if (aSourceElement == NULL)
443 LOG_ERROR(
"Unable to configure data source! (XML data element is NULL)");
449 igsioTransformName sourceId(this->GetId());
450 aSourceElement->SetAttribute(
"Id", sourceId.From().c_str());
454 XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(
Id, aSourceElement);
457 XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(
PortName, aSourceElement);
460 if (aSourceElement->GetAttribute(
"AveragedItemsForFiltering") != NULL)
462 aSourceElement->SetIntAttribute(
"AveragedItemsForFiltering", this->
GetBuffer()->GetAveragedItemsForFiltering());
468 vtkSmartPointer<vtkXMLDataElement> customPropertiesElement = vtkSmartPointer<vtkXMLDataElement>::New();
469 customPropertiesElement->SetName(
"CustomProperties");
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);
479 aSourceElement->AddNestedElement(customPropertiesElement);
486 aSourceElement->SetVectorAttribute(
"ClipRectangleOrigin", 3, tmpValue);
490 aSourceElement->SetVectorAttribute(
"ClipRectangleSize", 3, tmpValue);
500 LOG_TRACE(
"vtkPlusDataSource::WriteConfiguration");
502 if (aSourceElement == NULL)
504 LOG_ERROR(
"Unable to configure source! (XML data element is NULL)");
510 igsioTransformName sourceId(this->GetId());
511 aSourceElement->SetAttribute(
"Id", sourceId.From().c_str());
515 XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(
Id, aSourceElement);
517 XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(
PortName, aSourceElement);
525 std::ostringstream ss;
533 std::map< std::string, std::string > :: iterator prop = this->
CustomProperties.find(propertyName);
534 std::string propValue;
537 propValue = prop->second;
549 PlusStatus vtkPlusDataSource::AddItem(vtkImageData* frame, US_IMAGE_ORIENTATION usImageOrientation, US_IMAGE_TYPE imageType,
long frameNumber,
double unfilteredTimestamp,
double filteredTimestamp,
const igsioFieldMapType* customFields )
562 double filteredTimestamp)
564 return this->
GetBuffer()->
AddItem(customFields, frameNumber, unfilteredTimestamp, filteredTimestamp);
569 unsigned int numberOfScalarComponents, US_IMAGE_TYPE imageType,
int numberOfBytesToSkip,
long frameNumber,
double unfilteredTimestamp ,
570 double filteredTimestamp ,
const igsioFieldMapType* customFields )
572 return this->
GetBuffer()->
AddItem(imageDataPtr, usImageOrientation, frameSizeInPx, pixelType, numberOfScalarComponents, imageType, numberOfBytesToSkip, frameNumber,
577 PlusStatus vtkPlusDataSource::AddItem(
void* imageDataPtr,
const FrameSizeType& frameSize,
unsigned int frameSizeInBytes, US_IMAGE_TYPE imageType,
long frameNumber,
double unfilteredTimestamp ,
double filteredTimestamp ,
const igsioFieldMapType* customFields )
579 return this->
GetBuffer()->
AddItem(imageDataPtr, frameSize, frameSizeInBytes, imageType, frameNumber, unfilteredTimestamp, filteredTimestamp, customFields);
601 FrameSizeType outputFrameSizeInPx = {
x,
y, z};
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()))
607 LOG_ERROR(
"Unable to determine clipping details in vtkPlusDataSource::SetInputFrameSize. Cannot continue.");
611 int extents[6] = {0, static_cast<int>(
x) - 1, 0, static_cast<int>(
y) - 1, 0, static_cast<int>(z) - 1};
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." 635 igsioVideoFrame::FlipInfoType flipInfo;
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()));
644 if (flipInfo.tranpose == igsioVideoFrame::TRANSPOSE_IJKtoKIJ)
646 unsigned int temp = outputFrameSizeInPx[0];
647 outputFrameSizeInPx[0] = outputFrameSizeInPx[2];
648 outputFrameSizeInPx[2] = outputFrameSizeInPx[1];
649 outputFrameSizeInPx[1] = temp;
652 return this->
GetBuffer()->
SetFrameSize(outputFrameSizeInPx[0], outputFrameSizeInPx[1], outputFrameSizeInPx[2]);
691 if (imageOrientation <= US_IMG_ORIENT_XX || imageOrientation >= US_IMG_ORIENT_LAST)
693 LOG_ERROR(
"vtkPlusDataSource::SetInputImageOrientation failed: invalid image orientation received");
696 if (imageOrientation <= US_IMG_ORIENT_FU)
711 if (imageOrientation != US_IMG_ORIENT_MF && imageOrientation != US_IMG_ORIENT_FM)
713 LOG_ERROR(
"vtkPlusDataSource::SetOutputImageOrientation failed: only standard MF and FM orientations are allowed, got " 714 << igsioCommon::GetStringFromUsImageOrientation(imageOrientation));
virtual BufferItemUidType GetLatestItemUidInBuffer()
bool GetTimeStampReporting()
void SetTimeStampReporting(bool enable)
std::string GetCustomProperty(const std::string &propertyName)
virtual PlusStatus SetBufferSize(int n)
PlusStatus SetImageType(US_IMAGE_TYPE imageType)
virtual void SetLocalTimeOffsetSec(double offsetSec)
virtual ItemStatus GetOldestStreamBufferItem(StreamBufferItem *bufferItem)
virtual PlusStatus SetOutputImageOrientation(US_IMAGE_ORIENTATION imageOrientation)
virtual PlusStatus WriteToSequenceFile(const char *filename, bool useCompression=false)
DataItemTemporalInterpolationType
US_IMAGE_TYPE GetImageType()
std::string GetTransformName() const
std::string ReferenceCoordinateFrameName
virtual double GetLocalTimeOffsetSec()
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *toolElement)
PlusStatus SetId(const char *aSourceId)
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)
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)
virtual bool GetLatestItemHasValidVideoData()
virtual ItemStatus GetItemUidFromTime(double time, BufferItemUidType &uid)
void SetTimeStampReporting(bool enable)
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 ×tamp)
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)
FrameSizeType InputFrameSize
virtual unsigned int GetNumberOfScalarComponents()
CustomPropertyMap CustomProperties
vtkStandardNewMacro(vtkPlusDataSource)
int GetNumberOfBytesPerPixel()
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()
virtual ItemStatus GetLatestTimeStamp(double &latestTimestamp)
virtual ItemStatus GetTimeStamp(BufferItemUidType uid, double ×tamp)
const char const char * value
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)
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
virtual ItemStatus GetLatestTimeStamp(double &latestTimestamp)
std::array< int, 3 > ClipRectangleOrigin
virtual void SetAveragedItemsForFiltering(int averagedItemsForFiltering)
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.