From 874e2e39a0ef964adec92306fe49b52baf56c194 Mon Sep 17 00:00:00 2001 From: mwganson Date: Wed, 16 Oct 2024 05:21:47 +0000 Subject: [PATCH 1/3] [Points WB] fix issue where points are inaccurately imported when the points are far from the origin. This PR checks if the bounding box contains the origin and offers to move it to the origin if not, addresses issue #5808 --- src/Mod/Points/Gui/Command.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/Mod/Points/Gui/Command.cpp b/src/Mod/Points/Gui/Command.cpp index 016f1d8e35..ab18b36fa8 100644 --- a/src/Mod/Points/Gui/Command.cpp +++ b/src/Mod/Points/Gui/Command.cpp @@ -24,6 +24,7 @@ #ifndef _PreComp_ #include #include +#include #include #endif @@ -98,7 +99,39 @@ void CmdPointsImport::activated(int iMsg) commitCommand(); updateActive(); + + /** check if boundbox contains the origin, offer to move it to the origin if not + * addresses issue #5808 where an imported points cloud that was far from the + * origin had inaccuracies in the relative positioning of the points due to + * imprecise floating point variables used in COIN + **/ + Points::Feature *pcFtr = dynamic_cast(doc->getDocument()->getActiveObject()); + if (pcFtr) { + auto points = pcFtr->Points.getValue(); + auto bbox = points.getBoundBox(); + auto center = bbox.GetCenter(); + + if (!bbox.IsInBox(Base::Vector3d(0,0,0))) { + QMessageBox msgBox; + msgBox.setIcon(QMessageBox::Question); + msgBox.setWindowTitle(QObject::tr( "Points not at Origin")); + msgBox.setText(QObject::tr("The Bounding Box of the imported points does not contain the origin. " + "Do you want to translate it to the origin?")); + msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + msgBox.setDefaultButton(QMessageBox::Yes); + auto ret = msgBox.exec(); + + if (ret == QMessageBox::Yes) { + Points::PointKernel translatedPoints; + for (const auto& point : points) { + translatedPoints.push_back(point - center); + } + pcFtr->Points.setValue(translatedPoints); + } + } + } } + } bool CmdPointsImport::isActive() From a02ab5b0d3d2ef5381c736e57be14c2b0f055db6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 3 Nov 2024 23:25:19 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/Mod/Points/Gui/Command.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Mod/Points/Gui/Command.cpp b/src/Mod/Points/Gui/Command.cpp index ab18b36fa8..92d4b6b184 100644 --- a/src/Mod/Points/Gui/Command.cpp +++ b/src/Mod/Points/Gui/Command.cpp @@ -105,18 +105,20 @@ void CmdPointsImport::activated(int iMsg) * origin had inaccuracies in the relative positioning of the points due to * imprecise floating point variables used in COIN **/ - Points::Feature *pcFtr = dynamic_cast(doc->getDocument()->getActiveObject()); + Points::Feature* pcFtr = + dynamic_cast(doc->getDocument()->getActiveObject()); if (pcFtr) { auto points = pcFtr->Points.getValue(); auto bbox = points.getBoundBox(); auto center = bbox.GetCenter(); - if (!bbox.IsInBox(Base::Vector3d(0,0,0))) { + if (!bbox.IsInBox(Base::Vector3d(0, 0, 0))) { QMessageBox msgBox; msgBox.setIcon(QMessageBox::Question); - msgBox.setWindowTitle(QObject::tr( "Points not at Origin")); - msgBox.setText(QObject::tr("The Bounding Box of the imported points does not contain the origin. " - "Do you want to translate it to the origin?")); + msgBox.setWindowTitle(QObject::tr("Points not at Origin")); + msgBox.setText(QObject::tr( + "The Bounding Box of the imported points does not contain the origin. " + "Do you want to translate it to the origin?")); msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); msgBox.setDefaultButton(QMessageBox::Yes); auto ret = msgBox.exec(); @@ -131,7 +133,6 @@ void CmdPointsImport::activated(int iMsg) } } } - } bool CmdPointsImport::isActive() From fb410d15a268325052d75cc32131492705a57773 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Fri, 6 Dec 2024 10:33:56 -0600 Subject: [PATCH 3/3] Update src/Mod/Points/Gui/Command.cpp --- src/Mod/Points/Gui/Command.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Mod/Points/Gui/Command.cpp b/src/Mod/Points/Gui/Command.cpp index 92d4b6b184..02f1597396 100644 --- a/src/Mod/Points/Gui/Command.cpp +++ b/src/Mod/Points/Gui/Command.cpp @@ -105,8 +105,7 @@ void CmdPointsImport::activated(int iMsg) * origin had inaccuracies in the relative positioning of the points due to * imprecise floating point variables used in COIN **/ - Points::Feature* pcFtr = - dynamic_cast(doc->getDocument()->getActiveObject()); + auto* pcFtr = dynamic_cast(doc->getDocument()->getActiveObject()); if (pcFtr) { auto points = pcFtr->Points.getValue(); auto bbox = points.getBoundBox();