PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkDataCollectorVideoAcqTest.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 
12 #include "PlusConfigure.h"
13 #include "vtkPlusDataCollector.h"
14 #include "vtkPlusChannel.h"
15 #include "vtkPlusDataSource.h"
16 #include "vtkPlusDevice.h"
17 #include "vtkPlusBuffer.h"
18 #include "vtkSmartPointer.h"
19 #include "vtkTimerLog.h"
20 #include "vtkXMLUtilities.h"
21 #include "vtksys/CommandLineArguments.hxx"
22 #include "vtksys/SystemTools.hxx"
23 
24 int main(int argc, char **argv)
25 {
26  std::string inputConfigFileName;
27  double inputAcqTimeLength(60);
28  std::string outputVideoBufferSequenceFileName("VideoBufferMetafile");
29 
30  int verboseLevel=vtkPlusLogger::LOG_LEVEL_UNDEFINED;
31 
32  vtksys::CommandLineArguments args;
33  args.Initialize(argc, argv);
34 
35  args.AddArgument("--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFileName, "Name of the input configuration file.");
36  args.AddArgument("--acq-time-length", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputAcqTimeLength, "Length of acquisition time in seconds (Default: 60s)");
37  args.AddArgument("--output-video-buffer-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &outputVideoBufferSequenceFileName, "Filename of the output video bufffer sequence metafile (Default: VideoBufferMetafile)");
38  args.AddArgument("--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel, "Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
39 
40  if ( !args.Parse() )
41  {
42  std::cerr << "Problem parsing arguments" << std::endl;
43  std::cout << "Help: " << args.GetHelp() << std::endl;
44  exit(EXIT_FAILURE);
45  }
46 
47  vtkPlusLogger::Instance()->SetLogLevel(verboseLevel);
48 
49  if (inputConfigFileName.empty())
50  {
51  std::cerr << "config-file is required" << std::endl;
52  exit(EXIT_FAILURE);
53  }
54 
56  vtkSmartPointer<vtkXMLDataElement> configRootElement = vtkSmartPointer<vtkXMLDataElement>::New();
57  if (PlusXmlUtils::ReadDeviceSetConfigurationFromFile(configRootElement, inputConfigFileName.c_str())==PLUS_FAIL)
58  {
59  LOG_ERROR("Unable to read configuration from file " << inputConfigFileName.c_str());
60  return EXIT_FAILURE;
61  }
62 
63  vtkSmartPointer<vtkPlusDataCollector> dataCollector = vtkSmartPointer<vtkPlusDataCollector>::New();
64  dataCollector->ReadConfiguration( configRootElement );
65  dataCollector->Connect();
66  dataCollector->Start();
67 
68  const double acqStartTime = vtkTimerLog::GetUniversalTime();
69 
70  while ( acqStartTime + inputAcqTimeLength > vtkTimerLog::GetUniversalTime() )
71  {
72  LOG_INFO( acqStartTime + inputAcqTimeLength - vtkTimerLog::GetUniversalTime() << " seconds left..." );
73  vtksys::SystemTools::Delay(1000);
74  }
75 
76 
77  LOG_INFO("Copy video buffer");
78  vtkPlusBuffer* buffer = vtkPlusBuffer::New();
79  vtkPlusDevice* device = NULL;
80  if( dataCollector->GetDevice(device, "VideoDevice") != PLUS_SUCCESS )
81  {
82  LOG_ERROR("Unable to locate the device with Id=\"SomeVideoSource\". Check config file.");
83  exit(EXIT_FAILURE);
84  }
85  vtkPlusChannel* aChannel(NULL);
86  vtkPlusDataSource* aSource(NULL);
87  if( device->GetOutputChannelByName(aChannel, "VideoStream") == PLUS_SUCCESS && aChannel->GetVideoSource(aSource) == PLUS_SUCCESS )
88  {
89  aSource->DeepCopyBufferTo(*buffer);
90 
91  LOG_INFO("write video buffer to " << outputVideoBufferSequenceFileName);
92  buffer->WriteToSequenceFile(outputVideoBufferSequenceFileName.c_str(), true);
93 
94  buffer->Delete();
95 
96  std::cout << "Test completed successfully!" << std::endl;
97  return EXIT_SUCCESS;
98  }
99  else
100  {
101  LOG_ERROR("Unable to retrieve the video source.");
102  exit(EXIT_FAILURE);
103  }
104 }
105 
Abstract interface for tracker and video devices.
Definition: vtkPlusDevice.h:60
static vtkPlusBuffer * New()
#define PLUS_FAIL
Definition: PlusCommon.h:43
PlusStatus GetOutputChannelByName(vtkPlusChannel *&aChannel, const char *aChannelId)
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
virtual PlusStatus DeepCopyBufferTo(vtkPlusBuffer &bufferToFill)
int main(int argc, char **argv)
static vtkIGSIOLogger * Instance()
Contains an optional timestamped circular buffer containing the video images and a number of timestam...
PlusStatus GetVideoSource(vtkPlusDataSource *&aVideoSource) const
virtual PlusStatus WriteToSequenceFile(const char *filename, bool useCompression=false)
static PlusStatus ReadDeviceSetConfigurationFromFile(vtkXMLDataElement *config, const char *filename)
Definition: PlusXmlUtils.h:23
Interface to a 3D positioning tool, video source, or generalized data stream.