PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPhilips3DProbeVideoSourceTest1.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 
18 #include "PlusConfigure.h"
19 #include "vtkCallbackCommand.h"
20 #include "vtkImageData.h"
22 #include "vtkPlusChannel.h"
23 #include "vtkIGSIOTrackedFrameList.h"
24 #include "vtkXMLUtilities.h"
25 #include "vtksys/CommandLineArguments.hxx"
26 #include <stdlib.h>
27 
28 //----------------------------------------------------------------------------
29 
30 int main(int argc, char* argv[])
31 {
32  bool printHelp(false);
33  std::string inputConfigFileName;
34  std::string inputPhilipsIp;
35 
36  vtksys::CommandLineArguments args;
37  args.Initialize(argc, argv);
38 
39  int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
40 
41  args.AddArgument("--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp, "Print this help.");
42  args.AddArgument("--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFileName, "Config file containing the device configuration.");
43  args.AddArgument("--philips-ip", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputPhilipsIp, "IP address of the Philips scanner (overrides the IP address parameter defined in the config file).");
44  args.AddArgument("--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel, "Verbose level 1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
45 
46  if ( !args.Parse() )
47  {
48  std::cerr << "Problem parsing arguments" << std::endl;
49  std::cout << "\n\nvtkPlusPhilips3DProbeVideoSourceTest1 help:" << args.GetHelp() << std::endl;
50  exit(EXIT_FAILURE);
51  }
52 
53  vtkPlusLogger::Instance()->SetLogLevel(verboseLevel);
54 
55  if ( printHelp )
56  {
57  std::cout << "\n\nvtkPlusPhilips3DProbeVideoSourceTest1 help:" << args.GetHelp() << std::endl;
58  exit(EXIT_SUCCESS);
59  }
60 
61  // Read config file
62  LOG_DEBUG("Reading config file...");
63  vtkSmartPointer<vtkXMLDataElement> configRootElement = vtkSmartPointer<vtkXMLDataElement>::New();
64  if (PlusXmlUtils::ReadDeviceSetConfigurationFromFile(configRootElement, inputConfigFileName.c_str())==PLUS_FAIL)
65  {
66  LOG_ERROR("Unable to read configuration from file " << inputConfigFileName.c_str());
67  return EXIT_FAILURE;
68  }
69 
70  vtkSmartPointer<vtkPlusPhilips3DProbeVideoSource> philipsDevice = vtkSmartPointer<vtkPlusPhilips3DProbeVideoSource>::New();
71  philipsDevice->SetDeviceId("VideoDevice");
72  philipsDevice->ReadConfiguration(configRootElement);
73 
74  if (!inputPhilipsIp.empty())
75  {
76  philipsDevice->SetIPAddress(inputPhilipsIp.c_str());
77  }
78 
79  if ( philipsDevice->Connect() != PLUS_SUCCESS )
80  {
81  LOG_ERROR( "Unable to connect to Philips ie33 machine at " << philipsDevice->GetIPAddress() << ":" << philipsDevice->GetPort() );
82  exit(EXIT_FAILURE);
83  }
84 
85  philipsDevice->StartRecording();
86 
87  // just run the recording for a few seconds then exit
88  LOG_DEBUG("Rendering disabled. Wait for just a few seconds to acquire data before exiting");
89 #ifdef _WIN32
90  Sleep(3*1000);
91 #else
92  usleep(3 * 1000000);
93 #endif
94 
95  vtkSmartPointer<vtkIGSIOTrackedFrameList> frameList = vtkSmartPointer<vtkIGSIOTrackedFrameList>::New();
96  vtkPlusChannel* channel = *philipsDevice->GetOutputChannelsStart();
97 
98  double oldTimestamp(0.0);
99  channel->GetOldestTimestamp(oldTimestamp);
100  channel->GetTrackedFrameList(oldTimestamp, frameList, 30);
101 
102  philipsDevice->StopRecording();
103  philipsDevice->Disconnect();
104 
105  return EXIT_SUCCESS;
106 }
107 
int * channel
Definition: phidget22.h:1303
#define PLUS_FAIL
Definition: PlusCommon.h:43
int main(int argc, char *argv[])
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
static vtkIGSIOLogger * Instance()
Contains an optional timestamped circular buffer containing the video images and a number of timestam...
static PlusStatus ReadDeviceSetConfigurationFromFile(vtkXMLDataElement *config, const char *filename)
Definition: PlusXmlUtils.h:23