]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_ModulusArray.hxx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MEDMEM / MEDMEM_ModulusArray.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #ifndef __MEDMODULUSARRAY_H__
23 #define __MEDMODULUSARRAY_H__
24
25 #include "MEDMEM.hxx"
26
27 #include "MEDMEM_Utilities.hxx"
28 #include "MEDMEM_define.hxx"
29
30
31 /*
32   This class is use to set cyclic (modulus length) array.
33   (array[length+1]==array[1])
34
35   We use it in particular to compare faces nodes lists to know if
36   they are the same (positive or negative cycle) !
37 */
38
39 namespace MEDMEM {
40 class MEDMEM_EXPORT MEDMODULUSARRAY {
41 private:
42   // nb vertex nodes; only vertex nodes are in cycle
43   int   _length ;
44   // total nb nodes; not vertex nodes exists in 2-nd order elements,
45   // only presence of not vertex nodes is checked by compare()
46   int   _length2;
47   const int * _array ;
48
49   inline bool compareNotVertexNodes(const MEDMODULUSARRAY &modulusArray) const;
50
51 public:
52   MEDMODULUSARRAY(int length, const int * array) :
53     _length(length), _length2(length), _array(array) {}
54
55   MEDMODULUSARRAY(int vertexLength, int totalLength, const int * array):
56     _length(vertexLength), _length2( totalLength ), _array(array) {}
57
58   ~MEDMODULUSARRAY() {}
59
60   inline const int operator[](const int &i) const ;
61
62   inline int compare(const MEDMODULUSARRAY &modulusArray) const;
63
64   const int  *getArray(int& length) const { length=_length; return _array; }
65 };
66
67
68 inline const int MEDMODULUSARRAY::operator[](const int &i) const
69 {
70   int position = i%_length ;
71   //int position = i%_length2 ;
72   if (position < 0)
73     position+=_length ;
74   //position += _length2 ;
75   return _array[position] ;
76 }
77
78 inline int MEDMODULUSARRAY::compare(const MEDMODULUSARRAY &modulusArray) const
79 {
80   int ret = 0 ;
81
82   if (modulusArray._length  != _length ||
83       modulusArray._length2 != _length2 )
84     return ret ;
85
86   if (_length==1)
87     if (_array[0]==modulusArray[0])
88       return 1;
89     else 
90       return 0;
91
92   if (_length==2) {
93     if ((_array[0]==modulusArray[0])&(_array[1]==modulusArray[1]))
94       ret = 1;
95     else if ((_array[0]==modulusArray[1])&(_array[1]==modulusArray[0]))
96       ret = -1;
97     else
98       return 0;
99     if ( !compareNotVertexNodes( modulusArray ) )
100       ret = 0;
101     return ret;
102   }
103
104   //search if there is one start point in common in two array
105   for(int i=0;i<_length;i++)
106     if ( _array[0] == modulusArray[i] ) {
107       // we search if cycle is the same
108       if (_array[1]==modulusArray[i+1]){ // positive order
109         ret=1;
110         for(int j=2;j<_length;j++)
111           if (_array[j]!=modulusArray[i+j]) {
112             ret = 0 ;
113             break ;
114           }
115       } else if(_array[1]==modulusArray[i-1]) { //negative order
116         ret=-1;
117         for(int j=2;j<_length;j++)
118           if (_array[j]!=modulusArray[i-j]) {
119             ret = 0 ;
120             break ;
121           }
122       }
123       if (ret!=0) {// we have found it !
124         if ( !compareNotVertexNodes( modulusArray ) )
125           ret = 0;
126         break ;
127       }
128       // else we continue if there is another start point i
129     }
130     return ret ;
131 }
132
133 /*!
134  * \brief Check presence of the same not vertex nodes
135   * \retval bool - comparison result
136  */
137 inline bool MEDMODULUSARRAY::compareNotVertexNodes(const MEDMODULUSARRAY &modulusArray) const
138 {
139   if ( _length2 > _length ) {
140     for ( int i = _length; i < _length2; ++i ) {
141       bool found = false;
142       for ( int j = _length; ( j < _length2 && !found ); ++j )
143         found = ( _array[ i ] == modulusArray._array[ j ] );
144       if ( !found )
145         return false;
146     }
147   }
148   return true;
149 }
150
151 }
152
153 # endif         /* # ifndef __MEDMODULUSARRAY_H__ */
154