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]; am1_[i] = m.am1_[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 | // Calcul des cofacteurs
|
---|
89 | am1_[0] = (a_[4]*a_[8] - a_[5]*a_[7])/determ ;
|
---|
90 | am1_[1] = -(a_[3]*a_[8] - a_[5]*a_[6])/determ ;
|
---|
91 | am1_[2] = (a_[3]*a_[7] - a_[4]*a_[6])/determ ;
|
---|
92 | am1_[3] = -(a_[1]*a_[8] - a_[7]*a_[2])/determ ;
|
---|
93 | am1_[4] = (a_[0]*a_[8] - a_[6]*a_[2])/determ ;
|
---|
94 | am1_[5] = -(a_[0]*a_[7] - a_[6]*a_[1])/determ ;
|
---|
95 | am1_[6] = (a_[1]*a_[5] - a_[4]*a_[2])/determ ;
|
---|
96 | am1_[7] = -(a_[0]*a_[5] - a_[3]*a_[2])/determ ;
|
---|
97 | am1_[8] = (a_[0]*a_[4] - a_[3]*a_[1])/determ ;
|
---|
98 | /****************************************/
|
---|
99 | /* c'est la version qui marche, mais la convention semble
|
---|
100 | differente de celle de [3*r + c]...? */
|
---|
101 |
|
---|
102 |
|
---|
103 | /* // Transposition */
|
---|
104 | /* am1_ = am1_.Transpose() ; */
|
---|
105 | /* a_ = am1_; // marche pas bien : "request for member `Transpose' in `Matrix3x3::am1_', */
|
---|
106 | /* //which is of non-aggregate type 'double[9]' */
|
---|
107 |
|
---|
108 | // Calcul de l'inverse avec transpostion incluse
|
---|
109 | /* am1_[0] = (a_[4]*a_[8] - a_[5]*a_[7])/determ ; */
|
---|
110 | /* am1_[3] = -(a_[3]*a_[8] - a_[5]*a_[6])/determ ; */
|
---|
111 | /* am1_[6] = (a_[3]*a_[7] - a_[4]*a_[6])/determ ; */
|
---|
112 | /* am1_[1] = -(a_[1]*a_[8] - a_[7]*a_[2])/determ ; */
|
---|
113 | /* am1_[4] = (a_[0]*a_[8] - a_[6]*a_[2])/determ ; */
|
---|
114 | /* am1_[7] = -(a_[0]*a_[7] - a_[6]*a_[1])/determ ; */
|
---|
115 | /* am1_[2] = (a_[1]*a_[5] - a_[4]*a_[2])/determ ; */
|
---|
116 | /* am1_[5] = -(a_[0]*a_[5] - a_[3]*a_[2])/determ ; */
|
---|
117 | /* am1_[8] = (a_[0]*a_[4] - a_[3]*a_[1])/determ ; */
|
---|
118 | a_ = am1_;
|
---|
119 | return (*this);}
|
---|
120 |
|
---|
121 |
|
---|
122 | protected:
|
---|
123 | double a_[9], am1_[9];
|
---|
124 |
|
---|
125 | };
|
---|
126 |
|
---|
127 |
|
---|
128 | class RingOfMatrix3x3 {
|
---|
129 | public:
|
---|
130 | RingOfMatrix3x3(int_4 npix);
|
---|
131 | virtual ~RingOfMatrix3x3();
|
---|
132 |
|
---|
133 | inline int_4 Size() { return size_; }
|
---|
134 | inline Matrix3x3& GetElement(int_4 n)
|
---|
135 | {
|
---|
136 | if ((n<0) || (n>=size_))
|
---|
137 | throw RangeCheckError("RingOfMatrix3x3::GetElement() - Out of range index");
|
---|
138 | return mtxtab_[n];
|
---|
139 | }
|
---|
140 | inline Matrix3x3& operator()(int_4 n) { return GetElement(n); }
|
---|
141 |
|
---|
142 | protected:
|
---|
143 | Matrix3x3 *mtxtab_;
|
---|
144 | int_4 size_;
|
---|
145 | };
|
---|
146 |
|
---|
147 |
|
---|