PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkUSDigitalEncodersTrackerTest.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 "vtkCommand.h"
14 #include "vtkPlusDataCollector.h"
15 #include "vtkMatrix4x4.h"
16 #include "vtkPlusChannel.h"
17 #include "vtkPlusDataSource.h"
18 #include "vtkPlusDevice.h"
19 #include "vtkSmartPointer.h"
21 #include "vtkXMLUtilities.h"
22 #include "vtksys/CommandLineArguments.hxx"
23 #include "vtksys/SystemTools.hxx"
24 
25 int main(int argc, char** argv)
26 {
27  bool printHelp(false);
28  std::string inputConfigFileName = "USDigitalEncodersTracker.xml";
29  std::string inputToolSourceId;
30  double inputAcqTimeLength(60);
31  std::string outputTrackerBufferSequenceFileName;
32  bool renderingOff(false);
33 
34  int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
35 
36  vtksys::CommandLineArguments args;
37  args.Initialize(argc, argv);
38 
39  args.AddArgument("--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp, "Print this help.");
40  args.AddArgument("--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFileName, "Name of the input configuration file.");
41  args.AddArgument("--tool-name", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputToolSourceId, "Will print the actual transform of this tool (names were defined in the config file, default is the first active tool)");
42  args.AddArgument("--acq-time-length", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputAcqTimeLength, "Length of acquisition time in seconds (Default: 60s)");
43  args.AddArgument("--output-tracker-buffer-seq-file-name", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &outputTrackerBufferSequenceFileName, "Filename of the output tracker bufffer sequence metafile (Default: TrackerBufferMetafile)");
44  args.AddArgument("--rendering-off", vtksys::CommandLineArguments::NO_ARGUMENT, &renderingOff, "Run test without rendering.");
45  args.AddArgument("--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel, "Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
46 
47  if(!args.Parse())
48  {
49  std::cerr << "Problem parsing arguments" << std::endl;
50  std::cout << "Help: " << args.GetHelp() << std::endl;
51  exit(EXIT_FAILURE);
52  }
53 
54  if(printHelp)
55  {
56  std::cout << args.GetHelp() << std::endl;
57  exit(EXIT_SUCCESS);
58  }
59 
60  vtkPlusLogger::Instance()->SetLogLevel(verboseLevel);
61 
62  if(inputConfigFileName.empty())
63  {
64  std::cerr << "--config-file is required" << std::endl;
65  exit(EXIT_FAILURE);
66  }
67 
69 
70  vtkSmartPointer< vtkPlusUSDigitalEncodersTracker > usDigitalEncodersTracker =
71  vtkSmartPointer< vtkPlusUSDigitalEncodersTracker >::New();
72 
73  vtkSmartPointer<vtkXMLDataElement> configRootElement = vtkSmartPointer<vtkXMLDataElement>::New();
74  if(PlusXmlUtils::ReadDeviceSetConfigurationFromFile(configRootElement, inputConfigFileName.c_str()) == PLUS_FAIL)
75  {
76  LOG_ERROR("Unable to read configuration from file " << inputConfigFileName.c_str());
77  return EXIT_FAILURE;
78  }
79 
80  usDigitalEncodersTracker->ReadConfiguration(configRootElement);
81 
82  if(usDigitalEncodersTracker->Connect() != PLUS_SUCCESS)
83  {
84  LOG_ERROR("Unable to connect to US Digital encoders!");
85  exit(EXIT_FAILURE);
86  }
87 
88  usDigitalEncodersTracker->StartRecording();
89 
90  bool bTask = true;
91  std::string inputMessage;
92  while(bTask)
93  {
94  std::getline(std::cin, inputMessage);
95  std::cout << " Input :: " << inputMessage << std::endl;
96  if(inputMessage.find("quit") != std::string::npos)
97  {
98  bTask = false;
99  break;
100  }
101  }
102 
103  usDigitalEncodersTracker->StopRecording();
104  usDigitalEncodersTracker->Disconnect();
105 
106  std::cout << "Test completed successfully!" << std::endl;
107  return EXIT_SUCCESS;
108 }
#define PLUS_FAIL
Definition: PlusCommon.h:43
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
static vtkIGSIOLogger * Instance()
int main(int argc, char **argv)
static PlusStatus ReadDeviceSetConfigurationFromFile(vtkXMLDataElement *config, const char *filename)
Definition: PlusXmlUtils.h:23