7 #include "PlusConfigure.h" 9 #include "igsioTrackedFrame.h" 12 #include "vtkObjectFactory.h" 15 #include "vtkIGSIOTrackedFrameList.h" 17 #include "vtkIGSIOTransformRepository.h" 18 #include "vtksys/SystemTools.hxx" 27 , LastProcessedInputDataTimestamp(0)
28 , EnableProcessing(true)
29 , ProcessingAlgorithmAccessMutex(vtkSmartPointer<vtkIGSIORecursiveCriticalSection>::New())
31 , ProcessorAlgorithm(NULL)
72 LOG_ERROR(
"Failed to read transform repository configuration");
82 int numberOfNestedElements = deviceConfig->GetNumberOfNestedElements();
83 for (
int nestedElemIndex = 0; nestedElemIndex < numberOfNestedElements; ++nestedElemIndex)
85 vtkXMLDataElement* processorElement = deviceConfig->GetNestedElement(nestedElemIndex);
95 LOG_WARNING(
"Multiple " << processorElement->GetName() <<
" elements found in ImageProcessor configuration. Only the first one is used, all others are ignored");
100 const char* processorType = processorElement->GetAttribute(
"Type");
101 if (processorType == NULL)
103 LOG_ERROR(
"Type attribute of Processor element is missing");
108 vtkSmartPointer<vtkPlusBoneEnhancer> boneEnhancer = vtkSmartPointer<vtkPlusBoneEnhancer>::New();
109 vtkSmartPointer<vtkPlusTransverseProcessEnhancer> TransverseProcessEnhancer = vtkSmartPointer<vtkPlusTransverseProcessEnhancer>::New();
110 if (!(STRCASECMP(boneEnhancer->GetProcessorTypeName(), processorType)))
113 boneEnhancer->ReadConfiguration(processorElement);
118 else if (!(STRCASECMP(TransverseProcessEnhancer->GetProcessorTypeName(), processorType)))
121 TransverseProcessEnhancer->ReadConfiguration(processorElement);
128 LOG_ERROR(
"Unknown processor type: " << processorType);
140 deviceElement->SetAttribute(
"EnableCapturing", this->
EnableProcessing ?
"TRUE" :
"FALSE");
146 if (processorElement == NULL)
156 vtkXMLDataElement* processorElement = NULL;
159 deviceElement->RemoveNestedElement(processorElement);
169 bool lowestRateKnown =
false;
170 double lowestRate = 30;
177 lowestRateKnown =
true;
186 LOG_WARNING(
"vtkPlusImageProcessorVideoSource acquisition rate is not known");
213 LOG_ERROR(
"ImageProcessor device requires exactly 1 input stream (that contains video data). Check configuration.");
228 double oldestTrackingTimestamp(0);
233 LOG_INFO(
"Processed image generation started. No tracking data was available between " << this->
LastProcessedInputDataTimestamp <<
"-" << oldestTrackingTimestamp <<
234 "sec, therefore no processed images were generated during this time period.");
238 igsioTrackedFrame trackedFrame;
246 LOG_TRACE(
"Image to be processed: timestamp=" << trackedFrame.GetTimestamp());
250 LOG_ERROR(
"No output channels defined");
254 double latestFrameAlreadyAddedTimestamp = 0;
257 double frameTimestamp = trackedFrame.GetTimestamp();
258 if (latestFrameAlreadyAddedTimestamp >= frameTimestamp)
264 vtkSmartPointer<vtkIGSIOTrackedFrameList> trackingFrames = vtkSmartPointer<vtkIGSIOTrackedFrameList>::New();
265 trackingFrames->AddTrackedFrame(&trackedFrame);
275 LOG_ERROR(
"Unable to retrieve the video source in the image processor device.");
282 if (processedFrames == NULL || processedFrames->GetNumberOfTrackedFrames() < 1)
284 LOG_ERROR(
"Failed to retrieve processed frame");
288 igsioTrackedFrame* processedTrackedFrame = processedFrames->GetTrackedFrame(0);
295 igsioVideoFrame* videoFrame = processedTrackedFrame->GetImageData();
296 if (videoFrame == NULL)
298 LOG_ERROR(
"Invalid video frame received, cannot use it to initialize the video buffer");
301 aSource->
SetPixelType(videoFrame->GetVTKScalarPixelType());
302 unsigned int numberOfScalarComponents(1);
303 if (videoFrame->GetNumberOfScalarComponents(numberOfScalarComponents) !=
PLUS_SUCCESS)
305 LOG_ERROR(
"Unable to retrieve number of scalar components.");
313 igsioFieldMapType customFields = processedTrackedFrame->GetCustomFields();
328 LOG_ERROR(
"No output channels defined for ImageProcessor");
335 LOG_WARNING(
"ImageProcessor is expecting one output channel and there are " << this->
OutputChannels.size() <<
" channels. First output channel will be used.");
340 LOG_ERROR(
"No input channel is set for ImageProcessor");
353 if (processingStartsNow)
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
virtual vtkIGSIOTrackedFrameList * GetOutputFrames()
virtual PlusStatus Update()
double LastProcessedInputDataTimestamp
vtkStandardNewMacro(vtkPlusImageProcessorVideoSource)
Abstract interface for tracker and video devices.
virtual ~vtkPlusImageProcessorVideoSource()
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_WRITING(deviceConfig, rootConfigElement)
Virtual device that performs real-time image processing on the input channel.
Class to abstract away specific sequence file read/write details.
ChannelContainer InputChannels
vtkPlusImageProcessorVideoSource()
virtual std::string GetDeviceId() const
PlusStatus SetInputFrameSize(unsigned int x, unsigned int y, unsigned int z)
virtual PlusStatus InternalDisconnect()
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)
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
PlusStatus SetImageType(US_IMAGE_TYPE imageType)
virtual PlusStatus NotifyConfigured()
PlusStatus SetPixelType(igsioCommon::VTKScalarPixelType pixelType)
virtual double GetAcquisitionRate() const
vtkPlusLogger::LogLevelType GracePeriodLogLevel
double MissingInputGracePeriodSec
virtual void SetCorrectlyConfigured(bool)
unsigned long FrameNumber
double RecordingStartTime
virtual PlusStatus GetMostRecentTimestamp(double &ts)
ChannelContainer::const_iterator ChannelContainerConstIterator
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_READING(deviceConfig, rootConfigElement)
vtkPlusTrackedFrameProcessor * ProcessorAlgorithm
virtual PlusStatus InternalConnect()
vtkSmartPointer< vtkIGSIORecursiveCriticalSection > ProcessingAlgorithmAccessMutex
bool StartThreadForInternalUpdates
void SetEnableProcessing(bool aValue)
bool HasGracePeriodExpired()
Contains an optional timestamped circular buffer containing the video images and a number of timestam...
virtual void SetInputFrames(vtkIGSIOTrackedFrameList *inputFrames)
ChannelContainer OutputChannels
PlusStatus SetNumberOfScalarComponents(unsigned int numberOfScalarComponents)
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *)
virtual PlusStatus InternalUpdate()
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *processingElement)
static const char * GetTagName()
PlusStatus GetVideoSource(vtkPlusDataSource *&aVideoSource) const
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *)
virtual void SetTransformRepository(vtkIGSIOTransformRepository *transformRepository)
vtkPlusDevice * GetOwnerDevice() const
vtkIGSIOTransformRepository * TransformRepository
virtual int GetNumberOfItems()
Interface to a 3D positioning tool, video source, or generalized data stream.