| 1 |
// MEFISTO : library to compute 2D triangulation from segmented boundaries |
| 2 |
// |
| 3 |
// Copyright (C) 2006-2015 CEA/DEN, EDF R&D, OPEN CASCADE |
| 4 |
// |
| 5 |
// This library is free software; you can redistribute it and/or |
| 6 |
// modify it under the terms of the GNU Lesser General Public |
| 7 |
// License as published by the Free Software Foundation; either |
| 8 |
// version 2.1 of the License, or (at your option) any later version. |
| 9 |
// |
| 10 |
// This library is distributed in the hope that it will be useful, |
| 11 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
// Lesser General Public License for more details. |
| 14 |
// |
| 15 |
// You should have received a copy of the GNU Lesser General Public |
| 16 |
// License along with this library; if not, write to the Free Software |
| 17 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 |
// |
| 19 |
// See http://www.salome-platform.org/ or email : [email protected] |
| 20 |
// |
| 21 |
// File : Rn.h |
| 22 |
// Module : SMESH |
| 23 |
// Authors: Frederic HECHT & Alain PERRONNET |
| 24 |
// Date : 13 novembre 2006 |
| 25 |
|
| 26 |
#ifndef Rn__h |
| 27 |
#define Rn__h |
| 28 |
|
| 29 |
#include <gp_Pnt.hxx> //Dans OpenCascade |
| 30 |
#include <gp_Vec.hxx> //Dans OpenCascade |
| 31 |
#include <gp_Dir.hxx> //Dans OpenCascade |
| 32 |
|
| 33 |
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 34 |
// BUT: Definir les espaces affines R R_2 R_3 R_4 soit Rn pour n=1,2,3,4 |
| 35 |
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 36 |
// AUTEUR : Frederic HECHT ANALYSE NUMERIQUE UPMC PARIS OCTOBRE 2000 |
| 37 |
// MODIFS : Alain PERRONNET ANALYSE NUMERIQUE UPMC PARIS NOVEMBRE 2000 |
| 38 |
//............................................................................... |
| 39 |
#include <iostream> |
| 40 |
#include <cmath> |
| 41 |
|
| 42 |
|
| 43 |
template<class T> inline T Abs (const T &a){return a <0 ? -a : a;} |
| 44 |
template<class T> inline void Echange (T& a,T& b) {T c=a;a=b;b=c;} |
| 45 |
|
| 46 |
template<class T> inline T Min (const T &a,const T &b) {return a < b ? a : b;} |
| 47 |
template<class T> inline T Max (const T &a,const T & b) {return a > b ? a : b;} |
| 48 |
|
| 49 |
template<class T> inline T Max (const T &a,const T & b,const T & c){return Max(Max(a,b),c);} |
| 50 |
template<class T> inline T Min (const T &a,const T & b,const T & c){return Min(Min(a,b),c);} |
| 51 |
|
| 52 |
template<class T> inline T Max (const T &a,const T & b,const T & c,const T & d) |
| 53 |
{return Max(Max(a,b),Max(c,d));} |
| 54 |
template<class T> inline T Min (const T &a,const T & b,const T & c,const T & d) |
| 55 |
{return Min(Min(a,b),Min(c,d));} |
| 56 |
|
| 57 |
//le type Nom des entities geometriques P L S V O |
| 58 |
//=========== |
| 59 |
typedef char Nom[1+24]; |
| 60 |
|
| 61 |
//le type N des nombres entiers positifs |
| 62 |
//========= |
| 63 |
#ifndef PCLINUX64 |
| 64 |
typedef unsigned long int N; |
| 65 |
#else |
| 66 |
typedef unsigned int N; |
| 67 |
#endif |
| 68 |
|
| 69 |
//le type Z des nombres entiers relatifs |
| 70 |
//========= |
| 71 |
#ifndef PCLINUX64 |
| 72 |
typedef long int Z; |
| 73 |
#else |
| 74 |
typedef int Z; |
| 75 |
#endif |
| 76 |
|
| 77 |
//le type R des nombres "reels" |
| 78 |
//========= |
| 79 |
typedef double R; |
| 80 |
|
| 81 |
//le type XPoint des coordonnees d'un pixel dans une fenetre |
| 82 |
//============== |
| 83 |
//typedef struct { short int x,y } XPoint; //en fait ce type est defini dans X11-Window |
| 84 |
// #include <X11/Xlib.h> |
| 85 |
//la classe R_2 |
| 86 |
//============ |
| 87 |
class R_2 |
| 88 |
{ |
| 89 |
friend std::ostream& operator << (std::ostream& f, const R_2 & P) |
| 90 |
{ f << P.x << ' ' << P.y ; return f; } |
| 91 |
friend std::istream& operator >> (std::istream& f, R_2 & P) |
| 92 |
{ f >> P.x >> P.y ; return f; } |
| 93 |
|
| 94 |
friend std::ostream& operator << (std::ostream& f, const R_2 * P) |
| 95 |
{ f << P->x << ' ' << P->y ; return f; } |
| 96 |
friend std::istream& operator >> (std::istream& f, R_2 * P) |
| 97 |
{ f >> P->x >> P->y ; return f; } |
| 98 |
|
| 99 |
public: |
| 100 |
R x,y; //les donnees |
| 101 |
|
| 102 |
R_2 () :x(0),y(0) {} //les constructeurs |
| 103 |
R_2 (R a,R b) :x(a),y(b) {} |
| 104 |
R_2 (R_2 A,R_2 B) :x(B.x-A.x),y(B.y-A.y) {} //vecteur defini par 2 points |
| 105 |
|
| 106 |
R_2 operator+(R_2 P) const {return R_2(x+P.x,y+P.y);} // Q+P possible |
| 107 |
R_2 operator+=(R_2 P) {x += P.x;y += P.y; return *this;}// Q+=P; |
| 108 |
R_2 operator-(R_2 P) const {return R_2(x-P.x,y-P.y);} // Q-P |
| 109 |
R_2 operator-=(R_2 P) {x -= P.x;y -= P.y; return *this;} // Q-=P; |
| 110 |
R_2 operator-()const {return R_2(-x,-y);} // -Q |
| 111 |
R_2 operator+()const {return *this;} // +Q |
| 112 |
R operator,(R_2 P)const {return x*P.x+y*P.y;} // produit scalaire (Q,P) |
| 113 |
R operator^(R_2 P)const {return x*P.y-y*P.x;} // produit vectoriel Q^P |
| 114 |
R_2 operator*(R c)const {return R_2(x*c,y*c);} // produit a droite P*c |
| 115 |
R_2 operator*=(R c) {x *= c; y *= c; return *this;} |
| 116 |
R_2 operator/(R c)const {return R_2(x/c,y/c);} // division par un reel |
| 117 |
R_2 operator/=(R c) {x /= c; y /= c; return *this;} |
| 118 |
R & operator[](int i) {return (&x)[i];} // la coordonnee i |
| 119 |
R_2 orthogonal() {return R_2(-y,x);} //le vecteur orthogonal dans R_2 |
| 120 |
friend R_2 operator*(R c,R_2 P) {return P*c;} // produit a gauche c*P |
| 121 |
}; |
| 122 |
|
| 123 |
|
| 124 |
//la classe R_3 |
| 125 |
//============ |
| 126 |
class R_3 |
| 127 |
{ |
| 128 |
friend std::ostream& operator << (std::ostream& f, const R_3 & P) |
| 129 |
{ f << P.x << ' ' << P.y << ' ' << P.z ; return f; } |
| 130 |
friend std::istream& operator >> (std::istream& f, R_3 & P) |
| 131 |
{ f >> P.x >> P.y >> P.z ; return f; } |
| 132 |
|
| 133 |
friend std::ostream& operator << (std::ostream& f, const R_3 * P) |
| 134 |
{ f << P->x << ' ' << P->y << ' ' << P->z ; return f; } |
| 135 |
friend std::istream& operator >> (std::istream& f, R_3 * P) |
| 136 |
{ f >> P->x >> P->y >> P->z ; return f; } |
| 137 |
|
| 138 |
public: |
| 139 |
R x,y,z; //les 3 coordonnees |
| 140 |
|
| 141 |
R_3 () :x(0),y(0),z(0) {} //les constructeurs |
| 142 |
R_3 (R a,R b,R c):x(a),y(b),z(c) {} //Point ou Vecteur (a,b,c) |
| 143 |
R_3 (R_3 A,R_3 B):x(B.x-A.x),y(B.y-A.y),z(B.z-A.z) {} //Vecteur AB |
| 144 |
|
| 145 |
R_3 (gp_Pnt P) : x(P.X()), y(P.Y()), z(P.Z()) {} //Point d'OpenCascade |
| 146 |
R_3 (gp_Vec V) : x(V.X()), y(V.Y()), z(V.Z()) {} //Vecteur d'OpenCascade |
| 147 |
R_3 (gp_Dir P) : x(P.X()), y(P.Y()), z(P.Z()) {} //Direction d'OpenCascade |
| 148 |
|
| 149 |
R_3 operator+(R_3 P)const {return R_3(x+P.x,y+P.y,z+P.z);} |
| 150 |
R_3 operator+=(R_3 P) {x += P.x; y += P.y; z += P.z; return *this;} |
| 151 |
R_3 operator-(R_3 P)const {return R_3(x-P.x,y-P.y,z-P.z);} |
| 152 |
R_3 operator-=(R_3 P) {x -= P.x; y -= P.y; z -= P.z; return *this;} |
| 153 |
R_3 operator-()const {return R_3(-x,-y,-z);} |
| 154 |
R_3 operator+()const {return *this;} |
| 155 |
R operator,(R_3 P)const {return x*P.x+y*P.y+z*P.z;} // produit scalaire |
| 156 |
R_3 operator^(R_3 P)const {return R_3(y*P.z-z*P.y ,P.x*z-x*P.z, x*P.y-y*P.x);} // produit vectoriel |
| 157 |
R_3 operator*(R c)const {return R_3(x*c,y*c,z*c);} |
| 158 |
R_3 operator*=(R c) {x *= c; y *= c; z *= c; return *this;} |
| 159 |
R_3 operator/(R c)const {return R_3(x/c,y/c,z/c);} |
| 160 |
R_3 operator/=(R c) {x /= c; y /= c; z /= c; return *this;} |
| 161 |
R & operator[](int i) {return (&x)[i];} |
| 162 |
friend R_3 operator*(R c,R_3 P) {return P*c;} |
| 163 |
|
| 164 |
R_3 operator=(gp_Pnt P) {return R_3(P.X(),P.Y(),P.Z());} |
| 165 |
R_3 operator=(gp_Dir P) {return R_3(P.X(),P.Y(),P.Z());} |
| 166 |
|
| 167 |
friend gp_Pnt gp_pnt(R_3 xyz) { return gp_Pnt(xyz.x,xyz.y,xyz.z); } |
| 168 |
//friend gp_Pnt operator=() { return gp_Pnt(x,y,z); } |
| 169 |
friend gp_Dir gp_dir(R_3 xyz) { return gp_Dir(xyz.x,xyz.y,xyz.z); } |
| 170 |
|
| 171 |
bool DansPave( R_3 & xyzMin, R_3 & xyzMax ) |
| 172 |
{ return xyzMin.x<=x && x<=xyzMax.x && |
| 173 |
xyzMin.y<=y && y<=xyzMax.y && |
| 174 |
xyzMin.z<=z && z<=xyzMax.z; } |
| 175 |
}; |
| 176 |
|
| 177 |
//la classe R_4 |
| 178 |
//============ |
| 179 |
class R_4: public R_3 |
| 180 |
{ |
| 181 |
friend std::ostream& operator <<(std::ostream& f, const R_4 & P ) |
| 182 |
{ f << P.x << ' ' << P.y << ' ' << P.z << ' ' << P.omega; return f; } |
| 183 |
friend std::istream& operator >>(std::istream& f, R_4 & P) |
| 184 |
{ f >> P.x >> P.y >> P.z >> P.omega ; return f; } |
| 185 |
|
| 186 |
friend std::ostream& operator <<(std::ostream& f, const R_4 * P ) |
| 187 |
{ f << P->x << ' ' << P->y << ' ' << P->z << ' ' << P->omega; return f; } |
| 188 |
friend std::istream& operator >>(std::istream& f, R_4 * P) |
| 189 |
{ f >> P->x >> P->y >> P->z >> P->omega ; return f; } |
| 190 |
|
| 191 |
public: |
| 192 |
R omega; //la donnee du poids supplementaire |
| 193 |
|
| 194 |
R_4 () :omega(1.0) {} //les constructeurs |
| 195 |
R_4 (R a,R b,R c,R d):R_3(a,b,c),omega(d) {} |
| 196 |
R_4 (R_4 A,R_4 B) :R_3(B.x-A.x,B.y-A.y,B.z-A.z),omega(B.omega-A.omega) {} |
| 197 |
|
| 198 |
R_4 operator+(R_4 P)const {return R_4(x+P.x,y+P.y,z+P.z,omega+P.omega);} |
| 199 |
R_4 operator+=(R_4 P) {x += P.x;y += P.y;z += P.z;omega += P.omega;return *this;} |
| 200 |
R_4 operator-(R_4 P)const {return R_4(x-P.x,y-P.y,z-P.z,omega-P.omega);} |
| 201 |
R_4 operator-=(R_4 P) {x -= P.x;y -= P.y;z -= P.z;omega -= P.omega;return *this;} |
| 202 |
R_4 operator-()const {return R_4(-x,-y,-z,-omega);} |
| 203 |
R_4 operator+()const {return *this;} |
| 204 |
R operator,(R_4 P)const {return x*P.x+y*P.y+z*P.z+omega*P.omega;} // produit scalaire |
| 205 |
R_4 operator*(R c)const {return R_4(x*c,y*c,z*c,omega*c);} |
| 206 |
R_4 operator*=(R c) {x *= c; y *= c; z *= c; omega *= c; return *this;} |
| 207 |
R_4 operator/(R c)const {return R_4(x/c,y/c,z/c,omega/c);} |
| 208 |
R_4 operator/=(R c) {x /= c; y /= c; z /= c; omega /= c; return *this;} |
| 209 |
R & operator[](int i) {return (&x)[i];} |
| 210 |
friend R_4 operator*(R c,R_4 P) {return P*c;} |
| 211 |
}; |
| 212 |
|
| 213 |
//quelques fonctions supplementaires sur ces classes |
| 214 |
//================================================== |
| 215 |
inline R Aire2d(const R_2 A,const R_2 B,const R_2 C){return (B-A)^(C-A);} |
| 216 |
inline R Angle2d(R_2 P){ return atan2(P.y,P.x);} |
| 217 |
|
| 218 |
inline R Norme2_2(const R_2 & A){ return (A,A);} |
| 219 |
inline R Norme2(const R_2 & A){ return sqrt((A,A));} |
| 220 |
inline R NormeInfinie(const R_2 & A){return Max(Abs(A.x),Abs(A.y));} |
| 221 |
|
| 222 |
inline R Norme2_2(const R_3 & A){ return (A,A);} |
| 223 |
inline R Norme2(const R_3 & A){ return sqrt((A,A));} |
| 224 |
inline R NormeInfinie(const R_3 & A){return Max(Abs(A.x),Abs(A.y),Abs(A.z));} |
| 225 |
|
| 226 |
inline R Norme2_2(const R_4 & A){ return (A,A);} |
| 227 |
inline R Norme2(const R_4 & A){ return sqrt((A,A));} |
| 228 |
inline R NormeInfinie(const R_4 & A){return Max(Abs(A.x),Abs(A.y),Abs(A.z),Abs(A.omega));} |
| 229 |
|
| 230 |
inline R_2 XY(R_3 P) {return R_2(P.x, P.y);} //restriction a R_2 d'un R_3 par perte de z |
| 231 |
inline R_3 Min(R_3 P, R_3 Q) |
| 232 |
{return R_3(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 |
| 233 |
inline R_3 Max(R_3 P, R_3 Q) |
| 234 |
{return R_3(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 |
| 235 |
|
| 236 |
#endif |