Salome HOME
updating the main trunk with the CEA debug devellopment from the branch
[modules/med.git] / src / INTERPOLATION / MEDMEM_WrapperNodes.hxx
1
2 #ifndef MEDMEM_WRAPPER_NODES_HXX
3 #define MEDMEM_WRAPPER_NODES_HXX
4
5 #ifndef NULL
6 #define NULL 0
7 #endif
8
9 #include <math.h>
10
11 //////////////////////////////////////////////////////////////////
12 ///                                                            ///
13 ///                        DECLARATIONS                        ///
14 ///                                                            ///
15 //////////////////////////////////////////////////////////////////
16
17 /*********************************************************/
18 /*                                                       */
19 /*                Classe Wrapper_Noeud                   */
20 /*                                                       */
21 /*********************************************************/
22
23 template <int DIMENSION> class Wrapper_Noeud
24 {
25 protected :
26         double * coordonnees;
27 public :
28         Wrapper_Noeud():coordonnees(NULL) 
29                 {
30                 }
31         Wrapper_Noeud(double * coord):coordonnees(coord) 
32                 {
33                 }
34         ~Wrapper_Noeud() 
35                 {
36                 }
37         void positionne(double *place) 
38                 {
39                 coordonnees=place;
40                 }
41         const double & operator[] (int i) const
42                 {
43                 return coordonnees[i];
44                 }
45         double operator[] (int i)
46                 {
47                 return coordonnees[i];
48                 }
49         friend double DistanceInf(const Wrapper_Noeud<DIMENSION> &A,const Wrapper_Noeud<DIMENSION> &B) 
50                 {
51                 double max=0;
52                 double tmp;
53                 for (int i=0;i<DIMENSION;i++)
54                         {
55                         tmp=fabs(A[i]-B[i]);
56                         if (tmp>max) max=tmp;
57                         }
58                 return max;
59                 }
60         friend double DistanceL2(const Wrapper_Noeud<DIMENSION> &A,const Wrapper_Noeud<DIMENSION> &B)  
61                 {
62                 double tmp,somme=0;
63                 for (int i=0;i<DIMENSION;i++)
64                         {
65                         tmp=(A[i]-B[i]);
66                         somme+=tmp*tmp;
67                         }
68                 return sqrt(somme);
69                 }
70         friend int operator==(const Wrapper_Noeud<DIMENSION> &A,const Wrapper_Noeud<DIMENSION> &B)
71                 {
72                 for (int i=0;i<DIMENSION;i++) if (A[i]!=B[i]) return 1;
73                 return 0;
74                 }
75         friend ostream & operator<<(ostream &os,const Wrapper_Noeud<DIMENSION> &A)
76                 {
77                 os<<"( "<<flush;
78                 for (int i=0;i<DIMENSION;i++) os<<A[i]<<" "<<flush;
79                 os<<")"<<flush;
80                 return os;
81                 }
82         };
83
84 /*********************************************************/
85 /*                                                       */
86 /*             Classe Nuage_Wrapper_Noeud                */
87 /*                                                       */
88 /*********************************************************/
89
90         
91 template <int DIMENSION> class Wrapper_Nuage_Noeud
92         {
93         protected : 
94                 int nbr_noeuds;
95                 double * noeuds;
96                 Wrapper_Noeud<DIMENSION> show;
97         public :
98                 Wrapper_Nuage_Noeud():nbr_noeuds(0),noeuds(NULL) {}
99                 Wrapper_Nuage_Noeud(int nn, double *n):nbr_noeuds(nn),noeuds(n),show(noeuds) {}
100                 ~Wrapper_Nuage_Noeud() {}
101                 Wrapper_Noeud<DIMENSION> & operator [] (int i)
102                         {
103                         show.positionne((double *) &noeuds[DIMENSION*i]);
104                         return show;
105                         }
106                 int size() const {return nbr_noeuds;}
107                 int SIZE() const {return nbr_noeuds;}
108                 void affiche()
109                         {
110                         int i,j;
111                         for (i=0;i<nbr_noeuds;i++)
112                                 {
113                                 cout<<"Noeud "<<i<<" : "<<flush;
114                                 for (j=0;j<DIMENSION;j++) cout<<noeuds[i*DIMENSION+j]<<" "<<flush;
115                                 cout<<endl;
116                                 }
117                         }
118         };
119
120
121 #endif