From 88e32eba9b4f619fb845e2c7cdab34bddf6891e3 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 3 Aug 2022 16:18:14 +0200 Subject: [PATCH] App: changes in ComplexGeoData: * rename some methods * distinguish between Point and Vector * support of arrays of Point or Vector --- src/App/ComplexGeoData.h | 43 +++++++++++++++++++++++-- src/Mod/Mesh/App/Core/Algorithm.h | 3 ++ src/Mod/Mesh/App/Mesh.cpp | 52 ++++++------------------------- src/Mod/Points/App/Points.h | 6 ++-- 4 files changed, 57 insertions(+), 47 deletions(-) diff --git a/src/App/ComplexGeoData.h b/src/App/ComplexGeoData.h index 5aeefe5cb9..6ea8a3af1b 100644 --- a/src/App/ComplexGeoData.h +++ b/src/App/ComplexGeoData.h @@ -24,6 +24,7 @@ #ifndef _AppComplexGeoData_h_ #define _AppComplexGeoData_h_ +#include #include #include #include @@ -199,14 +200,52 @@ public: protected: /// from local to outside - inline Base::Vector3d transformToOutside(const Base::Vector3f& vec) const + inline Base::Vector3d transformPointToOutside(const Base::Vector3f& vec) const { return getTransform() * Base::Vector3d(static_cast(vec.x), static_cast(vec.y), static_cast(vec.z)); } + /// from local to outside + template + inline std::vector transformPointsToOutside(const std::vector& input) const + { + std::vector output; + output.reserve(input.size()); + Base::Matrix4D mat(getTransform()); + std::transform(input.cbegin(), input.cend(), std::back_inserter(output), [&mat](const Vec& vec) { + return mat * Base::Vector3d(static_cast(vec.x), + static_cast(vec.y), + static_cast(vec.z)); + }); + + return output; + } + inline Base::Vector3d transformVectorToOutside(const Base::Vector3f& vec) const + { + Base::Matrix4D mat(getTransform()); + mat.setCol(3, Base::Vector3d()); + return mat * Base::Vector3d(static_cast(vec.x), + static_cast(vec.y), + static_cast(vec.z)); + } + template + std::vector transformVectorsToOutside(const std::vector& input) const + { + std::vector output; + output.reserve(input.size()); + Base::Matrix4D mat(getTransform()); + mat.setCol(3, Base::Vector3d()); + std::transform(input.cbegin(), input.cend(), std::back_inserter(output), [&mat](const Vec& vec) { + return mat * Base::Vector3d(static_cast(vec.x), + static_cast(vec.y), + static_cast(vec.z)); + }); + + return output; + } /// from local to inside - inline Base::Vector3f transformToInside(const Base::Vector3d& vec) const + inline Base::Vector3f transformPointToInside(const Base::Vector3d& vec) const { Base::Matrix4D tmpM(getTransform()); tmpM.inverse(); diff --git a/src/Mod/Mesh/App/Core/Algorithm.h b/src/Mod/Mesh/App/Core/Algorithm.h index 4ab6700ac8..730bcb6015 100644 --- a/src/Mod/Mesh/App/Core/Algorithm.h +++ b/src/Mod/Mesh/App/Core/Algorithm.h @@ -537,6 +537,9 @@ public: /// Rebuilds up data structure void Rebuild (); const Base::Vector3f& operator[] (PointIndex) const; + const std::vector& GetValues() const { + return _norm; + } protected: const MeshKernel &_rclMesh; /**< The mesh kernel. */ diff --git a/src/Mod/Mesh/App/Mesh.cpp b/src/Mod/Mesh/App/Mesh.cpp index 4436902f74..1a1ce46990 100644 --- a/src/Mod/Mesh/App/Mesh.cpp +++ b/src/Mod/Mesh/App/Mesh.cpp @@ -174,7 +174,7 @@ Base::BoundBox3d MeshObject::getBoundBox()const Base::BoundBox3d Bnd2; if (Bnd.IsValid()) { for (int i =0 ;i<=7;i++) - Bnd2.Add(transformToOutside(Bnd.CalcPoint(i))); + Bnd2.Add(transformPointToOutside(Bnd.CalcPoint(i))); } return Bnd2; @@ -184,7 +184,7 @@ bool MeshObject::getCenterOfGravity(Base::Vector3d& center) const { MeshCore::MeshAlgorithm alg(_kernel); Base::Vector3f pnt = alg.GetGravityPoint(); - center = transformToOutside(pnt); + center = transformPointToOutside(pnt); return true; } @@ -311,26 +311,9 @@ void MeshObject::getPoints(std::vector &Points, std::vector &Normals, float /*Accuracy*/, uint16_t /*flags*/) const { - Base::Matrix4D mat = _Mtrx; - - unsigned long ctpoints = _kernel.CountPoints(); - Points.reserve(ctpoints); - for (unsigned long i=0; i temp = _kernel.CalcVertexNormals(); - Base::Vector3d normal = transformToOutside(temp[index]); - - // the normal is a vector, hence we must not apply the translation part - // of the transformation to the vector - normal.x -= _Mtrx[0][3]; - normal.y -= _Mtrx[1][3]; - normal.z -= _Mtrx[2][3]; + Base::Vector3d normal = transformVectorToOutside(temp[index]); normal.Normalize(); return normal; } @@ -1044,19 +1021,10 @@ std::vector MeshObject::getPointNormals() const { std::vector temp = _kernel.CalcVertexNormals(); - std::vector normals; - normals.reserve(temp.size()); - for (std::vector::iterator it = temp.begin(); it != temp.end(); ++it) { - Base::Vector3d normal = transformToOutside(*it); - // the normal is a vector, hence we must not apply the translation part - // of the transformation to the vector - normal.x -= _Mtrx[0][3]; - normal.y -= _Mtrx[1][3]; - normal.z -= _Mtrx[2][3]; - normal.Normalize(); - normals.push_back(normal); + std::vector normals = transformVectorsToOutside(temp); + for (auto& n : normals) { + n.Normalize(); } - return normals; } diff --git a/src/Mod/Points/App/Points.h b/src/Mod/Points/App/Points.h index 6c23b39196..eaa0ae5eaa 100644 --- a/src/Mod/Points/App/Points.h +++ b/src/Mod/Points/App/Points.h @@ -130,15 +130,15 @@ public: /// get the points inline const Base::Vector3d getPoint(const int idx) const { - return transformToOutside(_Points[idx]); + return transformPointToOutside(_Points[idx]); } /// set the points inline void setPoint(const int idx,const Base::Vector3d& point) { - _Points[idx] = transformToInside(point); + _Points[idx] = transformPointToInside(point); } /// insert the points inline void push_back(const Base::Vector3d& point) { - _Points.push_back(transformToInside(point)); + _Points.push_back(transformPointToInside(point)); } class PointsExport const_point_iterator