| 1 | #include "machdefs.h"
 | 
|---|
| 2 | #include "pexceptions.h"
 | 
|---|
| 3 | 
 | 
|---|
| 4 | /*
 | 
|---|
| 5 | #include <math.h>
 | 
|---|
| 6 | #include <iostream.h>
 | 
|---|
| 7 | #include <fstream.h>
 | 
|---|
| 8 | 
 | 
|---|
| 9 | #include "tarrinit.h"
 | 
|---|
| 10 | #include "array.h"
 | 
|---|
| 11 | #include "ctimer.h"
 | 
|---|
| 12 | #include "timing.h"
 | 
|---|
| 13 | */
 | 
|---|
| 14 | 
 | 
|---|
| 15 | 
 | 
|---|
| 16 | 
 | 
|---|
| 17 | // -------------------------------------------------------
 | 
|---|
| 18 | // Classe simple de matrice 3x3 - sans allocation memoire
 | 
|---|
| 19 | // -------------------------------------------------------
 | 
|---|
| 20 | 
 | 
|---|
| 21 | class Matrix3x3 {
 | 
|---|
| 22 | public:
 | 
|---|
| 23 |   inline        Matrix3x3(bool raz=true) 
 | 
|---|
| 24 |   { 
 | 
|---|
| 25 |     if (raz) 
 | 
|---|
| 26 |       for(int i=0; i<9; i++) a_[i]=0.; 
 | 
|---|
| 27 |   } 
 | 
|---|
| 28 |   inline        Matrix3x3(const Matrix3x3 & m)
 | 
|---|
| 29 |   { 
 | 
|---|
| 30 |     for(int i=0; i<9; i++)  a_[i] = m.a_[i]; 
 | 
|---|
| 31 |   }
 | 
|---|
| 32 | 
 | 
|---|
| 33 |   inline        ~Matrix3x3() { }
 | 
|---|
| 34 | 
 | 
|---|
| 35 |   inline Matrix3x3& Set(const Matrix3x3 & m)
 | 
|---|
| 36 |                    { for(int i=0; i<9; i++) a_[i] = m.a_[i]; return (*this); }
 | 
|---|
| 37 |   inline Matrix3x3& operator = (const Matrix3x3 & a)
 | 
|---|
| 38 |                    { return Set(a); }
 | 
|---|
| 39 | 
 | 
|---|
| 40 |   inline double operator()(int r, int c) const 
 | 
|---|
| 41 |                 { return a_[r*3+c]; }
 | 
|---|
| 42 |   inline double& operator()(int r, int c) 
 | 
|---|
| 43 |                 { return a_[r*3+c]; }
 | 
|---|
| 44 | 
 | 
|---|
| 45 |   inline int NRows() const {return 3; }
 | 
|---|
| 46 |   inline int NCols() const {return 3; }
 | 
|---|
| 47 | 
 | 
|---|
| 48 |   inline Matrix3x3& AddElt(const Matrix3x3 & m)
 | 
|---|
| 49 |                    { for(int i=0; i<9; i++) a_[i] += m.a_[i]; return (*this); }
 | 
|---|
| 50 |   inline Matrix3x3& MulElt(const Matrix3x3 & m)
 | 
|---|
| 51 |                    { for(int i=0; i<9; i++) a_[i] *= m.a_[i]; return (*this); }
 | 
|---|
| 52 |   
 | 
|---|
| 53 |   // Multiplication de deux Matrix3x3 entre elles  
 | 
|---|
| 54 | /*    inline Matrix3x3& MulMat(const Matrix3x3 & m) */
 | 
|---|
| 55 | /*      { */
 | 
|---|
| 56 | /*        Matrix3x3 c; */
 | 
|---|
| 57 | /*        // c.Set(0.); */
 | 
|---|
| 58 | /*        for(int r=0; r<=2; r++) */
 | 
|---|
| 59 | /*      for(int c=0; c<=2; c++) */
 | 
|---|
| 60 | /*        c.a_[r*3+c] = 0.; */
 | 
|---|
| 61 |       
 | 
|---|
| 62 | /*        for(int r=0; r<=2; r++) */
 | 
|---|
| 63 | /*      for(int c=0; c<=2; c++) */
 | 
|---|
| 64 | /*        for(int k=0; k<=2; k++) */
 | 
|---|
| 65 | /*          c.a_[3*r+c] += a_[3*r+k] * m.a_[3*k+c]; */
 | 
|---|
| 66 |       
 | 
|---|
| 67 | /*        a_ = c; */
 | 
|---|
| 68 | /*        return(*this); */
 | 
|---|
| 69 | /*      } */
 | 
|---|
| 70 | 
 | 
|---|
| 71 |   inline Matrix3x3& Transpose()
 | 
|---|
| 72 |     {
 | 
|---|
| 73 |       double c;
 | 
|---|
| 74 |       c = a_[1]; a_[1] = a_[3]; a_[3] = c;
 | 
|---|
| 75 |       c = a_[2]; a_[2] = a_[6]; a_[6] = c;
 | 
|---|
| 76 |       c = a_[5]; a_[5] = a_[7]; a_[7] = c;
 | 
|---|
| 77 |       return (*this);
 | 
|---|
| 78 |     }
 | 
|---|
| 79 | 
 | 
|---|
| 80 |   inline Matrix3x3& Inverse()
 | 
|---|
| 81 |     {
 | 
|---|
| 82 |       // Calcul du determinant global
 | 
|---|
| 83 |       double determ;
 | 
|---|
| 84 |       determ =  a_[0]*a_[4]*a_[8] + a_[3]*a_[7]*a_[2] + a_[6]*a_[1]*a_[5];
 | 
|---|
| 85 |       determ -= a_[2]*a_[4]*a_[6] + a_[5]*a_[7]*a_[0] + a_[8]*a_[1]*a_[3];
 | 
|---|
| 86 |       // prevoir un break si determ <= threshold
 | 
|---|
| 87 | 
 | 
|---|
| 88 |       double am1_[9];
 | 
|---|
| 89 |       // Calcul des cofacteurs
 | 
|---|
| 90 |       am1_[0] =  (a_[4]*a_[8] - a_[5]*a_[7])/determ ; 
 | 
|---|
| 91 |       am1_[1] = -(a_[3]*a_[8] - a_[5]*a_[6])/determ ; 
 | 
|---|
| 92 |       am1_[2] =  (a_[3]*a_[7] - a_[4]*a_[6])/determ ; 
 | 
|---|
| 93 |       am1_[3] = -(a_[1]*a_[8] - a_[7]*a_[2])/determ ; 
 | 
|---|
| 94 |       am1_[4] =  (a_[0]*a_[8] - a_[6]*a_[2])/determ ; 
 | 
|---|
| 95 |       am1_[5] = -(a_[0]*a_[7] - a_[6]*a_[1])/determ ; 
 | 
|---|
| 96 |       am1_[6] =  (a_[1]*a_[5] - a_[4]*a_[2])/determ ; 
 | 
|---|
| 97 |       am1_[7] = -(a_[0]*a_[5] - a_[3]*a_[2])/determ ; 
 | 
|---|
| 98 |       am1_[8] =  (a_[0]*a_[4] - a_[3]*a_[1])/determ ; 
 | 
|---|
| 99 |       /****************************************/
 | 
|---|
| 100 |       /* c'est la version qui marche, mais la convention semble 
 | 
|---|
| 101 |          differente de celle de [3*r + c]...? */
 | 
|---|
| 102 | 
 | 
|---|
| 103 | 
 | 
|---|
| 104 | /*        // Transposition */
 | 
|---|
| 105 | /*        am1_ = am1_.Transpose() ; */
 | 
|---|
| 106 | /*        a_ = am1_; // marche pas bien : "request for member `Transpose' in `Matrix3x3::am1_', */
 | 
|---|
| 107 | /*                   //which is of non-aggregate type 'double[9]' */
 | 
|---|
| 108 | 
 | 
|---|
| 109 |       // Calcul de l'inverse avec transpostion incluse
 | 
|---|
| 110 | /*        am1_[0] =  (a_[4]*a_[8] - a_[5]*a_[7])/determ ; */
 | 
|---|
| 111 | /*        am1_[3] = -(a_[3]*a_[8] - a_[5]*a_[6])/determ ; */
 | 
|---|
| 112 | /*        am1_[6] =  (a_[3]*a_[7] - a_[4]*a_[6])/determ ; */
 | 
|---|
| 113 | /*        am1_[1] = -(a_[1]*a_[8] - a_[7]*a_[2])/determ ; */
 | 
|---|
| 114 | /*        am1_[4] =  (a_[0]*a_[8] - a_[6]*a_[2])/determ ; */
 | 
|---|
| 115 | /*        am1_[7] = -(a_[0]*a_[7] - a_[6]*a_[1])/determ ; */
 | 
|---|
| 116 | /*        am1_[2] =  (a_[1]*a_[5] - a_[4]*a_[2])/determ ; */
 | 
|---|
| 117 | /*        am1_[5] = -(a_[0]*a_[5] - a_[3]*a_[2])/determ ; */
 | 
|---|
| 118 | /*        am1_[8] =  (a_[0]*a_[4] - a_[3]*a_[1])/determ ; */
 | 
|---|
| 119 |       for(int k=0; k<9; k++) a_[k] = am1_[k];
 | 
|---|
| 120 |       return (*this);}
 | 
|---|
| 121 | 
 | 
|---|
| 122 | 
 | 
|---|
| 123 | protected:
 | 
|---|
| 124 |   double a_[9];
 | 
|---|
| 125 |   
 | 
|---|
| 126 | };
 | 
