PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkInfraredTEEV2CamTest.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 ULL & 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"
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  bool printHelp(false);
48 
49  vtksys::CommandLineArguments args;
50  args.Initialize(argc, argv);
51 
52  int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
53 
54  args.AddArgument("--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp, "Print this help.");
55  args.AddArgument("--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel, "Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
56 
57  if ( !args.Parse() )
58  {
59  std::cerr << "Problem parsing arguments" << std::endl;
60  std::cout << "\n\nvtkInfraredTEEV2CamTest help:" << args.GetHelp() << std::endl;
61  exit(EXIT_FAILURE);
62  }
63 
64  vtkPlusLogger::Instance()->SetLogLevel(verboseLevel);
65 
66  if ( printHelp )
67  {
68  std::cout << "\n\nvtkInfraredTEEV2CamTest help:" << args.GetHelp() << std::endl;
69  exit(EXIT_SUCCESS);
70  }
71 
72  vtkSmartPointer<vtkPlusInfraredTEEV2Cam> infraredTEEV2Cam = vtkSmartPointer<vtkPlusInfraredTEEV2Cam>::New();
73 
74  infraredTEEV2Cam->CreateDefaultOutputChannel();
75 
76 // Add an observer to warning and error events for redirecting it to the stdout
77  vtkSmartPointer<vtkCallbackCommand> callbackCommand = vtkSmartPointer<vtkCallbackCommand>::New();
78  callbackCommand->SetCallback(PrintLogsCallback);
79  infraredTEEV2Cam->AddObserver("WarningEvent", callbackCommand);
80  infraredTEEV2Cam->AddObserver("ErrorEvent", callbackCommand);
81 
82  LOG_INFO("Initialize...");
83  infraredTEEV2Cam->Connect();
84 
85  if ( infraredTEEV2Cam->GetConnected() )
86  {
87  LOG_INFO("Start recording...");
88  infraredTEEV2Cam->StartRecording();
89  }
90  else
91  {
92  infraredTEEV2Cam->Disconnect();
93  LOG_ERROR( "Unable to connect to Thermal Expert EV2 device");
94  exit(EXIT_FAILURE);
95  }
96 
97  LOG_INFO("Stop recording...");
98  infraredTEEV2Cam->StopRecording();
99  infraredTEEV2Cam->Disconnect();
100  LOG_INFO("Exit successfully");
101  exit(EXIT_SUCCESS);
102 }
103 
104 
105  // Callback function for error and warning redirects
106 void PrintLogsCallback(vtkObject* obj, unsigned long eid, void* clientdata, void* calldata)
107 {
108  if ( eid == vtkCommand::GetEventIdFromString("WarningEvent") )
109  {
110  LOG_WARNING((const char*)calldata);
111  }
112  else if ( eid == vtkCommand::GetEventIdFromString("ErrorEvent") )
113  {
114  LOG_ERROR((const char*)calldata);
115  }
116 }
vtkRenderWindowInteractor * iren
vtkImageViewer * viewer
void PrintLogsCallback(vtkObject *obj, unsigned long eid, void *clientdata, void *calldata)
int main(int argc, char **argv)
static vtkIGSIOLogger * Instance()