[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

[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Update src/Mod/Points/Gui/Command.cpp

backport of PR #17282
This commit is contained in:
Adrian Insaurralde Avalos
2024-12-15 18:11:13 -03:00
parent 2ea219412b
commit b5ee6ef952
+33
View File
@@ -24,6 +24,7 @@
#ifndef _PreComp_
#include <Inventor/events/SoMouseButtonEvent.h>
#include <QInputDialog>
#include <QMessageBox>
#include <algorithm>
#endif
@@ -98,6 +99,38 @@ 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
**/
auto* pcFtr = dynamic_cast<Points::Feature*>(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);
}
}
}
}
}