From c48cb4da97f6da4673c59bc7018f4a26cfb3d698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=CA=B3=20Pierre-=C3=89douard=20Cailliau?= Date: Sun, 23 Jan 2022 00:14:43 +0100 Subject: [PATCH 01/12] The element MLMatrix44 is a list, so values are separed by spaces and carriage return are ignored. --- src/meshlabplugins/io_base/load_project.cpp | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/meshlabplugins/io_base/load_project.cpp b/src/meshlabplugins/io_base/load_project.cpp index c07b4e8e9..469dc09c6 100644 --- a/src/meshlabplugins/io_base/load_project.cpp +++ b/src/meshlabplugins/io_base/load_project.cpp @@ -230,20 +230,10 @@ std::vector loadMLP( vcg::Matrix44f trm; if (tr.childNodes().size() == 1) { if (!binary) { - QStringList rows = tr.firstChild().nodeValue().split("\n", QString::SkipEmptyParts); - int i = 0; - for (const QString& row : qAsConst(rows)){ - if (rows.size() > 0) { - QStringList values = row.split(" ", QString::SkipEmptyParts); - int j = 0; - for (const QString& value : qAsConst(values)) { - if (i < 4 && j < 4) { - md.mm()->cm.Tr[i][j] = value.toFloat(); - j++; - } - } - i++; - } + auto const & values = tr.childNodes(); + auto * v = md.mm()->cm.V(); + for (auto index = 0u; index < values.length(); ++index) { + v[index] = values.item(index).nodeName().toFloat(); } } else { From 3cd7e62c0027128bb835c50c007c58608d0ec0a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=CA=B3=20Pierre-=C3=89douard=20Cailliau?= Date: Sun, 23 Jan 2022 00:41:43 +0100 Subject: [PATCH 02/12] Correct mistake. --- src/meshlabplugins/io_base/load_project.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/meshlabplugins/io_base/load_project.cpp b/src/meshlabplugins/io_base/load_project.cpp index 469dc09c6..64d866c8f 100644 --- a/src/meshlabplugins/io_base/load_project.cpp +++ b/src/meshlabplugins/io_base/load_project.cpp @@ -231,7 +231,7 @@ std::vector loadMLP( if (tr.childNodes().size() == 1) { if (!binary) { auto const & values = tr.childNodes(); - auto * v = md.mm()->cm.V(); + auto * v = md.mm()->cm.Tr.V(); for (auto index = 0u; index < values.length(); ++index) { v[index] = values.item(index).nodeName().toFloat(); } From 686499790b7e7a836741272b315914b259596266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=CA=B3=20Pierre-=C3=89douard=20Cailliau?= Date: Mon, 24 Jan 2022 23:22:28 +0100 Subject: [PATCH 03/12] Consumes the values one by one. --- src/meshlabplugins/io_base/load_project.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/meshlabplugins/io_base/load_project.cpp b/src/meshlabplugins/io_base/load_project.cpp index 64d866c8f..63a1b48b6 100644 --- a/src/meshlabplugins/io_base/load_project.cpp +++ b/src/meshlabplugins/io_base/load_project.cpp @@ -230,10 +230,17 @@ std::vector loadMLP( vcg::Matrix44f trm; if (tr.childNodes().size() == 1) { if (!binary) { - auto const & values = tr.childNodes(); - auto * v = md.mm()->cm.Tr.V(); - for (auto index = 0u; index < values.length(); ++index) { - v[index] = values.item(index).nodeName().toFloat(); + auto * const v = md.mm()->cm.Tr.V(); + auto const rows = tr.firstChild().nodeValue().split("\n", QString::SkipEmptyParts); + auto i = 0u; + for (auto const & row: rows) { + if (rows.size() > 0u) { + auto const values = row.split(" ", QString::SkipEmptyParts); + for (auto const & value: values) { + if (i >= 16u) break; + v[i++] = value.toFloat(); + } + } } } else { From 8db5e2733ba1722c9a6e27645bd0ac72d37148ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=CA=B3=20Pierre-=C3=89douard=20Cailliau?= Date: Sun, 23 Jan 2022 00:14:43 +0100 Subject: [PATCH 04/12] Consumes the values of MLMatrix44 one by one. The MLMatrix44 element is of type of the Vector16 simple type that is a restriction of the other VectorList simple type that is a list of decimal simple type. MeshLabProject XML schema: meshlab/docs/meshlabprojspecificationformat.xsd So values are separed by spaces (by XML list definition) and carriage return are ignored (by XML definition). Consequently, there is no need to prejudge the presence and position of any line breaks. --- src/meshlabplugins/io_base/load_project.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/meshlabplugins/io_base/load_project.cpp b/src/meshlabplugins/io_base/load_project.cpp index c07b4e8e9..63a1b48b6 100644 --- a/src/meshlabplugins/io_base/load_project.cpp +++ b/src/meshlabplugins/io_base/load_project.cpp @@ -230,19 +230,16 @@ std::vector loadMLP( vcg::Matrix44f trm; if (tr.childNodes().size() == 1) { if (!binary) { - QStringList rows = tr.firstChild().nodeValue().split("\n", QString::SkipEmptyParts); - int i = 0; - for (const QString& row : qAsConst(rows)){ - if (rows.size() > 0) { - QStringList values = row.split(" ", QString::SkipEmptyParts); - int j = 0; - for (const QString& value : qAsConst(values)) { - if (i < 4 && j < 4) { - md.mm()->cm.Tr[i][j] = value.toFloat(); - j++; - } + auto * const v = md.mm()->cm.Tr.V(); + auto const rows = tr.firstChild().nodeValue().split("\n", QString::SkipEmptyParts); + auto i = 0u; + for (auto const & row: rows) { + if (rows.size() > 0u) { + auto const values = row.split(" ", QString::SkipEmptyParts); + for (auto const & value: values) { + if (i >= 16u) break; + v[i++] = value.toFloat(); } - i++; } } } From 10aa65b7274784485ed0400f6978943e542177f1 Mon Sep 17 00:00:00 2001 From: PeC-KAYO Date: Tue, 25 Jan 2022 20:04:23 +0100 Subject: [PATCH 05/12] Apply suggestions from code review --- src/meshlabplugins/io_base/load_project.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/meshlabplugins/io_base/load_project.cpp b/src/meshlabplugins/io_base/load_project.cpp index 63a1b48b6..dab7aa0f3 100644 --- a/src/meshlabplugins/io_base/load_project.cpp +++ b/src/meshlabplugins/io_base/load_project.cpp @@ -233,7 +233,7 @@ std::vector loadMLP( auto * const v = md.mm()->cm.Tr.V(); auto const rows = tr.firstChild().nodeValue().split("\n", QString::SkipEmptyParts); auto i = 0u; - for (auto const & row: rows) { + { if (rows.size() > 0u) { auto const values = row.split(" ", QString::SkipEmptyParts); for (auto const & value: values) { From 5951ae03f630f78aa24322caa1f5cec9e46128c5 Mon Sep 17 00:00:00 2001 From: PeC-KAYO Date: Tue, 25 Jan 2022 20:10:18 +0100 Subject: [PATCH 06/12] Apply suggestions from code review --- src/meshlabplugins/io_base/load_project.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/meshlabplugins/io_base/load_project.cpp b/src/meshlabplugins/io_base/load_project.cpp index dab7aa0f3..c2a3b3927 100644 --- a/src/meshlabplugins/io_base/load_project.cpp +++ b/src/meshlabplugins/io_base/load_project.cpp @@ -233,8 +233,8 @@ std::vector loadMLP( auto * const v = md.mm()->cm.Tr.V(); auto const rows = tr.firstChild().nodeValue().split("\n", QString::SkipEmptyParts); auto i = 0u; - { - if (rows.size() > 0u) { + for (auto const & row: rows) { + { auto const values = row.split(" ", QString::SkipEmptyParts); for (auto const & value: values) { if (i >= 16u) break; From 1ab2177fa372c6d884774104346a8833cb214938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=CA=B3=20Pierre-=C3=89douard=20Cailliau?= Date: Wed, 26 Jan 2022 14:16:44 +0100 Subject: [PATCH 07/12] Stream Matrrix44m one one line, as an XML list simple type. --- src/meshlabplugins/io_base/save_project.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/meshlabplugins/io_base/save_project.cpp b/src/meshlabplugins/io_base/save_project.cpp index a46a5de1d..4ad6312e4 100644 --- a/src/meshlabplugins/io_base/save_project.cpp +++ b/src/meshlabplugins/io_base/save_project.cpp @@ -7,6 +7,10 @@ #include #include +#unclude // std::copy +#unclude // std::ostream_iterator +#unclude // std::ostringstream + namespace mlp { QDomElement matrix44mToXML(const Matrix44m &m, bool binary, QDomDocument &doc) @@ -18,11 +22,11 @@ QDomElement matrix44mToXML(const Matrix44m &m, bool binary, QDomDocument &doc) QDomText nd = doc.createTextNode(QString(value)); } else { - QString Row[4]; - for (int i = 0; i < 4; ++i) - Row[i] = QString("%1 %2 %3 %4 \n").arg(m[i][0]).arg(m[i][1]).arg(m[i][2]).arg(m[i][3]); - - nd = doc.createTextNode("\n" + Row[0] + Row[1] + Row[2] + Row[3]); + std::ostringstream matrix; + std::copy(std::begin(m.V()), std::end(m.V() + 16u), + std::ostream_iterator(matrix, " ")); + //std::experimental::make_ostream_joiner(matrix, ", ")); // with + nd = doc.createTextNode(matrix.str()); } matrixElem.appendChild(nd); From a9f9ec955b938b5bd5458a5f962383c4a4d9b6ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=CA=B3=20Pierre-=C3=89douard=20Cailliau?= Date: Wed, 26 Jan 2022 14:31:44 +0100 Subject: [PATCH 08/12] Correct mistake. --- src/meshlabplugins/io_base/save_project.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/meshlabplugins/io_base/save_project.cpp b/src/meshlabplugins/io_base/save_project.cpp index 4ad6312e4..a46062f55 100644 --- a/src/meshlabplugins/io_base/save_project.cpp +++ b/src/meshlabplugins/io_base/save_project.cpp @@ -7,9 +7,9 @@ #include #include -#unclude // std::copy -#unclude // std::ostream_iterator -#unclude // std::ostringstream +#include // std::copy +#include // std::ostream_iterator +#include // std::ostringstream namespace mlp { From 9c65b399b40a0de0e718b48866836885471ceff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=CA=B3=20Pierre-=C3=89douard=20Cailliau?= Date: Wed, 26 Jan 2022 14:45:44 +0100 Subject: [PATCH 09/12] Correct mistake. --- src/meshlabplugins/io_base/save_project.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/meshlabplugins/io_base/save_project.cpp b/src/meshlabplugins/io_base/save_project.cpp index a46062f55..e52cdf522 100644 --- a/src/meshlabplugins/io_base/save_project.cpp +++ b/src/meshlabplugins/io_base/save_project.cpp @@ -23,7 +23,7 @@ QDomElement matrix44mToXML(const Matrix44m &m, bool binary, QDomDocument &doc) } else { std::ostringstream matrix; - std::copy(std::begin(m.V()), std::end(m.V() + 16u), + std::copy(m.V(), m.V() + 16u, std::ostream_iterator(matrix, " ")); //std::experimental::make_ostream_joiner(matrix, ", ")); // with nd = doc.createTextNode(matrix.str()); From c0ab75edbf881514dce5a4198e095bca835290d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=CA=B3=20Pierre-=C3=89douard=20Cailliau?= Date: Wed, 26 Jan 2022 14:57:33 +0100 Subject: [PATCH 10/12] Correct mistake. --- src/meshlabplugins/io_base/save_project.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/meshlabplugins/io_base/save_project.cpp b/src/meshlabplugins/io_base/save_project.cpp index e52cdf522..85b2cbf24 100644 --- a/src/meshlabplugins/io_base/save_project.cpp +++ b/src/meshlabplugins/io_base/save_project.cpp @@ -26,7 +26,7 @@ QDomElement matrix44mToXML(const Matrix44m &m, bool binary, QDomDocument &doc) std::copy(m.V(), m.V() + 16u, std::ostream_iterator(matrix, " ")); //std::experimental::make_ostream_joiner(matrix, ", ")); // with - nd = doc.createTextNode(matrix.str()); + nd = doc.createTextNode(QString(matrix.str())); } matrixElem.appendChild(nd); From 6666f4cc0e9c285f33bf3fd71a980d0098203f9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=CA=B3=20Pierre-=C3=89douard=20Cailliau?= Date: Wed, 26 Jan 2022 16:25:21 +0100 Subject: [PATCH 11/12] Correct mistake. --- src/meshlabplugins/io_base/save_project.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/meshlabplugins/io_base/save_project.cpp b/src/meshlabplugins/io_base/save_project.cpp index 85b2cbf24..2ea0a6000 100644 --- a/src/meshlabplugins/io_base/save_project.cpp +++ b/src/meshlabplugins/io_base/save_project.cpp @@ -26,7 +26,7 @@ QDomElement matrix44mToXML(const Matrix44m &m, bool binary, QDomDocument &doc) std::copy(m.V(), m.V() + 16u, std::ostream_iterator(matrix, " ")); //std::experimental::make_ostream_joiner(matrix, ", ")); // with - nd = doc.createTextNode(QString(matrix.str())); + nd = doc.createTextNode(QString(matrix.str().c_str())); } matrixElem.appendChild(nd); From c6dbfc8f7e7f800feaa3b3f667c5e80b37025efe Mon Sep 17 00:00:00 2001 From: alemuntoni Date: Thu, 27 Jan 2022 10:30:59 +0100 Subject: [PATCH 12/12] save matrix in single row on mlp --- src/meshlabplugins/io_base/load_project.cpp | 19 ++++++++----------- src/meshlabplugins/io_base/save_project.cpp | 14 +++++--------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/meshlabplugins/io_base/load_project.cpp b/src/meshlabplugins/io_base/load_project.cpp index c2a3b3927..858f35558 100644 --- a/src/meshlabplugins/io_base/load_project.cpp +++ b/src/meshlabplugins/io_base/load_project.cpp @@ -227,19 +227,16 @@ std::vector loadMLP( QDomNode tr = mesh.firstChildElement("MLMatrix44"); if (!tr.isNull()) { - vcg::Matrix44f trm; if (tr.childNodes().size() == 1) { if (!binary) { - auto * const v = md.mm()->cm.Tr.V(); - auto const rows = tr.firstChild().nodeValue().split("\n", QString::SkipEmptyParts); - auto i = 0u; - for (auto const & row: rows) { - { - auto const values = row.split(" ", QString::SkipEmptyParts); - for (auto const & value: values) { - if (i >= 16u) break; - v[i++] = value.toFloat(); - } + Scalarm* v = md.mm()->cm.Tr.V(); + const QStringList rows = tr.firstChild().nodeValue().split("\n", Qt::SkipEmptyParts); + unsigned int i = 0; + for (const QString& row: rows) { + const QStringList values = row.split(" ", Qt::SkipEmptyParts); + for (const QString& value: values) { + if (i >= 16u) break; + v[i++] = value.toFloat(); } } } diff --git a/src/meshlabplugins/io_base/save_project.cpp b/src/meshlabplugins/io_base/save_project.cpp index 2ea0a6000..2d3e7c4e1 100644 --- a/src/meshlabplugins/io_base/save_project.cpp +++ b/src/meshlabplugins/io_base/save_project.cpp @@ -7,10 +7,6 @@ #include #include -#include // std::copy -#include // std::ostream_iterator -#include // std::ostringstream - namespace mlp { QDomElement matrix44mToXML(const Matrix44m &m, bool binary, QDomDocument &doc) @@ -22,11 +18,11 @@ QDomElement matrix44mToXML(const Matrix44m &m, bool binary, QDomDocument &doc) QDomText nd = doc.createTextNode(QString(value)); } else { - std::ostringstream matrix; - std::copy(m.V(), m.V() + 16u, - std::ostream_iterator(matrix, " ")); - //std::experimental::make_ostream_joiner(matrix, ", ")); // with - nd = doc.createTextNode(QString(matrix.str().c_str())); + QString row[4]; + for (int i = 0; i < 4; ++i) + row[i] = QString("%1 %2 %3 %4 ").arg(m[i][0]).arg(m[i][1]).arg(m[i][2]).arg(m[i][3]); + + nd = doc.createTextNode("\n" + row[0] + row[1] + row[2] + row[3] + "\n"); } matrixElem.appendChild(nd);