Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/smesh.git] / src / MEFISTO2 / Rn.h
1 #ifndef Rn__h
2 #define Rn__h
3
4 #include <gp_Pnt.hxx>      //Dans OpenCascade
5 #include <gp_Vec.hxx>      //Dans OpenCascade
6 #include <gp_Dir.hxx>      //Dans OpenCascade
7
8 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9 // BUT:   Definir les espaces affines R R2 R3 R4 soit Rn pour n=1,2,3,4
10 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11 // AUTEUR : Frederic HECHT      ANALYSE NUMERIQUE UPMC  PARIS   OCTOBRE   2000
12 // MODIFS : Alain    PERRONNET  ANALYSE NUMERIQUE UPMC  PARIS   NOVEMBRE  2000
13 //...............................................................................
14 #include <iostream>
15 #include <cmath>
16
17 using namespace std;
18
19 template<class T> inline T Abs (const T &a){return a <0 ? -a : a;}
20 template<class T> inline void Echange (T& a,T& b) {T c=a;a=b;b=c;}
21
22 template<class T> inline T Min (const T &a,const T &b)  {return a < b ? a : b;}
23 template<class T> inline T Max (const T &a,const T & b) {return a > b ? a : b;}
24
25 template<class T> inline T Max (const T &a,const T & b,const T & c){return Max(Max(a,b),c);}
26 template<class T> inline T Min (const T &a,const T & b,const T & c){return Min(Min(a,b),c);}
27
28 template<class T> inline T Max (const T &a,const T & b,const T & c,const T & d)
29  {return Max(Max(a,b),Max(c,d));}
30 template<class T> inline T Min (const T &a,const T & b,const T & c,const T & d)
31  {return Min(Min(a,b),Min(c,d));}
32
33 //le type Nom des entites geometriques P L S V O
34 //===========
35 typedef char Nom[1+24];
36
37 //le type N des nombres entiers positifs
38 //=========
39 typedef unsigned long int N;
40
41 //le type Z des nombres entiers relatifs
42 //=========
43 typedef long int Z;
44
45 //le type R des nombres "reels"
46 //=========
47 typedef double R;
48
49 //le type XPoint  des coordonnees d'un pixel dans une fenetre
50 //==============
51 //typedef struct { short int x,y } XPoint;  //en fait ce type est defini dans X11-Window
52                                             // #include <X11/Xlib.h>
53 //la classe R2
54 //============
55 class R2 
56 {
57   friend ostream& operator << (ostream& f, const R2 & P)
58   { f << P.x << ' ' << P.y ; return f; }
59   friend istream& operator >> (istream& f, R2 & P)
60   { f >> P.x >> P.y ; return f; }
61
62   friend ostream& operator << (ostream& f, const R2 * P)
63   { f << P->x << ' ' << P->y ; return f; }
64   friend istream& operator >> (istream& f, R2 * P)
65   { f >> P->x >> P->y ; return f; }
66
67 public:
68   R x,y;  //les donnees
69
70   R2 () :x(0),y(0) {}              //les constructeurs
71   R2 (R a,R b)   :x(a),y(b)  {}
72   R2 (R2 A,R2 B) :x(B.x-A.x),y(B.y-A.y)  {} //vecteur defini par 2 points
73
74   R2  operator+(R2 P) const {return R2(x+P.x,y+P.y);}     // Q+P possible
75   R2  operator+=(R2 P)  {x += P.x;y += P.y; return *this;}// Q+=P;
76   R2  operator-(R2 P) const {return R2(x-P.x,y-P.y);}     // Q-P
77   R2  operator-=(R2 P) {x -= P.x;y -= P.y; return *this;} // Q-=P;
78   R2  operator-()const  {return R2(-x,-y);}               // -Q
79   R2  operator+()const  {return *this;}                   // +Q
80   R   operator,(R2 P)const {return x*P.x+y*P.y;} // produit scalaire (Q,P)
81   R   operator^(R2 P)const {return x*P.y-y*P.x;} // produit vectoriel Q^P
82   R2  operator*(R c)const {return R2(x*c,y*c);}  // produit a droite  P*c
83   R2  operator*=(R c)  {x *= c; y *= c; return *this;}
84   R2  operator/(R c)const {return R2(x/c,y/c);}  // division par un reel
85   R2  operator/=(R c)  {x /= c; y /= c; return *this;}
86   R & operator[](int i) {return (&x)[i];}        // la coordonnee i
87   R2  orthogonal() {return R2(-y,x);}    //le vecteur orthogonal dans R2
88   friend R2 operator*(R c,R2 P) {return P*c;}    // produit a gauche c*P
89 };
90
91
92 //la classe R3
93 //============
94 class R3
95 {
96   friend ostream& operator << (ostream& f, const R3 & P)
97   { f << P.x << ' ' << P.y << ' ' << P.z ; return f; }
98   friend istream& operator >> (istream& f, R3 & P)
99   { f >> P.x >> P.y >> P.z ; return f; }
100
101   friend ostream& operator << (ostream& f, const R3 * P)
102   { f << P->x << ' ' << P->y << ' ' << P->z ; return f; }
103   friend istream& operator >> (istream& f, R3 * P)
104   { f >> P->x >> P->y >> P->z ; return f; }
105
106 public:  
107   R  x,y,z;  //les 3 coordonnees
108  
109   R3 () :x(0),y(0),z(0) {}  //les constructeurs
110   R3 (R a,R b,R c):x(a),y(b),z(c)  {}                  //Point ou Vecteur (a,b,c)
111   R3 (R3 A,R3 B):x(B.x-A.x),y(B.y-A.y),z(B.z-A.z)  {}  //Vecteur AB
112
113   R3 (gp_Pnt P) : x(P.X()), y(P.Y()), z(P.Z()) {}      //Point     d'OpenCascade
114   R3 (gp_Vec V) : x(V.X()), y(V.Y()), z(V.Z()) {}      //Vecteur   d'OpenCascade
115   R3 (gp_Dir P) : x(P.X()), y(P.Y()), z(P.Z()) {}      //Direction d'OpenCascade
116
117   R3   operator+(R3 P)const  {return R3(x+P.x,y+P.y,z+P.z);}
118   R3   operator+=(R3 P)  {x += P.x; y += P.y; z += P.z; return *this;}
119   R3   operator-(R3 P)const  {return R3(x-P.x,y-P.y,z-P.z);}
120   R3   operator-=(R3 P)  {x -= P.x; y -= P.y; z -= P.z; return *this;}
121   R3   operator-()const  {return R3(-x,-y,-z);}
122   R3   operator+()const  {return *this;}
123   R    operator,(R3 P)const {return  x*P.x+y*P.y+z*P.z;} // produit scalaire
124   R3   operator^(R3 P)const {return R3(y*P.z-z*P.y ,P.x*z-x*P.z, x*P.y-y*P.x);} // produit vectoriel
125   R3   operator*(R c)const {return R3(x*c,y*c,z*c);}
126   R3   operator*=(R c)  {x *= c; y *= c; z *= c; return *this;}
127   R3   operator/(R c)const {return R3(x/c,y/c,z/c);}
128   R3   operator/=(R c)  {x /= c; y /= c; z /= c; return *this;}
129   R  & operator[](int i) {return (&x)[i];}
130   friend R3 operator*(R c,R3 P) {return P*c;}
131
132   R3   operator=(gp_Pnt P) {return R3(P.X(),P.Y(),P.Z());}
133   R3   operator=(gp_Dir P) {return R3(P.X(),P.Y(),P.Z());}
134
135   friend gp_Pnt gp_pnt(R3 xyz) { return gp_Pnt(xyz.x,xyz.y,xyz.z); }
136   //friend gp_Pnt operator=() { return gp_Pnt(x,y,z); }
137   friend gp_Dir gp_dir(R3 xyz) { return gp_Dir(xyz.x,xyz.y,xyz.z); }
138
139   bool  DansPave( R3 & xyzMin, R3 & xyzMax )
140     { return xyzMin.x<=x && x<=xyzMax.x &&
141              xyzMin.y<=y && y<=xyzMax.y &&
142              xyzMin.z<=z && z<=xyzMax.z; }
143 };
144
145 //la classe R4
146 //============
147 class R4: public R3
148 {
149   friend ostream& operator <<(ostream& f, const R4 & P )
150   { f << P.x << ' ' << P.y << ' ' << P.z << ' ' << P.omega; return f; }
151   friend istream& operator >>(istream& f,  R4 & P)
152   { f >> P.x >>  P.y >>  P.z >> P.omega ; return f; }
153
154   friend ostream& operator <<(ostream& f, const R4 * P )
155   { f << P->x << ' ' << P->y << ' ' << P->z << ' ' << P->omega; return f; }
156   friend istream& operator >>(istream& f,  R4 * P)
157   { f >> P->x >>  P->y >>  P->z >> P->omega ; return f; }
158
159 public:  
160   R  omega;  //la donnee du poids supplementaire
161  
162   R4 () :omega(1.0) {}  //les constructeurs
163   R4 (R a,R b,R c,R d):R3(a,b,c),omega(d) {}
164   R4 (R4 A,R4 B) :R3(B.x-A.x,B.y-A.y,B.z-A.z),omega(B.omega-A.omega) {}
165
166   R4   operator+(R4 P)const  {return R4(x+P.x,y+P.y,z+P.z,omega+P.omega);}
167   R4   operator+=(R4 P)  {x += P.x;y += P.y;z += P.z;omega += P.omega;return *this;}
168   R4   operator-(R4 P)const  {return R4(x-P.x,y-P.y,z-P.z,omega-P.omega);}
169   R4   operator-=(R4 P) {x -= P.x;y -= P.y;z -= P.z;omega -= P.omega;return *this;}
170   R4   operator-()const  {return R4(-x,-y,-z,-omega);}
171   R4   operator+()const  {return *this;}
172   R    operator,(R4 P)const {return  x*P.x+y*P.y+z*P.z+omega*P.omega;} // produit scalaire
173   R4   operator*(R c)const {return R4(x*c,y*c,z*c,omega*c);}
174   R4   operator*=(R c)  {x *= c; y *= c; z *= c; omega *= c; return *this;}
175   R4   operator/(R c)const {return R4(x/c,y/c,z/c,omega/c);}
176   R4   operator/=(R c)  {x /= c; y /= c; z /= c; omega /= c; return *this;}
177   R  & operator[](int i) {return (&x)[i];}
178   friend R4 operator*(R c,R4 P) {return P*c;}
179 };
180
181 //quelques fonctions supplementaires sur ces classes
182 //==================================================
183 inline R Aire2d(const R2 A,const R2 B,const R2 C){return (B-A)^(C-A);} 
184 inline R Angle2d(R2 P){ return atan2(P.y,P.x);}
185
186 inline R Norme2_2(const R2 & A){ return (A,A);}
187 inline R Norme2(const R2 & A){ return sqrt((A,A));}
188 inline R NormeInfinie(const R2 & A){return Max(Abs(A.x),Abs(A.y));}
189
190 inline R Norme2_2(const R3 & A){ return (A,A);}
191 inline R Norme2(const R3 & A){ return sqrt((A,A));}
192 inline R NormeInfinie(const R3 & A){return Max(Abs(A.x),Abs(A.y),Abs(A.z));}
193
194 inline R Norme2_2(const R4 & A){ return (A,A);}
195 inline R Norme2(const R4 & A){ return sqrt((A,A));}
196 inline R NormeInfinie(const R4 & A){return Max(Abs(A.x),Abs(A.y),Abs(A.z),Abs(A.omega));}
197
198 inline R2 XY(R3 P) {return R2(P.x, P.y);}  //restriction a R2 d'un R3 par perte de z
199 inline R3 Min(R3 P, R3 Q) 
200 {return R3(P.x<Q.x ? P.x : Q.x, P.y<Q.y ? P.y : Q.y, P.z<Q.z ? P.z : Q.z);} //Pt de xyz Min
201 inline R3 Max(R3 P, R3 Q) 
202 {return R3(P.x>Q.x ? P.x : Q.x, P.y>Q.y ? P.y : Q.y, P.z>Q.z ? P.z : Q.z);} //Pt de xyz Max
203
204 #endif