PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkLeapMotionTest1.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 // Local includes
8 #include "PlusConfigure.h"
9 #include "vtkPlusDataSource.h"
10 #include "vtkPlusLeapMotion.h"
11 
12 // VTK includes
13 #include <vtkNew.h>
14 #include <vtkMatrix4x4.h>
15 #include <vtksys/CommandLineArguments.hxx>
16 
17 // STL includes
18 #include <chrono>
19 #include <thread>
20 
21 int main(int argc, char** argv)
22 {
23  double frameRate = 60;
24  bool printHelp(false);
25 
26  vtksys::CommandLineArguments args;
27  args.Initialize(argc, argv);
28 
29  int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
30 
31  args.AddArgument("--frame-rate", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &frameRate, "Requested acquisition frame rate (in FPS, default = 30)");
32  args.AddArgument("--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp, "Print this help.");
33  args.AddArgument("--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel, "Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
34 
35  if (!args.Parse())
36  {
37  std::cerr << "Problem parsing arguments" << std::endl;
38  std::cout << std::endl << std::endl << "vtkLeapMotionTest1 help:" << args.GetHelp() << std::endl;
39  exit(EXIT_FAILURE);
40  }
41 
42  vtkPlusLogger::Instance()->SetLogLevel(verboseLevel);
43 
44  if (printHelp)
45  {
46  std::cout << std::endl << std::endl << "vtkLeapMotionTest1 help:" << args.GetHelp() << std::endl;
47  exit(EXIT_SUCCESS);
48 
49  }
50 
51  vtkNew<vtkPlusLeapMotion> leapMotion;
52  leapMotion->SetDeviceId("LeapMotionDevice");
53  leapMotion->SetToolReferenceFrameName("Tracker");
54 
55  vtkNew<vtkPlusDataSource> source;
56  source->SetId("LeftIndexDistal");
57  source->SetType(DATA_SOURCE_TYPE_TOOL);
58  vtkNew<vtkPlusChannel> channel;
59  channel->SetChannelId("TrackerChannel");
60  channel->AddTool(source);
61  leapMotion->AddTool(source);
62  leapMotion->AddOutputChannel(channel);
63 
64  if (leapMotion->Connect() != PLUS_SUCCESS)
65  {
66  LOG_ERROR("Unable to connect to device");
67  exit(EXIT_FAILURE);
68  }
69 
70  if (leapMotion->StartRecording() != PLUS_SUCCESS)
71  {
72  LOG_ERROR("Unable to start recording");
73  exit(EXIT_FAILURE);
74  }
75 
76  std::this_thread::sleep_for(std::chrono::milliseconds(100));
77 
78  igsioTrackedFrame frame;
79  if (channel->GetTrackedFrame(frame) != PLUS_SUCCESS)
80  {
81  LOG_ERROR("Unable to retrieve frame from channel.");
82  exit(EXIT_FAILURE);
83  }
84 
85  vtkNew<vtkMatrix4x4> mat;
86  if (frame.GetFrameTransform(igsioTransformName("LeftIndexDistal", "Tracker"), mat) != PLUS_SUCCESS)
87  {
88  LOG_ERROR("Unable to retrieve left index distal transform.");
89  exit(EXIT_FAILURE);
90  }
91 
92  if (leapMotion->StopRecording() != PLUS_SUCCESS)
93  {
94  LOG_ERROR("Unable to stop recording.");
95  exit(EXIT_FAILURE);
96  }
97 
98  if (leapMotion->Disconnect() != PLUS_SUCCESS)
99  {
100  LOG_ERROR("Unable to disconnect");
101  exit(EXIT_FAILURE);
102  }
103 
104  return EXIT_SUCCESS;
105 
106 }
int * channel
Definition: phidget22.h:1303
const char * source
Definition: phidget22.h:2461
int main(int argc, char **argv)
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
static vtkIGSIOLogger * Instance()