Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / INTERP_KERNEL / TetraAffineTransform.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #ifndef __TETRA_AFFINE_TRANSFORM_HXX__
20 #define __TETRA_AFFINE_TRANSFORM_HXX__
21
22 #include "INTERPKERNELDefines.hxx"
23
24 #undef INVERSION_SELF_CHECK // debugging : check that calculated inverse is correct
25
26 namespace INTERP_KERNEL
27 {
28   /**
29    * \brief Class representing an affine transformation x -> Ax + b that transforms a given tetrahedron
30    * into the unit tetrahedron.
31    *
32    */
33   class INTERPKERNEL_EXPORT TetraAffineTransform
34   {
35
36   public:
37     TetraAffineTransform(const double** pts);
38
39     void apply(double* destPt, const double* srcPt) const;
40
41     void reverseApply(double* destPt, const double* srcPt) const;
42
43     double determinant() const;
44
45     void dump() const;
46
47   private:
48
49     void invertLinearTransform();
50
51     void calculateDeterminant();
52
53     void factorizeLU(double* lu, int* idx) const;
54       
55     void forwardSubstitution(double* x, const double* lu, const double* b, const int* idx) const;
56
57     void backwardSubstitution(double* x, const double* lu, const double* b, const int* idx) const;
58
59     // The affine transformation Ax + b is represented with _linear_transformation containing the elements of
60     // A in row-first ordering and _translation containing the elements of b
61
62     /// 3x3 matrix A in affine transform x -> Ax + b
63     double _linear_transform[9];
64
65     /// 3x1 vector b in affine transform x -> Ax + b
66     double _translation[3];
67
68     /// The determinant of the matrix A is calculated at the construction of the object and cached.
69     double _determinant;
70
71     /// 3x3 matrix AT is transposed A matrix used for y -> ATy - c transformation
72     double _back_linear_transform[9];
73
74     /// 3x1 vector c in affine transform y -> ATy - c
75     double _back_translation[3];
76
77   };
78 }
79
80 #endif