|---|
| 127 | 
 | 
|---|
| 128 | 
 | 
|---|
| 129 | class RingOfMatrix3x3 {
 | 
|---|
| 130 | public:
 | 
|---|
| 131 |                 RingOfMatrix3x3(int_4 npix);
 | 
|---|
| 132 |   virtual      ~RingOfMatrix3x3();
 | 
|---|
| 133 | 
 | 
|---|
| 134 |   inline int_4  Size() { return size_; }
 | 
|---|
| 135 |   inline Matrix3x3& GetElement(int_4 n) 
 | 
|---|
| 136 |   {
 | 
|---|
| 137 |     if ((n<0) || (n>=size_))
 | 
|---|
| 138 |       throw RangeCheckError("RingOfMatrix3x3::GetElement() - Out of range index");
 | 
|---|
| 139 |     return mtxtab_[n];
 | 
|---|
| 140 |   }
 | 
|---|
| 141 |   inline Matrix3x3& operator()(int_4 n) { return GetElement(n); }
 | 
|---|
| 142 | 
 | 
|---|
| 143 | protected:
 | 
|---|
| 144 |   Matrix3x3 *mtxtab_;
 | 
|---|
| 145 |   int_4 size_;  
 | 
|---|
| 146 | };
 | 
|---|
| 147 | 
 | 
|---|
| 148 | 
 | 
|---|