PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusClariusCommand.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 "vtkPlusDataCollector.h"
10 #include "Clarius/vtkPlusClarius.h"
11 
12 #include "vtkImageData.h"
13 #include "vtkDICOMImageReader.h"
14 #include "vtkObjectFactory.h"
15 #include "vtkPlusChannel.h"
17 #include "vtkIGSIOTrackedFrameList.h"
20 #include <vtkImageFlip.h>
21 #include <vtkPointData.h>
22 #include <vtkDirectory.h>
23 
24 static const std::string SAVE_CLARIUS_RAW_DATA_CMD = "SaveRawData";
25 
27 
28 //----------------------------------------------------------------------------
30  : CompressRawData(false)
31  , RawDataLastNSeconds(-1.0)
32 {
33 }
34 
35 //----------------------------------------------------------------------------
37 {
38 }
39 
40 //----------------------------------------------------------------------------
41 void vtkPlusClariusCommand::PrintSelf(ostream& os, vtkIndent indent)
42 {
43  this->Superclass::PrintSelf(os, indent);
44 }
45 
46 //----------------------------------------------------------------------------
47 void vtkPlusClariusCommand::GetCommandNames(std::list<std::string>& cmdNames)
48 {
49  cmdNames.clear();
50  cmdNames.push_back(SAVE_CLARIUS_RAW_DATA_CMD);
51 }
52 
53 //----------------------------------------------------------------------------
54 std::string vtkPlusClariusCommand::GetDescription(const std::string& commandName)
55 {
56  std::string desc;
57  if (commandName.empty() || igsioCommon::IsEqualInsensitive(commandName, SAVE_CLARIUS_RAW_DATA_CMD))
58  {
60  desc += ": Acquire the raw data from the Clarius. The data will be saved in the output directory as a .tar";
61  }
62  return desc;
63 }
64 
65 //----------------------------------------------------------------------------
67 {
68  this->SetName(SAVE_CLARIUS_RAW_DATA_CMD);
69 }
70 
71 //----------------------------------------------------------------------------
73 {
75  {
76  return PLUS_FAIL;
77  }
78 
79  XML_READ_BOOL_ATTRIBUTE_OPTIONAL(CompressRawData, aConfig);
80  XML_READ_STRING_ATTRIBUTE_OPTIONAL(ClariusDeviceId, aConfig);
81  XML_READ_STRING_ATTRIBUTE_OPTIONAL(OutputFilename, aConfig);
82  XML_READ_SCALAR_ATTRIBUTE_OPTIONAL(double, RawDataLastNSeconds, aConfig);
83 
84  return PLUS_SUCCESS;
85 }
86 
87 //----------------------------------------------------------------------------
89 {
91  {
92  return PLUS_FAIL;
93  }
94  XML_WRITE_BOOL_ATTRIBUTE(CompressRawData, aConfig);
95  XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(ClariusDeviceId, aConfig);
96  XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(OutputFilename, aConfig);
97  std::stringstream ss;
98  ss << RawDataLastNSeconds;
99  std::string string = ss.str();
100  aConfig->SetAttribute("RawDataLastNSeconds", string.c_str());
101  return PLUS_SUCCESS;
102 }
103 
104 //----------------------------------------------------------------------------
106 {
107  LOG_DEBUG("vtkPlusClariusCommand::Execute: " << (!this->Name.empty() ? this->Name : "(undefined)")
108  << ", device: " << (this->ClariusDeviceId.empty() ? "(undefined)" : this->ClariusDeviceId));
109 
110  if (this->Name.empty())
111  {
112  this->QueueCommandResponse(PLUS_FAIL, "Clarius command failed, no command name specified");
113  return PLUS_FAIL;
114  }
115 
116  vtkPlusClarius* clariusDevice = this->GetClariusDevice();
117  if (clariusDevice == NULL)
118  {
119  this->QueueCommandResponse(PLUS_FAIL, std::string("Clarius command failed: device ")
120  + (this->ClariusDeviceId.empty() ? "(undefined)" : this->ClariusDeviceId) + " is not found");
121  return PLUS_FAIL;
122  }
123 
124  if (igsioCommon::IsEqualInsensitive(this->Name, SAVE_CLARIUS_RAW_DATA_CMD))
125  {
126  LOG_INFO("Acquiring the raw data from Clarius: Device ID: " << this->GetClariusDeviceId());
127 
128  if (!this->GetOutputFilename().empty())
129  {
130  clariusDevice->SetRawDataOutputFilename(this->GetOutputFilename());
131  }
132 
133  this->QueueCommandResponse(PLUS_SUCCESS, "Clarius: Raw data request received");
134  clariusDevice->SetCompressRawData(this->GetCompressRawData());
135  return clariusDevice->RequestLastNSecondsRawData(this->GetRawDataLastNSeconds());
136  ;
137  }
138  this->QueueCommandResponse(PLUS_FAIL, "vtkPlusClariusCommand::Execute: failed, unknown command name: " + this->Name);
139  return PLUS_FAIL;
140 }
141 
142 //----------------------------------------------------------------------------
144 {
145  vtkPlusDataCollector* dataCollector = GetDataCollector();
146  if (dataCollector == NULL)
147  {
148  LOG_ERROR("Data collector is invalid");
149  return NULL;
150  }
151  if (!GetClariusDeviceId().empty())
152  {
153  // Reconstructor device ID is specified
154  vtkPlusDevice* device = NULL;
155  if (dataCollector->GetDevice(device, GetClariusDeviceId()) != PLUS_SUCCESS)
156  {
157  LOG_ERROR("No Clarius device has been found by the name " << this->GetClariusDeviceId());
158  return NULL;
159  }
160  // device found
161  vtkPlusClarius* ClariusDevice = vtkPlusClarius::SafeDownCast(device);
162  if (ClariusDevice == NULL)
163  {
164  // wrong type
165  LOG_ERROR("The specified device " << GetClariusDeviceId() << " is not Clarius Device");
166  return NULL;
167  }
168  return ClariusDevice;
169  }
170  else
171  {
172  // No Clarius device id is specified, auto-detect the first one and use that
173  for (DeviceCollectionConstIterator it = dataCollector->GetDeviceConstIteratorBegin(); it != dataCollector->GetDeviceConstIteratorEnd(); ++it)
174  {
175  vtkPlusClarius* ClariusDevice = vtkPlusClarius::SafeDownCast(*it);
176  if (ClariusDevice != NULL)
177  {
178  // found a recording device
179  SetClariusDeviceId(ClariusDevice->GetDeviceId());
180  return ClariusDevice;
181  }
182  }
183  LOG_ERROR("No Clarius Device has been found");
184  return NULL;
185  }
186 }
virtual void PrintSelf(ostream &os, vtkIndent indent)
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
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
vtkStandardNewMacro(vtkPlusClariusCommand)
virtual void SetCompressRawData(bool)
virtual std::string GetDescription(const std::string &commandName)
PlusStatus GetDevice(vtkPlusDevice *&aDevice, const std::string &aDeviceId) const
std::string Name
static vtkPlusClarius * SafeDownCast(vtkObject *o)
igsioStatus PlusStatus
Definition: PlusCommon.h:40
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
virtual std::string GetDeviceId() const
#define PLUS_FAIL
Definition: PlusCommon.h:43
static const std::string SAVE_CLARIUS_RAW_DATA_CMD
DeviceCollectionConstIterator GetDeviceConstIteratorBegin() const
virtual void GetCommandNames(std::list< std::string > &cmdNames)
DeviceCollectionConstIterator GetDeviceConstIteratorEnd() const
Manages devices that record image or positional data.
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
PlusStatus RequestLastNSecondsRawData(double lastNSeconds)
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
vtkPlusClarius * GetClariusDevice()
void QueueCommandResponse(PlusStatus status, const std::string &message, const std::string &error="", const igtl::MessageBase::MetaDataMap *metaData=nullptr)
virtual bool GetCompressRawData()
virtual vtkPlusDataCollector * GetDataCollector()
This command reconstructs a volume from an image sequence and saves it to disk or sends it to the cli...
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
virtual double GetRawDataLastNSeconds()
Interface to the Clarius ultrasound scans This class talks with a Clarius Scanner over the Clarius AP...
virtual PlusStatus Execute()