PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusIEEListener.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 /*=========================================================================
8 The following copyright notice is applicable to parts of this file:
9 Copyright (c) 2014, Robarts Research Institute, The University of Western Ontario, London, Ontario, Canada
10 All rights reserved.
11 Authors include:
12 * Elvis Chen (Robarts Research Institute and The University of Western Ontario)
13 * Adam Rankin (Robarts Research Institute and The University of Western Ontario)
14 =========================================================================*/
15 
16 
17 // Plus Includes
18 #include "PlusConfigure.h"
19 #include "vtkPlusIEEListener.h"
20 
21 //----------------------------------------------------------------------------
22 
24 vtkPlusIEEListener* vtkPlusIEEListener::New(bool forceZQuantize, double resolutionFactor, bool integerZ, bool isotropic, bool quantizeDim, int zDecimation, bool set4PtFIR, int latAndElevSmoothingIndex)
25 {
26  return new vtkPlusIEEListener(forceZQuantize, resolutionFactor, integerZ, isotropic, quantizeDim, zDecimation, set4PtFIR, latAndElevSmoothingIndex);
27 }
28 
29 //----------------------------------------------------------------------------
31 : vtkObject()
32 , StreamManager(new CStreamMgr())
33 , MachineName("")
34 , Port(4013)
35 , Connected(false)
36 {
37 }
38 
39 //----------------------------------------------------------------------------
40 vtkPlusIEEListener::vtkPlusIEEListener(bool forceZQuantize, double resolutionFactor, bool integerZ, bool isotropic, bool quantizeDim, int zDecimation, bool set4PtFIR, int latAndElevSmoothingIndex)
41  : vtkObject()
42  , StreamManager(new CStreamMgr(forceZQuantize, resolutionFactor, integerZ, isotropic, quantizeDim, zDecimation, set4PtFIR, latAndElevSmoothingIndex))
43  , MachineName("")
44  , Port(4013)
45  , Connected(false)
46 {
47 }
48 
49 //----------------------------------------------------------------------------
51 {
52 }
53 
54 //----------------------------------------------------------------------------
55 PlusStatus vtkPlusIEEListener::Connect(CLIENT_POSTSCANCONVERT_CALLBACK callback, vtkPlusLogger::LogLevelType logType)
56 {
57  if( this->MachineName.empty() || this->Port <= 0 )
58  {
59  LOG_ERROR("MachineName not set or invalid port: " << this->MachineName << ":" << this->Port );
60  return PLUS_FAIL;
61  }
62  if( !StreamManager->Initialize() )
63  {
64  LOG_ERROR("Failed to initialize:");
65  return PLUS_FAIL;
66  }
67 
68  StreamManager->RegisterCallback(callback);
69 
70  HRESULT resultCode = StreamManager->Start((char*)this->MachineName.c_str(), this->Port);
71  if( resultCode < 0)
72  {
73  LOG_DYNAMIC("Unable to connect to Philips iE33 system at " << this->MachineName << ":" << this->Port << ". Error code: " << std::hex << resultCode, logType);
74  return PLUS_FAIL;
75  }
76  else
77  {
78  this->Connected = true;
79  }
80  return PLUS_SUCCESS;
81 }
82 
83 //----------------------------------------------------------------------------
85 {
86  if (StreamManager != NULL && StreamManager->IsConnected())
87  {
88  LOG_INFO("Stopping stream:");
89  StreamManager->Stop();
90 
91  LOG_INFO("Shutdown stream:");
92  StreamManager->Shutdown();
93 
94  this->Connected = false;
95  return PLUS_SUCCESS;
96  }
97  return PLUS_FAIL;
98 }
99 
100 //----------------------------------------------------------------------------
101 void vtkPlusIEEListener::PrintSelf(ostream& os, vtkIndent indent)
102 {
103  this->Superclass::PrintSelf(os,indent);
104 
105  os << indent << "MachineName: " << this->MachineName << "\n";
106  os << indent << "Port: " << this->Port << "\n";
107  os << indent << "Connected: " << this->Connected << "\n";
108 }
109 
110 //----------------------------------------------------------------------------
111 void vtkPlusIEEListener::SetMachineName(const std::string& machineName)
112 {
113  this->MachineName = machineName;
114 }
115 
116 //----------------------------------------------------------------------------
118 {
119  this->Port = port;
120 }
121 
122 //----------------------------------------------------------------------------
124 {
125  return this->StreamManager->IsConnected();
126 }
void SetPortNumber(unsigned int port)
static vtkPlusIEEListener * New()
igsioStatus PlusStatus
Definition: PlusCommon.h:40
#define PLUS_FAIL
Definition: PlusCommon.h:43
int port
Definition: phidget22.h:2454
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
vtkStandardNewMacro(vtkPlusIEEListener)
CStreamMgr * StreamManager
PlusStatus Connect(CLIENT_POSTSCANCONVERT_CALLBACK callback, vtkPlusLogger::LogLevelType logType=vtkPlusLogger::LOG_LEVEL_ERROR)
void SetMachineName(const std::string &machineName)