11 #include <igtl_header.h> 15 : ClientHeaderVersion(IGTL_HEADER_VERSION_1)
17 , TDATARequested(false)
18 , LastTDATASentTimeStamp(-1)
26 if (strXmlData == NULL)
28 LOG_ERROR(
"Failed to set ClientInfo - input xml data string is invalid");
32 vtkSmartPointer<vtkXMLDataElement> xmldata = vtkSmartPointer<vtkXMLDataElement>::Take(vtkXMLUtilities::ReadElementFromString(strXmlData));
35 LOG_ERROR(
"Failed to set ClientInfo - invalid xml data string: " << strXmlData);
48 LOG_ERROR(
"Failed to set ClientInfo - invalid xml data string!");
57 if (xmldata->GetAttribute(
"Resolution") != NULL)
60 XML_READ_SCALAR_ATTRIBUTE_NONMEMBER_OPTIONAL(
int, Resolution, resolution, xmldata);
63 LOG_WARNING(
"Old parameter name \"Resolution\" detected. Please replace with \"TDATAResolution\".");
64 xmldata->RemoveAttribute(
"Resolution");
65 xmldata->SetIntAttribute(
"TDATAResolution", resolution);
69 vtkXMLDataElement* messageTypes = xmldata->FindNestedElementWithName(
"MessageTypes");
70 if (messageTypes != NULL)
72 for (
int i = 0;
i < messageTypes->GetNumberOfNestedElements(); ++
i)
74 const char* name = messageTypes->GetNestedElement(
i)->GetName();
75 if (name == NULL || STRCASECMP(name,
"Message") != 0)
79 vtkXMLDataElement* typeElem = messageTypes->GetNestedElement(
i);
81 XML_READ_STRING_ATTRIBUTE_NONMEMBER_REQUIRED(Type, type, typeElem);
87 vtkXMLDataElement* transformNames = xmldata->FindNestedElementWithName(
"TransformNames");
88 if (transformNames != NULL)
90 for (
int i = 0;
i < transformNames->GetNumberOfNestedElements(); ++
i)
92 const char* transform = transformNames->GetNestedElement(
i)->GetName();
93 if (transform == NULL || STRCASECMP(transform,
"Transform") != 0)
97 vtkXMLDataElement* transformElem = transformNames->GetNestedElement(
i);
99 XML_READ_STRING_ATTRIBUTE_NONMEMBER_OPTIONAL(Name, name, transformElem);
102 LOG_WARNING(
"In TransformNames child transform #" <<
i <<
" definition is incomplete: required Name attribute is missing.");
106 igsioTransformName tName;
109 LOG_WARNING(
"Invalid transform name: " << name);
117 vtkXMLDataElement* imageNames = xmldata->FindNestedElementWithName(
"ImageNames");
118 if (imageNames != NULL)
120 for (
int i = 0;
i < imageNames->GetNumberOfNestedElements(); ++
i)
122 const char* image = imageNames->GetNestedElement(
i)->GetName();
123 if (image == NULL || STRCASECMP(image,
"Image") != 0)
127 vtkXMLDataElement* imageElem = imageNames->GetNestedElement(
i);
128 std::string embeddedTransformToFrame;
129 XML_READ_STRING_ATTRIBUTE_NONMEMBER_OPTIONAL(EmbeddedTransformToFrame, embeddedTransformToFrame, imageElem);
130 if (embeddedTransformToFrame.empty())
132 LOG_WARNING(
"EmbeddedTransformToFrame attribute of ImageNames/Image element #" <<
i <<
" is missing. This element will be ignored.");
137 XML_READ_STRING_ATTRIBUTE_NONMEMBER_OPTIONAL(Name, name, imageElem);
140 LOG_WARNING(
"Name attribute of ImageNames/Image element # " <<
i <<
" is missing. This element will be ignored.");
147 stream.
FrameConverter = vtkSmartPointer<vtkIGSIOFrameConverter>::New();
155 vtkXMLDataElement* videoNames = xmldata->FindNestedElementWithName(
"VideoNames");
156 if (videoNames != NULL)
158 for (
int i = 0;
i < videoNames->GetNumberOfNestedElements(); ++
i)
160 const char* video = videoNames->GetNestedElement(
i)->GetName();
161 if (video == NULL || STRCASECMP(video,
"Video") != 0)
165 vtkXMLDataElement* videoElem = videoNames->GetNestedElement(
i);
166 std::string embeddedTransformToFrame;
167 XML_READ_STRING_ATTRIBUTE_NONMEMBER_OPTIONAL(EmbeddedTransformToFrame, embeddedTransformToFrame, videoElem);
168 if (embeddedTransformToFrame.empty())
170 LOG_WARNING(
"EmbeddedTransformToFrame attribute of VideoNames/Video element #" <<
i <<
" is missing. This element will be ignored.");
175 XML_READ_STRING_ATTRIBUTE_NONMEMBER_OPTIONAL(Name, name, videoElem);
178 LOG_WARNING(
"Name attribute of videoNames/Video element # " <<
i <<
" is missing. This element will be ignored.");
185 stream.
FrameConverter = vtkSmartPointer<vtkIGSIOFrameConverter>::New();
188 XML_FIND_NESTED_ELEMENT_OPTIONAL(encodingElem, videoElem,
"Encoding");
206 vtkXMLDataElement* stringNames = xmldata->FindNestedElementWithName(
"StringNames");
207 if (stringNames != NULL)
209 for (
int i = 0;
i < stringNames->GetNumberOfNestedElements(); ++
i)
211 const char*
string = stringNames->GetNestedElement(
i)->GetName();
212 if (
string == NULL || STRCASECMP(
string,
"String") != 0)
216 vtkXMLDataElement* stringElem = stringNames->GetNestedElement(
i);
218 XML_READ_STRING_ATTRIBUTE_NONMEMBER_OPTIONAL(Name, name, stringElem);
221 LOG_WARNING(
"In StringNames child element #" <<
i <<
" definition is incomplete: required Name attribute is missing");
230 (*this) = clientInfo;
238 vtkSmartPointer<vtkXMLDataElement> xmldata = vtkSmartPointer<vtkXMLDataElement>::New();
239 xmldata->SetName(
"ClientInfo");
240 xmldata->SetAttribute(
"TDATARequested", (this->
GetTDATARequested() ?
"TRUE" :
"FALSE"));
243 vtkSmartPointer<vtkXMLDataElement> messageTypes = vtkSmartPointer<vtkXMLDataElement>::New();
244 messageTypes->SetName(
"MessageTypes");
247 vtkSmartPointer<vtkXMLDataElement>
message = vtkSmartPointer<vtkXMLDataElement>::New();
250 messageTypes->AddNestedElement(
message);
252 xmldata->AddNestedElement(messageTypes);
254 vtkSmartPointer<vtkXMLDataElement> transformNames = vtkSmartPointer<vtkXMLDataElement>::New();
255 transformNames->SetName(
"TransformNames");
260 std::string transformName;
262 LOG_ERROR(
"Failed to add transform name to client info - transform name is invalid (" << transformName <<
").");
265 vtkSmartPointer<vtkXMLDataElement> transform = vtkSmartPointer<vtkXMLDataElement>::New();
266 transform->SetName(
"Transform");
269 transform->SetAttribute(
"Name", tname.c_str());
270 transformNames->AddNestedElement(transform);
272 xmldata->AddNestedElement(transformNames);
274 vtkSmartPointer<vtkXMLDataElement> stringNames = vtkSmartPointer<vtkXMLDataElement>::New();
275 stringNames->SetName(
"StringNames");
280 LOG_ERROR(
"Failed to add string name to client info - string name is empty");
283 vtkSmartPointer<vtkXMLDataElement> stringElem = vtkSmartPointer<vtkXMLDataElement>::New();
284 stringElem->SetName(
"String");
285 stringElem->SetAttribute(
"Name",
StringNames[
i].c_str());
286 stringNames->AddNestedElement(stringElem);
288 xmldata->AddNestedElement(stringNames);
290 vtkSmartPointer<vtkXMLDataElement> imageNames = vtkSmartPointer<vtkXMLDataElement>::New();
291 imageNames->SetName(
"ImageNames");
294 vtkSmartPointer<vtkXMLDataElement> image = vtkSmartPointer<vtkXMLDataElement>::New();
295 image->SetName(
"Image");
297 image->SetAttribute(
"EmbeddedTransformToFrame",
ImageStreams[
i].EmbeddedTransformToFrame.c_str());
298 imageNames->AddNestedElement(image);
300 xmldata->AddNestedElement(imageNames);
302 std::ostringstream os;
303 igsioCommon::XML::PrintXML(os, vtkIndent(0), xmldata);
304 strXmlData = os.str();
311 os << indent <<
"Message types: ";
327 os << indent <<
". ";
329 os << indent <<
"TDATARequested: " << (this->
GetTDATARequested() ?
"TRUE" :
"FALSE") <<
". ";
333 os <<
". Transforms: ";
355 std::ostringstream stringNames;
373 std::ostringstream imageNames;
void SetLastTDATASentTimeStamp(double val)
double GetLastTDATASentTimeStamp() const
std::string EmbeddedTransformToFrame
std::vector< ImageStream > ImageStreams
std::vector< std::string > IgtlMessageTypes
void SetClientHeaderVersion(int version)
PlusStatus SetClientInfoFromXmlData(const char *strXmlData)
std::vector< std::string > StringNames
vtkSmartPointer< vtkIGSIOFrameConverter > FrameConverter
std::vector< igsioTransformName > TransformNames
bool GetTDATARequested() const
EncodingParameters EncodeVideoParameters
double LastTDATASentTimeStamp
int GetTDATAResolution() const
std::vector< VideoStream > VideoStreams
int GetClientHeaderVersion() const
void SetTDATARequested(bool val)
This class provides client information for vtkPlusOpenIGTLinkServer.
void SetTDATAResolution(int val)
vtkSmartPointer< vtkIGSIOFrameConverter > FrameConverter
std::string EmbeddedTransformToFrame
void GetClientInfoInXmlData(std::string &strXmlData)
virtual void PrintSelf(ostream &os, vtkIndent indent)