PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusConoProbeLinkCommand.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 
12 #include "vtkPlusDataCollector.h"
13 
14 namespace
15 {
16  static const std::string SHOW_CMD = "ShowProbeDialog";
17 }
18 
20 
21 //----------------------------------------------------------------------------
23 {
24 }
25 
26 //----------------------------------------------------------------------------
28 {
29 }
30 
31 //----------------------------------------------------------------------------
33 {
34  this->SetName(SHOW_CMD);
35 }
36 
37 //----------------------------------------------------------------------------
38 void vtkPlusConoProbeLinkCommand::GetCommandNames(std::list<std::string>& cmdNames)
39 {
40  cmdNames.clear();
41  cmdNames.push_back(SHOW_CMD);
42 }
43 
44 //----------------------------------------------------------------------------
45 std::string vtkPlusConoProbeLinkCommand::GetDescription(const std::string& commandName)
46 {
47  std::string desc;
48  if (commandName.empty() || igsioCommon::IsEqualInsensitive(commandName, SHOW_CMD))
49  {
50  desc += SHOW_CMD;
51  desc += ": Opens the Probe Dialog part of the Optimet Smart32 SDK. ConoProbeDeviceId: ID of the ConoProbe device.";
52  }
53  return desc;
54 }
55 
56 //----------------------------------------------------------------------------
57 void vtkPlusConoProbeLinkCommand::PrintSelf(ostream& os, vtkIndent indent)
58 {
59  this->Superclass::PrintSelf(os, indent);
60 }
61 
62 //----------------------------------------------------------------------------
64 {
66  {
67  return PLUS_FAIL;
68  }
69 
70  XML_READ_STRING_ATTRIBUTE_REQUIRED(ConoProbeDeviceId, aConfig);
71 
72  return PLUS_SUCCESS;
73 }
74 
75 //----------------------------------------------------------------------------
77 {
79  {
80  return PLUS_FAIL;
81  }
82 
83  XML_WRITE_STRING_ATTRIBUTE_REMOVE_IF_EMPTY(ConoProbeDeviceId, aConfig);
84 
85  return PLUS_SUCCESS;
86 }
87 
88 //----------------------------------------------------------------------------
90 {
91  vtkPlusDataCollector* dataCollector = GetDataCollector();
92  if (dataCollector == NULL)
93  {
94  LOG_ERROR("Data collector is invalid");
95  return NULL;
96  }
97  vtkPlusOptimetConoProbeMeasurer* conoProbeDevice = NULL;
98  if (!conoProbeDeviceID.empty())
99  {
100  // ConoProbe device ID is specified
101  vtkPlusDevice* device = NULL;
102  if (dataCollector->GetDevice(device, conoProbeDeviceID) != PLUS_SUCCESS)
103  {
104  LOG_ERROR("No OptimetConoProbe has been found by the name " << conoProbeDeviceID);
105  return NULL;
106  }
107  // device found
108  conoProbeDevice = vtkPlusOptimetConoProbeMeasurer::SafeDownCast(device);
109  if (conoProbeDevice == NULL)
110  {
111  // wrong type
112  LOG_ERROR("The specified device " << conoProbeDeviceID << " is not VirtualStreamCapture");
113  return NULL;
114  }
115  }
116  else
117  {
118  // No ConoProbe device id is specified, auto-detect the first one and use that
119  for (DeviceCollectionConstIterator it = dataCollector->GetDeviceConstIteratorBegin(); it != dataCollector->GetDeviceConstIteratorEnd(); ++it)
120  {
121  conoProbeDevice = vtkPlusOptimetConoProbeMeasurer::SafeDownCast(*it);
122  if (conoProbeDevice != NULL)
123  {
124  // found a recording device
125  break;
126  }
127  }
128  if (conoProbeDevice == NULL)
129  {
130  LOG_ERROR("No OptimetConoProbe has been found");
131  return NULL;
132  }
133  }
134  return conoProbeDevice;
135 }
136 
137 //----------------------------------------------------------------------------
139 {
140  LOG_INFO("vtkPlusConoProbeLinkCommand::Execute:");
141 
142  if (this->Name.empty())
143  {
144  this->QueueStringResponse("Command failed, no command name specified", PLUS_FAIL);
145  return PLUS_FAIL;
146  }
147 
149  if (conoProbeDevice == NULL)
150  {
151  this->QueueStringResponse(std::string("OptimetConoProbe has not been found (")
152  + (!this->ConoProbeDeviceId.empty() ? this->ConoProbeDeviceId : "auto-detect") + "), " + this->Name + " failed", PLUS_FAIL);
153  return PLUS_FAIL;
154  }
155 
156  std::string responseMessageBase = std::string("OptimetConoProbe (") + conoProbeDevice->GetDeviceId() + ") " + this->Name;
157  LOG_INFO("vtkPlusConoProbeLinkCommand::Execute: " << this->Name);
158  if (igsioCommon::IsEqualInsensitive(this->Name, SHOW_CMD))
159  {
160  if (conoProbeDevice->ShowProbeDialog())
161  {
162  this->QueueStringResponse(responseMessageBase + " successful", PLUS_SUCCESS);
163  return PLUS_SUCCESS;
164  }
165  this->QueueStringResponse(responseMessageBase + " failed", PLUS_FAIL);
166  return PLUS_FAIL;
167  }
168 
169  this->QueueStringResponse(responseMessageBase + " unknown command: " + this->Name, PLUS_FAIL);
170  return PLUS_FAIL;
171 }
virtual void PrintSelf(ostream &os, vtkIndent indent)
Abstract interface for tracker and video devices.
Definition: vtkPlusDevice.h:60
std::vector< vtkPlusDevice * >::const_iterator DeviceCollectionConstIterator
Definition: vtkPlusDevice.h:48
vtkPlusOptimetConoProbeMeasurer * GetConoProbeDevice(const std::string &conoProbeDeviceID)
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
PlusStatus GetDevice(vtkPlusDevice *&aDevice, const std::string &aDeviceId) const
std::string Name
vtkStandardNewMacro(vtkPlusConoProbeLinkCommand)
igsioStatus PlusStatus
Definition: PlusCommon.h:40
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
virtual std::string GetDeviceId() const
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
#define PLUS_FAIL
Definition: PlusCommon.h:43
static vtkPlusOptimetConoProbeMeasurer * SafeDownCast(vtkObject *o)
DeviceCollectionConstIterator GetDeviceConstIteratorBegin() const
DeviceCollectionConstIterator GetDeviceConstIteratorEnd() const
Manages devices that record image or positional data.
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
This command allows for communicating with the OptimetConoProbe device.
virtual std::string GetDescription(const std::string &commandName)
virtual vtkPlusDataCollector * GetDataCollector()
virtual void GetCommandNames(std::list< std::string > &cmdNames)
virtual void PrintSelf(ostream &os, vtkIndent indent)
Interface for the Optimet ConoProbe This class talks with Optimet ConoProbe over the Optimet Smart32 ...
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)