PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkIntelRealSenseCamTest.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 "vtksys/CommandLineArguments.hxx"
9 #include "vtkPlusIntelRealSenseCamera.h"
10 #include "vtkImageData.h"
11 #include "vtkImageViewer2.h"
12 #include "vtkRenderWindowInteractor.h"
13 #include "vtkRenderer.h"
14 #include "vtkSmartPointer.h"
15 #include "vtkCommand.h"
16 #include "vtkCallbackCommand.h"
17 
18 void PrintLogsCallback(vtkObject* obj, unsigned long eid, void* clientdata, void* calldata);
19 
20 class vtkMyCallback : public vtkCommand
21 {
22 public:
23  static vtkMyCallback *New()
24  {return new vtkMyCallback;}
25  virtual void Execute(vtkObject *caller, unsigned long, void*)
26  {
27  viewer->Render();
28 
29  //update the timer so it will trigger again
30  iren->CreateTimer(VTKI_TIMER_UPDATE);
31  }
32  vtkImageViewer2 *viewer;
33  vtkRenderWindowInteractor *iren;
34 protected:
35  vtkMyCallback()
36  {
37  viewer = NULL;
38  iren = NULL;
39  }
40 };
41 
42 int main(int argc, char **argv)
43 {
44  bool printHelp(false);
45 
46  vtksys::CommandLineArguments args;
47  args.Initialize(argc, argv);
48 
49  int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
50 
51  args.AddArgument("--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp, "Print this help.");
52  args.AddArgument("--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel, "Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
53 
54  if ( !args.Parse() )
55  {
56  std::cerr << "Problem parsing arguments" << std::endl;
57  std::cout << "\n\nvtkIntelRealSenseCamTest help:" << args.GetHelp() << std::endl;
58  exit(EXIT_FAILURE);
59  }
60 
61  vtkPlusLogger::Instance()->SetLogLevel(verboseLevel);
62 
63  if ( printHelp )
64  {
65  std::cout << "\n\nvtkIntelRealSenseCamTest help:" << args.GetHelp() << std::endl;
66  exit(EXIT_SUCCESS);
67 
68  }
69 
70  vtkSmartPointer<vtkPlusIntelRealSenseCamera> infraredIntelRealsenseCam = vtkSmartPointer<vtkPlusIntelRealSenseCamera>::New();
71 
72  infraredIntelRealsenseCam->CreateDefaultOutputChannel();
73 
74 // Add an observer to warning and error events for redirecting it to the stdout
75  vtkSmartPointer<vtkCallbackCommand> callbackCommand = vtkSmartPointer<vtkCallbackCommand>::New();
76  callbackCommand->SetCallback(PrintLogsCallback);
77  infraredIntelRealsenseCam->AddObserver("WarningEvent", callbackCommand);
78  infraredIntelRealsenseCam->AddObserver("ErrorEvent", callbackCommand);
79 
80  LOG_INFO("Initialize...");
81  infraredIntelRealsenseCam->Connect();
82 
83  if ( infraredIntelRealsenseCam->GetConnected() )
84  {
85  LOG_INFO("Start recording...");
86  infraredIntelRealsenseCam->StartRecording();
87  }
88  else
89  {
90  infraredIntelRealsenseCam->Disconnect();
91  LOG_ERROR( "Unable to connect to IC capture device");
92  exit(EXIT_FAILURE);
93  }
94 
95  LOG_INFO("Stop recording...");
96  infraredIntelRealsenseCam->StopRecording();
97  infraredIntelRealsenseCam->Disconnect();
98  LOG_INFO("Exit successfully");
99  exit(EXIT_SUCCESS);
100 }
101 
102 
103  // Callback function for error and warning redirects
104 void PrintLogsCallback(vtkObject* obj, unsigned long eid, void* clientdata, void* calldata)
105 {
106  if ( eid == vtkCommand::GetEventIdFromString("WarningEvent") )
107  {
108  LOG_WARNING((const char*)calldata);
109  }
110  else if ( eid == vtkCommand::GetEventIdFromString("ErrorEvent") )
111  {
112  LOG_ERROR((const char*)calldata);
113  }
114 }
vtkRenderWindowInteractor * iren
int main(int argc, char **argv)
void PrintLogsCallback(vtkObject *obj, unsigned long eid, void *clientdata, void *calldata)
vtkImageViewer * viewer
static vtkIGSIOLogger * Instance()