8 #include "PlusConfigure.h" 13 #include "vtkIGSIORecursiveCriticalSection.h" 15 #include "vtkIGSIOTrackedFrameList.h" 18 #include <vtkImageData.h> 19 #include <vtkInformation.h> 20 #include <vtkInformationVector.h> 21 #include <vtkMatrix4x4.h> 22 #include <vtkMultiThreader.h> 23 #include <vtkObjectFactory.h> 24 #include <vtkStreamingDemandDrivenPipeline.h> 25 #include <vtkWindows.h> 26 #include <vtksys/SystemTools.hxx> 35 #if ( _MSC_VER >= 1300 ) // Visual studio .NET 36 #pragma warning ( disable : 4311 ) 37 #pragma warning ( disable : 4312 ) 40 #define LOCAL_LOG_ERROR(msg) \ 42 std::ostringstream msgStream; \ 43 if( this->DeviceId.empty() ) \ 45 msgStream << " " << msg << std::ends; \ 49 msgStream << this->DeviceId << ": " << msg << std::ends; \ 51 std::string finalStr(msgStream.str()); \ 52 LOG_ERROR(finalStr); \ 54 #define LOCAL_LOG_WARNING(msg) \ 56 std::ostringstream msgStream; \ 57 if( this->DeviceId.empty() ) \ 59 msgStream << " " << msg << std::ends; \ 63 msgStream << this->DeviceId << ": " << msg << std::ends; \ 65 std::string finalStr(msgStream.str()); \ 66 LOG_WARNING(finalStr); \ 68 #define LOCAL_LOG_INFO(msg) \ 70 std::ostringstream msgStream; \ 71 if( this->DeviceId.empty() ) \ 73 msgStream << " " << msg << std::ends; \ 77 msgStream << this->DeviceId << ": " << msg << std::ends; \ 79 std::string finalStr(msgStream.str()); \ 82 #define LOCAL_LOG_DEBUG(msg) \ 84 std::ostringstream msgStream; \ 85 if( this->DeviceId.empty() ) \ 87 msgStream << " " << msg << std::ends; \ 91 msgStream << this->DeviceId << ": " << msg << std::ends; \ 93 std::string finalStr(msgStream.str()); \ 94 LOG_DEBUG(finalStr); \ 96 #define LOCAL_LOG_TRACE(msg) \ 98 std::ostringstream msgStream; \ 99 if( this->DeviceId.empty() ) \ 101 msgStream << " " << msg << std::ends; \ 105 msgStream << this->DeviceId << ": " << msg << std::ends; \ 107 std::string finalStr(msgStream.str()); \ 108 LOG_TRACE(finalStr); \ 126 , Threader(vtkMultiThreader::New())
129 , ToolReferenceFrameName(
"")
131 , DataCollector(NULL)
132 , AcquisitionRate(30)
134 , DesiredTimestamp(-1)
135 , UpdateWithDesiredTimestamp(0)
136 , TimestampClosestToDesired(-1)
139 , OutputNeedsInitialization(1)
140 , CorrectlyConfigured(true)
141 , StartThreadForInternalUpdates(false)
142 , LocalTimeOffsetSec(0.0)
143 , MissingInputGracePeriodSec(0.0)
144 , RequireImageOrientationInConfiguration(false)
145 , RequirePortNameInDeviceSetConfiguration(false)
147 this->SetNumberOfInputPorts(0);
150 this->
UpdateMutex = vtkIGSIORecursiveCriticalSection::New();
164 (*it)->UnRegister(
this);
170 it->second->UnRegister(
this);
175 it->second->UnRegister(
this);
180 it->second->UnRegister(
this);
197 this->Superclass::PrintSelf(os, indent);
199 os << indent <<
"Connected: " << (this->
Connected ?
"Yes\n" :
"No\n");
200 os << indent <<
"SDK version: " << this->
GetSdkVersion() << std::endl;
201 os << indent <<
"AcquisitionRate: " << this->
AcquisitionRate << std::endl;
202 os << indent <<
"Recording: " << (this->
Recording ?
"On\n" :
"Off\n");
207 str->PrintSelf(os, indent);
234 for (std::map<std::string, std::string>::iterator it = this->
Parameters.begin(); it != this->
Parameters.end(); ++it)
236 os << indent << indent << it->first <<
": " << it->second << std::endl;
244 std::string ver = std::string(
"Plus-") + std::string(PLUSLIB_VERSION);
266 return this->
Tools.begin();
272 return this->
Tools.end();
278 return this->
Tools.size();
290 if (tool->GetId().empty())
292 LOCAL_LOG_ERROR(
"Failed to add tool to tracker, tool source ID must be defined!");
298 LOCAL_LOG_ERROR(
"Tool with ID '" << tool->GetId() <<
"' is already in the tool container!");
302 if (requireUniquePortName && !tool->GetPortName().empty())
307 if (it->second->GetPortName().empty())
311 if (tool->GetPortName() == it->second->GetPortName())
313 LOCAL_LOG_ERROR(
"Failed to add '" << tool->GetId() <<
"' tool to container: tool with name '" << it->second->GetId()
314 <<
"' is already defined on port '" << tool->GetPortName() <<
"'!");
320 tool->Register(
this);
322 this->
Tools[tool->GetId()] = tool;
330 if (aSourceId == NULL)
332 LOCAL_LOG_ERROR(
"vtkPlusDevice::GetTool failed: aToolSourceId is invalid");
344 aSource = this->
Fields.find(aSourceId)->second;
354 return this->
Fields.begin();
360 return this->
Fields.end();
368 LOCAL_LOG_ERROR(
"Failed to add field data source to device, source is NULL!");
372 if (aSource->GetId().empty())
374 LOCAL_LOG_ERROR(
"Failed to add field data to device, field data source ID must be defined!");
380 LOCAL_LOG_ERROR(
"Field data with ID '" << aSource->GetId() <<
"' is already in the field data container!");
384 aSource->Register(
this);
386 this->
Fields[aSource->GetId()] = aSource;
394 return this->
Fields.size();
400 if (this->
Tools.size() == 0)
402 LOCAL_LOG_ERROR(
"Failed to get first active tool - there are no tools!");
407 aTool = this->
Tools.begin()->second;
415 if (aToolSourceId == NULL)
417 LOCAL_LOG_ERROR(
"vtkPlusDevice::GetTool failed: aToolSourceId is invalid");
421 if (this->
Tools.find(aToolSourceId) != this->
Tools.end())
423 aTool = this->
Tools.find(aToolSourceId)->second;
433 return this->
GetTool(aToolSourceId.c_str(), aTool);
439 if (portName == NULL)
453 if (portName == it->second->GetPortName())
455 aSource = it->second;
466 if (aPortName == NULL)
482 if (it->second->GetPortName().empty())
484 LOCAL_LOG_DEBUG(
"Port name is not defined for video source " << (!it->second->GetId().empty() ? it->second->GetId() :
"unknown"));
487 if (aPortName == it->second->GetPortName())
489 sources.push_back(it->second);
499 LOCAL_LOG_TRACE(
"vtkPlusDevice::SetToolsBufferSize(" << aBufferSize <<
")");
502 it->second->SetBufferSize(aBufferSize);
509 LOCAL_LOG_TRACE(
"vtkPlusDevice::SetFieldDataSourcesBufferSize(" << aBufferSize <<
")");
512 it->second->SetBufferSize(aBufferSize);
551 outDeviceList.push_back(
channel->GetOwnerDevice());
562 (*it)->GetOwnerDevice()->GetInputDevicesRecursive(outDeviceList);
563 outDeviceList.push_back((*it)->GetOwnerDevice());
593 outValue = this->
Parameters.find(key)->second;
616 vtkPlusDevice* ewwwwDevice = const_cast<vtkPlusDevice*>(&device);
617 this->SetNumberOfInputPorts(ewwwwDevice->GetNumberOfInputPorts());
625 LOCAL_LOG_ERROR(
"Copy of tool '" << it->first <<
"' failed - unable to add tool to the container!");
632 LOCAL_LOG_ERROR(
"Copy of tool '" << it->first <<
"' failed - unable to get tool from container!");
641 LOCAL_LOG_DEBUG(
"Copy the buffer of field data source: " << it->first);
644 LOCAL_LOG_ERROR(
"Copy of field data source '" << it->first <<
"' failed - unable to add field data source to the container!");
651 LOCAL_LOG_ERROR(
"Copy of field data source '" << it->first <<
"' failed - unable to get field data source from container!");
717 LOCAL_LOG_TRACE(
"vtkPlusDevice::WriteToolsToSequenceFile: " << filename);
721 LOCAL_LOG_ERROR(
"Failed to write tracker to metafile - there are no active tools!");
726 int numberOfItems(-1);
729 if (numberOfItems < 0 || numberOfItems > it->second->GetNumberOfItems())
731 numberOfItems = it->second->GetNumberOfItems();
735 vtkSmartPointer<vtkIGSIOTrackedFrameList> trackedFrameList = vtkSmartPointer<vtkIGSIOTrackedFrameList>::New();
742 for (
int i = 0 ;
i < numberOfItems;
i++)
745 igsioTrackedFrame trackedFrame;
746 igsioVideoFrame videoFrame;
747 FrameSizeType frameSize = {1, 1, 1};
749 videoFrame.AllocateFrame(frameSize, VTK_UNSIGNED_CHAR, 1);
750 trackedFrame.SetImageData(videoFrame);
757 LOCAL_LOG_ERROR(
"Failed to get tracker buffer item with UID: " << uid);
764 std::ostringstream timestampFieldValue;
765 timestampFieldValue << std::fixed << frameTimestamp;
766 trackedFrame.SetFrameField(
"Timestamp", timestampFieldValue.str());
769 std::ostringstream unfilteredtimestampFieldValue;
771 trackedFrame.SetFrameField(
"UnfilteredTimestamp", unfilteredtimestampFieldValue.str());
774 std::ostringstream frameNumberFieldValue;
775 frameNumberFieldValue << std::fixed << bufferItem.
GetIndex();
776 trackedFrame.SetFrameField(
"FrameNumber", frameNumberFieldValue.str());
784 LOCAL_LOG_ERROR(
"Failed to get tracker buffer item from time: " << std::fixed << frameTimestamp);
788 vtkSmartPointer<vtkMatrix4x4> toolMatrix = vtkSmartPointer<vtkMatrix4x4>::New();
796 trackedFrame.SetFrameTransform(toolToTrackerTransform, toolMatrix);
799 trackedFrame.SetFrameTransformStatus(toolToTrackerTransform, toolBufferItem.
GetStatus());
804 trackedFrameList->AddTrackedFrame(&trackedFrame);
810 LOCAL_LOG_ERROR(
"Failed to save tracked frames to sequence metafile!");
838 if (rootXMLElement == NULL)
844 vtkXMLDataElement* dataCollectionElement = rootXMLElement->FindNestedElementWithName(
"DataCollection");
845 if (dataCollectionElement == NULL)
847 LOCAL_LOG_ERROR(
"Unable to find data collection element in XML tree!");
851 vtkXMLDataElement* deviceXMLElement = NULL;
852 for (
int i = 0;
i < dataCollectionElement->GetNumberOfNestedElements(); ++
i)
854 deviceXMLElement = dataCollectionElement->GetNestedElement(
i);
856 if (deviceXMLElement->GetName() != NULL &&
857 deviceXMLElement->GetAttribute(
"Id") != NULL &&
858 std::string(deviceXMLElement->GetName()) ==
"Device" &&
859 std::string(deviceXMLElement->GetAttribute(
"Id")) == this->
GetDeviceId())
861 return deviceXMLElement;
871 if (rootXMLElement == NULL || aChannelId == NULL)
873 LOCAL_LOG_ERROR(
"Unable to find XML element for this channel. Bad inputs.");
879 vtkXMLDataElement* outputChannelsElement = deviceXMLElement->FindNestedElementWithName(
"OutputChannels");
880 if (outputChannelsElement != NULL)
882 for (
int i = 0;
i < outputChannelsElement->GetNumberOfNestedElements(); ++
i)
884 vtkXMLDataElement* anXMLElement = outputChannelsElement->GetNestedElement(
i);
886 if (anXMLElement->GetName() != NULL &&
887 anXMLElement->GetAttribute(
"Id") != NULL &&
888 STRCASECMP(anXMLElement->GetName(),
"OutputChannel") == 0 &&
889 STRCASECMP(anXMLElement->GetAttribute(
"Id"), aChannelId) == 0)
902 if (rootXMLElement == NULL || aChannelId == NULL)
904 LOCAL_LOG_ERROR(
"Unable to find XML element for this channel. Bad inputs.");
910 vtkXMLDataElement* inputChannelsElement = deviceXMLElement->FindNestedElementWithName(
"InputChannels");
911 if (inputChannelsElement != NULL)
913 for (
int i = 0;
i < inputChannelsElement->GetNumberOfNestedElements(); ++
i)
915 vtkXMLDataElement* anXMLElement = inputChannelsElement->GetNestedElement(
i);
917 if (anXMLElement->GetName() != NULL && anXMLElement->GetAttribute(
"Id") != NULL &&
918 STRCASECMP(anXMLElement->GetName(),
"InputChannel") == 0 && STRCASECMP(anXMLElement->GetAttribute(
"Id"), aChannelId) == 0)
933 if (rootXMLElement == NULL)
941 if (deviceXMLElement == NULL)
948 const char* referenceName = deviceXMLElement->GetAttribute(
"ToolReferenceFrame");
949 if (referenceName != NULL)
962 if (deviceXMLElement->GetAttribute(
"MissingInputGracePeriodSec") != NULL)
967 vtkXMLDataElement* dataSourcesElement = deviceXMLElement->FindNestedElementWithName(
"DataSources");
968 if (dataSourcesElement != NULL)
971 for (
int source = 0;
source < dataSourcesElement->GetNumberOfNestedElements();
source++)
973 vtkXMLDataElement* dataSourceElement = dataSourcesElement->GetNestedElement(
source);
975 if (STRCASECMP(dataSourceElement->GetName(),
"DataSource") != 0)
981 std::string sourceId = dataSourceElement->GetAttribute(
"Id") != NULL ? dataSourceElement->GetAttribute(
"Id") :
"";
982 if (sourceId.empty())
984 LOG_ERROR(
"Unable to find attribute \"Id\"! \"Id\" attribute is mandatory in source definition. Skipping.");
990 LOG_ERROR(
"Data source \"" << this->
ToolReferenceFrameName <<
"\" cannot have same name as the ToolReferenceFrameName. Skipping.");
996 LOG_ERROR(
"Data source name \"" << sourceId <<
"\" is not unique. Skipping.");
1000 vtkSmartPointer<vtkPlusDataSource> aDataSource = vtkSmartPointer<vtkPlusDataSource>::New();
1001 bool isEqual(
false);
1006 if (aDataSource->ReadConfiguration(dataSourceElement, this->RequirePortNameInDeviceSetConfiguration, this->RequireImageOrientationInConfiguration, this->GetDeviceId()) !=
PLUS_SUCCESS)
1008 LOCAL_LOG_ERROR(
"Unable to add tool to tracker - failed to read tool configuration");
1014 LOCAL_LOG_ERROR(
"Failed to add tool '" << (!aDataSource->GetId().empty() ? aDataSource->GetId() :
"(unspecified)") <<
"' to device on port " << (!aDataSource->GetPortName().empty() ? aDataSource->GetPortName() :
"(unspecified)"));
1019 if (aDataSource->ReadConfiguration(dataSourceElement, this->RequirePortNameInDeviceSetConfiguration, this->RequireImageOrientationInConfiguration, this->GetDeviceId()) !=
PLUS_SUCCESS)
1021 LOCAL_LOG_ERROR(
"Unable to add field data source to device - failed to read field data source configuration");
1027 LOCAL_LOG_ERROR(
"Failed to add field data source '" << (!aDataSource->GetId().empty() ? aDataSource->GetId() :
"(unspecified)") <<
"' to device.");
1036 LOCAL_LOG_ERROR(
"Failed to add video source '" << (!aDataSource->GetId().empty() ? aDataSource->GetId() :
"(unspecified)") <<
"' to device.");
1043 double acquisitionRate = 0;
1044 if (deviceXMLElement->GetScalarAttribute(
"AcquisitionRate", acquisitionRate))
1053 vtkXMLDataElement* outputChannelsElement = deviceXMLElement->FindNestedElementWithName(
"OutputChannels");
1054 if (outputChannelsElement != NULL)
1059 vtkXMLDataElement* channelElement = outputChannelsElement->GetNestedElement(
channel);
1060 if (STRCASECMP(channelElement->GetName(),
"OutputChannel") != 0)
1066 if (channelElement->GetAttribute(
"Id") == NULL)
1068 LOCAL_LOG_ERROR(
"No channel Id present. Skipping channel configuration.");
1075 if (STRCASECMP((*it)->GetChannelId(), channelElement->GetAttribute(
"Id")) == 0)
1077 LOCAL_LOG_ERROR(
"Channel with duplicate channel Id \'" << (*it)->GetChannelId() <<
"\'. Skipping channel configuration.");
1087 vtkSmartPointer<vtkPlusChannel> aChannel = vtkSmartPointer<vtkPlusChannel>::New();
1088 aChannel->SetOwnerDevice(
this);
1094 double localTimeOffsetSec = 0;
1095 if (deviceXMLElement->GetScalarAttribute(
"LocalTimeOffsetSec", localTimeOffsetSec))
1098 LOCAL_LOG_INFO(
"Local time offset: " << 1000 * localTimeOffsetSec <<
"ms");
1103 LOCAL_LOG_DEBUG(
"Local time offset was not defined in device configuration");
1110 for (
int i = 0;
i < parametersElem->GetNumberOfNestedElements(); ++
i)
1112 vtkXMLDataElement* element = parametersElem->GetNestedElement(
i);
1119 std::string name = element->GetAttribute(
"name") ? element->GetAttribute(
"name") :
"";
1120 std::string
value = element->GetAttribute(
"value") ? element->GetAttribute(
"value") :
"";
1140 LOCAL_LOG_ERROR(
"Unable to write configuration: xml data element is NULL!");
1146 if (deviceDataElement == NULL)
1148 LOCAL_LOG_ERROR(
"Unable to write configuration: xml data element is NULL!");
1152 vtkXMLDataElement* dataSourcesElement = deviceDataElement->FindNestedElementWithName(
"DataSources");
1153 if (dataSourcesElement != NULL)
1155 for (
int i = 0;
i < dataSourcesElement->GetNumberOfNestedElements();
i++)
1157 vtkXMLDataElement* dataSourceElement = dataSourcesElement->GetNestedElement(
i);
1158 if (STRCASECMP(dataSourceElement->GetName(),
"DataSource") != 0)
1164 bool isEqual(
false);
1168 if (dataSourceElement->GetAttribute(
"Id") == NULL || this->
GetTool(toolId.GetTransformName(), aDataSource) !=
PLUS_SUCCESS)
1177 if (dataSourceElement->GetAttribute(
"Id") == NULL || this->
GetFieldDataSource(dataSourceElement->GetAttribute(
"Id"), aDataSource) !=
PLUS_SUCCESS)
1179 LOCAL_LOG_ERROR(
"Unable to retrieve field data source when saving config.");
1186 if (dataSourceElement->GetAttribute(
"Id") == NULL || this->
GetVideoSource(dataSourceElement->GetAttribute(
"Id"), aDataSource) !=
PLUS_SUCCESS)
1188 LOCAL_LOG_ERROR(
"Unable to retrieve video source when saving config.");
1208 parameterList->RemoveAllNestedElements();
1210 for (std::map<std::string, std::string>::iterator it = this->
Parameters.begin(); it != this->
Parameters.end(); ++it)
1212 vtkSmartPointer<vtkXMLDataElement> parameter = vtkSmartPointer<vtkXMLDataElement>::New();
1214 parameter->SetAttribute(
"name", it->first.c_str());
1215 parameter->SetAttribute(
"value", it->second.c_str());
1217 parameterList->AddNestedElement(parameter);
1294 LOCAL_LOG_ERROR(
"Cannot start recording, internal StartRecording failed");
1304 this->
Threader->SpawnThread((vtkThreadFunctionType)\
1334 vtkIGSIOAccurateTimer::Delay(0.1);
1338 this->
Threader->TerminateThread(tempID);
1361 unsigned long updatecount = 0;
1362 self->ThreadAlive =
true;
1364 while (self->IsRecording() &&
self->GetCorrectlyConfigured())
1366 double newtime = vtkIGSIOAccurateTimer::GetSystemTime();
1377 igsioLockGuard<vtkIGSIORecursiveCriticalSection> updateMutexGuardedLock(self->UpdateMutex);
1378 if (!self->Recording)
1383 self->InternalUpdate();
1384 self->UpdateTime.Modified();
1387 double delay = (newtime + 1.0 / rate - vtkIGSIOAccurateTimer::GetSystemTime());
1390 vtkIGSIOAccurateTimer::Delay(delay);
1396 self->ThreadAlive =
false;
1429 if (aSourceId.empty())
1444 if (it->second->GetId() == aSourceId)
1446 outVal = it->second->GetBufferSize();
1453 if (it->second->GetId() == aSourceId)
1455 outVal = it->second->GetBufferSize();
1460 LOCAL_LOG_ERROR(
"Unable to find tool " << aSourceId <<
" when requesting its buffer size.");
1470 LOCAL_LOG_TRACE(
"vtkPlusDevice::SetBufferSize(" << FrameBufferSize <<
")");
1472 if (FrameBufferSize < 0)
1474 LOCAL_LOG_ERROR(
"vtkPlusDevice::SetBufferSize: There must be at least one framebuffer");
1478 if (aSourceId.empty())
1498 if (it->second->GetId() == aSourceId)
1500 it->second->SetBufferSize(FrameBufferSize);
1506 if (it->second->GetId() == aSourceId)
1508 it->second->SetBufferSize(FrameBufferSize);
1520 it->second->SetStartTime(startTime);
1525 it->second->SetStartTime(startTime);
1530 it->second->SetStartTime(startTime);
1539 double sumStartTime = 0.0;
1540 double numberOfBuffers(0);
1543 sumStartTime += it->second->GetStartTime();
1549 sumStartTime += it->second->GetStartTime();
1555 sumStartTime += it->second->GetStartTime();
1559 return sumStartTime / numberOfBuffers;
1565 igsioLockGuard<vtkIGSIORecursiveCriticalSection> updateMutexGuardedLock(this->
UpdateMutex);
1585 it->second->Clear();
1589 it->second->Clear();
1593 it->second->Clear();
1612 igsioLockGuard<vtkIGSIORecursiveCriticalSection> updateMutexGuardedLock(this->
UpdateMutex);
1621 if (aToolSourceId.empty())
1633 LOCAL_LOG_ERROR(
"Failed to update tool - unable to find tool: " << aToolSourceId);
1640 unsigned long frameNumber = tool->GetFrameNumber() + 1 ;
1644 return bufferStatus;
1651 for (std::vector<vtkPlusDataSource*>::const_iterator it = videoSources.begin(); it != videoSources.end(); ++it)
1654 if (
source->AddItem(&frame, frameNumber, unfilteredTimestamp, filteredTimestamp, customFields) !=
PLUS_SUCCESS)
1663 PlusStatus vtkPlusDevice::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 ,
double filteredTimestamp ,
const igsioFieldMapType* customFields )
1666 for (std::vector<vtkPlusDataSource*>::const_iterator it = videoSources.begin(); it != videoSources.end(); ++it)
1669 if (
source->AddItem(imageDataPtr, usImageOrientation, frameSizeInPx, pixelType, numberOfScalarComponents, imageType, numberOfBytesToSkip, frameNumber, unfilteredTimestamp, filteredTimestamp, customFields) !=
PLUS_SUCCESS)
1680 if (aToolSourceId.empty())
1692 LOCAL_LOG_ERROR(
"Failed to update tool - unable to find tool: " << aToolSourceId);
1698 PlusStatus bufferStatus = tool->
AddTimeStampedItem(matrix, status, frameNumber, unfilteredtimestamp, UNDEFINED_TIMESTAMP, customFields);
1701 return bufferStatus;
1716 vtkInformation* outInfo = outputVector->GetInformationObject(0);
1727 if (aSource == NULL)
1735 int extent[6] = { 0, static_cast<int>(frameSize[0]) - 1, 0, static_cast<int>(frameSize[1]) - 1, 0, static_cast<int>(frameSize[2]) - 1 };
1736 outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), extent, 6);
1740 double spacing[3] = { 1, 1, 1 };
1741 outInfo->Set(vtkDataObject::SPACING(), spacing, 3);
1742 double origin[3] = { 0, 0, 0 };
1743 outInfo->Set(vtkDataObject::ORIGIN(), origin, 3);
1746 vtkDataObject::SetPointDataActiveScalarInfo(outInfo, aSource->
GetPixelType(), 1);
1754 int vtkPlusDevice::RequestData(vtkInformation* vtkNotUsed(request), vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* vtkNotUsed(outputVector))
1767 if (aSource == NULL)
1774 LOCAL_LOG_DEBUG(
"Cannot request data from video source, the video buffer is empty or does not exist!");
1775 vtkImageData*
data = vtkImageData::SafeDownCast(this->GetOutputDataObject(0));
1777 data->SetExtent(0, frameSize[0] - 1, 0, frameSize[1] - 1, 0, frameSize[2] - 1);
1788 LOCAL_LOG_ERROR(
"Unable to copy video data to the requested output!");
1798 LOCAL_LOG_ERROR(
"Unable to copy video data to the requested output!");
1811 vtkImageData*
data = vtkImageData::SafeDownCast(this->GetOutputDataObject(0));
1812 FrameSizeType frameSize = { 0, 0, 0 };
1814 data->SetExtent(0, frameSize[0] - 1, 0, frameSize[1] - 1, 0, frameSize[2] - 1);
1817 unsigned char* outPtr = (
unsigned char*)
data->GetScalarPointer();
1818 memcpy(outPtr, sourcePtr, bytesToCopy);
1839 if (
x == frameSize[0] &&
y == frameSize[1] && z == frameSize[2])
1844 if (
x != 0 &&
y != 0 && z == 0)
1850 if (
x < 1 ||
y < 1 || z < 1)
1852 LOCAL_LOG_ERROR(
"SetInputFrameSize: Illegal frame size " <<
x <<
"x" <<
y <<
"x" << z);
1867 FrameSizeType dim = {0, 0, 0};
1901 FrameSizeType dim = {0, 0, 0};
1967 return US_IMG_TYPE_XX;
1990 LOCAL_LOG_ERROR(
"Failed to get first output channel - there are no output channels!");
2002 if (aChannelId == NULL)
2011 if (STRCASECMP(
channel->GetChannelId(), aChannelId) == 0)
2036 if (aChannel == NULL)
2038 LOCAL_LOG_ERROR(
"vtkPlusDevice::AddInputChannel failed: input channel is invalid");
2043 if (STRCASECMP((*it)->GetChannelId(), aChannel->
GetChannelId()) == 0)
2071 LOCAL_LOG_TRACE(
"vtkPlusDevice::InternalWriteOutputChannels( " << rootXMLElement->GetName() <<
")");
2084 LOCAL_LOG_TRACE(
"vtkPlusDevice::InternalWriteInputChannels( " << rootXMLElement->GetName() <<
")");
2097 for (DataSourceContainer::iterator it = begin(this->
Tools); it != end(this->
Tools); ++it)
2099 if (it->second->GetId() == aSourceId)
2106 if (it->second->GetId() == aSourceId)
2111 for (DataSourceContainer::iterator it = begin(this->
Fields); it != end(this->
Fields); ++it)
2113 if (it->second->GetId() == aSourceId)
2167 if (aVideo->GetId().empty())
2169 LOCAL_LOG_ERROR(
"Failed to add video to device, image Id must be defined!");
2178 if (aVideo->GetId() == it->second->GetId())
2180 LOCAL_LOG_ERROR(
"Failed to add '" << aVideo->GetId() <<
"' video to container: video with Id '" << it->second->GetId()
2181 <<
"' is already defined'!");
2186 aVideo->Register(
this);
2192 LOCAL_LOG_ERROR(
"Image with Id '" << aVideo->GetId() <<
"' is already in the image container!");
2204 LOCAL_LOG_ERROR(
"Failed to get first active video source - there are no video sources!");
2216 if (aSourceId == NULL)
2224 aVideoSource = this->
VideoSources.find(aSourceId)->second;
2234 std::vector<vtkPlusDataSource*> results;
2237 results.push_back(it->second);
2247 LOCAL_LOG_ERROR(
"Failed to get video source, index is outside of range.");
2248 aVideoSource = NULL;
2253 for (
unsigned int i = 0 ;
i < index; ++
i)
2257 aVideoSource = it->second;
2315 LOG_TRACE(
"vtkPlusDataCollectorFile::GetTrackerToolReferenceFrame");
2318 std::vector<igsioTransformName> transformNames;
2319 aFrame.GetFrameTransformNameList(transformNames);
2321 if (transformNames.size() == 0)
2323 LOG_ERROR(
"No transforms found in tracked frame!");
2327 std::string frameName =
"";
2328 for (std::vector<igsioTransformName>::iterator it = transformNames.begin(); it != transformNames.end(); ++it)
2330 if (frameName ==
"")
2332 frameName = it->To();
2334 else if (frameName != it->To())
2336 LOG_ERROR(
"Destination coordinate frame names are not the same!");
2341 aToolReferenceFrameName = frameName;
2349 LOCAL_LOG_ERROR(
"Calling base IsTracker. Override in the derived classes.");
2362 if (aChannel == NULL)
2372 aChannel->Register(
this);
2398 vtkSmartPointer<vtkPlusChannel> aChannel = vtkSmartPointer<vtkPlusChannel>::New();
2399 aChannel->SetOwnerDevice(
this);
2400 aChannel->SetChannelId(channelId != NULL ? channelId :
"OutputChannel");
2421 LOG_ERROR(
"Failed to set video buffer size!");
2433 aChannel->SetVideoSource(aDataSource);
2441 aVideoSource = NULL;
2444 LOCAL_LOG_ERROR(
"Failed to get first active output video source - there are no output channels");
2449 if ((*it)->GetVideoSource(aVideoSource) ==
PLUS_SUCCESS && aVideoSource != NULL)
2456 LOG_ERROR(
"There is no active video sources in the output channel(s)");
2468 PlusStatus vtkPlusDevice::GetImage(
const std::string& requestedImageId, std::string& assignedImageId,
const std::string& imageReferencFrameName, vtkImageData* imageData, vtkMatrix4x4* ijkToReferenceTransform)
DataSourceContainer::const_iterator DataSourceContainerConstIterator
PlusStatus GetDataSource(const char *aSourceId, vtkPlusDataSource *&aSource)
DataSourceContainerConstIterator GetVideoSourceIteratorBegin() const
static const int VIRTUAL_DEVICE_FRAME_RATE
#define LOCAL_LOG_INFO(msg)
std::string ToolReferenceFrameName
virtual PlusStatus SetInputFrameSize(vtkPlusDataSource &aSource, unsigned int x, unsigned int y, unsigned int z)
virtual PlusStatus SetBufferSize(int n)
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
PlusStatus AddInputChannel(vtkPlusChannel *aChannel)
virtual void SetLocalTimeOffsetSec(double aTimeOffsetSec)
static const std::string RFMODE_PORT_NAME
vtkPlusDataCollector * DataCollector
ToolStatus GetStatus() const
void DeepCopy(const vtkPlusDevice &device)
virtual unsigned long GetFrameNumber() const
virtual PlusStatus InternalStopRecording()
PlusStatus AddVideoSource(vtkPlusDataSource *anImage)
virtual void SetLocalTimeOffsetSec(double offsetSec)
virtual void InternalWriteOutputChannels(vtkXMLDataElement *rootXMLElement)
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aChannelElement)
Abstract interface for tracker and video devices.
US_IMAGE_TYPE GetImageType()
virtual void InternalWriteInputChannels(vtkXMLDataElement *rootXMLElement)
PlusStatus GetInputDevices(std::vector< vtkPlusDevice * > &outDeviceList) const
virtual double GetLocalTimeOffsetSec()
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *toolElement)
static const std::string PARAMETER_XML_ELEMENT_TAG
virtual int GetNumberOfVideoSources() const
virtual PlusStatus GetInputFrameSize(vtkPlusChannel &aChannel, unsigned int &x, unsigned int &y, unsigned int &z) const
vtkXMLDataElement * FindOutputChannelElement(vtkXMLDataElement *rootXMLElement, const char *aChannelId)
PlusStatus SetId(const char *aSourceId)
double GetMissingInputGracePeriodSec() const
PlusStatus EnsureUniqueDataSourceId(const std::string &aSourceId)
virtual ItemStatus GetStreamBufferItem(BufferItemUidType uid, StreamBufferItem *bufferItem)
vtkStandardNewMacro(vtkPlusDevice)
virtual PlusStatus ToolTimeStampedUpdateWithoutFiltering(const std::string &aToolSourceId, vtkMatrix4x4 *matrix, ToolStatus status, double unfilteredtimestamp, double filteredtimestamp, const igsioFieldMapType *customFields=NULL)
PlusStatus GetFirstOutputChannel(vtkPlusChannel *&aChannel)
virtual PlusStatus InternalConnect()
virtual PlusStatus StartRecording()
#define LOCAL_LOG_TRACE(msg)
virtual PlusStatus SetParameter(const std::string &key, const std::string &value)
void SetFieldDataSourcesBufferSize(int aBufferSize)
ChannelContainer InputChannels
static const std::string BMODE_PORT_NAME
PlusStatus GetVideoSourceByIndex(const unsigned int index, vtkPlusDataSource *&aVideoSource)
virtual std::string GetDeviceId() const
virtual bool IsTracker() const
PlusStatus AddTool(vtkPlusDataSource *tool, bool requireUniquePortName=true)
PlusStatus SetInputFrameSize(unsigned int x, unsigned int y, unsigned int z)
virtual PlusStatus ToolTimeStampedUpdate(const std::string &aToolSourceId, vtkMatrix4x4 *matrix, ToolStatus status, unsigned long frameNumber, double unfilteredtimestamp, const igsioFieldMapType *customFields=NULL)
double GetRecordingStartTime() const
std::vector< vtkPlusDataSource * > GetVideoSources() const
bool RequirePortNameInDeviceSetConfiguration
virtual std::string GetParameter(const std::string &key) const
DataSourceContainer VideoSources
std::map< std::string, std::string > Parameters
PlusStatus AddTimeStampedItem(vtkMatrix4x4 *matrix, ToolStatus status, unsigned long frameNumber, double unfilteredTimestamp, double filteredTimestamp=UNDEFINED_TIMESTAMP, const igsioFieldMapType *customFields=NULL)
PlusStatus GetInputDevicesRecursive(std::vector< vtkPlusDevice * > &outDeviceList) const
bool RequireImageOrientationInConfiguration
virtual unsigned int GetNumberOfScalarComponents()
PlusStatus SetImageType(US_IMAGE_TYPE imageType)
PlusStatus SetAcquisitionRate(double aRate)
virtual double GetStartTime()
virtual PlusStatus SetInputImageOrientation(US_IMAGE_ORIENTATION imageOrientation)
DataSourceContainer Tools
PlusStatus GetVideoSourcesByPortName(const char *aPortName, std::vector< vtkPlusDataSource * > &sources)
virtual int GetNumberOfTools() const
virtual std::string GetSdkVersion()
static std::string DATA_SOURCE_TYPE_FIELDDATA_TAG
PlusStatus SetPixelType(igsioCommon::VTKScalarPixelType pixelType)
virtual vtkPlusDataCollector * GetDataCollector()
virtual PlusStatus Probe()
double LocalTimeOffsetSec
vtkMultiThreader * Threader
static std::string DATA_SOURCE_TYPE_VIDEO_TAG
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
DataSourceContainer Fields
virtual PlusStatus SetPixelType(vtkPlusChannel &aChannel, igsioCommon::VTKScalarPixelType pixelType)
virtual double GetAcquisitionRate() const
virtual PlusStatus GetImageMetaData(igsioCommon::ImageMetaDataList &imageMetaDataItems)
PlusStatus GetOutputChannelByName(vtkPlusChannel *&aChannel, const char *aChannelId)
PlusStatus GetFirstVideoSource(vtkPlusDataSource *&anImage)
double GetFilteredTimestamp(double localTimeOffsetSec)
PlusStatus AddOutputChannel(vtkPlusChannel *aChannel)
virtual igsioCommon::VTKScalarPixelType GetPixelType()
virtual PlusStatus Disconnect()
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *)
virtual PlusStatus ForceUpdate()
PlusStatus GetFirstActiveOutputVideoSource(vtkPlusDataSource *&aVideoSource)
static igsioStatus Write(const std::string &filename, igsioTrackedFrame *frame, US_IMAGE_ORIENTATION orientationInFile=US_IMG_ORIENT_MF, bool useCompression=true, bool EnableImageDataWrite=true)
double MissingInputGracePeriodSec
virtual PlusStatus GetOutputFrameSize(vtkPlusChannel &aChannel, unsigned int &x, unsigned int &y, unsigned int &z) const
virtual bool GetCorrectlyConfigured() const
virtual PlusStatus Reset()
PlusStatus GetFirstActiveTool(vtkPlusDataSource *&aTool) const
unsigned long FrameNumber
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *)
ChannelContainerConstIterator GetOutputChannelsEnd() const
virtual BufferItemUidType GetOldestItemUidInBuffer()
Manages devices that record image or positional data.
PlusStatus GetToolByPortName(const char *aPortName, vtkPlusDataSource *&aSource)
PlusStatus AddFieldDataSource(vtkPlusDataSource *aSource)
virtual PlusStatus InternalStartRecording()
static PlusStatus GetToolReferenceFrameFromTrackedFrame(igsioTrackedFrame &aFrame, std::string &aToolReferenceFrameName)
DataSourceContainerConstIterator GetVideoSourceIteratorEnd() const
double RecordingStartTime
virtual PlusStatus SetBufferSize(vtkPlusChannel &aChannel, int FrameBufferSize, const std::string &aSourceId=std::string(""))
ChannelContainerConstIterator GetOutputChannelsStart() const
virtual PlusStatus Connect()
vtkIGSIORecursiveCriticalSection * UpdateMutex
vtkXMLDataElement * FindThisDeviceElement(vtkXMLDataElement *rootXMLElement)
virtual PlusStatus WriteToolsToSequenceFile(const std::string &filename, bool useCompression=false)
ChannelContainer::const_iterator ChannelContainerConstIterator
StreamBufferItem * CurrentStreamBufferItem
virtual void SetFrameNumber(unsigned long)
virtual PlusStatus GetImage(const std::string &requestedImageId, std::string &assignedImageId, const std::string &imageReferencFrameName, vtkImageData *imageData, vtkMatrix4x4 *ijkToReferenceTransform)
double InternalUpdateRate
void DeepCopy(const vtkPlusDataSource &source)
#define LOCAL_LOG_DEBUG(msg)
virtual int GetNumberOfFieldDataSources() const
virtual PlusStatus StopRecording()
PlusStatus GetMatrix(vtkMatrix4x4 *outputMatrix)
static const int FRAME_RATE_AVERAGING
void SetDevice(vtkPlusDevice *_arg)
static void * vtkDataCaptureThread(vtkMultiThreader::ThreadInfo *data)
double GetInternalUpdateRate() const
virtual char * GetChannelId()
virtual US_IMAGE_TYPE GetImageType(vtkPlusChannel &aChannel)
double GetUnfilteredTimestamp(double localTimeOffsetSec)
#define LOCAL_LOG_WARNING(msg)
DataSourceContainer::iterator DataSourceContainerIterator
virtual int GetBufferSize()
igsioVideoFrame & GetFrame()
int UpdateWithDesiredTimestamp
const char const char * value
virtual PlusStatus SetImageType(vtkPlusChannel &aChannel, US_IMAGE_TYPE imageType)
static std::string DATA_SOURCE_TYPE_TOOL_TAG
virtual bool IsRecording() const
virtual bool IsConnected() const
virtual ItemStatus GetLatestStreamBufferItem(StreamBufferItem *bufferItem)
virtual int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
bool StartThreadForInternalUpdates
virtual FrameSizeType GetOutputFrameSize() const
virtual void SetDataCollector(vtkPlusDataCollector *_arg)
DataSourceContainerConstIterator GetToolIteratorBegin() const
static const std::string PARAMETERS_XML_ELEMENT_TAG
virtual ItemStatus GetStreamBufferItemFromTime(double time, StreamBufferItem *bufferItem, vtkPlusBuffer::DataItemTemporalInterpolationType interpolation)
bool HasGracePeriodExpired()
virtual int GetConnected() const
virtual PlusStatus CreateDefaultOutputChannel(const char *channelId=NULL, bool addSource=true)
bool GetStartThreadForInternalUpdates() const
Contains an optional timestamped circular buffer containing the video images and a number of timestam...
virtual PlusStatus GetBufferSize(vtkPlusChannel &aChannel, int &outVal, const std::string &aSourceId=std::string(""))
ChannelContainer OutputChannels
virtual PlusStatus AddVideoItemToVideoSources(const std::vector< vtkPlusDataSource * > &videoSources, const igsioVideoFrame &frame, long frameNumber, double unfilteredTimestamp=UNDEFINED_TIMESTAMP, double filteredTimestamp=UNDEFINED_TIMESTAMP, const igsioFieldMapType *customFields=NULL)
virtual double GetLocalTimeOffsetSec() const
Direction vectors of rods y
virtual PlusStatus NotifyConfigured()
double TimestampClosestToDesired
virtual void SetStartTime(double startTime)
std::set< std::string > ReportedUnknownTools
static vtkPlusDataSource * New()
virtual igsioCommon::VTKScalarPixelType GetPixelType(vtkPlusChannel &aChannel)
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
std::string GetToolReferenceFrameName() const
void SetToolReferenceFrameName(const std::string &frameName)
virtual PlusStatus InternalDisconnect()
DataSourceContainerConstIterator GetFieldDataSourcessIteratorEnd() const
PlusStatus GetVideoSource(vtkPlusDataSource *&aVideoSource) const
PlusStatus GetVideoSource(const char *aSourceId, vtkPlusDataSource *&aVideoSource)
virtual bool IsVirtual() const
virtual int OutputChannelCount() const
PlusStatus GetTool(const char *aToolSourceId, vtkPlusDataSource *&aTool) const
ChannelContainer::iterator ChannelContainerIterator
vtkXMLDataElement * FindInputChannelElement(vtkXMLDataElement *rootXMLElement, const char *aChannelId)
unsigned long long BufferItemUidType
void SetOwnerDevice(vtkPlusDevice *_arg)
virtual PlusStatus SendText(const std::string &textToSend, std::string *textReceived=NULL)
FrameSizeType GetInputFrameSize() const
DataSourceContainerConstIterator GetToolIteratorEnd() const
DataSourceContainerConstIterator GetFieldDataSourcessIteratorBegin() const
vtkPlusDevice * GetOwnerDevice() const
virtual PlusStatus InternalUpdate()
void SetToolsBufferSize(int aBufferSize)
virtual bool IsResettable()
#define LOCAL_LOG_ERROR(msg)
virtual int GetNumberOfItems()
double GetTimestamp(double localTimeOffsetSec)
PlusStatus GetFieldDataSource(const char *aSourceId, vtkPlusDataSource *&aSource) const
void SetDeviceId(const std::string &id)
virtual double GetFrameTimeStamp() const
Interface to a 3D positioning tool, video source, or generalized data stream.