49 #include <visp/vpXmlParserHomogeneousMatrix.h>
55 #include <visp/vpDebug.h>
56 #include <visp/vpThetaUVector.h>
61 #define LABEL_XML_ROOT "root"
62 #define LABEL_XML_M "homogeneous_transformation"
63 #define LABEL_XML_M_NAME "name"
64 #define LABEL_XML_VALUE "values"
65 #define LABEL_XML_TRANSLATION "translation"
66 #define LABEL_XML_TX "tx"
67 #define LABEL_XML_TY "ty"
68 #define LABEL_XML_TZ "tz"
69 #define LABEL_XML_ROTATION "rotation"
70 #define LABEL_XML_TUX "theta_ux"
71 #define LABEL_XML_TUY "theta_uy"
72 #define LABEL_XML_TUZ "theta_uz"
99 this->m_M = twinParser.m_M;
100 this->m_name = twinParser.m_name;
115 const std::string &name)
120 doc = xmlParseFile(filename.c_str());
123 std::cerr << std::endl
124 <<
"ERROR:" << std::endl;
125 std::cerr <<
" I cannot open the file "<< filename << std::endl;
130 node = xmlDocGetRootElement(doc);
137 int ret =
this ->read (doc, node, name);
156 const std::string &name)
161 doc = xmlReadFile(filename.c_str(), NULL, XML_PARSE_NOWARNING + XML_PARSE_NOERROR
162 + XML_PARSE_NOBLANKS);
164 doc = xmlNewDoc ((xmlChar*)
"1.0");
165 node = xmlNewNode(NULL,(xmlChar*)LABEL_XML_ROOT);
166 xmlDocSetRootElement(doc,node);
167 xmlNodePtr node_tmp = xmlNewComment((xmlChar*)
168 "This file stores homogeneous matrix used\n"
169 " in the vpHomogeneousMatrix Class of ViSP available\n"
170 " at http://www.irisa.fr/lagadic/visp/visp.html .\n"
171 " It can be read with the parse method of\n"
172 " the vpXmlParserHomogeneousMatrix class.");
173 xmlAddChild(node,node_tmp);
176 node = xmlDocGetRootElement(doc);
185 int M_isFound = count(doc, node, name);
189 std::cout <<
"There is already an homogeneous matrix "<< std::endl
190 <<
"available in the file with the input name: "<< name <<
"."<< std::endl
191 <<
"Please delete it manually from the xml file."<< std::endl;
198 xmlSaveFormatFile(filename.c_str(), doc, 1);
216 vpXmlParserHomogeneousMatrix::read (xmlDocPtr doc, xmlNodePtr node,
217 const std::string& name)
223 unsigned int nbM = 0;
225 for (node = node->xmlChildrenNode; node != NULL; node = node->next)
227 if (node->type != XML_ELEMENT_NODE)
continue;
228 if (
SEQUENCE_OK != str2xmlcode ((
char*)(node ->name), prop))
235 if (
SEQUENCE_OK == this->read_matrix (doc, node, name))
243 vpCERROR <<
"No Homogeneous matrix is available" << std::endl
244 <<
"with name: " << name << std::endl;
248 vpCERROR << nbM <<
" There are more Homogeneous matrix" << std::endl
249 <<
"with the same name : " << std::endl
250 <<
"precise your choice..." << std::endl;
266 vpXmlParserHomogeneousMatrix::count (xmlDocPtr doc, xmlNodePtr node,
267 const std::string& name)
273 for (node = node->xmlChildrenNode; node != NULL; node = node->next)
275 if (node->type != XML_ELEMENT_NODE)
continue;
276 if (
SEQUENCE_OK != str2xmlcode ((
char*)(node ->name), prop))
281 if (
SEQUENCE_OK == this->read_matrix (doc, node, name))
300 vpXmlParserHomogeneousMatrix::read_matrix (xmlDocPtr doc, xmlNodePtr node,
301 const std::string& name)
305 std::string M_name_tmp =
"";
310 for (node = node->xmlChildrenNode; node != NULL; node = node->next)
313 if (node->type != XML_ELEMENT_NODE)
continue;
314 if (
SEQUENCE_OK != str2xmlcode ((
char*)(node ->name), prop))
325 M_name_tmp = val_char;
331 if (name == M_name_tmp)
333 std::cout <<
"Found Homogeneous Matrix with name: \"" << M_name_tmp <<
"\"" << std::endl;
334 back = read_values(doc, node, M_tmp);
355 if( !(name == M_name_tmp)){
362 this-> m_name = M_name_tmp;
380 vpXmlParserHomogeneousMatrix::read_values (xmlDocPtr doc, xmlNodePtr node,
398 for (node = node->xmlChildrenNode; node != NULL; node = node->next)
401 if (node->type != XML_ELEMENT_NODE)
continue;
402 if (
SEQUENCE_OK != str2xmlcode ((
char*)(node ->name), prop))
450 vpCERROR <<
"ERROR in 'model' field:\n";
451 vpCERROR <<
"it must contain 6 parameters\n";
479 int vpXmlParserHomogeneousMatrix::
480 write (xmlNodePtr node,
const std::string& name)
485 xmlNodePtr node_matrix;
486 xmlNodePtr node_values;
496 node_tmp = xmlNewComment((xmlChar*)
"Homogeneous Matrix");
497 xmlAddChild(node,node_tmp);
498 node_matrix = xmlNewNode(NULL,(xmlChar*)LABEL_XML_M);
499 xmlAddChild(node,node_matrix);
504 node_tmp = xmlNewComment((xmlChar*)
"Name of the homogeneous matrix");
505 xmlAddChild(node_matrix,node_tmp);
506 xmlNewTextChild(node_matrix,NULL,(xmlChar*)LABEL_XML_M_NAME, (xmlChar*)name.c_str());
511 node_values = xmlNewNode(NULL,(xmlChar*)LABEL_XML_VALUE);
512 xmlAddChild(node_matrix,node_values);
514 node_tmp = xmlNewComment((xmlChar*)
"Translation vector with values in meters");
515 xmlAddChild(node_values,node_tmp);
518 sprintf(str,
"%f", m_M[0][3]);
519 xmlNewTextChild(node_values,NULL,(xmlChar*)LABEL_XML_TX,(xmlChar*)str);
522 sprintf(str,
"%f", m_M[1][3]);
523 xmlNewTextChild(node_values,NULL,(xmlChar*)LABEL_XML_TY,(xmlChar*)str);
526 sprintf(str,
"%f", m_M[2][3]);
527 xmlNewTextChild(node_values,NULL,(xmlChar*)LABEL_XML_TZ,(xmlChar*)str);
529 node_tmp = xmlNewComment((xmlChar*)
"Rotational vector expressed in angle axis representation with values in radians");
530 xmlAddChild(node_values,node_tmp);
533 sprintf(str,
"%f", tu[0]);
534 xmlNewTextChild(node_values,NULL,(xmlChar*)LABEL_XML_TUX,(xmlChar*)str);
537 sprintf(str,
"%f", tu[1]);
538 xmlNewTextChild(node_values,NULL,(xmlChar*)LABEL_XML_TUY,(xmlChar*)str);
541 sprintf(str,
"%f", tu[2]);
542 xmlNewTextChild(node_values,NULL,(xmlChar*)LABEL_XML_TUZ,(xmlChar*)str);
557 vpXmlParserHomogeneousMatrix::str2xmlcode (
char * str, vpXmlCodeType & res)
564 if (! strcmp (str, LABEL_XML_M))
568 else if (! strcmp (str, LABEL_XML_M_NAME))
572 else if (! strcmp (str, LABEL_XML_VALUE))
576 else if (! strcmp (str, LABEL_XML_TX))
580 else if (! strcmp (str, LABEL_XML_TY))
584 else if (! strcmp (str, LABEL_XML_TZ))
588 else if (! strcmp (str, LABEL_XML_TUX))
592 else if (! strcmp (str, LABEL_XML_TUY))
596 else if (! strcmp (str, LABEL_XML_TUZ))
608 #endif //VISP_HAVE_XML2
int parse(vpHomogeneousMatrix &M, const std::string &filename, const std::string &name)
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
vpXmlParserHomogeneousMatrix & operator=(const vpXmlParserHomogeneousMatrix &twinparser)
double xmlReadDoubleChild(xmlDocPtr doc, xmlNodePtr node)
char * xmlReadCharChild(xmlDocPtr doc, xmlNodePtr node)
The vpRotationMatrix considers the particular case of a rotation matrix.
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 homogenous matrix in a file.
void extract(vpRotationMatrix &R) const
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
Construction from translation vector and rotation matrix.
vpXmlParserHomogeneousMatrix()
Class that consider the case of the parameterization for the rotation.