38 #include <visp3/ustk_core/usImageHeaderXmlParser.h>
40 #if defined(VISP_HAVE_XML2) && (defined(USTK_HAVE_QT5) || defined(USTK_HAVE_VTK_QT))
82 for (xmlNodePtr dataNode = node->xmlChildrenNode; dataNode != NULL; dataNode = dataNode->next) {
83 if (dataNode->type == XML_ELEMENT_NODE) {
84 std::map<std::string, int>::iterator iter_data = this->nodeMap.find((
char *)dataNode->name);
85 if (iter_data != nodeMap.end()) {
86 switch (iter_data->second) {
88 this->m_imageHeader.
frameCount = xmlReadUInt32Child(doc, dataNode);
91 this->m_imageHeader.
timeStamp = xmlReadUInt64Child(doc, dataNode);
94 this->m_imageHeader.
dataRate = xmlReadDoubleChild(doc, dataNode);
97 this->m_imageHeader.
dataLength = xmlReadIntChild(doc, dataNode);
100 this->m_imageHeader.
ss = xmlReadIntChild(doc, dataNode);
103 this->m_imageHeader.
imageType = xmlReadIntChild(doc, dataNode);
106 this->m_imageHeader.
frameWidth = xmlReadIntChild(doc, dataNode);
109 this->m_imageHeader.
frameHeight = xmlReadIntChild(doc, dataNode);
112 this->m_imageHeader.
pixelWidth = xmlReadDoubleChild(doc, dataNode);
115 this->m_imageHeader.
pixelHeight = xmlReadDoubleChild(doc, dataNode);
127 this->m_imageHeader.
scanLinePitch = xmlReadDoubleChild(doc, dataNode);
130 this->m_imageHeader.
scanLineNumber = xmlReadIntChild(doc, dataNode);
133 this->m_imageHeader.
imageDepth = xmlReadIntChild(doc, dataNode);
136 this->m_imageHeader.
anglePerFr = xmlReadDoubleChild(doc, dataNode);
142 this->m_imageHeader.
motorRadius = xmlReadDoubleChild(doc, dataNode);
145 this->m_imageHeader.
motorType = xmlReadIntChild(doc, dataNode);
148 this->m_sequence_name = xmlReadStringChild(doc, dataNode);
151 vpTRACE(
"unknown tag in readConfigNode : %d, %s", iter_data->second, (iter_data->first).c_str());
165 xmlWriteUInt32Child(node,
"frame_count", this->m_imageHeader.
frameCount);
166 xmlWriteUInt64Child(node,
"time_stamp", this->m_imageHeader.
timeStamp);
167 xmlWriteDoubleChild(node,
"time_rate", this->m_imageHeader.
dataRate);
168 xmlWriteIntChild(node,
"data_length", this->m_imageHeader.
dataLength);
169 xmlWriteIntChild(node,
"sample_size", this->m_imageHeader.
ss);
170 xmlWriteIntChild(node,
"image_type", this->m_imageHeader.
imageType);
171 xmlWriteIntChild(node,
"frame_with", this->m_imageHeader.
frameWidth);
172 xmlWriteIntChild(node,
"frame_height", this->m_imageHeader.
frameHeight);
173 xmlWriteDoubleChild(node,
"pixel_width", this->m_imageHeader.
pixelWidth);
174 xmlWriteDoubleChild(node,
"pixel_height", this->m_imageHeader.
pixelHeight);
175 xmlWriteIntChild(node,
"transmit_frequency", this->m_imageHeader.
transmitFrequency);
176 xmlWriteIntChild(node,
"sampling_frequency", this->m_imageHeader.
samplingFrequency);
177 xmlWriteDoubleChild(node,
"transducer_radius", this->m_imageHeader.
transducerRadius);
178 xmlWriteDoubleChild(node,
"scanline_pitch", this->m_imageHeader.
scanLinePitch);
179 xmlWriteUnsignedIntChild(node,
"scanline_number", this->m_imageHeader.
scanLineNumber);
180 xmlWriteIntChild(node,
"image_depth", this->m_imageHeader.
imageDepth);
181 xmlWriteDoubleChild(node,
"angle_per_frame", this->m_imageHeader.
anglePerFr);
182 xmlWriteIntChild(node,
"frame_per_volume", this->m_imageHeader.
framesPerVolume);
183 xmlWriteDoubleChild(node,
"motor_radius", this->m_imageHeader.
motorRadius);
184 xmlWriteIntChild(node,
"motor_type", this->m_imageHeader.
motorType);
185 xmlWriteStringChild(node,
"sequence_name", this->m_sequence_name);
188 uint32_t usImageHeaderXmlParser::xmlReadUInt32Child(xmlDocPtr doc, xmlNodePtr node)
190 if (node->xmlChildrenNode == NULL) {
191 std::string errorMsg =
"Empty node " + std::string((
char *)node->name) +
", cannot read int";
192 std::cerr << errorMsg << std::endl;
193 throw vpException(vpException::fatalError, errorMsg);
196 char *control_convert;
199 val_char = (
char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
200 val_int = (uint32_t)strtol((
char *)val_char, &control_convert, 10);
202 if (val_char == control_convert) {
203 xmlFree((xmlChar *)val_char);
204 throw vpException(vpException::ioError,
"cannot parse entry to quint32");
206 xmlFree((xmlChar *)val_char);
211 uint64_t usImageHeaderXmlParser::xmlReadUInt64Child(xmlDocPtr doc, xmlNodePtr node)
213 if (node->xmlChildrenNode == NULL) {
214 std::string errorMsg =
"Empty node " + std::string((
char *)node->name) +
", cannot read int";
215 std::cerr << errorMsg << std::endl;
216 throw vpException(vpException::fatalError, errorMsg);
219 char *control_convert;
222 val_char = (
char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
223 val_int = (uint64_t)strtoull((
char *)val_char, &control_convert, 10);
225 if (val_char == control_convert) {
226 xmlFree((xmlChar *)val_char);
227 throw vpException(vpException::ioError,
"cannot parse entry to quint64");
229 xmlFree((xmlChar *)val_char);
234 void usImageHeaderXmlParser::xmlWriteUInt32Child(xmlNodePtr node,
const char *label,
const uint32_t value)
236 std::ostringstream os;
238 xmlNodePtr tmp = xmlNewChild(node, NULL, (xmlChar *)label, (xmlChar *)os.str().c_str());
239 xmlAddChild(node, tmp);
242 void usImageHeaderXmlParser::xmlWriteUInt64Child(xmlNodePtr node,
const char *label,
const uint64_t value)
244 std::ostringstream os;
246 xmlNodePtr tmp = xmlNewChild(node, NULL, (xmlChar *)label, (xmlChar *)os.str().c_str());
247 xmlAddChild(node, tmp);