src/INTERPOLATION/MEDMEM_WrapperNodes.hxx

Go to the documentation of this file.
00001 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00002 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00003 // 
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public
00006 // License as published by the Free Software Foundation; either 
00007 // version 2.1 of the License.
00008 // 
00009 // This library is distributed in the hope that it will be useful 
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
00012 // Lesser General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public  
00015 // License along with this library; if not, write to the Free Software 
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00017 //
00018 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00019 //
00020 
00021 #ifndef MEDMEM_WRAPPER_NODES_HXX
00022 #define MEDMEM_WRAPPER_NODES_HXX
00023 
00024 #ifndef NULL
00025 #define NULL 0
00026 #endif
00027 
00028 #include <math.h>
00029 
00035 
00036 /*********************************************************/
00037 /*                                                       */
00038 /*                Classe Wrapper_Noeud                   */
00039 /*                                                       */
00040 /*********************************************************/
00041 
00042 template <int DIMENSION> class Wrapper_Noeud
00043 {
00044 protected :
00045      double * coordonnees;
00046 public :
00047      Wrapper_Noeud():coordonnees(NULL) 
00048           {
00049           }
00050      Wrapper_Noeud(double * coord):coordonnees(coord) 
00051           {
00052           }
00053      ~Wrapper_Noeud() 
00054           {
00055           }
00056      void positionne(double *place) 
00057           {
00058           coordonnees=place;
00059           }
00060      const double & operator[] (int i) const
00061           {
00062           return coordonnees[i];
00063           }
00064      double operator[] (int i)
00065           {
00066           return coordonnees[i];
00067           }
00068      friend double DistanceInf(const Wrapper_Noeud<DIMENSION> &A,const Wrapper_Noeud<DIMENSION> &B) 
00069           {
00070           double max=0;
00071           double tmp;
00072           for (int i=0;i<DIMENSION;i++)
00073                {
00074                tmp=fabs(A[i]-B[i]);
00075                if (tmp>max) max=tmp;
00076                }
00077           return max;
00078           }
00079      friend double DistanceL2(const Wrapper_Noeud<DIMENSION> &A,const Wrapper_Noeud<DIMENSION> &B)  
00080           {
00081           double tmp,somme=0;
00082           for (int i=0;i<DIMENSION;i++)
00083                {
00084                tmp=(A[i]-B[i]);
00085                somme+=tmp*tmp;
00086                }
00087           return sqrt(somme);
00088           }
00089      friend int operator==(const Wrapper_Noeud<DIMENSION> &A,const Wrapper_Noeud<DIMENSION> &B)
00090           {
00091           for (int i=0;i<DIMENSION;i++) if (A[i]!=B[i]) return 1;
00092           return 0;
00093           }
00094      friend ostream & operator<<(ostream &os,const Wrapper_Noeud<DIMENSION> &A)
00095           {
00096           os<<"( "<<flush;
00097           for (int i=0;i<DIMENSION;i++) os<<A[i]<<" "<<flush;
00098           os<<")"<<flush;
00099           return os;
00100           }
00101      };
00102 
00103 /*********************************************************/
00104 /*                                                       */
00105 /*             Classe Nuage_Wrapper_Noeud                */
00106 /*                                                       */
00107 /*********************************************************/
00108 
00109      
00110 template <int DIMENSION> class Wrapper_Nuage_Noeud
00111      {
00112      protected : 
00113           int nbr_noeuds;
00114           double * noeuds;
00115           Wrapper_Noeud<DIMENSION> show;
00116      public :
00117           Wrapper_Nuage_Noeud():nbr_noeuds(0),noeuds(NULL) {}
00118           Wrapper_Nuage_Noeud(int nn, double *n):nbr_noeuds(nn),noeuds(n),show(noeuds) {}
00119           ~Wrapper_Nuage_Noeud() {}
00120           Wrapper_Noeud<DIMENSION> & operator [] (int i)
00121                {
00122                show.positionne((double *) &noeuds[DIMENSION*i]);
00123                return show;
00124                }
00125           int size() const {return nbr_noeuds;}
00126           int SIZE() const {return nbr_noeuds;}
00127           void affiche()
00128                {
00129                int i,j;
00130                for (i=0;i<nbr_noeuds;i++)
00131                     {
00132                     cout<<"Noeud "<<i<<" : "<<flush;
00133                     for (j=0;j<DIMENSION;j++) cout<<noeuds[i*DIMENSION+j]<<" "<<flush;
00134                     cout<<endl;
00135                     }
00136                }
00137      };
00138 
00139 
00140 #endif