45 #include <visp3/core/vpXmlParserHomogeneousMatrix.h> 47 #ifdef VISP_HAVE_PUGIXML 49 #include <pugixml.hpp> 53 #define LABEL_XML_ROOT "root" 54 #define LABEL_XML_M "homogeneous_transformation" 55 #define LABEL_XML_M_NAME "name" 56 #define LABEL_XML_VALUE "values" 57 #define LABEL_XML_TRANSLATION "translation" 58 #define LABEL_XML_TX "tx" 59 #define LABEL_XML_TY "ty" 60 #define LABEL_XML_TZ "tz" 61 #define LABEL_XML_ROTATION "rotation" 62 #define LABEL_XML_TUX "theta_ux" 63 #define LABEL_XML_TUY "theta_uy" 64 #define LABEL_XML_TUZ "theta_uz" 66 #ifndef DOXYGEN_SHOULD_SKIP_THIS 67 class vpXmlParserHomogeneousMatrix::Impl
87 Impl() : m_M(), m_name()
93 pugi::xml_document doc;
94 if (!doc.load_file(filename.c_str())) {
95 std::cerr << std::endl <<
"ERROR:" << std::endl;
96 std::cerr <<
" I cannot open the file " << filename << std::endl;
101 pugi::xml_node node = doc.document_element();
106 int ret = read(node, name);
120 int read(
const pugi::xml_node &node_,
const std::string &name)
125 unsigned int nbM = 0;
127 for (pugi::xml_node node = node_.first_child(); node; node = node.next_sibling()) {
128 if (node.type() != pugi::node_element)
131 if (
SEQUENCE_OK != str2xmlcode(node.name(), prop)) {
132 prop = CODE_XML_OTHER;
136 if (prop == CODE_XML_M) {
145 std::cerr <<
"No Homogeneous matrix is available" << std::endl <<
"with name: " << name << std::endl;
146 }
else if (nbM > 1) {
148 std::cerr << nbM <<
" There are more Homogeneous matrix" << std::endl
149 <<
"with the same name : " << std::endl
150 <<
"precise your choice..." << std::endl;
164 int read_matrix(
const pugi::xml_node &node_,
const std::string &name)
168 std::string M_name_tmp =
"";
173 for (pugi::xml_node node = node_.first_child(); node; node = node.next_sibling()) {
174 if (node.type() != pugi::node_element)
177 if (
SEQUENCE_OK != str2xmlcode(node.name(), prop)) {
178 prop = CODE_XML_OTHER;
183 case CODE_XML_M_NAME: {
184 M_name_tmp = node.text().as_string();
189 if (name == M_name_tmp) {
190 std::cout <<
"Found Homogeneous Matrix with name: \"" << M_name_tmp <<
"\"" << std::endl;
191 back = read_values(node, M_tmp);
211 if (!(name == M_name_tmp)) {
217 this->m_name = M_name_tmp;
246 for (pugi::xml_node node = node_.first_child(); node; node = node.next_sibling()) {
247 if (node.type() != pugi::node_element)
250 if (
SEQUENCE_OK != str2xmlcode(node.name(), prop)) {
251 prop = CODE_XML_OTHER;
257 tx_ = node.text().as_double();
261 ty_ = node.text().as_double();
265 tz_ = node.text().as_double();
269 tux_ = node.text().as_double();
273 tuy_ = node.text().as_double();
277 tuz_ = node.text().as_double();
284 case CODE_XML_M_NAME:
294 std::cerr <<
"ERROR in 'model' field:\n";
295 std::cerr <<
"it must contain 6 parameters\n";
301 M.
buildFrom(tx_, ty_, tz_, tux_, tuy_, tuz_);
315 const std::string &name)
317 pugi::xml_document doc;
320 if (!doc.load_file(filename.c_str(), pugi::parse_default | pugi::parse_comments)) {
321 node = doc.append_child(pugi::node_declaration);
322 node.append_attribute(
"version") =
"1.0";
323 node = doc.append_child(LABEL_XML_ROOT);
324 pugi::xml_node nodeComment = node.append_child(pugi::node_comment);
325 nodeComment.set_value(
"This file stores homogeneous matrix used\n" 326 " in the vpHomogeneousMatrix Class of ViSP available\n" 327 " at https://visp.inria.fr/download/ .\n" 328 " It can be read with the parse method of\n" 329 " the vpXmlParserHomogeneousMatrix class.");
332 node = doc.document_element();
339 int M_isFound = count(node, name);
342 std::cout <<
"There is already an homogeneous matrix " << std::endl
343 <<
"available in the file with the input name: " << name <<
"." << std::endl
344 <<
"Please delete it manually from the xml file." << std::endl;
350 doc.save_file(filename.c_str(), PUGIXML_TEXT(
" "));
365 int count(
const pugi::xml_node &node_,
const std::string &name)
370 for (pugi::xml_node node = node_.first_child(); node; node = node.next_sibling()) {
371 if (node.type() != pugi::node_element)
374 if (
SEQUENCE_OK != str2xmlcode(node.name(), prop)) {
375 prop = CODE_XML_OTHER;
377 if (prop == CODE_XML_M) {
394 int write(pugi::xml_node &node,
const std::string &name)
398 pugi::xml_node node_tmp;
399 pugi::xml_node node_matrix;
400 pugi::xml_node node_values;
409 node_tmp = node.append_child(pugi::node_comment);
410 node_tmp.set_value(
"Homogeneous Matrix");
411 node_matrix = node.append_child(LABEL_XML_M);
415 node_tmp = node_matrix.append_child(pugi::node_comment);
416 node_tmp.set_value(
"Name of the homogeneous matrix");
417 node_matrix.append_child(LABEL_XML_M_NAME).append_child(pugi::node_pcdata).set_value(name.c_str());
421 node_values = node_matrix.append_child(LABEL_XML_VALUE);
423 node_tmp = node_values.append_child(pugi::node_comment);
424 node_tmp.set_value(
"Translation vector with values in meters");
427 node_values.append_child(LABEL_XML_TX).append_child(pugi::node_pcdata).text() = m_M[0][3];
430 node_values.append_child(LABEL_XML_TY).append_child(pugi::node_pcdata).text() = m_M[1][3];
433 node_values.append_child(LABEL_XML_TZ).append_child(pugi::node_pcdata).text() = m_M[2][3];
435 node_tmp = node_values.append_child(pugi::node_comment);
436 node_tmp.set_value(
"Rotational vector expressed in angle axis " 437 "representation with values in radians");
440 node_values.append_child(LABEL_XML_TUX).append_child(pugi::node_pcdata).text() = tu[0];
443 node_values.append_child(LABEL_XML_TUY).append_child(pugi::node_pcdata).text() = tu[1];
446 node_values.append_child(LABEL_XML_TUZ).append_child(pugi::node_pcdata).text() = tu[2];
462 vpXmlCodeType val_int = CODE_XML_BAD;
465 if (!strcmp(str, LABEL_XML_M)) {
466 val_int = CODE_XML_M;
467 }
else if (!strcmp(str, LABEL_XML_M_NAME)) {
468 val_int = CODE_XML_M_NAME;
469 }
else if (!strcmp(str, LABEL_XML_VALUE)) {
470 val_int = CODE_XML_VALUE;
471 }
else if (!strcmp(str, LABEL_XML_TX)) {
472 val_int = CODE_XML_TX;
473 }
else if (!strcmp(str, LABEL_XML_TY)) {
474 val_int = CODE_XML_TY;
475 }
else if (!strcmp(str, LABEL_XML_TZ)) {
476 val_int = CODE_XML_TZ;
477 }
else if (!strcmp(str, LABEL_XML_TUX)) {
478 val_int = CODE_XML_TUX;
479 }
else if (!strcmp(str, LABEL_XML_TUY)) {
480 val_int = CODE_XML_TUY;
481 }
else if (!strcmp(str, LABEL_XML_TUZ)) {
482 val_int = CODE_XML_TUZ;
484 val_int = CODE_XML_OTHER;
500 #endif //DOXYGEN_SHOULD_SKIP_THIS 521 return m_impl->parse(M, filename, name);
533 const std::string &name)
535 return m_impl->save(M, filename, name);
540 return m_impl->getHomogeneousMatrix();
545 return m_impl->getHomogeneousMatrixName();
550 m_impl->setHomogeneousMatrixName(name);
552 #elif !defined(VISP_BUILD_SHARED_LIBS) 555 void dummy_vpXmlParserHomogeneousMatrix(){};
556 #endif //VISP_HAVE_PUGIXML int parse(vpHomogeneousMatrix &M, const std::string &filename, const std::string &name)
void setHomogeneousMatrixName(const std::string &name)
Implementation of an homogeneous matrix and operations on such kind of matrices.
std::string getHomogeneousMatrixName() const
Implementation of a rotation matrix and operations on such kind of matrices.
int save(const vpHomogeneousMatrix &M, const std::string &filename, const std::string &name)
void buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
vpHomogeneousMatrix getHomogeneousMatrix() const
vpXmlParserHomogeneousMatrix()
Implementation of a rotation vector as axis-angle minimal representation.
~vpXmlParserHomogeneousMatrix()