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