13 #include "PlusConfigure.h" 22 #include <vtkSmartPointer.h> 23 #include <vtkTimerLog.h> 24 #include <vtkXMLUtilities.h> 25 #include <vtksys/CommandLineArguments.hxx> 26 #include <vtksys/SystemTools.hxx> 28 int main(
int argc,
char** argv)
30 int numberOfFailures(0);
31 std::string inputConfigFileName;
32 double inputAcqTimeLength(20);
33 std::string outputTrackerBufferSequenceFileName(
"TrackerBufferMetafile.nrrd");
34 std::string outputVideoBufferSequenceFileName(
"VideoBufferMetafile.nrrd");
35 std::string inputVideoBufferMetafile;
36 std::string inputTrackerBufferMetafile;
37 bool outputCompressed(
true);
39 int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
41 vtksys::CommandLineArguments args;
42 args.Initialize(argc, argv);
44 args.AddArgument(
"--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFileName,
"Name of the input configuration file.");
45 args.AddArgument(
"--acq-time-length", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputAcqTimeLength,
"Length of acquisition time in seconds (Default: 20s)");
46 args.AddArgument(
"--video-buffer-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputVideoBufferMetafile,
"Video buffer sequence metafile.");
47 args.AddArgument(
"--tracker-buffer-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputTrackerBufferMetafile,
"Tracker buffer sequence metafile.");
48 args.AddArgument(
"--output-tracker-buffer-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &outputTrackerBufferSequenceFileName,
"Filename of the output tracker buffer sequence metafile (Default: TrackerBufferMetafile)");
49 args.AddArgument(
"--output-video-buffer-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &outputVideoBufferSequenceFileName,
"Filename of the output video buffer sequence metafile (Default: VideoBufferMetafile)");
50 args.AddArgument(
"--output-compressed", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &outputCompressed,
"Compressed output (0=non-compressed, 1=compressed, default:compressed)");
51 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
55 std::cerr <<
"Problem parsing arguments" << std::endl;
56 std::cout <<
"Help: " << args.GetHelp() << std::endl;
62 if (inputConfigFileName.empty())
64 std::cerr <<
"input-config-file-name is required" << std::endl;
70 vtkSmartPointer<vtkXMLDataElement> configRootElement = vtkSmartPointer<vtkXMLDataElement>::New();
73 LOG_ERROR(
"Unable to read configuration from file " << inputConfigFileName.c_str());
79 vtkSmartPointer<vtkPlusDataCollector> dataCollector = vtkSmartPointer<vtkPlusDataCollector>::New();
81 if (dataCollector->ReadConfiguration(configRootElement) !=
PLUS_SUCCESS)
83 LOG_ERROR(
"Unable to configure data collector in configuration file specified by: " << inputConfigFileName);
89 if (!inputVideoBufferMetafile.empty())
91 if (dataCollector->GetDevice(videoDevice,
"VideoDevice") !=
PLUS_SUCCESS)
93 LOG_ERROR(
"Unable to locate the device with Id=\"VideoDevice\". Check config file.");
97 if (videoSource == NULL)
99 LOG_ERROR(
"Unable to cast device to vtkPlusSavedDataSource.");
105 if (!inputTrackerBufferMetafile.empty())
107 if (dataCollector->GetDevice(trackerDevice,
"TrackerDevice") !=
PLUS_SUCCESS)
109 LOG_ERROR(
"Unable to locate the device with Id=\"TrackerDevice\". Check config file.");
115 LOG_ERROR(
"Unable to cast tracker to vtkPlusSavedDataSource");
123 LOG_ERROR(
"Failed to connect to data collector!");
129 LOG_ERROR(
"Failed to start data collection");
133 const double acqStartTime = vtkTimerLog::GetUniversalTime();
135 while (acqStartTime + inputAcqTimeLength > vtkTimerLog::GetUniversalTime())
137 LOG_INFO(acqStartTime + inputAcqTimeLength - vtkTimerLog::GetUniversalTime() <<
" seconds left...");
138 vtksys::SystemTools::Delay(1000);
141 vtkSmartPointer<vtkPlusBuffer> videobuffer = vtkSmartPointer<vtkPlusBuffer>::New();
146 LOG_ERROR(
"Unable to retrieve the video source.");
152 vtkSmartPointer<vtkPlusDevice> tracker = vtkSmartPointer<vtkPlusDevice>::New();
153 if (trackerDevice != NULL)
155 LOG_INFO(
"Copy tracker");
156 tracker->DeepCopy(*trackerDevice);
159 if (videoDevice != NULL)
162 LOG_INFO(
"Write video buffer to " << fullPath);
163 videobuffer->WriteToSequenceFile(fullPath.c_str(), outputCompressed);
166 if (trackerDevice != NULL)
169 LOG_INFO(
"Write tracker buffer to " << fullPath);
170 tracker->WriteToolsToSequenceFile(fullPath.c_str(), outputCompressed);
173 if (videoDevice != NULL)
176 if (vtksys::SystemTools::FileExists(fullPath.c_str(),
true))
178 LOG_INFO(
"Remove generated video metafile!");
179 if (!vtksys::SystemTools::RemoveFile(fullPath.c_str()))
181 LOG_ERROR(
"Unable to remove generated video buffer: " << fullPath);
187 LOG_ERROR(
"Unable to find video buffer at: " << fullPath);
192 if (trackerDevice != NULL)
195 if (vtksys::SystemTools::FileExists(fullPath.c_str(),
true))
197 LOG_INFO(
"Remove generated tracker metafile!");
198 if (!vtksys::SystemTools::RemoveFile(fullPath.c_str()))
200 LOG_ERROR(
"Unable to remove generated tracker buffer: " << fullPath);
206 LOG_ERROR(
"Unable to find tracker buffer at: " << fullPath);
213 LOG_ERROR(
"Failed to stop data collection!");
217 if (numberOfFailures > 0)
219 LOG_ERROR(
"Number of failures: " << numberOfFailures);
223 std::cout <<
"Test completed successfully!" << std::endl;
std::string GetOutputPath(const std::string &subPath)
Abstract interface for tracker and video devices.
static vtkPlusConfig * GetInstance()
PlusStatus GetOutputChannelByName(vtkPlusChannel *&aChannel, const char *aChannelId)
int main(int argc, char **argv)
virtual PlusStatus DeepCopyBufferTo(vtkPlusBuffer &bufferToFill)
virtual void SetSequenceFile(const char *)
Class for providing VTK video input interface from sequence fileAttributes:
static vtkIGSIOLogger * Instance()
Contains an optional timestamped circular buffer containing the video images and a number of timestam...
PlusStatus GetVideoSource(vtkPlusDataSource *&aVideoSource) const
void SetDeviceSetConfigurationData(vtkXMLDataElement *deviceSetConfigurationData)
static PlusStatus ReadDeviceSetConfigurationFromFile(vtkXMLDataElement *config, const char *filename)
Interface to a 3D positioning tool, video source, or generalized data stream.