Back to index

salome-med  6.5.0
MEDMEM_ModulusArray.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #ifndef __MEDMODULUSARRAY_H__
00024 #define __MEDMODULUSARRAY_H__
00025 
00026 #include "MEDMEM.hxx"
00027 
00028 #include "MEDMEM_Utilities.hxx"
00029 #include "MEDMEM_define.hxx"
00030 
00031 
00032 /*
00033   This class is use to set cyclic (modulus length) array.
00034   (array[length+1]==array[1])
00035 
00036   We use it in particular to compare faces nodes lists to know if
00037   they are the same (positive or negative cycle) !
00038 */
00039 
00040 namespace MEDMEM {
00041 class MEDMEM_EXPORT MEDMODULUSARRAY {
00042 private:
00043   // nb vertex nodes; only vertex nodes are in cycle
00044   int   _length ;
00045   // total nb nodes; not vertex nodes exists in 2-nd order elements,
00046   // only presence of not vertex nodes is checked by compare()
00047   int   _length2;
00048   const int * _array ;
00049 
00050   inline bool compareNotVertexNodes(const MEDMODULUSARRAY &modulusArray) const;
00051 
00052 public:
00053   MEDMODULUSARRAY(int length, const int * array) :
00054     _length(length), _length2(length), _array(array) {}
00055 
00056   MEDMODULUSARRAY(int vertexLength, int totalLength, const int * array):
00057     _length(vertexLength), _length2( totalLength ), _array(array) {}
00058 
00059   ~MEDMODULUSARRAY() {}
00060 
00061   inline const int operator[](const int &i) const ;
00062 
00063   inline int compare(const MEDMODULUSARRAY &modulusArray) const;
00064 
00065   const int  *getArray(int& length) const { length=_length; return _array; }
00066 };
00067 
00068 
00069 inline const int MEDMODULUSARRAY::operator[](const int &i) const
00070 {
00071   int position = i%_length ;
00072   //int position = i%_length2 ;
00073   if (position < 0)
00074     position+=_length ;
00075   //position += _length2 ;
00076   return _array[position] ;
00077 }
00078 
00079 inline int MEDMODULUSARRAY::compare(const MEDMODULUSARRAY &modulusArray) const
00080 {
00081   int ret = 0 ;
00082 
00083   if (modulusArray._length  != _length ||
00084       modulusArray._length2 != _length2 )
00085     return ret ;
00086 
00087   if (_length==1)
00088     {
00089       if (_array[0]==modulusArray[0])
00090         return 1;
00091       else 
00092         return 0;
00093     }
00094 
00095   if (_length==2) {
00096     if ((_array[0]==modulusArray[0])&(_array[1]==modulusArray[1]))
00097       ret = 1;
00098     else if ((_array[0]==modulusArray[1])&(_array[1]==modulusArray[0]))
00099       ret = -1;
00100     else
00101       return 0;
00102     if ( !compareNotVertexNodes( modulusArray ) )
00103       ret = 0;
00104     return ret;
00105   }
00106 
00107   //search if there is one start point in common in two array
00108   for(int i=0;i<_length;i++)
00109     if ( _array[0] == modulusArray[i] ) {
00110       // we search if cycle is the same
00111       if (_array[1]==modulusArray[i+1]){ // positive order
00112         ret=1;
00113         for(int j=2;j<_length;j++)
00114           if (_array[j]!=modulusArray[i+j]) {
00115             ret = 0 ;
00116             break ;
00117           }
00118       } else if(_array[1]==modulusArray[i-1]) { //negative order
00119         ret=-1;
00120         for(int j=2;j<_length;j++)
00121           if (_array[j]!=modulusArray[i-j]) {
00122             ret = 0 ;
00123             break ;
00124           }
00125       }
00126       if (ret!=0) {// we have found it !
00127         if ( !compareNotVertexNodes( modulusArray ) )
00128           ret = 0;
00129         break ;
00130       }
00131       // else we continue if there is another start point i
00132     }
00133     return ret ;
00134 }
00135 
00140 inline bool MEDMODULUSARRAY::compareNotVertexNodes(const MEDMODULUSARRAY &modulusArray) const
00141 {
00142   if ( _length2 > _length ) {
00143     for ( int i = _length; i < _length2; ++i ) {
00144       bool found = false;
00145       for ( int j = _length; ( j < _length2 && !found ); ++j )
00146         found = ( _array[ i ] == modulusArray._array[ j ] );
00147       if ( !found )
00148         return false;
00149     }
00150   }
00151   return true;
00152 }
00153 
00154 }
00155 
00156 # endif         /* # ifndef __MEDMODULUSARRAY_H__ */
00157