45 #include <visp3/core/vpXmlParserHomogeneousMatrix.h>
51 #include <visp3/core/vpDebug.h>
52 #include <visp3/core/vpThetaUVector.h>
57 #define LABEL_XML_ROOT "root"
58 #define LABEL_XML_M "homogeneous_transformation"
59 #define LABEL_XML_M_NAME "name"
60 #define LABEL_XML_VALUE "values"
61 #define LABEL_XML_TRANSLATION "translation"
62 #define LABEL_XML_TX "tx"
63 #define LABEL_XML_TY "ty"
64 #define LABEL_XML_TZ "tz"
65 #define LABEL_XML_ROTATION "rotation"
66 #define LABEL_XML_TUX "theta_ux"
67 #define LABEL_XML_TUY "theta_uy"
68 #define LABEL_XML_TUZ "theta_uz"
95 this->m_M = twinParser.m_M;
96 this->m_name = twinParser.m_name;
111 const std::string &name)
116 doc = xmlParseFile(filename.c_str());
119 std::cerr << std::endl
120 <<
"ERROR:" << std::endl;
121 std::cerr <<
" I cannot open the file "<< filename << std::endl;
126 node = xmlDocGetRootElement(doc);
133 int ret =
this ->read (doc, node, name);
152 const std::string &name)
157 doc = xmlReadFile(filename.c_str(), NULL, XML_PARSE_NOWARNING + XML_PARSE_NOERROR
158 + XML_PARSE_NOBLANKS);
160 doc = xmlNewDoc ((xmlChar*)
"1.0");
161 node = xmlNewNode(NULL,(xmlChar*)LABEL_XML_ROOT);
162 xmlDocSetRootElement(doc,node);
163 xmlNodePtr node_tmp = xmlNewComment((xmlChar*)
164 "This file stores homogeneous matrix used\n"
165 " in the vpHomogeneousMatrix Class of ViSP available\n"
166 " at http://www.irisa.fr/lagadic/visp/visp.html .\n"
167 " It can be read with the parse method of\n"
168 " the vpXmlParserHomogeneousMatrix class.");
169 xmlAddChild(node,node_tmp);
172 node = xmlDocGetRootElement(doc);
181 int M_isFound = count(doc, node, name);
185 std::cout <<
"There is already an homogeneous matrix "<< std::endl
186 <<
"available in the file with the input name: "<< name <<
"."<< std::endl
187 <<
"Please delete it manually from the xml file."<< std::endl;
194 xmlSaveFormatFile(filename.c_str(), doc, 1);
212 vpXmlParserHomogeneousMatrix::read (xmlDocPtr doc, xmlNodePtr node,
213 const std::string& name)
219 unsigned int nbM = 0;
221 for (node = node->xmlChildrenNode; node != NULL; node = node->next)
223 if (node->type != XML_ELEMENT_NODE)
continue;
224 if (
SEQUENCE_OK != str2xmlcode ((
char*)(node ->name), prop))
231 if (
SEQUENCE_OK == this->read_matrix (doc, node, name))
239 vpCERROR <<
"No Homogeneous matrix is available" << std::endl
240 <<
"with name: " << name << std::endl;
244 vpCERROR << nbM <<
" There are more Homogeneous matrix" << std::endl
245 <<
"with the same name : " << std::endl
246 <<
"precise your choice..." << std::endl;
262 vpXmlParserHomogeneousMatrix::count (xmlDocPtr doc, xmlNodePtr node,
263 const std::string& name)
269 for (node = node->xmlChildrenNode; node != NULL; node = node->next)
271 if (node->type != XML_ELEMENT_NODE)
continue;
272 if (
SEQUENCE_OK != str2xmlcode ((
char*)(node ->name), prop))
277 if (
SEQUENCE_OK == this->read_matrix (doc, node, name))
296 vpXmlParserHomogeneousMatrix::read_matrix (xmlDocPtr doc, xmlNodePtr node,
297 const std::string& name)
301 std::string M_name_tmp =
"";
306 for (node = node->xmlChildrenNode; node != NULL; node = node->next)
309 if (node->type != XML_ELEMENT_NODE)
continue;
310 if (
SEQUENCE_OK != str2xmlcode ((
char*)(node ->name), prop))
321 M_name_tmp = val_char;
327 if (name == M_name_tmp)
329 std::cout <<
"Found Homogeneous Matrix with name: \"" << M_name_tmp <<
"\"" << std::endl;
330 back = read_values(doc, node, M_tmp);
351 if( !(name == M_name_tmp)){
358 this-> m_name = M_name_tmp;
376 vpXmlParserHomogeneousMatrix::read_values (xmlDocPtr doc, xmlNodePtr node,
394 for (node = node->xmlChildrenNode; node != NULL; node = node->next)
397 if (node->type != XML_ELEMENT_NODE)
continue;
398 if (
SEQUENCE_OK != str2xmlcode ((
char*)(node ->name), prop))
446 vpCERROR <<
"ERROR in 'model' field:\n";
447 vpCERROR <<
"it must contain 6 parameters\n";
475 int vpXmlParserHomogeneousMatrix::
476 write (xmlNodePtr node,
const std::string& name)
481 xmlNodePtr node_matrix;
482 xmlNodePtr node_values;
491 node_tmp = xmlNewComment((xmlChar*)
"Homogeneous Matrix");
492 xmlAddChild(node,node_tmp);
493 node_matrix = xmlNewNode(NULL,(xmlChar*)LABEL_XML_M);
494 xmlAddChild(node,node_matrix);
499 node_tmp = xmlNewComment((xmlChar*)
"Name of the homogeneous matrix");
500 xmlAddChild(node_matrix,node_tmp);
501 xmlNewTextChild(node_matrix,NULL,(xmlChar*)LABEL_XML_M_NAME, (xmlChar*)name.c_str());
506 node_values = xmlNewNode(NULL,(xmlChar*)LABEL_XML_VALUE);
507 xmlAddChild(node_matrix,node_values);
511 node_tmp = xmlNewComment((xmlChar*)
"Translation vector with values in meters");
512 xmlAddChild(node_values,node_tmp);
515 sprintf(str,
"%f", m_M[0][3]);
516 xmlNewTextChild(node_values,NULL,(xmlChar*)LABEL_XML_TX,(xmlChar*)str);
519 sprintf(str,
"%f", m_M[1][3]);
520 xmlNewTextChild(node_values,NULL,(xmlChar*)LABEL_XML_TY,(xmlChar*)str);
523 sprintf(str,
"%f", m_M[2][3]);
524 xmlNewTextChild(node_values,NULL,(xmlChar*)LABEL_XML_TZ,(xmlChar*)str);
526 node_tmp = xmlNewComment((xmlChar*)
"Rotational vector expressed in angle axis representation with values in radians");
527 xmlAddChild(node_values,node_tmp);
530 sprintf(str,
"%f", tu[0]);
531 xmlNewTextChild(node_values,NULL,(xmlChar*)LABEL_XML_TUX,(xmlChar*)str);
534 sprintf(str,
"%f", tu[1]);
535 xmlNewTextChild(node_values,NULL,(xmlChar*)LABEL_XML_TUY,(xmlChar*)str);
538 sprintf(str,
"%f", tu[2]);
539 xmlNewTextChild(node_values,NULL,(xmlChar*)LABEL_XML_TUZ,(xmlChar*)str);
554 vpXmlParserHomogeneousMatrix::str2xmlcode (
char * str, vpXmlCodeType & res)
561 if (! strcmp (str, LABEL_XML_M))
565 else if (! strcmp (str, LABEL_XML_M_NAME))
569 else if (! strcmp (str, LABEL_XML_VALUE))
573 else if (! strcmp (str, LABEL_XML_TX))
577 else if (! strcmp (str, LABEL_XML_TY))
581 else if (! strcmp (str, LABEL_XML_TZ))
585 else if (! strcmp (str, LABEL_XML_TUX))
589 else if (! strcmp (str, LABEL_XML_TUY))
593 else if (! strcmp (str, LABEL_XML_TUZ))
605 #elif !defined(VISP_BUILD_SHARED_LIBS)
607 void dummy_vpXmlParserHomogeneousMatrix() {};
608 #endif //VISP_HAVE_XML2
int parse(vpHomogeneousMatrix &M, const std::string &filename, const std::string &name)
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpXmlParserHomogeneousMatrix & operator=(const vpXmlParserHomogeneousMatrix &twinparser)
double xmlReadDoubleChild(xmlDocPtr doc, xmlNodePtr node)
char * xmlReadCharChild(xmlDocPtr doc, xmlNodePtr node)
Implementation of a rotation matrix and operations on such kind of matrices.
This class intends to simplify the creation of xml parser based on the libxml2 third party library...
int save(const vpHomogeneousMatrix &M, const std::string &filename, const std::string &name)
XML parser to load and save an homogeneous matrix in a file.
void extract(vpRotationMatrix &R) const
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
vpXmlParserHomogeneousMatrix()
Implementation of a rotation vector as axis-angle minimal representation.