PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkOvrvisionProVideoSourceTest.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 
7 // Local includes
8 #include "PlusConfigure.h"
10 #include "vtkPlusDataSource.h"
11 
12 // VTK includes
13 #include <vtkCallbackCommand.h>
14 #include <vtkSmartPointer.h>
15 #include <vtksys/CommandLineArguments.hxx>
16 
17 void PrintLogsCallback( vtkObject* obj, unsigned long eid, void* clientdata, void* calldata );
18 
19 int main( int argc, char** argv )
20 {
21  bool printHelp( false );
22  std::string inputConfigFileName;
23  bool renderingOff( false );
24 
25  vtksys::CommandLineArguments args;
26  args.Initialize( argc, argv );
27 
28  int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
29 
30  args.AddArgument( "--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp, "Print this help." );
31  args.AddArgument("--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFileName, "Config file containing the device configuration.");
32  args.AddArgument( "--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel, "Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)" );
33 
34  if ( !args.Parse() )
35  {
36  std::cerr << "Problem parsing arguments" << std::endl;
37  std::cout << "\n\nvtkPlusOvrvisionProVideoSourceTest help:" << args.GetHelp() << std::endl;
38  exit( EXIT_FAILURE );
39  }
40 
41  vtkPlusLogger::Instance()->SetLogLevel( verboseLevel );
42 
43  if ( printHelp )
44  {
45  std::cout << "\n\nvtkPlusOvrvisionProVideoSourceTest help:" << args.GetHelp() << std::endl;
46  exit( EXIT_SUCCESS );
47  }
48 
49  // Read config file
50  LOG_DEBUG("Reading config file...");
51  vtkSmartPointer<vtkXMLDataElement> configRootElement = vtkSmartPointer<vtkXMLDataElement>::New();
52  if (PlusXmlUtils::ReadDeviceSetConfigurationFromFile(configRootElement, inputConfigFileName.c_str()) == PLUS_FAIL)
53  {
54  LOG_ERROR("Unable to read configuration from file " << inputConfigFileName.c_str());
55  return EXIT_FAILURE;
56  }
57 
58  vtkSmartPointer<vtkPlusOvrvisionProVideoSource> device = vtkSmartPointer<vtkPlusOvrvisionProVideoSource>::New();
59  device->SetDeviceId("OvrvisionPro");
60 
61  // Add an observer to warning and error events for redirecting it to the stdout
62  vtkSmartPointer<vtkCallbackCommand> callbackCommand = vtkSmartPointer<vtkCallbackCommand>::New();
63  callbackCommand->SetCallback( PrintLogsCallback );
64  device->AddObserver( "WarningEvent", callbackCommand );
65  device->AddObserver( "ErrorEvent", callbackCommand );
66 
67  device->ReadConfiguration(configRootElement);
68 
69  LOG_INFO( "Initialize..." );
70  device->Connect();
71 
72  Sleep( 1000 ); // Wait a bit
73 
74  auto channel = *device->GetOutputChannelsStart();
75  if ( channel == nullptr )
76  {
77  LOG_ERROR("No channel configured for device.");
78  exit(EXIT_FAILURE);
79  }
80 
81  igsioTrackedFrame frame;
82  if (channel->GetTrackedFrame(frame) != PLUS_SUCCESS)
83  {
84  LOG_ERROR("Unable to retrieve frame from device.");
85  exit(EXIT_FAILURE);
86  }
87 
88  // TODO : some sort of image validation?
89 
90  device->Disconnect();
91  LOG_INFO( "Exit successfully" );
92  exit( EXIT_SUCCESS );
93 }
94 
95 // Callback function for error and warning redirects
96 void PrintLogsCallback( vtkObject* obj, unsigned long eid, void* clientdata, void* calldata )
97 {
98  if ( eid == vtkCommand::GetEventIdFromString( "WarningEvent" ) )
99  {
100  LOG_WARNING( ( const char* )calldata );
101  }
102  else if ( eid == vtkCommand::GetEventIdFromString( "ErrorEvent" ) )
103  {
104  LOG_ERROR( ( const char* )calldata );
105  }
106 }
int * channel
Definition: phidget22.h:1303
#define PLUS_FAIL
Definition: PlusCommon.h:43
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
int main(int argc, char **argv)
void PrintLogsCallback(vtkObject *obj, unsigned long eid, void *clientdata, void *calldata)
static vtkIGSIOLogger * Instance()
static PlusStatus ReadDeviceSetConfigurationFromFile(vtkXMLDataElement *config, const char *filename)
Definition: PlusXmlUtils.h:23