7 #include "PlusConfigure.h" 11 #include "vtkObjectFactory.h" 17 #include <vtkVariant.h> 18 #include <vtkSmartPointer.h> 26 static const std::string SET_US_PARAMETER_CMD =
"SetUsParameter";
47 SetName(SET_US_PARAMETER_CMD);
60 cmdNames.push_back(SET_US_PARAMETER_CMD);
67 if (commandName.empty() || igsioCommon::IsEqualInsensitive(commandName, SET_US_PARAMETER_CMD))
69 desc += SET_US_PARAMETER_CMD;
71 desc +=
": Set depth 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");
95 const char* parameterValue = currentElem->GetAttribute(
"Value");
96 if (!parameterName || !parameterValue)
98 LOG_ERROR(
"Unable to find required Name or Value attribute in " << (currentElem->GetName() ? currentElem->GetName() :
"(undefined)") <<
" element in SetUsParameter command");
117 XML_WRITE_STRING_ATTRIBUTE_IF_NOT_EMPTY(
UsDeviceId, aConfig);
120 std::map<std::string, std::string>::iterator paramIt;
123 vtkSmartPointer<vtkXMLDataElement> paramElem = vtkSmartPointer<vtkXMLDataElement>::New();
124 paramElem->SetName(
"Parameter");
125 paramElem->SetAttribute(
"Name", paramIt->first.c_str());
126 paramElem->SetAttribute(
"Value", paramIt->second.c_str());
127 aConfig->AddNestedElement(paramElem);
136 LOG_DEBUG(
"vtkPlusSetUsParameterCommand::Execute: " << (!this->
Name.empty() ? this->
Name :
"(undefined)")
139 if (this->
Name.empty())
144 else if (!igsioCommon::IsEqualInsensitive(this->
Name, SET_US_PARAMETER_CMD))
151 if (usDevice == NULL)
154 + (this->
UsDeviceId.empty() ?
"(undefined)" : this->
UsDeviceId) + std::string(
" is not found."));
160 std::string resultString =
"<CommandReply>";
161 std::string error =
"";
162 std::map < std::string, std::pair<IANA_ENCODING_TYPE, std::string> > metaData;
165 std::map<std::string, std::string>::iterator paramIt;
168 std::string parameterName = paramIt->first;
169 std::string
value = paramIt->second;
170 resultString +=
"<Parameter Name=\"" + parameterName +
"\"";
174 std::stringstream ss;
176 std::vector<double> numbers((std::istream_iterator<double>(ss)), std::istream_iterator<double>());
177 if (numbers.size() != 3)
179 error +=
"Failed to parse " + parameterName +
".";
180 resultString +=
" Success=\"false\"/>";
181 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"FAIL");
189 std::stringstream ss;
191 std::vector<int> numbers((std::istream_iterator<int>(ss)), std::istream_iterator<int>());
192 if (numbers.size() != 3)
194 error +=
"Failed to parse " + parameterName +
". ";
195 resultString +=
" Success=\"false\"/>";
196 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"FAIL");
200 imagingParameters->
SetImageSize(numbers[0], numbers[1], numbers[2]);
217 double parameterValue = vtkVariant(
value).ToDouble(&valid);
220 error +=
"Failed to parse " + parameterName +
". ";
221 resultString +=
" Success=\"false\"/>";
222 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"FAIL");
226 imagingParameters->
SetValue<
double>(parameterName, parameterValue);
230 error +=
"Invalid parameter " + parameterName +
". ";
231 resultString +=
" Success=\"false\"/>";
232 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"FAIL");
239 error +=
"Failed to set " + parameterName +
". ";
240 resultString +=
" Success=\"false\"/>";
241 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"FAIL");
246 resultString +=
" Success=\"true\"/>";
247 metaData[parameterName] = std::make_pair(IANA_TYPE_US_ASCII,
"SUCCESS");
249 resultString +=
"</CommandReply>";
253 LOG_WARNING(
"Failed to set US parameter, result string was: " << resultString);
256 vtkSmartPointer<vtkPlusCommandRTSCommandResponse> commandResponse = vtkSmartPointer<vtkPlusCommandRTSCommandResponse>::New();
257 commandResponse->UseDefaultFormatOff();
258 commandResponse->SetClientId(this->
ClientId);
259 commandResponse->SetOriginalId(this->
Id);
260 commandResponse->SetDeviceName(this->
DeviceName);
261 commandResponse->SetCommandName(this->GetName());
262 commandResponse->SetStatus(status);
264 commandResponse->SetErrorString(error);
265 commandResponse->SetResultString(resultString);
266 commandResponse->SetParameters(metaData);
276 if (dataCollector == NULL)
278 LOG_ERROR(
"Data collector is invalid");
288 LOG_ERROR(
"No ultrasound device has been found by the name " << this->
UsDeviceId);
292 usDevice = dynamic_cast<vtkPlusUsDevice*>(device);
293 if (usDevice == NULL)
296 LOG_ERROR(
"The specified device " << this->
UsDeviceId <<
" is not UsDevice");
305 usDevice = dynamic_cast<vtkPlusUsDevice*>(*it);
306 if (usDevice != NULL)
312 if (usDevice == NULL)
314 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
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
virtual void PrintSelf(ostream &os, vtkIndent indent)
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
static const char * KEY_FREQUENCY
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
virtual std::string GetDeviceId() const
virtual void GetCommandNames(std::list< std::string > &cmdNames)
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *aConfig)
static const char * KEY_GAIN
virtual PlusStatus SetNewImagingParameters(const vtkPlusUsImagingParameters &newImagingParameters)
PlusStatus SetTimeGainCompensation(const std::vector< double > &tgc)
virtual PlusStatus Execute()
DeviceCollectionConstIterator GetDeviceConstIteratorBegin() const
static const char * KEY_INTENSITY
DeviceCollectionConstIterator GetDeviceConstIteratorEnd() const
Manages devices that record image or positional data.
bool RespondWithCommandMessage
virtual ~vtkPlusSetUsParameterCommand()
vtkPlusUsDevice * GetUsDevice()
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *aConfig)
virtual std::string GetDescription(const std::string &commandName)
static const char * KEY_SECTOR
static const char * KEY_POWER
PlusStatus SetImageSize(const FrameSizeType &imageSize)
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()
static const char * KEY_SOUNDVELOCITY
void SetNameToSetUsParameter()
static const char * KEY_VOLTAGE
const char const char * value
static const char * KEY_ZOOM
PlusStatus SetValue(const std::string ¶mName, T aValue)
vtkPlusSetUsParameterCommand()
PlusCommandResponseList CommandResponseQueue
vtkStandardNewMacro(vtkPlusSetUsParameterCommand)
Abstract interface for ultrasound video devices.
std::map< std::string, std::string > RequestedParameterChanges
static const char * KEY_TGC
This command requests ultrasound parameter change in the client.