Back to index

salome-smesh  6.5.0
Rn.h
Go to the documentation of this file.
00001 //  MEFISTO :  library to compute 2D triangulation from segmented boundaries
00002 //
00003 // Copyright (C) 2006-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00018 //
00019 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00020 //
00021 //  File   : Rn.h
00022 //  Module : SMESH
00023 //  Authors: Frederic HECHT & Alain PERRONNET
00024 //  Date   : 13 novembre 2006
00025 
00026 #ifndef Rn__h
00027 #define Rn__h
00028 
00029 #include <gp_Pnt.hxx>      //Dans OpenCascade
00030 #include <gp_Vec.hxx>      //Dans OpenCascade
00031 #include <gp_Dir.hxx>      //Dans OpenCascade
00032 
00033 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00034 // BUT:   Definir les espaces affines R R2 R3 R4 soit Rn pour n=1,2,3,4
00035 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00036 // AUTEUR : Frederic HECHT      ANALYSE NUMERIQUE UPMC  PARIS   OCTOBRE   2000
00037 // MODIFS : Alain    PERRONNET  ANALYSE NUMERIQUE UPMC  PARIS   NOVEMBRE  2000
00038 //...............................................................................
00039 #include <iostream>
00040 #include <cmath>
00041 
00042 
00043 template<class T> inline T Abs (const T &a){return a <0 ? -a : a;}
00044 template<class T> inline void Echange (T& a,T& b) {T c=a;a=b;b=c;}
00045 
00046 template<class T> inline T Min (const T &a,const T &b)  {return a < b ? a : b;}
00047 template<class T> inline T Max (const T &a,const T & b) {return a > b ? a : b;}
00048 
00049 template<class T> inline T Max (const T &a,const T & b,const T & c){return Max(Max(a,b),c);}
00050 template<class T> inline T Min (const T &a,const T & b,const T & c){return Min(Min(a,b),c);}
00051 
00052 template<class T> inline T Max (const T &a,const T & b,const T & c,const T & d)
00053  {return Max(Max(a,b),Max(c,d));}
00054 template<class T> inline T Min (const T &a,const T & b,const T & c,const T & d)
00055  {return Min(Min(a,b),Min(c,d));}
00056 
00057 //le type Nom des entites geometriques P L S V O
00058 //===========
00059 typedef char Nom[1+24];
00060 
00061 //le type N des nombres entiers positifs
00062 //=========
00063 #ifndef PCLINUX64
00064 typedef unsigned long int N;
00065 #else 
00066 typedef unsigned int N;
00067 #endif
00068 
00069 //le type Z des nombres entiers relatifs
00070 //=========
00071 #ifndef PCLINUX64
00072 typedef long int Z;
00073 #else
00074 typedef int Z;
00075 #endif
00076 
00077 //le type R des nombres "reels"
00078 //=========
00079 typedef double R;
00080 
00081 //le type XPoint  des coordonnees d'un pixel dans une fenetre
00082 //==============
00083 //typedef struct { short int x,y } XPoint;  //en fait ce type est defini dans X11-Window
00084                                             // #include <X11/Xlib.h>
00085 //la classe R2
00086 //============
00087 class R2 
00088 {
00089   friend std::ostream& operator << (std::ostream& f, const R2 & P)
00090   { f << P.x << ' ' << P.y ; return f; }
00091   friend std::istream& operator >> (std::istream& f, R2 & P)
00092   { f >> P.x >> P.y ; return f; }
00093 
00094   friend std::ostream& operator << (std::ostream& f, const R2 * P)
00095   { f << P->x << ' ' << P->y ; return f; }
00096   friend std::istream& operator >> (std::istream& f, R2 * P)
00097   { f >> P->x >> P->y ; return f; }
00098 
00099 public:
00100   R x,y;  //les donnees
00101 
00102   R2 () :x(0),y(0) {}              //les constructeurs
00103   R2 (R a,R b)   :x(a),y(b)  {}
00104   R2 (R2 A,R2 B) :x(B.x-A.x),y(B.y-A.y)  {} //vecteur defini par 2 points
00105 
00106   R2  operator+(R2 P) const {return R2(x+P.x,y+P.y);}     // Q+P possible
00107   R2  operator+=(R2 P)  {x += P.x;y += P.y; return *this;}// Q+=P;
00108   R2  operator-(R2 P) const {return R2(x-P.x,y-P.y);}     // Q-P
00109   R2  operator-=(R2 P) {x -= P.x;y -= P.y; return *this;} // Q-=P;
00110   R2  operator-()const  {return R2(-x,-y);}               // -Q
00111   R2  operator+()const  {return *this;}                   // +Q
00112   R   operator,(R2 P)const {return x*P.x+y*P.y;} // produit scalaire (Q,P)
00113   R   operator^(R2 P)const {return x*P.y-y*P.x;} // produit vectoriel Q^P
00114   R2  operator*(R c)const {return R2(x*c,y*c);}  // produit a droite  P*c
00115   R2  operator*=(R c)  {x *= c; y *= c; return *this;}
00116   R2  operator/(R c)const {return R2(x/c,y/c);}  // division par un reel
00117   R2  operator/=(R c)  {x /= c; y /= c; return *this;}
00118   R & operator[](int i) {return (&x)[i];}        // la coordonnee i
00119   R2  orthogonal() {return R2(-y,x);}    //le vecteur orthogonal dans R2
00120   friend R2 operator*(R c,R2 P) {return P*c;}    // produit a gauche c*P
00121 };
00122 
00123 
00124 //la classe R3
00125 //============
00126 class R3
00127 {
00128   friend std::ostream& operator << (std::ostream& f, const R3 & P)
00129   { f << P.x << ' ' << P.y << ' ' << P.z ; return f; }
00130   friend std::istream& operator >> (std::istream& f, R3 & P)
00131   { f >> P.x >> P.y >> P.z ; return f; }
00132 
00133   friend std::ostream& operator << (std::ostream& f, const R3 * P)
00134   { f << P->x << ' ' << P->y << ' ' << P->z ; return f; }
00135   friend std::istream& operator >> (std::istream& f, R3 * P)
00136   { f >> P->x >> P->y >> P->z ; return f; }
00137 
00138 public:  
00139   R  x,y,z;  //les 3 coordonnees
00140  
00141   R3 () :x(0),y(0),z(0) {}  //les constructeurs
00142   R3 (R a,R b,R c):x(a),y(b),z(c)  {}                  //Point ou Vecteur (a,b,c)
00143   R3 (R3 A,R3 B):x(B.x-A.x),y(B.y-A.y),z(B.z-A.z)  {}  //Vecteur AB
00144 
00145   R3 (gp_Pnt P) : x(P.X()), y(P.Y()), z(P.Z()) {}      //Point     d'OpenCascade
00146   R3 (gp_Vec V) : x(V.X()), y(V.Y()), z(V.Z()) {}      //Vecteur   d'OpenCascade
00147   R3 (gp_Dir P) : x(P.X()), y(P.Y()), z(P.Z()) {}      //Direction d'OpenCascade
00148 
00149   R3   operator+(R3 P)const  {return R3(x+P.x,y+P.y,z+P.z);}
00150   R3   operator+=(R3 P)  {x += P.x; y += P.y; z += P.z; return *this;}
00151   R3   operator-(R3 P)const  {return R3(x-P.x,y-P.y,z-P.z);}
00152   R3   operator-=(R3 P)  {x -= P.x; y -= P.y; z -= P.z; return *this;}
00153   R3   operator-()const  {return R3(-x,-y,-z);}
00154   R3   operator+()const  {return *this;}
00155   R    operator,(R3 P)const {return  x*P.x+y*P.y+z*P.z;} // produit scalaire
00156   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
00157   R3   operator*(R c)const {return R3(x*c,y*c,z*c);}
00158   R3   operator*=(R c)  {x *= c; y *= c; z *= c; return *this;}
00159   R3   operator/(R c)const {return R3(x/c,y/c,z/c);}
00160   R3   operator/=(R c)  {x /= c; y /= c; z /= c; return *this;}
00161   R  & operator[](int i) {return (&x)[i];}
00162   friend R3 operator*(R c,R3 P) {return P*c;}
00163 
00164   R3   operator=(gp_Pnt P) {return R3(P.X(),P.Y(),P.Z());}
00165   R3   operator=(gp_Dir P) {return R3(P.X(),P.Y(),P.Z());}
00166 
00167   friend gp_Pnt gp_pnt(R3 xyz) { return gp_Pnt(xyz.x,xyz.y,xyz.z); }
00168   //friend gp_Pnt operator=() { return gp_Pnt(x,y,z); }
00169   friend gp_Dir gp_dir(R3 xyz) { return gp_Dir(xyz.x,xyz.y,xyz.z); }
00170 
00171   bool  DansPave( R3 & xyzMin, R3 & xyzMax )
00172     { return xyzMin.x<=x && x<=xyzMax.x &&
00173              xyzMin.y<=y && y<=xyzMax.y &&
00174              xyzMin.z<=z && z<=xyzMax.z; }
00175 };
00176 
00177 //la classe R4
00178 //============
00179 class R4: public R3
00180 {
00181   friend std::ostream& operator <<(std::ostream& f, const R4 & P )
00182   { f << P.x << ' ' << P.y << ' ' << P.z << ' ' << P.omega; return f; }
00183   friend istream& operator >>(istream& f,  R4 & P)
00184   { f >> P.x >>  P.y >>  P.z >> P.omega ; return f; }
00185 
00186   friend std::ostream& operator <<(std::ostream& f, const R4 * P )
00187   { f << P->x << ' ' << P->y << ' ' << P->z << ' ' << P->omega; return f; }
00188   friend istream& operator >>(istream& f,  R4 * P)
00189   { f >> P->x >>  P->y >>  P->z >> P->omega ; return f; }
00190 
00191 public:  
00192   R  omega;  //la donnee du poids supplementaire
00193  
00194   R4 () :omega(1.0) {}  //les constructeurs
00195   R4 (R a,R b,R c,R d):R3(a,b,c),omega(d) {}
00196   R4 (R4 A,R4 B) :R3(B.x-A.x,B.y-A.y,B.z-A.z),omega(B.omega-A.omega) {}
00197 
00198   R4   operator+(R4 P)const  {return R4(x+P.x,y+P.y,z+P.z,omega+P.omega);}
00199   R4   operator+=(R4 P)  {x += P.x;y += P.y;z += P.z;omega += P.omega;return *this;}
00200   R4   operator-(R4 P)const  {return R4(x-P.x,y-P.y,z-P.z,omega-P.omega);}
00201   R4   operator-=(R4 P) {x -= P.x;y -= P.y;z -= P.z;omega -= P.omega;return *this;}
00202   R4   operator-()const  {return R4(-x,-y,-z,-omega);}
00203   R4   operator+()const  {return *this;}
00204   R    operator,(R4 P)const {return  x*P.x+y*P.y+z*P.z+omega*P.omega;} // produit scalaire
00205   R4   operator*(R c)const {return R4(x*c,y*c,z*c,omega*c);}
00206   R4   operator*=(R c)  {x *= c; y *= c; z *= c; omega *= c; return *this;}
00207   R4   operator/(R c)const {return R4(x/c,y/c,z/c,omega/c);}
00208   R4   operator/=(R c)  {x /= c; y /= c; z /= c; omega /= c; return *this;}
00209   R  & operator[](int i) {return (&x)[i];}
00210   friend R4 operator*(R c,R4 P) {return P*c;}
00211 };
00212 
00213 //quelques fonctions supplementaires sur ces classes
00214 //==================================================
00215 inline R Aire2d(const R2 A,const R2 B,const R2 C){return (B-A)^(C-A);} 
00216 inline R Angle2d(R2 P){ return atan2(P.y,P.x);}
00217 
00218 inline R Norme2_2(const R2 & A){ return (A,A);}
00219 inline R Norme2(const R2 & A){ return sqrt((A,A));}
00220 inline R NormeInfinie(const R2 & A){return Max(Abs(A.x),Abs(A.y));}
00221 
00222 inline R Norme2_2(const R3 & A){ return (A,A);}
00223 inline R Norme2(const R3 & A){ return sqrt((A,A));}
00224 inline R NormeInfinie(const R3 & A){return Max(Abs(A.x),Abs(A.y),Abs(A.z));}
00225 
00226 inline R Norme2_2(const R4 & A){ return (A,A);}
00227 inline R Norme2(const R4 & A){ return sqrt((A,A));}
00228 inline R NormeInfinie(const R4 & A){return Max(Abs(A.x),Abs(A.y),Abs(A.z),Abs(A.omega));}
00229 
00230 inline R2 XY(R3 P) {return R2(P.x, P.y);}  //restriction a R2 d'un R3 par perte de z
00231 inline R3 Min(R3 P, R3 Q) 
00232 {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
00233 inline R3 Max(R3 P, R3 Q) 
00234 {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
00235 
00236 #endif