From 103667f2f567c5cafc4853de3cd87436399e43df Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christian=20V=C3=B6gl?= <cvoegl@suse.com>
Date: Thu, 10 Dec 2020 13:48:47 +0100
Subject: [PATCH] Added rotate method to MeshOperations

---
 src/mesh_common/MeshOperations.h  | 18 ++++++++++++++++++
 tests/mesh/MeshOperationsTest.cpp | 22 ++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/src/mesh_common/MeshOperations.h b/src/mesh_common/MeshOperations.h
index b87081750..1694edf87 100644
--- a/src/mesh_common/MeshOperations.h
+++ b/src/mesh_common/MeshOperations.h
@@ -49,6 +49,9 @@ void translate( MeshType & mesh, const Vector3< typename MeshType::Scalar > & of
 template< typename MeshType >
 void scale( MeshType & mesh, const Vector3< typename MeshType::Scalar > & scaleFactors );
 
+template< typename MeshType >
+void rotate( MeshType& mesh, Vector3<typename  MeshType::Scalar > axis, typename MeshType::Scalar angle, Vector3< typename MeshType::scalar> axis_foot);
+
 template< typename MeshType >
 typename MeshType::Scalar computeVolume( const MeshType & mesh );
 
@@ -182,6 +185,21 @@ void scale( MeshType & mesh, const Vector3< typename MeshType::Scalar > & scaleF
    }
 }
 
+template< typename MeshType >
+void rotate( MeshType& mesh, Vector3<typename  MeshType::Scalar > axis, typename MeshType::Scalar angle, Vector3< typename MeshType::Scalar> axis_foot)
+{
+    Matrix3< typename MeshType::Scalar > mat(axis, angle);
+
+    for( auto v_it = mesh.vertices_begin(); v_it != mesh.vertices_end(); ++v_it)
+    {
+        auto &p = mesh.point(*v_it);
+        p -= mesh::toOpenMesh(axis_foot);
+        p = mat*p;
+        p += mesh::toOpenMesh(axis_foot);
+    }
+}
+
+
 
 template< typename MeshType >
 typename MeshType::Scalar computeVolume( const MeshType & mesh )
diff --git a/tests/mesh/MeshOperationsTest.cpp b/tests/mesh/MeshOperationsTest.cpp
index 6cceae10e..a17d14c72 100644
--- a/tests/mesh/MeshOperationsTest.cpp
+++ b/tests/mesh/MeshOperationsTest.cpp
@@ -120,6 +120,28 @@ void testCube()
    WALBERLA_CHECK_FLOAT_EQUAL( inertiaTensor(0,0), aabb.volume() * ( aabb.ySize() * aabb.ySize() + aabb.zSize() * aabb.zSize() ) / real_t(12) );
    WALBERLA_CHECK_FLOAT_EQUAL( inertiaTensor(1,1), aabb.volume() * ( aabb.xSize() * aabb.xSize() + aabb.zSize() * aabb.zSize() ) / real_t(12) );
    WALBERLA_CHECK_FLOAT_EQUAL( inertiaTensor(2,2), aabb.volume() * ( aabb.xSize() * aabb.xSize() + aabb.ySize() * aabb.ySize() ) / real_t(12) );
+
+
+   rotate(mesh, Vector3<Scalar>{0, 0, 1}, static_cast<Scalar>(M_PI_2), Vector3<Scalar>{-4, 0, 0});
+   aabb = computeAABB( mesh );
+
+   WALBERLA_CHECK_FLOAT_EQUAL( aabb.xMin(), Scalar(-5.5) );
+   WALBERLA_CHECK_FLOAT_EQUAL( aabb.yMin(), Scalar(3) );
+   WALBERLA_CHECK_FLOAT_EQUAL( aabb.zMin(), Scalar(-0.25) );
+
+   WALBERLA_CHECK_FLOAT_EQUAL( aabb.xMax(), Scalar(-2.5) );
+   WALBERLA_CHECK_FLOAT_EQUAL( aabb.yMax(), Scalar(5) );
+   WALBERLA_CHECK_FLOAT_EQUAL( aabb.zMax(), Scalar(0.25) );
+
+
+   WALBERLA_CHECK_FLOAT_EQUAL( computeSurfaceArea( mesh ), Scalar(2) * ( aabb.xSize() * aabb.ySize() + aabb.xSize() * aabb.zSize() + aabb.ySize() * aabb.zSize() ) );
+   WALBERLA_CHECK_FLOAT_EQUAL( computeVolume( mesh ),  aabb.volume() );
+   centroid = computeCentroid( mesh );
+   aabbCenter = aabb.center();
+   WALBERLA_CHECK_FLOAT_EQUAL( centroid[0], aabbCenter[0] );
+   WALBERLA_CHECK_FLOAT_EQUAL( centroid[1], aabbCenter[1] );
+   WALBERLA_CHECK_FLOAT_EQUAL( centroid[2], aabbCenter[2] );
+
 }
 
 int main( int argc, char * argv[] )
-- 
GitLab