Merge pull request #23100 from 3x380V/points

Points: Speed up translation of imported points
This commit is contained in:
Chris Hennes
2025-08-30 20:04:08 -05:00
committed by GitHub
6 changed files with 42 additions and 31 deletions

View File

@@ -294,6 +294,12 @@ Application *Command::getGuiApplication()
return Application::Instance;
}
App::Document* Command::getActiveDocument() const
{
Gui::Document* doc = getActiveGuiDocument();
return doc ? doc->getDocument() : nullptr;
}
Gui::Document* Command::getActiveGuiDocument() const
{
return getGuiApplication()->activeDocument();
@@ -304,22 +310,14 @@ App::Document* Command::getDocument(const char* Name) const
if (Name) {
return App::GetApplication().getDocument(Name);
}
else {
Gui::Document * pcDoc = getGuiApplication()->activeDocument();
if (pcDoc)
return pcDoc->getDocument();
else
return nullptr;
}
return getActiveDocument();
}
App::DocumentObject* Command::getObject(const char* Name) const
{
App::Document*pDoc = getDocument();
if (pDoc)
return pDoc->getObject(Name);
else
return nullptr;
App::Document* pDoc = getDocument();
return pDoc ? pDoc->getObject(Name) : nullptr;
}
int Command::_busy;

View File

@@ -379,6 +379,8 @@ public:
static Application* getGuiApplication();
/// Get a reference to the selection
static Gui::SelectionSingleton& getSelection();
/// Get pointer to the active app document
App::Document* getActiveDocument() const;
/// Get pointer to the active gui document
Gui::Document* getActiveGuiDocument() const;
/** Get pointer to the named or active App document

View File

@@ -99,6 +99,21 @@ void PointKernel::transformGeometry(const Base::Matrix4D& rclMat)
#endif
}
void PointKernel::moveGeometry(const Base::Vector3d& vec)
{
Base::Vector3f offset = Base::toVector<float>(vec);
std::vector<value_type>& kernel = getBasicPoints();
#ifdef _MSC_VER
Concurrency::parallel_for_each(kernel.begin(), kernel.end(), [offset](value_type& value) {
value += offset;
});
#else
QtConcurrent::blockingMap(kernel, [offset](value_type& value) {
value += offset;
});
#endif
}
Base::BoundBox3d PointKernel::getBoundBox() const
{
Base::BoundBox3d bnd;

View File

@@ -106,6 +106,7 @@ public:
double Accuracy,
uint16_t flags = 0) const override;
void transformGeometry(const Base::Matrix4D& rclMat) override;
void moveGeometry(const Base::Vector3d& vec);
Base::BoundBox3d getBoundBox() const override;
/** @name I/O */

View File

@@ -31,10 +31,10 @@
#include "Points.h"
#define POINTS_CT_GRID 256 // Default value for number of elements per grid
#define POINTS_MAX_GRIDS 100000 // Default value for maximum number of grids
#define POINTS_CT_GRID_PER_AXIS 20
#define PONTSGRID_BBOX_EXTENSION 10.0f
static constexpr int POINTS_CT_GRID = 256; // Default value for number of elements per grid
static constexpr int POINTS_MAX_GRIDS = 100000; // Default value for maximum number of grids
static constexpr int POINTS_CT_GRID_PER_AXIS = 20;
static constexpr float PONTSGRID_BBOX_EXTENSION = 10.0F;
namespace Points
@@ -203,7 +203,7 @@ public:
protected:
/** Adds a new point element to the grid structure. \a rclPt is the geometric point and \a
* ulPtIndex the corresponding index in the point kernel. */
void AddPoint(const Base::Vector3d& rclPt, unsigned long ulPtIndex, float fEpsilon = 0.0f);
void AddPoint(const Base::Vector3d& rclPt, unsigned long ulPtIndex, float fEpsilon = 0.0F);
/** Returns the grid numbers to the given point \a rclPoint. */
void Pos(const Base::Vector3d& rclPoint,
unsigned long& rulX,
@@ -329,11 +329,9 @@ private:
inline Base::BoundBox3d
PointsGrid::GetBoundBox(unsigned long ulX, unsigned long ulY, unsigned long ulZ) const
{
double fX {}, fY {}, fZ {};
fX = _fMinX + (double(ulX) * _fGridLenX);
fY = _fMinY + (double(ulY) * _fGridLenY);
fZ = _fMinZ + (double(ulZ) * _fGridLenZ);
double fX = _fMinX + (double(ulX) * _fGridLenX);
double fY = _fMinY + (double(ulY) * _fGridLenY);
double fZ = _fMinZ + (double(ulZ) * _fGridLenZ);
return Base::BoundBox3d(fX, fY, fZ, fX + _fGridLenX, fY + _fGridLenY, fZ + _fGridLenZ);
}

View File

@@ -89,13 +89,13 @@ void CmdPointsImport::activated(int iMsg)
if (!fn.isEmpty()) {
fn = Base::Tools::escapeEncodeFilename(fn);
Gui::Document* doc = getActiveGuiDocument();
App::Document* doc = getActiveDocument();
openCommand(QT_TRANSLATE_NOOP("Command", "Import points"));
addModule(Command::App, "Points");
doCommand(Command::Doc,
"Points.insert(\"%s\", \"%s\")",
fn.toUtf8().data(),
doc->getDocument()->getName());
doc->getName());
commitCommand();
updateActive();
@@ -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
**/
auto* pcFtr = dynamic_cast<Points::Feature*>(doc->getDocument()->getActiveObject());
if (pcFtr) {
if (auto pcFtr = dynamic_cast<Points::Feature*>(doc->getActiveObject())) {
auto points = pcFtr->Points.getValue();
auto bbox = points.getBoundBox();
auto center = bbox.GetCenter();
@@ -123,11 +122,9 @@ void CmdPointsImport::activated(int iMsg)
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);
Points::PointKernel* kernel = pcFtr->Points.startEditing();
kernel->moveGeometry(-center);
pcFtr->Points.finishEditing();
}
}
}