PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkBkProFocusCameraLinkVideoSourceTest.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"
9 #include "vtkCallbackCommand.h"
10 #include "vtkCommand.h"
11 #include "vtkImageData.h"
12 #include "vtkImageViewer2.h"
13 #include "vtkRenderWindowInteractor.h"
14 #include "vtkRenderer.h"
15 #include "vtkSmartPointer.h"
16 #include "vtksys/CommandLineArguments.hxx"
17 #include "vtkPlusDataSource.h"
18 
19 void PrintLogsCallback(vtkObject* obj, unsigned long eid, void* clientdata, void* calldata);
20 
21 class vtkMyCallback : public vtkCommand
22 {
23 public:
24  static vtkMyCallback *New()
25  {return new vtkMyCallback;}
26  virtual void Execute(vtkObject *caller, unsigned long, void*)
27  {
28  viewer->Render();
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  std::string iniFile="BkSettings/IniFile.ini";
45  bool showBmode(false);
46  bool showSapera(false);
47  bool printHelp(false);
48  bool renderingOff(false);
49 
50  vtksys::CommandLineArguments args;
51  args.Initialize(argc, argv);
52 
53  vtkPlusConfig::GetInstance(); // set default log level
54  int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
55 
56  args.AddArgument("--ini-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &iniFile, "Path to the BK ini file, relative to the configuration file directory. Default: BkSettings/IniFile.ini");
57  args.AddArgument("--show-bmode", vtksys::CommandLineArguments::NO_ARGUMENT, &showBmode, "Show B-mode image debug window");
58  args.AddArgument("--show-sapera", vtksys::CommandLineArguments::NO_ARGUMENT, &showSapera, "Show Sapera framegrabber debug window");
59  args.AddArgument("--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp, "Print this help.");
60  args.AddArgument("--rendering-off", vtksys::CommandLineArguments::NO_ARGUMENT, &renderingOff, "Run test without rendering the video source output to the screen.");
61  args.AddArgument("--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel, "Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
62 
63  if ( !args.Parse() )
64  {
65  std::cerr << "Problem parsing arguments" << std::endl;
66  std::cout << "\n\nvtkPlusBkProFocusCameraLinkVideoSourceTest help:" << args.GetHelp() << std::endl;
67  exit(EXIT_FAILURE);
68  }
69 
70  vtkPlusLogger::Instance()->SetLogLevel(verboseLevel);
71 
72  if ( printHelp )
73  {
74  std::cout << "\n\nvtkPlusBkProFocusCameraLinkVideoSourceTest help:" << args.GetHelp() << std::endl;
75  exit(EXIT_SUCCESS);
76 
77  }
78 
79  vtkSmartPointer<vtkPlusBkProFocusCameraLinkVideoSource> frameGrabber = vtkSmartPointer<vtkPlusBkProFocusCameraLinkVideoSource>::New();
80 
81  frameGrabber->SetIniFileName(iniFile.c_str());
82 
83  frameGrabber->SetShowBModeWindow(showBmode);
84  frameGrabber->SetShowSaperaWindow(showSapera);
85  frameGrabber->SetImagingMode(vtkPlusBkProFocusCameraLinkVideoSource::RfMode);
86 
87  frameGrabber->CreateDefaultOutputChannel();
88  vtkPlusDataSource* videoSource=NULL;
89  if (frameGrabber->GetFirstActiveOutputVideoSource(videoSource) != PLUS_SUCCESS )
90  {
91  LOG_ERROR("Unable to retrieve the video source.");
92  exit(EXIT_FAILURE);
93  }
94  videoSource->SetInputImageOrientation(US_IMG_ORIENT_FM);
95 
96  LOG_INFO("Initialize...");
97  frameGrabber->Connect();
98 
99  if ( frameGrabber->GetConnected() )
100  {
101  LOG_INFO("Start recording...");
102  frameGrabber->StartRecording();
103  }
104  else
105  {
106  frameGrabber->Disconnect();
107  LOG_ERROR( "Unable to connect to framegrabber");
108  exit(EXIT_FAILURE);
109  }
110 
111  if (renderingOff)
112  {
113  LOG_INFO("No need for rendering, stop the device...");
114  frameGrabber->StopRecording();
115  frameGrabber->Disconnect();
116  LOG_INFO("Exit successfully");
117  exit(EXIT_SUCCESS);
118  }
119 
120  vtkSmartPointer<vtkImageViewer2> viewer = vtkSmartPointer<vtkImageViewer2>::New();
121 
122  viewer->SetColorWindow(255);
123  viewer->SetColorLevel(100.5);
124  viewer->SetSize(1024,768);
125 
126  viewer->SetInput(frameGrabber->GetOutput());
127 
128  //Create the interactor that handles the event loop
129  vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
130  iren->SetRenderWindow(viewer->GetRenderWindow());
131  viewer->SetupInteractor(iren);
132 
133  viewer->Render();
134 
135  //establish timer event and create timer
136  vtkSmartPointer<vtkMyCallback> call = vtkSmartPointer<vtkMyCallback>::New();
137  call->iren=iren;
138  call->viewer=viewer;
139  iren->AddObserver(vtkCommand::TimerEvent, call);
140  iren->CreateTimer(VTKI_TIMER_FIRST); //VTKI_TIMER_FIRST = 0
141 
142  //iren must be initialized so that it can handle events
143  iren->Initialize();
144  iren->Start();
145 
146  frameGrabber->StopRecording();
147  frameGrabber->Disconnect();
148 
149  LOG_INFO("Exit successfully");
150  return EXIT_SUCCESS;
151 }
vtkRenderWindowInteractor * iren
virtual PlusStatus SetInputImageOrientation(US_IMAGE_ORIENTATION imageOrientation)
static vtkPlusConfig * GetInstance()
void PrintLogsCallback(vtkObject *obj, unsigned long eid, void *clientdata, void *calldata)
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
vtkImageViewer * viewer
int main(int argc, char **argv)
static vtkIGSIOLogger * Instance()
Interface to a 3D positioning tool, video source, or generalized data stream.