From f6a585e0a4c94958e1608bc3c18a63776bc7f29c Mon Sep 17 00:00:00 2001
From: Norihiro Watanabe <norihiro.watanabe@ufz.de>
Date: Mon, 27 Apr 2015 14:31:54 +0200
Subject: [PATCH] implement operator* for Matrix and Point3d multiplication

---
 MathLib/Point3d.h                          | 18 ++++++++++++++++++
 MeshLib/ElementCoordinatesMappingLocal.cpp | 12 +++---------
 MeshLib/ElementCoordinatesMappingLocal.h   |  4 +---
 3 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/MathLib/Point3d.h b/MathLib/Point3d.h
index 75368621aa8..ebc86d6fbe1 100644
--- a/MathLib/Point3d.h
+++ b/MathLib/Point3d.h
@@ -42,5 +42,23 @@ bool lessEq(const MathLib::Point3d& p0,
             const MathLib::Point3d& p1,
             double tol = std::numeric_limits<double>::epsilon());
 
+/**
+ * rotation of points
+ * @param mat a rotation matrix
+ * @param p   a point to be transformed
+ * @return a rotated point
+ */
+template <typename MATRIX>
+inline MathLib::Point3d operator*(MATRIX const& mat, MathLib::Point3d const& p)
+{
+    MathLib::Point3d new_p;
+    for (std::size_t i(0); i<3; ++i) {
+        for (std::size_t j(0); j<3; ++j) {
+            new_p[i] += mat(i,j)*p[j];
+        }
+    }
+    return new_p;
+}
+
 #endif /* POINT3D_H_ */
 
diff --git a/MeshLib/ElementCoordinatesMappingLocal.cpp b/MeshLib/ElementCoordinatesMappingLocal.cpp
index 44fd9ee973f..a0b8a5364ce 100644
--- a/MeshLib/ElementCoordinatesMappingLocal.cpp
+++ b/MeshLib/ElementCoordinatesMappingLocal.cpp
@@ -29,7 +29,7 @@ ElementCoordinatesMappingLocal::ElementCoordinatesMappingLocal(
         _point_vec.push_back(new MeshLib::Node(*(e.getNode(i))));
 
     getRotationMatrixToGlobal(e, global_coords, _point_vec, _matR2global);
-    rotateToLocal(e, global_coords, _matR2global.transpose(), _point_vec);
+    rotateToLocal(_matR2global.transpose(), _point_vec);
 }
 
 ElementCoordinatesMappingLocal::~ElementCoordinatesMappingLocal()
@@ -38,17 +38,11 @@ ElementCoordinatesMappingLocal::~ElementCoordinatesMappingLocal()
 }
 
 void ElementCoordinatesMappingLocal::rotateToLocal(
-    const Element &ele,
-    const CoordinateSystem &global_coords,
     const RotationMatrix &matR2local,
     std::vector<MeshLib::Node*> &vec_pt) const
 {
-    // rotate the point coordinates
-    for(unsigned i = 0; i < ele.getNNodes(); i++)
-    {
-        Eigen::Vector3d  x_new = matR2local * Eigen::Map<Eigen::Vector3d>(const_cast<double*>(vec_pt[i]->getCoords()));
-        vec_pt[i]->setCoords(x_new.data());
-    }
+    for(unsigned i = 0; i < vec_pt.size(); i++)
+        vec_pt[i]->setCoords((matR2local* (*vec_pt[i])).getCoords());
 }
 
 void ElementCoordinatesMappingLocal::getRotationMatrixToGlobal(
diff --git a/MeshLib/ElementCoordinatesMappingLocal.h b/MeshLib/ElementCoordinatesMappingLocal.h
index 81b72197baf..1cc97dddbfc 100644
--- a/MeshLib/ElementCoordinatesMappingLocal.h
+++ b/MeshLib/ElementCoordinatesMappingLocal.h
@@ -57,9 +57,7 @@ public:
 
 private:
     /// rotate points to local coordinates
-    void rotateToLocal(
-            const Element &e, const CoordinateSystem &coordinate_system,
-            const RotationMatrix &matR2local, std::vector<MeshLib::Node*> &vec_pt) const;
+    void rotateToLocal(const RotationMatrix &matR2local, std::vector<MeshLib::Node*> &vec_pt) const;
 
     /// get a rotation matrix to the global coordinates
     /// it computes R in x=R*x' where x is original coordinates and x' is local coordinates
-- 
GitLab