45 #include <visp3/core/vpXmlParserHomogeneousMatrix.h> 47 #include <pugixml.hpp> 51 #define LABEL_XML_ROOT "root" 52 #define LABEL_XML_M "homogeneous_transformation" 53 #define LABEL_XML_M_NAME "name" 54 #define LABEL_XML_VALUE "values" 55 #define LABEL_XML_TRANSLATION "translation" 56 #define LABEL_XML_TX "tx" 57 #define LABEL_XML_TY "ty" 58 #define LABEL_XML_TZ "tz" 59 #define LABEL_XML_ROTATION "rotation" 60 #define LABEL_XML_TUX "theta_ux" 61 #define LABEL_XML_TUY "theta_uy" 62 #define LABEL_XML_TUZ "theta_uz" 64 #ifndef DOXYGEN_SHOULD_SKIP_THIS 65 class vpXmlParserHomogeneousMatrix::Impl
85 Impl() : m_M(), m_name()
91 pugi::xml_document doc;
92 if (!doc.load_file(filename.c_str())) {
93 std::cerr << std::endl <<
"ERROR:" << std::endl;
94 std::cerr <<
" I cannot open the file " << filename << std::endl;
99 pugi::xml_node node = doc.document_element();
104 int ret = read(node, name);
118 int read(
const pugi::xml_node &node_,
const std::string &name)
123 unsigned int nbM = 0;
125 for (pugi::xml_node node = node_.first_child(); node; node = node.next_sibling()) {
126 if (node.type() != pugi::node_element)
129 if (
SEQUENCE_OK != str2xmlcode(node.name(), prop)) {
130 prop = CODE_XML_OTHER;
134 if (prop == CODE_XML_M) {
143 std::cerr <<
"No Homogeneous matrix is available" << std::endl <<
"with name: " << name << std::endl;
144 }
else if (nbM > 1) {
146 std::cerr << nbM <<
" There are more Homogeneous matrix" << std::endl
147 <<
"with the same name : " << std::endl
148 <<
"precise your choice..." << std::endl;
162 int read_matrix(
const pugi::xml_node &node_,
const std::string &name)
166 std::string M_name_tmp =
"";
171 for (pugi::xml_node node = node_.first_child(); node; node = node.next_sibling()) {
172 if (node.type() != pugi::node_element)
175 if (
SEQUENCE_OK != str2xmlcode(node.name(), prop)) {
176 prop = CODE_XML_OTHER;
181 case CODE_XML_M_NAME: {
182 M_name_tmp = node.text().as_string();
187 if (name == M_name_tmp) {
188 std::cout <<
"Found Homogeneous Matrix with name: \"" << M_name_tmp <<
"\"" << std::endl;
189 back = read_values(node, M_tmp);
209 if (!(name == M_name_tmp)) {
215 this->m_name = M_name_tmp;
244 for (pugi::xml_node node = node_.first_child(); node; node = node.next_sibling()) {
245 if (node.type() != pugi::node_element)
248 if (
SEQUENCE_OK != str2xmlcode(node.name(), prop)) {
249 prop = CODE_XML_OTHER;
255 tx_ = node.text().as_double();
259 ty_ = node.text().as_double();
263 tz_ = node.text().as_double();
267 tux_ = node.text().as_double();
271 tuy_ = node.text().as_double();
275 tuz_ = node.text().as_double();
282 case CODE_XML_M_NAME:
292 std::cerr <<
"ERROR in 'model' field:\n";
293 std::cerr <<
"it must contain 6 parameters\n";
299 M.
buildFrom(tx_, ty_, tz_, tux_, tuy_, tuz_);
313 const std::string &name)
315 pugi::xml_document doc;
318 if (!doc.load_file(filename.c_str(), pugi::parse_default | pugi::parse_comments)) {
319 node = doc.append_child(pugi::node_declaration);
320 node.append_attribute(
"version") =
"1.0";
321 node = doc.append_child(LABEL_XML_ROOT);
322 pugi::xml_node nodeComment = node.append_child(pugi::node_comment);
323 nodeComment.set_value(
"This file stores homogeneous matrix used\n" 324 " in the vpHomogeneousMatrix Class of ViSP available\n" 325 " at https://visp.inria.fr/download/ .\n" 326 " It can be read with the parse method of\n" 327 " the vpXmlParserHomogeneousMatrix class.");
330 node = doc.document_element();
337 int M_isFound = count(node, name);
340 std::cout <<
"There is already an homogeneous matrix " << std::endl
341 <<
"available in the file with the input name: " << name <<
"." << std::endl
342 <<
"Please delete it manually from the xml file." << std::endl;
348 doc.save_file(filename.c_str(), PUGIXML_TEXT(
" "));
363 int count(
const pugi::xml_node &node_,
const std::string &name)
368 for (pugi::xml_node node = node_.first_child(); node; node = node.next_sibling()) {
369 if (node.type() != pugi::node_element)
372 if (
SEQUENCE_OK != str2xmlcode(node.name(), prop)) {
373 prop = CODE_XML_OTHER;
375 if (prop == CODE_XML_M) {
392 int write(pugi::xml_node &node,
const std::string &name)
396 pugi::xml_node node_tmp;
397 pugi::xml_node node_matrix;
398 pugi::xml_node node_values;
407 node_tmp = node.append_child(pugi::node_comment);
408 node_tmp.set_value(
"Homogeneous Matrix");
409 node_matrix = node.append_child(LABEL_XML_M);
413 node_tmp = node_matrix.append_child(pugi::node_comment);
414 node_tmp.set_value(
"Name of the homogeneous matrix");
415 node_matrix.append_child(LABEL_XML_M_NAME).append_child(pugi::node_pcdata).set_value(name.c_str());
419 node_values = node_matrix.append_child(LABEL_XML_VALUE);
421 node_tmp = node_values.append_child(pugi::node_comment);
422 node_tmp.set_value(
"Translation vector with values in meters");
425 node_values.append_child(LABEL_XML_TX).append_child(pugi::node_pcdata).text() = m_M[0][3];
428 node_values.append_child(LABEL_XML_TY).append_child(pugi::node_pcdata).text() = m_M[1][3];
431 node_values.append_child(LABEL_XML_TZ).append_child(pugi::node_pcdata).text() = m_M[2][3];
433 node_tmp = node_values.append_child(pugi::node_comment);
434 node_tmp.set_value(
"Rotational vector expressed in angle axis " 435 "representation with values in radians");
438 node_values.append_child(LABEL_XML_TUX).append_child(pugi::node_pcdata).text() = tu[0];
441 node_values.append_child(LABEL_XML_TUY).append_child(pugi::node_pcdata).text() = tu[1];
444 node_values.append_child(LABEL_XML_TUZ).append_child(pugi::node_pcdata).text() = tu[2];
460 vpXmlCodeType val_int = CODE_XML_BAD;
463 if (!strcmp(str, LABEL_XML_M)) {
464 val_int = CODE_XML_M;
465 }
else if (!strcmp(str, LABEL_XML_M_NAME)) {
466 val_int = CODE_XML_M_NAME;
467 }
else if (!strcmp(str, LABEL_XML_VALUE)) {
468 val_int = CODE_XML_VALUE;
469 }
else if (!strcmp(str, LABEL_XML_TX)) {
470 val_int = CODE_XML_TX;
471 }
else if (!strcmp(str, LABEL_XML_TY)) {
472 val_int = CODE_XML_TY;
473 }
else if (!strcmp(str, LABEL_XML_TZ)) {
474 val_int = CODE_XML_TZ;
475 }
else if (!strcmp(str, LABEL_XML_TUX)) {
476 val_int = CODE_XML_TUX;
477 }
else if (!strcmp(str, LABEL_XML_TUY)) {
478 val_int = CODE_XML_TUY;
479 }
else if (!strcmp(str, LABEL_XML_TUZ)) {
480 val_int = CODE_XML_TUZ;
482 val_int = CODE_XML_OTHER;
498 #endif //DOXYGEN_SHOULD_SKIP_THIS 519 return m_impl->parse(M, filename, name);
531 const std::string &name)
533 return m_impl->save(M, filename, name);
538 return m_impl->getHomogeneousMatrix();
543 return m_impl->getHomogeneousMatrixName();
548 m_impl->setHomogeneousMatrixName(name);
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()