PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusGetFrameRateCommand.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"
9 
10 #include "vtkPlusDataCollector.h"
11 #include "vtkPlusChannel.h"
12 #include "vtkPlusDataSource.h"
13 
15 
16 namespace
17 {
18  static const std::string GET_FRAME_RATE_CMD = "GetFrameRate";
19 }
20 
21 //----------------------------------------------------------------------------
23  : ResponseExpected(true)
24 {
25  // It handles only one command, set its name by default
26  this->SetName(GET_FRAME_RATE_CMD);
27 }
28 
29 //----------------------------------------------------------------------------
31 {
32 }
33 
34 //----------------------------------------------------------------------------
36 {
37  this->SetName(GET_FRAME_RATE_CMD);
38 }
39 
40 //----------------------------------------------------------------------------
41 void vtkPlusGetFrameRateCommand::GetCommandNames(std::list<std::string>& cmdNames)
42 {
43  cmdNames.clear();
44  cmdNames.push_back(GET_FRAME_RATE_CMD);
45 }
46 
47 //----------------------------------------------------------------------------
48 std::string vtkPlusGetFrameRateCommand::GetDescription(const std::string& commandName)
49 {
50  std::string desc;
51  if (commandName.empty() || igsioCommon::IsEqualInsensitive(commandName, GET_FRAME_RATE_CMD))
52  {
53  desc += GET_FRAME_RATE_CMD;
54  desc += ": Get frame rate from a data channel.";
55  }
56  return desc;
57 }
58 
59 //----------------------------------------------------------------------------
61 {
62  return this->ChannelId;
63 }
64 
65 //----------------------------------------------------------------------------
66 void vtkPlusGetFrameRateCommand::SetChannelId(const std::string& channelId)
67 {
68  this->ChannelId = channelId;
69 }
70 
71 //----------------------------------------------------------------------------
72 void vtkPlusGetFrameRateCommand::PrintSelf(ostream& os, vtkIndent indent)
73 {
74  this->Superclass::PrintSelf(os, indent);
75 }
76 
77 //----------------------------------------------------------------------------
79 {
81  {
82  return PLUS_FAIL;
83  }
84  XML_READ_STRING_ATTRIBUTE_OPTIONAL(ChannelId, aConfig);
85  return PLUS_SUCCESS;
86 }
87 
88 //----------------------------------------------------------------------------
90 {
92  {
93  return PLUS_FAIL;
94  }
95  XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(ChannelId, aConfig);
96  return PLUS_SUCCESS;
97 }
98 
99 //----------------------------------------------------------------------------
101 {
102  LOG_DEBUG("vtkPlusGetFrameRateCommand::Execute: " << (!this->Name.empty() ? this->Name : "(undefined)")
103  << ", channel: " << (this->ChannelId.empty() ? "(undefined)" : this->ChannelId));
104 
105  vtkPlusDataCollector* dataCollector = GetDataCollector();
106  if (dataCollector == NULL)
107  {
108  this->QueueCommandResponse(PLUS_FAIL, "Command failed. See error message.", "Invalid data collector.");
109  return PLUS_FAIL;
110  }
111 
112  // Get device pointer
113  if (this->ChannelId.empty())
114  {
115  this->QueueCommandResponse(PLUS_FAIL, "Command failed. See error message.", "No ChannelId specified.");
116  return PLUS_FAIL;
117  }
118  vtkPlusChannel* channel = NULL;
119  if (dataCollector->GetChannel(channel, this->ChannelId) != PLUS_SUCCESS)
120  {
121  this->QueueCommandResponse(PLUS_FAIL, "Command failed. See error message.", std::string("Channel ")
122  + (this->ChannelId.empty() ? "(undefined)" : this->ChannelId) + std::string(" is not found."));
123  return PLUS_FAIL;
124  }
125 
126  // Get frame rate from corresponding video source
127  vtkPlusDataSource* dataSource = NULL;
128  channel->GetVideoSource(dataSource);
129  double stddev;
130  double framerate = dataSource->GetFrameRate(false, &stddev);
131 
132  std::map < std::string, std::pair<IANA_ENCODING_TYPE, std::string> > metaData;
133 
134  std::stringstream response;
135  std::string error = "";
136  response << "<CommandReply FrameRate=" << std::to_string(framerate) << " FrameRateStdDev=" << std::to_string(stddev) << " />";
137  metaData["FrameRate"] = std::make_pair(IANA_TYPE_US_ASCII, std::to_string(framerate));
138  metaData["FrameRateStdDev"] = std::make_pair(IANA_TYPE_US_ASCII, std::to_string(stddev));
139 
140  vtkSmartPointer<vtkPlusCommandRTSCommandResponse> commandResponse = vtkSmartPointer<vtkPlusCommandRTSCommandResponse>::New();
141  commandResponse->UseDefaultFormatOff();
142  commandResponse->SetClientId(this->ClientId);
143  commandResponse->SetOriginalId(this->Id);
144  commandResponse->SetCommandName(this->GetName());
145  commandResponse->SetStatus(PLUS_SUCCESS);
146  commandResponse->SetRespondWithCommandMessage(this->RespondWithCommandMessage);
147  commandResponse->SetErrorString(error);
148  commandResponse->SetResultString(response.str());
149  commandResponse->SetParameters(metaData);
150  this->CommandResponseQueue.push_back(commandResponse);
151 
152  return PLUS_SUCCESS;
153 }
int * channel
Definition: phidget22.h:1303
virtual void PrintSelf(ostream &os, vtkIndent indent)
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
virtual void PrintSelf(ostream &os, vtkIndent indent)
std::string Name
This command returns the current frame rate from a vtkPlusChannel's DataSource.This command is used f...
igsioStatus PlusStatus
Definition: PlusCommon.h:40
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
std::string to_string(ClariusAvailability avail)
virtual void SetChannelId(const std::string &channelId)
virtual std::string GetDescription(const std::string &commandName)
#define PLUS_FAIL
Definition: PlusCommon.h:43
virtual std::string GetChannelId() const
vtkStandardNewMacro(vtkPlusGetFrameRateCommand)
virtual void GetCommandNames(std::list< std::string > &cmdNames)
Manages devices that record image or positional data.
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
bool RespondWithCommandMessage
virtual double GetFrameRate(bool ideal=false, double *framePeriodStdevSecPtr=NULL)
void QueueCommandResponse(PlusStatus status, const std::string &message, const std::string &error="", const igtl::MessageBase::MetaDataMap *metaData=nullptr)
virtual vtkPlusDataCollector * GetDataCollector()
Contains an optional timestamped circular buffer containing the video images and a number of timestam...
PlusCommandResponseList CommandResponseQueue
PlusStatus GetChannel(vtkPlusChannel *&aChannel, const std::string &aChannelId) const
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
Interface to a 3D positioning tool, video source, or generalized data stream.