PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkNvidiaDVPVideoSourceTest.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 #include "PlusConfigure.h"
8 #include "vtkCallbackCommand.h"
9 #if WIN32
10 #include "vtkPlusNvidiaDVPVideoSourceWin32.h"
11 #elif __linux__
12 #include "vtkPlusNvidiaDVPVideoSourceLinux.h"
13 #endif
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  bool renderingOff( false );
23 
24  vtksys::CommandLineArguments args;
25  args.Initialize( argc, argv );
26 
27  int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
28 
29  args.AddArgument( "--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp, "Print this help." );
30  args.AddArgument( "--rendering-off", vtksys::CommandLineArguments::NO_ARGUMENT, &renderingOff, "Run test without rendering." );
31  args.AddArgument( "--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel, "Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)" );
32 
33  if ( !args.Parse() )
34  {
35  std::cerr << "Problem parsing arguments" << std::endl;
36  std::cout << "\n\nvtkPlusNvidiaDVPVideoSourceTest help:" << args.GetHelp() << std::endl;
37  exit( EXIT_FAILURE );
38  }
39 
40  vtkPlusLogger::Instance()->SetLogLevel( verboseLevel );
41 
42  if ( printHelp )
43  {
44  std::cout << "\n\nvtkPlusNvidiaDVPVideoSourceTest help:" << args.GetHelp() << std::endl;
45  exit( EXIT_SUCCESS );
46 
47  }
48 
49  vtkSmartPointer<vtkPlusNvidiaDVPVideoSource> dvpDevice = vtkSmartPointer<vtkPlusNvidiaDVPVideoSource>::New();
50 
51  // Add an observer to warning and error events for redirecting it to the stdout
52  vtkSmartPointer<vtkCallbackCommand> callbackCommand = vtkSmartPointer<vtkCallbackCommand>::New();
53  callbackCommand->SetCallback( PrintLogsCallback );
54  dvpDevice->AddObserver( "WarningEvent", callbackCommand );
55  dvpDevice->AddObserver( "ErrorEvent", callbackCommand );
56 
57  LOG_INFO( "Initialize..." );
58  dvpDevice->Connect();
59 
60  if ( dvpDevice->GetConnected() )
61  {
62  LOG_INFO( "Start recording..." );
63  dvpDevice->StartRecording();
64  }
65  else
66  {
67  dvpDevice->Disconnect();
68  LOG_ERROR( "Unable to connect to IC capture device" );
69  exit( EXIT_FAILURE );
70  }
71 
72  // TODO : make some graphics API specific calls to test data acquisition
73 
74  dvpDevice->StopRecording();
75  dvpDevice->Disconnect();
76  LOG_INFO( "Exit successfully" );
77  exit( EXIT_SUCCESS );
78 }
79 
80 // Callback function for error and warning redirects
81 void PrintLogsCallback( vtkObject* obj, unsigned long eid, void* clientdata, void* calldata )
82 {
83  if ( eid == vtkCommand::GetEventIdFromString( "WarningEvent" ) )
84  {
85  LOG_WARNING( ( const char* )calldata );
86  }
87  else if ( eid == vtkCommand::GetEventIdFromString( "ErrorEvent" ) )
88  {
89  LOG_ERROR( ( const char* )calldata );
90  }
91 }
int main(int argc, char **argv)
static vtkIGSIOLogger * Instance()
void PrintLogsCallback(vtkObject *obj, unsigned long eid, void *clientdata, void *calldata)