From cc737339add7a8c94cc1c01d4e86d4de9f5651c6 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 6 Aug 2018 18:52:01 +0200 Subject: [PATCH] paralleization of transformation and bounding box calculation --- src/Mod/Points/App/CMakeLists.txt | 13 +++++++++++ src/Mod/Points/App/Points.cpp | 27 +++++++++++++++++++--- src/Mod/Points/App/Properties.cpp | 16 +++++++------ src/Mod/Points/App/PropertyPointKernel.cpp | 7 ++---- 4 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/Mod/Points/App/CMakeLists.txt b/src/Mod/Points/App/CMakeLists.txt index 38cc7d4b50..adec068f43 100644 --- a/src/Mod/Points/App/CMakeLists.txt +++ b/src/Mod/Points/App/CMakeLists.txt @@ -16,6 +16,19 @@ set(Points_LIBS FreeCADApp ) +if (BUILD_QT5) + include_directories( + ${Qt5Concurrent_INCLUDE_DIRS} + ) + list(APPEND Points_LIBS + ${Qt5Concurrent_LIBRARIES} + ) +else() + include_directories( + ${QT_QTCORE_INCLUDE_DIR} + ) +endif() + generate_from_xml(PointsPy) SET(Points_SRCS diff --git a/src/Mod/Points/App/Points.cpp b/src/Mod/Points/App/Points.cpp index 27eb44b718..111d864df8 100644 --- a/src/Mod/Points/App/Points.cpp +++ b/src/Mod/Points/App/Points.cpp @@ -28,6 +28,7 @@ #endif #include +#include #include #include @@ -39,10 +40,14 @@ #include "PointsAlgos.h" #include "PointsPy.h" +#ifdef _WIN32 +# include +#endif + using namespace Points; using namespace std; -TYPESYSTEM_SOURCE(Points::PointKernel, Data::ComplexGeoData); +TYPESYSTEM_SOURCE(Points::PointKernel, Data::ComplexGeoData) std::vector PointKernel::getElementTypes(void) const { @@ -73,15 +78,31 @@ Data::Segment* PointKernel::getSubElement(const char* /*Type*/, unsigned long /* void PointKernel::transformGeometry(const Base::Matrix4D &rclMat) { std::vector& kernel = getBasicPoints(); - for (std::vector::iterator it = kernel.begin(); it != kernel.end(); ++it) - *it = rclMat * (*it); + QtConcurrent::blockingMap(kernel, [rclMat](value_type& value) { + rclMat.multVec(value, value); + }); } Base::BoundBox3d PointKernel::getBoundBox(void)const { Base::BoundBox3d bnd; + +#ifdef _WIN32 + // Thread-local bounding boxes + Concurrency::combinable bbs; + // Cannot use a const_point_iterator here as it is *not* a proper iterator (fails the for_each template) + Concurrency::parallel_for_each(_Points.begin(), _Points.end(), [this, &bbs](const value_type& value) { + Base::Vector3d vertd(value.x, value.y, value.z); + bbs.local().Add(this->_Mtrx * vertd); + }); + // Combine each thread-local bounding box in the final bounding box + bbs.combine_each([&bnd](const Base::BoundBox3d& lbb) { + bnd.Add(lbb); + }); +#else for (const_point_iterator it = begin(); it != end(); ++it) bnd.Add(*it); +#endif return bnd; } diff --git a/src/Mod/Points/App/Properties.cpp b/src/Mod/Points/App/Properties.cpp index 81c32e6aba..0d99158a32 100644 --- a/src/Mod/Points/App/Properties.cpp +++ b/src/Mod/Points/App/Properties.cpp @@ -39,13 +39,15 @@ #include "Properties.h" #include "PointsPy.h" +#include + using namespace Points; using namespace std; -TYPESYSTEM_SOURCE(Points::PropertyGreyValue, App::PropertyFloat); -TYPESYSTEM_SOURCE(Points::PropertyGreyValueList, App::PropertyLists); -TYPESYSTEM_SOURCE(Points::PropertyNormalList, App::PropertyLists); -TYPESYSTEM_SOURCE(Points::PropertyCurvatureList , App::PropertyLists); +TYPESYSTEM_SOURCE(Points::PropertyGreyValue, App::PropertyFloat) +TYPESYSTEM_SOURCE(Points::PropertyGreyValueList, App::PropertyLists) +TYPESYSTEM_SOURCE(Points::PropertyNormalList, App::PropertyLists) +TYPESYSTEM_SOURCE(Points::PropertyCurvatureList , App::PropertyLists) PropertyGreyValueList::PropertyGreyValueList() { @@ -387,9 +389,9 @@ void PropertyNormalList::transformGeometry(const Base::Matrix4D &mat) aboutToSetValue(); // Rotate the normal vectors - for (int ii=0; iibegin(); it != _cPoints->end(); ++it) - box.Add(*it); - return box; + return _cPoints->getBoundBox(); } PyObject *PropertyPointKernel::getPyObject(void)