Salome HOME
Bug fix: BuildIntersectCells() should no try to merge points at all. Done before.
[tools/medcoupling.git] / src / INTERP_KERNEL / TranslationRotationMatrix.hxx
index 8310ca704ac4399b02c6780fadeeec72d2f4353e..90a0f1fa7067920ec7dceca9108e4a0ba45a61a4 100644 (file)
@@ -1,29 +1,32 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #ifndef __TRANSLATIONROTATIONMATRIX_HXX__
 #define __TRANSLATIONROTATIONMATRIX_HXX__
 
+#include "INTERPKERNELDefines.hxx"
+
 #include <cmath>
 
 namespace INTERP_KERNEL
 {
-  class TranslationRotationMatrix
+  class INTERPKERNEL_EXPORT TranslationRotationMatrix
   {
 
   public:
@@ -116,7 +119,78 @@ namespace INTERP_KERNEL
       rotate_vector(P);
     }
                      
-       
+    /**
+     * Fills in rotation_matrix so that the triangle PP1, PP2, PP3 is in the plane Oxy, with PP1 at the origin and PP2 on Ox.
+     */
+    static void Rotate3DTriangle(const double* PP1,const double*PP2,const double*PP3, TranslationRotationMatrix& rotation_matrix)
+    {
+      double P1w[3];
+      double P2w[3];
+      double P3w[3];
+      P2w[0]=PP2[0]; P2w[1]=PP2[1];P2w[2]=PP2[2];
+      P3w[0]=PP3[0]; P3w[1]=PP3[1];P3w[2]=PP3[2];
+
+      // translating to set P1 at the origin
+      for (int i=0; i<3; i++)
+        {
+          P1w[i] = -PP1[i];
+          P2w[i] -= PP1[i];
+          P3w[i] -= PP1[i];
+        }
+
+      //initializes matrix
+      rotation_matrix.translate(P1w);
+
+      // rotating to set P2 on the Oxy plane
+      TranslationRotationMatrix A;
+      A.rotate_x(P2w);
+      A.rotate_vector(P3w);
+      rotation_matrix.multiply(A);
+
+      //rotating to set P2 on the Ox axis
+      TranslationRotationMatrix B;
+      B.rotate_z(P2w);
+      B.rotate_vector(P3w);
+      rotation_matrix.multiply(B);
+
+      //rotating to set P3 on the Oxy plane
+      TranslationRotationMatrix C;
+      C.rotate_x(P3w);
+      rotation_matrix.multiply(C);
+    }
+
+    /**
+     * Fills in rotation_matrix so that the bipoint PP1, PP2 is on the Ox axis.
+     */
+    static void Rotate3DBipoint(const double* PP1,const double*PP2, TranslationRotationMatrix& rotation_matrix)
+    {
+      double P1w[3];
+      double P2w[3];
+      P2w[0]=PP2[0]; P2w[1]=PP2[1];P2w[2]=PP2[2];
+
+      // translating to set P1 at the origin
+      for (int i=0; i<3; i++)
+        {
+          P1w[i] = -PP1[i];
+          P2w[i] -= PP1[i];
+        }
+
+      //initializes
+      rotation_matrix.translate(P1w);
+
+      // rotating to set P2 on the Oxy plane
+      TranslationRotationMatrix A;
+      A.rotate_x(P2w);
+      rotation_matrix.multiply(A);
+
+      //rotating to set P2 on the Ox axis
+      TranslationRotationMatrix B;
+      B.rotate_z(P2w);
+      rotation_matrix.multiply(B);
+    }
+
+
+
   private:
     static const double EPS;
     static const unsigned ROT_SIZE=9;
@@ -124,7 +198,6 @@ namespace INTERP_KERNEL
     double _rotation_coeffs[ROT_SIZE];
     double _translation_coeffs[TRANSL_SIZE];
   };
-  const double TranslationRotationMatrix::EPS=1e-12;
 }
 
 #endif