7 #include "PlusConfigure.h" 11 #include "vtkObjectFactory.h" 17 #include <vtkVariant.h> 18 #include <vtkSmartPointer.h> 26 static const std::string GET_US_PARAMETER_CMD =
"GetUsParameter";
47 SetName(GET_US_PARAMETER_CMD);
60 cmdNames.push_back(GET_US_PARAMETER_CMD);
67 if (commandName.empty() || igsioCommon::IsEqualInsensitive(commandName, GET_US_PARAMETER_CMD))
69 desc += GET_US_PARAMETER_CMD;
71 desc +=
": Get ultrasound image parameter. Attributes: UsDeviceId: ID of the ultrasound device.";
86 this->SetUsDeviceId(aConfig->GetAttribute(
"UsDeviceId"));
89 for (
int elemIndex = 0; elemIndex < aConfig->GetNumberOfNestedElements(); ++elemIndex)
91 vtkXMLDataElement* currentElem = aConfig->GetNestedElement(elemIndex);
92 if (igsioCommon::IsEqualInsensitive(currentElem->GetName(),
"Parameter"))
94 const char* parameterName = currentElem->GetAttribute(
"Name");
97 LOG_ERROR(
"Unable to find required Name attribute in " << (currentElem->GetName() ? currentElem->GetName() :
"(undefined)") <<
" element in GetUsParameter command");
116 XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(
UsDeviceId, aConfig);
119 std::vector<std::string>::iterator paramIt;
122 vtkSmartPointer<vtkXMLDataElement> paramElem = vtkSmartPointer<vtkXMLDataElement>::New();
123 paramElem->SetName(
"Parameter");
124 paramElem->SetAttribute(
"Name", paramIt->c_str());
125 aConfig->AddNestedElement(paramElem);
134 LOG_DEBUG(
"vtkPlusGetUsParameterCommand::Execute: " << (!this->
Name.empty() ? this->
Name :
"(undefined)")
137 if (this->
Name.empty())
142 else if (!igsioCommon::IsEqualInsensitive(this->
Name, GET_US_PARAMETER_CMD))
149 if (usDevice == NULL)
152 + (this->
UsDeviceId.empty() ?
"(undefined)" : this->
UsDeviceId) + std::string(
" is not found."));
156 std::map < std::string, std::pair<IANA_ENCODING_TYPE, std::string> > metaData;
159 std::string resultString =
"<CommandReply>";
160 std::string error =
"";
163 std::vector<std::string>::iterator paramIt;
166 std::string parameterName = *paramIt;
167 resultString +=
"<Parameter Name=\"" + parameterName +
"\"";
173 std::stringstream ss;
175 for (std::vector<double>::iterator numberIt = numbers.begin(); numberIt != numbers.end(); numberIt++)
177 ss << *numberIt <<
" ";
179 resultString +=
" Success=\"true\"";
180 resultString +=
" Value=\"" + ss.str() +
"\"";
181 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII, ss.str());
185 resultString +=
" Success=\"false\"";
186 error += parameterName +
" is not set. ";
194 std::stringstream ss;
195 FrameSizeType imageSize = imagingParameters->
GetImageSize();
196 for (FrameSizeType::iterator imageSizeIt = imageSize.begin(); imageSizeIt != imageSize.end(); ++imageSizeIt)
198 ss << *imageSizeIt <<
" ";
200 resultString +=
" Success=\"true\"";
201 resultString +=
" Value=\"" + ss.str() +
"\"";
202 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII, ss.str());
206 resultString +=
" Success=\"false\"";
207 error += parameterName +
" is not set. ";
224 if (imagingParameters->
IsSet(parameterName))
230 std::stringstream ss;
232 resultString +=
" Success=\"true\"";
233 resultString +=
" Value=\"" + ss.str() +
"\"";
234 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII, ss.str());
239 resultString +=
" Success=\"false\"";
240 error += parameterName +
" is not set. ";
246 error +=
"Invalid parameter " + parameterName +
". ";
247 resultString +=
" Success=\"false\"";
250 resultString +=
"/>";
253 resultString +=
"</CommandReply>";
257 LOG_WARNING(
"Failed to get US parameter, result string was: " << resultString);
260 vtkSmartPointer<vtkPlusCommandRTSCommandResponse> commandResponse = vtkSmartPointer<vtkPlusCommandRTSCommandResponse>::New();
261 commandResponse->UseDefaultFormatOff();
262 commandResponse->SetClientId(this->
ClientId);
263 commandResponse->SetOriginalId(this->
Id);
264 commandResponse->SetDeviceName(this->
DeviceName);
265 commandResponse->SetCommandName(this->GetName());
266 commandResponse->SetStatus(status);
268 commandResponse->SetErrorString(error);
269 commandResponse->SetResultString(resultString);
270 commandResponse->SetParameters(metaData);
280 if (dataCollector == NULL)
282 LOG_ERROR(
"Data collector is invalid");
292 LOG_ERROR(
"No ultrasound device has been found by the name " << this->
UsDeviceId);
296 usDevice = dynamic_cast<vtkPlusUsDevice*>(device);
297 if (usDevice == NULL)
300 LOG_ERROR(
"The specified device " << this->
UsDeviceId <<
" is not UsDevice");
309 usDevice = dynamic_cast<vtkPlusUsDevice*>(*it);
310 if (usDevice != NULL)
316 if (usDevice == NULL)
318 LOG_ERROR(
"No UsDevice has been found");
static const char * KEY_DYNRANGE
virtual vtkPlusUsImagingParameters * GetImagingParameters()
static const char * KEY_IMAGESIZE
virtual void PrintSelf(ostream &os, vtkIndent indent)
Abstract interface for tracker and video devices.
std::vector< vtkPlusDevice * >::const_iterator DeviceCollectionConstIterator
vtkPlusUsDevice * GetUsDevice()
virtual std::string GetDescription(const std::string &commandName)
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
static const char * KEY_DEPTH
This class is used to store a configuration of the imaging parameters of an ultrasound video device....
PlusStatus GetDevice(vtkPlusDevice *&aDevice, const std::string &aDeviceId) const
static const char * KEY_FOCUS_DEPTH
This command requests ultrasound parameter change in the client.
static const char * KEY_FREQUENCY
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
PlusStatus GetValue(const std::string ¶mName, T &outputValue) const
static const char * KEY_GAIN
virtual void PrintSelf(ostream &os, vtkIndent indent)
virtual ~vtkPlusGetUsParameterCommand()
void SetNameToGetUsParameter()
DeviceCollectionConstIterator GetDeviceConstIteratorBegin() const
static const char * KEY_INTENSITY
PlusStatus GetTimeGainCompensation(std::vector< double > &tgc) const
DeviceCollectionConstIterator GetDeviceConstIteratorEnd() const
virtual void GetCommandNames(std::list< std::string > &cmdNames)
Manages devices that record image or positional data.
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
bool RespondWithCommandMessage
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
static const char * KEY_SECTOR
static const char * KEY_POWER
void QueueCommandResponse(PlusStatus status, const std::string &message, const std::string &error="", const igtl::MessageBase::MetaDataMap *metaData=nullptr)
static const char * KEY_CONTRAST
virtual vtkPlusDataCollector * GetDataCollector()
PlusStatus GetImageSize(FrameSizeType &imageSize) const
vtkPlusGetUsParameterCommand()
static const char * KEY_SOUNDVELOCITY
static const char * KEY_VOLTAGE
const char const char * value
static const char * KEY_ZOOM
vtkStandardNewMacro(vtkPlusGetUsParameterCommand)
PlusCommandResponseList CommandResponseQueue
bool IsSet(const std::string ¶mName) const
Abstract interface for ultrasound video devices.
virtual PlusStatus Execute()
static const char * KEY_TGC
std::vector< std::string > RequestedParameters