46 #include <visp3/core/vpXmlParserHomogeneousMatrix.h> 52 #include <visp3/core/vpDebug.h> 53 #include <visp3/core/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" 95 this->m_M = twinParser.m_M;
96 this->m_name = twinParser.m_name;
114 doc = xmlParseFile(filename.c_str());
116 std::cerr << std::endl <<
"ERROR:" << std::endl;
117 std::cerr <<
" I cannot open the file " << filename << std::endl;
122 node = xmlDocGetRootElement(doc);
128 int ret = this->read(doc, node, name);
146 const std::string &name)
151 doc = xmlReadFile(filename.c_str(), NULL, XML_PARSE_NOWARNING + XML_PARSE_NOERROR + XML_PARSE_NOBLANKS);
153 doc = xmlNewDoc((xmlChar *)
"1.0");
154 node = xmlNewNode(NULL, (xmlChar *)LABEL_XML_ROOT);
155 xmlDocSetRootElement(doc, node);
156 xmlNodePtr node_tmp = xmlNewComment((xmlChar *)
"This file stores homogeneous matrix used\n" 157 " in the vpHomogeneousMatrix Class of ViSP available\n" 158 " at https://visp.inria.fr/download/ .\n" 159 " It can be read with the parse method of\n" 160 " the vpXmlParserHomogeneousMatrix class.");
161 xmlAddChild(node, node_tmp);
164 node = xmlDocGetRootElement(doc);
172 int M_isFound = count(doc, node, name);
176 std::cout <<
"There is already an homogeneous matrix " << std::endl
177 <<
"available in the file with the input name: " << name <<
"." << std::endl
178 <<
"Please delete it manually from the xml file." << std::endl;
185 xmlSaveFormatFile(filename.c_str(), doc, 1);
201 int vpXmlParserHomogeneousMatrix::read(xmlDocPtr doc, xmlNodePtr node,
const std::string &name)
207 unsigned int nbM = 0;
209 for (node = node->xmlChildrenNode; node != NULL; node = node->next) {
210 if (node->type != XML_ELEMENT_NODE)
212 if (
SEQUENCE_OK != str2xmlcode((
char *)(node->name), prop)) {
218 if (
SEQUENCE_OK == this->read_matrix(doc, node, name))
226 vpCERROR <<
"No Homogeneous matrix is available" << std::endl <<
"with name: " << name << std::endl;
227 }
else if (nbM > 1) {
229 vpCERROR << nbM <<
" There are more Homogeneous matrix" << std::endl
230 <<
"with the same name : " << std::endl
231 <<
"precise your choice..." << std::endl;
247 int vpXmlParserHomogeneousMatrix::count(xmlDocPtr doc, xmlNodePtr node,
const std::string &name)
253 for (node = node->xmlChildrenNode; node != NULL; node = node->next) {
254 if (node->type != XML_ELEMENT_NODE)
256 if (
SEQUENCE_OK != str2xmlcode((
char *)(node->name), prop)) {
260 if (
SEQUENCE_OK == this->read_matrix(doc, node, name))
278 int vpXmlParserHomogeneousMatrix::read_matrix(xmlDocPtr doc, xmlNodePtr node,
const std::string &name)
282 std::string M_name_tmp =
"";
287 for (node = node->xmlChildrenNode; node != NULL; node = node->next) {
289 if (node->type != XML_ELEMENT_NODE)
291 if (
SEQUENCE_OK != str2xmlcode((
char *)(node->name), prop)) {
299 M_name_tmp = val_char;
305 if (name == M_name_tmp) {
306 std::cout <<
"Found Homogeneous Matrix with name: \"" << M_name_tmp <<
"\"" << std::endl;
307 back = read_values(doc, node, M_tmp);
327 if (!(name == M_name_tmp)) {
333 this->m_name = M_name_tmp;
349 vpXmlParserHomogeneousMatrix::read_values(xmlDocPtr doc, xmlNodePtr node,
vpHomogeneousMatrix &M)
366 for (node = node->xmlChildrenNode; node != NULL; node = node->next) {
368 if (node->type != XML_ELEMENT_NODE)
370 if (
SEQUENCE_OK != str2xmlcode((
char *)(node->name), prop)) {
415 vpCERROR <<
"ERROR in 'model' field:\n";
416 vpCERROR <<
"it must contain 6 parameters\n";
422 M.
buildFrom(tx_, ty_, tz_, tux_, tuy_, tuz_);
444 int vpXmlParserHomogeneousMatrix::write(xmlNodePtr node,
const std::string &name)
449 xmlNodePtr node_matrix;
450 xmlNodePtr node_values;
459 node_tmp = xmlNewComment((xmlChar *)
"Homogeneous Matrix");
460 xmlAddChild(node, node_tmp);
461 node_matrix = xmlNewNode(NULL, (xmlChar *)LABEL_XML_M);
462 xmlAddChild(node, node_matrix);
467 node_tmp = xmlNewComment((xmlChar *)
"Name of the homogeneous matrix");
468 xmlAddChild(node_matrix, node_tmp);
469 xmlNewTextChild(node_matrix, NULL, (xmlChar *)LABEL_XML_M_NAME, (xmlChar *)name.c_str());
474 node_values = xmlNewNode(NULL, (xmlChar *)LABEL_XML_VALUE);
475 xmlAddChild(node_matrix, node_values);
479 node_tmp = xmlNewComment((xmlChar *)
"Translation vector with values in meters");
480 xmlAddChild(node_values, node_tmp);
483 sprintf(str,
"%f", m_M[0][3]);
484 xmlNewTextChild(node_values, NULL, (xmlChar *)LABEL_XML_TX, (xmlChar *)str);
487 sprintf(str,
"%f", m_M[1][3]);
488 xmlNewTextChild(node_values, NULL, (xmlChar *)LABEL_XML_TY, (xmlChar *)str);
491 sprintf(str,
"%f", m_M[2][3]);
492 xmlNewTextChild(node_values, NULL, (xmlChar *)LABEL_XML_TZ, (xmlChar *)str);
494 node_tmp = xmlNewComment((xmlChar *)
"Rotational vector expressed in angle axis " 495 "representation with values in radians");
496 xmlAddChild(node_values, node_tmp);
499 sprintf(str,
"%f", tu[0]);
500 xmlNewTextChild(node_values, NULL, (xmlChar *)LABEL_XML_TUX, (xmlChar *)str);
503 sprintf(str,
"%f", tu[1]);
504 xmlNewTextChild(node_values, NULL, (xmlChar *)LABEL_XML_TUY, (xmlChar *)str);
507 sprintf(str,
"%f", tu[2]);
508 xmlNewTextChild(node_values, NULL, (xmlChar *)LABEL_XML_TUZ, (xmlChar *)str);
530 if (!strcmp(str, LABEL_XML_M)) {
532 }
else if (!strcmp(str, LABEL_XML_M_NAME)) {
534 }
else if (!strcmp(str, LABEL_XML_VALUE)) {
536 }
else if (!strcmp(str, LABEL_XML_TX)) {
538 }
else if (!strcmp(str, LABEL_XML_TY)) {
540 }
else if (!strcmp(str, LABEL_XML_TZ)) {
542 }
else if (!strcmp(str, LABEL_XML_TUX)) {
544 }
else if (!strcmp(str, LABEL_XML_TUY)) {
546 }
else if (!strcmp(str, LABEL_XML_TUZ)) {
555 #elif !defined(VISP_BUILD_SHARED_LIBS) 558 void dummy_vpXmlParserHomogeneousMatrix(){};
559 #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.