PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusDeviceFactoryTest.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 "vtkPlusFakeTracker.h"
9 #include "vtkPlusDevice.h"
10 #include "vtkPlusDeviceFactory.h"
11 #include "vtkPlusSavedDataSource.h"
12 #include "vtksys/CommandLineArguments.hxx"
13 
14 int main (int argc, char* argv[])
15 {
16  bool printHelp(false);
17  int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
18 
19  vtksys::CommandLineArguments args;
20  args.Initialize(argc, argv);
21 
22  args.AddArgument("--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp, "Print this help.");
23  args.AddArgument("--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel, "Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
24 
25  if ( !args.Parse() )
26  {
27  std::cerr << "Problem parsing arguments" << std::endl;
28  std::cout << "\nHelp:" << args.GetHelp() << std::endl;
29  exit(EXIT_FAILURE);
30  }
31 
32  vtkPlusLogger::Instance()->SetLogLevel(verboseLevel);
33 
34  if ( printHelp )
35  {
36  std::cout << "\nHelp:" << args.GetHelp() << std::endl;
37  exit(EXIT_SUCCESS);
38 
39  }
40 
41  vtkPlusDevice* device = NULL;
42  vtkSmartPointer<vtkPlusDeviceFactory> deviceFactory = vtkSmartPointer<vtkPlusDeviceFactory>::New();
43 
44  std::ostringstream printself;
45  deviceFactory->PrintSelf(printself, vtkIndent());
46  LOG_INFO("device factory printself: " << printself.str());
47 
49  // device type: NULL
50 
51  LOG_INFO("Testing device factory create instance function with NULL device type...");
52  if ( deviceFactory->CreateInstance(NULL, device, "aDevice") == PLUS_SUCCESS )
53  {
54  LOG_ERROR("Expected failure in creating device instance, but method call returned with success");
55  return EXIT_FAILURE;
56  }
57  if ( device != NULL )
58  {
59  LOG_ERROR("NULL device expected!");
60  return EXIT_FAILURE;
61  }
62 
64  // device type: not existing device type
65 
66  LOG_INFO("Testing device factory create instance function with a not existing device type...");
67  if ( deviceFactory->CreateInstance("NotExistingAbc", device, "aDevice") == PLUS_SUCCESS )
68  {
69  LOG_ERROR("Expected failure in creating not existing device instance, but the operation was successful");
70  return EXIT_FAILURE;
71  }
72  if ( device != NULL )
73  {
74  LOG_ERROR("NULL device expected!");
75  return EXIT_FAILURE;
76  }
77 
79  // device type: Fakedevice
80 
81  LOG_INFO("Testing device factory create instance function with FakeTracker device type...");
82  if ( deviceFactory->CreateInstance("FakeTracker", device, "FakeTracker") != PLUS_SUCCESS )
83  {
84  LOG_ERROR("Failed to create Fakedevice device instance!");
85  return EXIT_FAILURE;
86  }
87  if ( dynamic_cast<vtkPlusFakeTracker*>(device) == NULL )
88  {
89  LOG_ERROR("Failed to create FakeTracker device instance!");
90  return EXIT_FAILURE;
91  }
92 
94  // Video source type: NULL
95 
96  LOG_INFO("Testing video source factory create instance function with NULL video source type...");
97  if ( deviceFactory->CreateInstance(NULL, device, "someDevice") == PLUS_SUCCESS )
98  {
99  LOG_ERROR("Expected failure in creating video source instance, but method call returned with success");
100  return EXIT_FAILURE;
101  }
102  if ( device != NULL )
103  {
104  LOG_ERROR("NULL video source expected!");
105  return EXIT_FAILURE;
106  }
107 
109  // Video source type: not existing device type
110 
111  LOG_INFO("Testing video source factory create instance function with not existing video source type...");
112  if ( deviceFactory->CreateInstance("NotExistingAbc", device, "anotherDevice") == PLUS_SUCCESS )
113  {
114  LOG_ERROR("Expected failure in creating not existing video source instance, but the operation was successful");
115  return EXIT_FAILURE;
116  }
117  if ( device != NULL )
118  {
119  LOG_ERROR("NULL video source expected!");
120  return EXIT_FAILURE;
121  }
122 
124  // Video source type: SavedDataset
125 
126  LOG_INFO("Testing video source factory create instance function with SavedDataset video source type...");
127  if ( deviceFactory->CreateInstance("SavedDataSource", device, "vidDevice") != PLUS_SUCCESS )
128  {
129  LOG_ERROR("Failed to create SavedDataset video source instance!");
130  return EXIT_FAILURE;
131  }
132  if ( dynamic_cast<vtkPlusSavedDataSource*>(device) == NULL )
133  {
134  LOG_ERROR("Failed to create SavedDataset video source instance!");
135  return EXIT_FAILURE;
136  }
137  device->Delete();
138  device=NULL;
139 
140  LOG_INFO("Test finished successfully!");
141  return EXIT_SUCCESS;
142 }
Abstract interface for tracker and video devices.
Definition: vtkPlusDevice.h:60
int main(int argc, char *argv[])
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
static vtkIGSIOLogger * Instance()